##// END OF EJS Templates
Merge pull request #1588 from thomir/gtk3-support...
Thomas Kluyver -
r6473:90967230 merge
parent child Browse files
Show More
@@ -0,0 +1,34 b''
1 # encoding: utf-8
2 """
3 Enable Gtk3 to be used interacive by IPython.
4
5 Authors: Thomi Richards
6 """
7 #-----------------------------------------------------------------------------
8 # Copyright (c) 2012, the IPython Development Team.
9 #
10 # Distributed under the terms of the Modified BSD License.
11 #
12 # The full license is in the file COPYING.txt, distributed with this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 import sys
20 from gi.repository import Gtk, GLib
21
22 #-----------------------------------------------------------------------------
23 # Code
24 #-----------------------------------------------------------------------------
25
26 def _main_quit(*args, **kwargs):
27 Gtk.main_quit()
28 return False
29
30
31 def inputhook_gtk3():
32 GLib.io_add_watch(sys.stdin, GLib.IO_IN, _main_quit)
33 Gtk.main()
34 return 0
@@ -0,0 +1,37 b''
1 #!/usr/bin/env python
2 """Simple Gtk example to manually test event loop integration.
3
4 This is meant to run tests manually in ipython as:
5
6 In [1]: %gui gtk3
7
8 In [2]: %run gui-gtk3.py
9 """
10
11 from gi.repository import Gtk
12
13
14 def hello_world(wigdet, data=None):
15 print("Hello World")
16
17 def delete_event(widget, event, data=None):
18 return False
19
20 def destroy(widget, data=None):
21 Gtk.main_quit()
22
23 window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
24 window.connect("delete_event", delete_event)
25 window.connect("destroy", destroy)
26 button = Gtk.Button("Hello World")
27 button.connect("clicked", hello_world, None)
28
29 window.add(button)
30 button.show()
31 window.show()
32
33 try:
34 from IPython.lib.inputhook import enable_gtk3
35 enable_gtk3()
36 except ImportError:
37 Gtk.main()
@@ -3420,6 +3420,7 b' Defaulting color scheme to \'NoColor\'"""'
3420 %gui wx # enable wxPython event loop integration
3420 %gui wx # enable wxPython event loop integration
3421 %gui qt4|qt # enable PyQt4 event loop integration
3421 %gui qt4|qt # enable PyQt4 event loop integration
3422 %gui gtk # enable PyGTK event loop integration
3422 %gui gtk # enable PyGTK event loop integration
3423 %gui gtk3 # enable Gtk3 event loop integration
3423 %gui tk # enable Tk event loop integration
3424 %gui tk # enable Tk event loop integration
3424 %gui OSX # enable Cocoa event loop integration
3425 %gui OSX # enable Cocoa event loop integration
3425 # (requires %matplotlib 1.1)
3426 # (requires %matplotlib 1.1)
@@ -21,6 +21,7 b' from IPython.lib.inputhook import ('
21 enable_tk, disable_tk,
21 enable_tk, disable_tk,
22 enable_glut, disable_glut,
22 enable_glut, disable_glut,
23 enable_pyglet, disable_pyglet,
23 enable_pyglet, disable_pyglet,
24 enable_gtk3, disable_gtk3,
24 set_inputhook, clear_inputhook,
25 set_inputhook, clear_inputhook,
25 current_gui
26 current_gui
26 )
27 )
@@ -36,6 +36,7 b" GUI_TK = 'tk'"
36 GUI_OSX = 'osx'
36 GUI_OSX = 'osx'
37 GUI_GLUT = 'glut'
37 GUI_GLUT = 'glut'
38 GUI_PYGLET = 'pyglet'
38 GUI_PYGLET = 'pyglet'
39 GUI_GTK3 = 'gtk3'
39 GUI_NONE = 'none' # i.e. disable
40 GUI_NONE = 'none' # i.e. disable
40
41
41 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
@@ -421,6 +422,33 b' class InputHookManager(object):'
421 """
422 """
422 self.clear_inputhook()
423 self.clear_inputhook()
423
424
425 def enable_gtk3(self, app=None):
426 """Enable event loop integration with Gtk3 (gir bindings).
427
428 Parameters
429 ----------
430 app : ignored
431 Ignored, it's only a placeholder to keep the call signature of all
432 gui activation methods consistent, which simplifies the logic of
433 supporting magics.
434
435 Notes
436 -----
437 This methods sets the PyOS_InputHook for Gtk3, which allows
438 the Gtk3 to integrate with terminal based applications like
439 IPython.
440 """
441 from IPython.lib.inputhookgtk3 import inputhook_gtk3
442 self.set_inputhook(inputhook_gtk3)
443 self._current_gui = GUI_GTK
444
445 def disable_gtk3(self):
446 """Disable event loop integration with PyGTK.
447
448 This merely sets PyOS_InputHook to NULL.
449 """
450 self.clear_inputhook()
451
424 def current_gui(self):
452 def current_gui(self):
425 """Return a string indicating the currently active GUI or None."""
453 """Return a string indicating the currently active GUI or None."""
426 return self._current_gui
454 return self._current_gui
@@ -439,6 +467,8 b' enable_glut = inputhook_manager.enable_glut'
439 disable_glut = inputhook_manager.disable_glut
467 disable_glut = inputhook_manager.disable_glut
440 enable_pyglet = inputhook_manager.enable_pyglet
468 enable_pyglet = inputhook_manager.enable_pyglet
441 disable_pyglet = inputhook_manager.disable_pyglet
469 disable_pyglet = inputhook_manager.disable_pyglet
470 enable_gtk3 = inputhook_manager.enable_gtk3
471 disable_gtk3 = inputhook_manager.disable_gtk3
442 clear_inputhook = inputhook_manager.clear_inputhook
472 clear_inputhook = inputhook_manager.clear_inputhook
443 set_inputhook = inputhook_manager.set_inputhook
473 set_inputhook = inputhook_manager.set_inputhook
444 current_gui = inputhook_manager.current_gui
474 current_gui = inputhook_manager.current_gui
@@ -480,6 +510,7 b' def enable_gui(gui=None, app=None):'
480 GUI_QT4: enable_qt4,
510 GUI_QT4: enable_qt4,
481 GUI_GLUT: enable_glut,
511 GUI_GLUT: enable_glut,
482 GUI_PYGLET: enable_pyglet,
512 GUI_PYGLET: enable_pyglet,
513 GUI_GTK3: enable_gtk3,
483 }
514 }
484 try:
515 try:
485 gui_hook = guis[gui]
516 gui_hook = guis[gui]
General Comments 0
You need to be logged in to leave comments. Login now