summaryrefslogtreecommitdiff
path: root/python/helpers/pydev/tests_mainloop
diff options
context:
space:
mode:
Diffstat (limited to 'python/helpers/pydev/tests_mainloop')
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-glut.py80
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-gtk.py49
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-gtk3.py45
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-pyglet.py35
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-qt.py45
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-tk.py44
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-wx.py174
7 files changed, 241 insertions, 231 deletions
diff --git a/python/helpers/pydev/tests_mainloop/gui-glut.py b/python/helpers/pydev/tests_mainloop/gui-glut.py
index f05a4bc0beaf..34a16b454171 100644
--- a/python/helpers/pydev/tests_mainloop/gui-glut.py
+++ b/python/helpers/pydev/tests_mainloop/gui-glut.py
@@ -9,42 +9,44 @@ To run this:
4) run: gl.glClearColor(1,1,1,1)
"""
-#!/usr/bin/env python
-import sys
-import OpenGL.GL as gl
-import OpenGL.GLUT as glut
-
-def close():
- glut.glutDestroyWindow(glut.glutGetWindow())
-
-def display():
- gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
- glut.glutSwapBuffers()
-
-def resize(width,height):
- gl.glViewport(0, 0, width, height+4)
- gl.glMatrixMode(gl.GL_PROJECTION)
- gl.glLoadIdentity()
- gl.glOrtho(0, width, 0, height+4, -1, 1)
- gl.glMatrixMode(gl.GL_MODELVIEW)
-
-if glut.glutGetWindow() > 0:
- interactive = True
- glut.glutInit(sys.argv)
- glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
- glut.GLUT_RGBA |
- glut.GLUT_DEPTH)
-else:
- interactive = False
-
-glut.glutCreateWindow('gui-glut')
-glut.glutDisplayFunc(display)
-glut.glutReshapeFunc(resize)
-# This is necessary on osx to be able to close the window
-# (else the close button is disabled)
-if sys.platform == 'darwin' and not bool(glut.HAVE_FREEGLUT):
- glut.glutWMCloseFunc(close)
-gl.glClearColor(0,0,0,1)
-
-if not interactive:
- glut.glutMainLoop()
+if __name__ == '__main__':
+
+ #!/usr/bin/env python
+ import sys
+ import OpenGL.GL as gl
+ import OpenGL.GLUT as glut
+
+ def close():
+ glut.glutDestroyWindow(glut.glutGetWindow())
+
+ def display():
+ gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
+ glut.glutSwapBuffers()
+
+ def resize(width,height):
+ gl.glViewport(0, 0, width, height+4)
+ gl.glMatrixMode(gl.GL_PROJECTION)
+ gl.glLoadIdentity()
+ gl.glOrtho(0, width, 0, height+4, -1, 1)
+ gl.glMatrixMode(gl.GL_MODELVIEW)
+
+ if glut.glutGetWindow() > 0:
+ interactive = True
+ glut.glutInit(sys.argv)
+ glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
+ glut.GLUT_RGBA |
+ glut.GLUT_DEPTH)
+ else:
+ interactive = False
+
+ glut.glutCreateWindow('gui-glut')
+ glut.glutDisplayFunc(display)
+ glut.glutReshapeFunc(resize)
+ # This is necessary on osx to be able to close the window
+ # (else the close button is disabled)
+ if sys.platform == 'darwin' and not bool(glut.HAVE_FREEGLUT):
+ glut.glutWMCloseFunc(close)
+ gl.glClearColor(0,0,0,1)
+
+ if not interactive:
+ glut.glutMainLoop()
diff --git a/python/helpers/pydev/tests_mainloop/gui-gtk.py b/python/helpers/pydev/tests_mainloop/gui-gtk.py
index 978f8f9a25f3..6df5c782e96a 100644
--- a/python/helpers/pydev/tests_mainloop/gui-gtk.py
+++ b/python/helpers/pydev/tests_mainloop/gui-gtk.py
@@ -8,27 +8,28 @@ To run this:
interactive console
"""
-import pygtk
-pygtk.require('2.0')
-import gtk
-
-
-def hello_world(wigdet, data=None):
- print("Hello World")
-
-def delete_event(widget, event, data=None):
- return False
-
-def destroy(widget, data=None):
- gtk.main_quit()
-
-window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-window.connect("delete_event", delete_event)
-window.connect("destroy", destroy)
-button = gtk.Button("Hello World")
-button.connect("clicked", hello_world, None)
-
-window.add(button)
-button.show()
-window.show()
-
+if __name__ == '__main__':
+ import pygtk
+ pygtk.require('2.0')
+ import gtk
+
+
+ def hello_world(wigdet, data=None):
+ print("Hello World")
+
+ def delete_event(widget, event, data=None):
+ return False
+
+ def destroy(widget, data=None):
+ gtk.main_quit()
+
+ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ window.connect("delete_event", delete_event)
+ window.connect("destroy", destroy)
+ button = gtk.Button("Hello World")
+ button.connect("clicked", hello_world, None)
+
+ window.add(button)
+ button.show()
+ window.show()
+
diff --git a/python/helpers/pydev/tests_mainloop/gui-gtk3.py b/python/helpers/pydev/tests_mainloop/gui-gtk3.py
index a787f7ee9e65..6351d5235ded 100644
--- a/python/helpers/pydev/tests_mainloop/gui-gtk3.py
+++ b/python/helpers/pydev/tests_mainloop/gui-gtk3.py
@@ -8,25 +8,26 @@ To run this:
interactive console
"""
-from gi.repository import Gtk
-
-
-def hello_world(wigdet, data=None):
- print("Hello World")
-
-def delete_event(widget, event, data=None):
- return False
-
-def destroy(widget, data=None):
- Gtk.main_quit()
-
-window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
-window.connect("delete_event", delete_event)
-window.connect("destroy", destroy)
-button = Gtk.Button("Hello World")
-button.connect("clicked", hello_world, None)
-
-window.add(button)
-button.show()
-window.show()
-
+if __name__ == '__main__':
+ from gi.repository import Gtk
+
+
+ def hello_world(wigdet, data=None):
+ print("Hello World")
+
+ def delete_event(widget, event, data=None):
+ return False
+
+ def destroy(widget, data=None):
+ Gtk.main_quit()
+
+ window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
+ window.connect("delete_event", delete_event)
+ window.connect("destroy", destroy)
+ button = Gtk.Button("Hello World")
+ button.connect("clicked", hello_world, None)
+
+ window.add(button)
+ button.show()
+ window.show()
+
diff --git a/python/helpers/pydev/tests_mainloop/gui-pyglet.py b/python/helpers/pydev/tests_mainloop/gui-pyglet.py
index b646093e0967..70f1a7f64724 100644
--- a/python/helpers/pydev/tests_mainloop/gui-pyglet.py
+++ b/python/helpers/pydev/tests_mainloop/gui-pyglet.py
@@ -8,20 +8,21 @@ To run this:
interactive console
"""
-import pyglet
-
-
-window = pyglet.window.Window()
-label = pyglet.text.Label('Hello, world',
- font_name='Times New Roman',
- font_size=36,
- x=window.width//2, y=window.height//2,
- anchor_x='center', anchor_y='center')
-@window.event
-def on_close():
- window.close()
-
-@window.event
-def on_draw():
- window.clear()
- label.draw()
+if __name__ == '__main__':
+ import pyglet
+
+
+ window = pyglet.window.Window()
+ label = pyglet.text.Label('Hello, world',
+ font_name='Times New Roman',
+ font_size=36,
+ x=window.width//2, y=window.height//2,
+ anchor_x='center', anchor_y='center')
+ @window.event
+ def on_close():
+ window.close()
+
+ @window.event
+ def on_draw():
+ window.clear()
+ label.draw()
diff --git a/python/helpers/pydev/tests_mainloop/gui-qt.py b/python/helpers/pydev/tests_mainloop/gui-qt.py
index c27cbd6ff1e6..30fc48d3845a 100644
--- a/python/helpers/pydev/tests_mainloop/gui-qt.py
+++ b/python/helpers/pydev/tests_mainloop/gui-qt.py
@@ -10,26 +10,27 @@ To run this:
Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/
"""
-import sys
-from PyQt4 import QtGui, QtCore
-
-class SimpleWindow(QtGui.QWidget):
- def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
-
- self.setGeometry(300, 300, 200, 80)
- self.setWindowTitle('Hello World')
-
- quit = QtGui.QPushButton('Close', self)
- quit.setGeometry(10, 10, 60, 35)
-
- self.connect(quit, QtCore.SIGNAL('clicked()'),
- self, QtCore.SLOT('close()'))
-
if __name__ == '__main__':
- app = QtCore.QCoreApplication.instance()
- if app is None:
- app = QtGui.QApplication([])
-
- sw = SimpleWindow()
- sw.show()
+ import sys
+ from PyQt4 import QtGui, QtCore
+
+ class SimpleWindow(QtGui.QWidget):
+ def __init__(self, parent=None):
+ QtGui.QWidget.__init__(self, parent)
+
+ self.setGeometry(300, 300, 200, 80)
+ self.setWindowTitle('Hello World')
+
+ quit = QtGui.QPushButton('Close', self)
+ quit.setGeometry(10, 10, 60, 35)
+
+ self.connect(quit, QtCore.SIGNAL('clicked()'),
+ self, QtCore.SLOT('close()'))
+
+ if __name__ == '__main__':
+ app = QtCore.QCoreApplication.instance()
+ if app is None:
+ app = QtGui.QApplication([])
+
+ sw = SimpleWindow()
+ sw.show()
diff --git a/python/helpers/pydev/tests_mainloop/gui-tk.py b/python/helpers/pydev/tests_mainloop/gui-tk.py
index 69ceb0b9f053..4cef45f91a4a 100644
--- a/python/helpers/pydev/tests_mainloop/gui-tk.py
+++ b/python/helpers/pydev/tests_mainloop/gui-tk.py
@@ -8,24 +8,26 @@ To run this:
interactive console
"""
-try:
- from Tkinter import *
-except:
- # Python 3
- from tkinter import *
-
-class MyApp:
-
- def __init__(self, root):
- frame = Frame(root)
- frame.pack()
-
- self.button = Button(frame, text="Hello", command=self.hello_world)
- self.button.pack(side=LEFT)
-
- def hello_world(self):
- print("Hello World!")
-
-root = Tk()
-
-app = MyApp(root)
+if __name__ == '__main__':
+
+ try:
+ from Tkinter import *
+ except:
+ # Python 3
+ from tkinter import *
+
+ class MyApp:
+
+ def __init__(self, root):
+ frame = Frame(root)
+ frame.pack()
+
+ self.button = Button(frame, text="Hello", command=self.hello_world)
+ self.button.pack(side=LEFT)
+
+ def hello_world(self):
+ print("Hello World!")
+
+ root = Tk()
+
+ app = MyApp(root)
diff --git a/python/helpers/pydev/tests_mainloop/gui-wx.py b/python/helpers/pydev/tests_mainloop/gui-wx.py
index 2101e7f214d4..b9c28bfc63ab 100644
--- a/python/helpers/pydev/tests_mainloop/gui-wx.py
+++ b/python/helpers/pydev/tests_mainloop/gui-wx.py
@@ -11,91 +11,93 @@ To run this:
Ref: Modified from wxPython source code wxPython/samples/simple/simple.py
"""
-import wx
-
-
-class MyFrame(wx.Frame):
- """
- This is MyFrame. It just shows a few controls on a wxPanel,
- and has a simple menu.
- """
- def __init__(self, parent, title):
- wx.Frame.__init__(self, parent, -1, title,
- pos=(150, 150), size=(350, 200))
-
- # Create the menubar
- menuBar = wx.MenuBar()
-
- # and a menu
- menu = wx.Menu()
-
- # add an item to the menu, using \tKeyName automatically
- # creates an accelerator, the third param is some help text
- # that will show up in the statusbar
- menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
-
- # bind the menu event to an event handler
- self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
-
- # and put the menu on the menubar
- menuBar.Append(menu, "&File")
- self.SetMenuBar(menuBar)
-
- self.CreateStatusBar()
-
- # Now create the Panel to put the other controls on.
- panel = wx.Panel(self)
-
- # and a few controls
- text = wx.StaticText(panel, -1, "Hello World!")
- text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
- text.SetSize(text.GetBestSize())
- btn = wx.Button(panel, -1, "Close")
- funbtn = wx.Button(panel, -1, "Just for fun...")
-
- # bind the button events to handlers
- self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
- self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
-
- # Use a sizer to layout the controls, stacked vertically and with
- # a 10 pixel border around each
- sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(text, 0, wx.ALL, 10)
- sizer.Add(btn, 0, wx.ALL, 10)
- sizer.Add(funbtn, 0, wx.ALL, 10)
- panel.SetSizer(sizer)
- panel.Layout()
-
-
- def OnTimeToClose(self, evt):
- """Event handler for the button click."""
- print("See ya later!")
- self.Close()
-
- def OnFunButton(self, evt):
- """Event handler for the button click."""
- print("Having fun yet?")
-
-
-class MyApp(wx.App):
- def OnInit(self):
- frame = MyFrame(None, "Simple wxPython App")
- self.SetTopWindow(frame)
-
- print("Print statements go to this stdout window by default.")
-
- frame.Show(True)
- return True
-
-
if __name__ == '__main__':
- app = wx.GetApp()
- if app is None:
- app = MyApp(redirect=False, clearSigInt=False)
- else:
- frame = MyFrame(None, "Simple wxPython App")
- app.SetTopWindow(frame)
- print("Print statements go to this stdout window by default.")
- frame.Show(True)
-
+ import wx
+
+
+ class MyFrame(wx.Frame):
+ """
+ This is MyFrame. It just shows a few controls on a wxPanel,
+ and has a simple menu.
+ """
+ def __init__(self, parent, title):
+ wx.Frame.__init__(self, parent, -1, title,
+ pos=(150, 150), size=(350, 200))
+
+ # Create the menubar
+ menuBar = wx.MenuBar()
+
+ # and a menu
+ menu = wx.Menu()
+
+ # add an item to the menu, using \tKeyName automatically
+ # creates an accelerator, the third param is some help text
+ # that will show up in the statusbar
+ menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
+
+ # bind the menu event to an event handler
+ self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
+
+ # and put the menu on the menubar
+ menuBar.Append(menu, "&File")
+ self.SetMenuBar(menuBar)
+
+ self.CreateStatusBar()
+
+ # Now create the Panel to put the other controls on.
+ panel = wx.Panel(self)
+
+ # and a few controls
+ text = wx.StaticText(panel, -1, "Hello World!")
+ text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
+ text.SetSize(text.GetBestSize())
+ btn = wx.Button(panel, -1, "Close")
+ funbtn = wx.Button(panel, -1, "Just for fun...")
+
+ # bind the button events to handlers
+ self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
+ self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
+
+ # Use a sizer to layout the controls, stacked vertically and with
+ # a 10 pixel border around each
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(text, 0, wx.ALL, 10)
+ sizer.Add(btn, 0, wx.ALL, 10)
+ sizer.Add(funbtn, 0, wx.ALL, 10)
+ panel.SetSizer(sizer)
+ panel.Layout()
+
+
+ def OnTimeToClose(self, evt):
+ """Event handler for the button click."""
+ print("See ya later!")
+ self.Close()
+
+ def OnFunButton(self, evt):
+ """Event handler for the button click."""
+ print("Having fun yet?")
+
+
+ class MyApp(wx.App):
+ def OnInit(self):
+ frame = MyFrame(None, "Simple wxPython App")
+ self.SetTopWindow(frame)
+
+ print("Print statements go to this stdout window by default.")
+
+ frame.Show(True)
+ return True
+
+
+ if __name__ == '__main__':
+
+ app = wx.GetApp()
+ if app is None:
+ app = MyApp(redirect=False, clearSigInt=False)
+ else:
+ frame = MyFrame(None, "Simple wxPython App")
+ app.SetTopWindow(frame)
+ print("Print statements go to this stdout window by default.")
+ frame.Show(True)
+