forked from ipython/ipython
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ipython#1588 from thomir/gtk3-support
Add Gtk3 event loop integration and example.
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# encoding: utf-8 | ||
""" | ||
Enable Gtk3 to be used interacive by IPython. | ||
Authors: Thomi Richards | ||
""" | ||
#----------------------------------------------------------------------------- | ||
# Copyright (c) 2012, the IPython Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
#----------------------------------------------------------------------------- | ||
|
||
#----------------------------------------------------------------------------- | ||
# Imports | ||
#----------------------------------------------------------------------------- | ||
|
||
import sys | ||
from gi.repository import Gtk, GLib | ||
|
||
#----------------------------------------------------------------------------- | ||
# Code | ||
#----------------------------------------------------------------------------- | ||
|
||
def _main_quit(*args, **kwargs): | ||
Gtk.main_quit() | ||
return False | ||
|
||
|
||
def inputhook_gtk3(): | ||
GLib.io_add_watch(sys.stdin, GLib.IO_IN, _main_quit) | ||
Gtk.main() | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
"""Simple Gtk example to manually test event loop integration. | ||
This is meant to run tests manually in ipython as: | ||
In [1]: %gui gtk3 | ||
In [2]: %run gui-gtk3.py | ||
""" | ||
|
||
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() | ||
|
||
try: | ||
from IPython.lib.inputhook import enable_gtk3 | ||
enable_gtk3() | ||
except ImportError: | ||
Gtk.main() |