Created
November 15, 2011 12:38
-
-
Save shellexy/1366990 to your computer and use it in GitHub Desktop.
提供 PyGtk3 的交互 shell
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# -*- Mode: python; c-basic-offset: 4 -*- | |
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: | |
'''Interactive Python Gir (Gtk3) Console | |
@author: Jiahua Huang <[email protected]> | |
@license: LGPLv3+ | |
''' | |
from gi.repository import Gtk, GLib, GObject | |
GLib.set_application_name('PyGirConsole') | |
def interact(): | |
import sys | |
sys.path.insert(0, '.') | |
import thread | |
import Queue | |
from code import InteractiveConsole | |
try: | |
import readline | |
import rlcompleter | |
readline.parse_and_bind('tab: complete') | |
readline.add_history('from gi.repository import Gtk, GLib, GObject') | |
except ImportError: | |
pass | |
class Console(InteractiveConsole): | |
q = Queue.Queue() | |
def _runcode(self, code): | |
InteractiveConsole.runcode(self, code) | |
self.q.put(1) | |
pass | |
def runcode(self, code): | |
GLib.idle_add(self._runcode, code) | |
self.q.get() | |
pass | |
pass | |
console = Console(globals()) | |
python_version = sys.version.split()[0] | |
gtk_version = '%s.%s.%s' % (Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version()) | |
banner = """Python %s, Gtk+ %s\nInteractive console to manipulate GTK+ widgets.""" % (python_version, gtk_version) | |
GObject.threads_init() | |
thread.start_new_thread(Gtk.main, ()) | |
console.interact(banner) | |
pass | |
if __name__ == '__main__': | |
interact() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
刚开始学pygtk3