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/README4
-rw-r--r--python/helpers/pydev/tests_mainloop/__not_in_default_pythonpath.txt1
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-glut.py50
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-gtk.py34
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-gtk3.py32
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-pyglet.py27
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-qt.py35
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-tk.py31
-rw-r--r--python/helpers/pydev/tests_mainloop/gui-wx.py101
9 files changed, 315 insertions, 0 deletions
diff --git a/python/helpers/pydev/tests_mainloop/README b/python/helpers/pydev/tests_mainloop/README
new file mode 100644
index 000000000000..65e699b98e55
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/README
@@ -0,0 +1,4 @@
+# Parts of IPython, files from: https://github.com/ipython/ipython/tree/rel-1.0.0/examples/lib
+# The files in this folder are manual tests for main loop integration
+
+# These tests have been modified to work in the PyDev Console context
diff --git a/python/helpers/pydev/tests_mainloop/__not_in_default_pythonpath.txt b/python/helpers/pydev/tests_mainloop/__not_in_default_pythonpath.txt
new file mode 100644
index 000000000000..29cdc5bc1078
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/__not_in_default_pythonpath.txt
@@ -0,0 +1 @@
+(no __init__.py file) \ No newline at end of file
diff --git a/python/helpers/pydev/tests_mainloop/gui-glut.py b/python/helpers/pydev/tests_mainloop/gui-glut.py
new file mode 100644
index 000000000000..f05a4bc0beaf
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-glut.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+"""Simple GLUT example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for glut
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ interactive console
+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()
diff --git a/python/helpers/pydev/tests_mainloop/gui-gtk.py b/python/helpers/pydev/tests_mainloop/gui-gtk.py
new file mode 100644
index 000000000000..978f8f9a25f3
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-gtk.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+"""Simple GTK example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for gtk
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ 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()
+
diff --git a/python/helpers/pydev/tests_mainloop/gui-gtk3.py b/python/helpers/pydev/tests_mainloop/gui-gtk3.py
new file mode 100644
index 000000000000..a787f7ee9e65
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-gtk3.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+"""Simple Gtk example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for gtk3
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ 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()
+
diff --git a/python/helpers/pydev/tests_mainloop/gui-pyglet.py b/python/helpers/pydev/tests_mainloop/gui-pyglet.py
new file mode 100644
index 000000000000..b646093e0967
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-pyglet.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+"""Simple pyglet example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for pyglet
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ 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()
diff --git a/python/helpers/pydev/tests_mainloop/gui-qt.py b/python/helpers/pydev/tests_mainloop/gui-qt.py
new file mode 100644
index 000000000000..c27cbd6ff1e6
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-qt.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+"""Simple Qt4 example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for qt
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ interactive console
+
+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()
diff --git a/python/helpers/pydev/tests_mainloop/gui-tk.py b/python/helpers/pydev/tests_mainloop/gui-tk.py
new file mode 100644
index 000000000000..69ceb0b9f053
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-tk.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+"""Simple Tk example to manually test event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for tk
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ 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)
diff --git a/python/helpers/pydev/tests_mainloop/gui-wx.py b/python/helpers/pydev/tests_mainloop/gui-wx.py
new file mode 100644
index 000000000000..2101e7f214d4
--- /dev/null
+++ b/python/helpers/pydev/tests_mainloop/gui-wx.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+"""
+A Simple wx example to test PyDev's event loop integration.
+
+To run this:
+1) Enable the PyDev GUI event loop integration for wx
+2) do an execfile on this script
+3) ensure you have a working GUI simultaneously with an
+ interactive console
+
+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)
+