? pyconsole.patch ? data/gedit-2.12.pc ? plugins/python_run Index: plugins/pythonconsole/pythonconsole.py =================================================================== RCS file: /cvs/gnome/gedit/plugins/pythonconsole/Attic/pythonconsole.py,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 pythonconsole.py --- plugins/pythonconsole/pythonconsole.py 29 Sep 2005 20:45:18 -0000 1.1.2.2 +++ plugins/pythonconsole/pythonconsole.py 2 Nov 2005 13:22:34 -0000 @@ -1,4 +1,6 @@ import gedit +import sys +import os class ConsolePlugin(gedit.Plugin): @@ -8,6 +10,7 @@ class ConsolePlugin(gedit.Plugin): def activate(self, window): # Build the console widget cons = init_console(window) + bottom = window.get_bottom_panel() image = gtk.Image() @@ -27,7 +30,14 @@ class ConsolePlugin(gedit.Plugin): bottom.remove_item(cons) def update_ui(self, window): - pass + doc = window.get_active_document() + if not doc is None: + doc_type = doc.get_mime_type() + cons = window._pythonconsole_window_data + if doc_type == 'text/x-python': + cons.run_button.set_sensitive(True) + else: + cons.run_button.set_sensitive(False) def init_console(window, quit_cb=None): console = Console(namespace={'__builtins__' : __builtins__, 'window' : window}, quit_cb=quit_cb) @@ -36,8 +46,10 @@ def init_console(window, quit_cb=None): console.eval() console.line.set_text("print 'You can use the window name:', window") console.eval() + return console - + + ## Begin shameless code stealing from ephy's console.py extension ## Code is taken as-is and can thus be updated at will by copy/pasting ## File: epiphany-extensions/extensions/python-console/console.py @@ -134,8 +146,9 @@ class gtkoutfile: class Console(gtk.VBox): def __init__(self, namespace={}, quit_cb=None): - gtk.VBox.__init__(self, spacing=12) - self.set_border_width(12) + gtk.VBox.__init__(self, spacing=1) + self.set_border_width(1) + self.gedit_win = namespace['window'] self.quit_cb = quit_cb @@ -166,6 +179,10 @@ class Console(gtk.VBox): self.inputbox = gtk.HBox(spacing=2) self.pack_end(self.inputbox, expand=False) self.inputbox.show() + self.run_button = gtk.Button("Run Script") + self.run_button.connect('clicked', self.run_script) + self.inputbox.pack_start(self.run_button, False, False) + self.run_button.show() self.prompt = gtk.Label(sys.ps1) self.prompt.set_padding(2, 0) @@ -325,3 +342,8 @@ class Console(gtk.VBox): #adj.set_value(adj.upper - adj.page_size) sys.stdout, self.stdout = self.stdout, sys.stdout sys.stderr, self.stderr = self.stderr, sys.stderr + + def run_script(self, button=None): + s,e = self.gedit_win.get_active_document().get_bounds() + code = self.gedit_win.get_active_document().get_text(s, e) + self.run(code)