Skip to content

Instantly share code, notes, and snippets.

@shellexy
Created November 15, 2011 12:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shellexy/1366990 to your computer and use it in GitHub Desktop.
Save shellexy/1366990 to your computer and use it in GitHub Desktop.
提供 PyGtk3 的交互 shell
#!/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 <jhuangjiahua@gmail.com>
@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()
@kevinzhow
Copy link

刚开始学pygtk3

@shellexy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment