[gedit] Port pythonconsole to libpeas and gsettings.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Port pythonconsole to libpeas and gsettings.
- Date: Thu, 1 Jul 2010 16:02:55 +0000 (UTC)
commit 4dcd8d84b1a6b11c5254416d9b5ed7af8105f538
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Jul 1 17:47:07 2010 +0200
Port pythonconsole to libpeas and gsettings.
configure.ac | 7 +-
plugins/Makefile.am | 4 +-
plugins/pythonconsole/pythonconsole/Makefile.am | 15 +-
plugins/pythonconsole/pythonconsole/__init__.py | 58 ++---
plugins/pythonconsole/pythonconsole/config.py | 91 ++-----
plugins/pythonconsole/pythonconsole/console.py | 301 +++++++++----------
...org.gnome.gedit.pythonconsole.gschema.xml.in.in | 22 ++
7 files changed, 229 insertions(+), 269 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ddb2476..b1411af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,8 @@ PKG_PROG_PKG_CONFIG
# needed on osx
AC_PROG_OBJC
+AM_PATH_PYTHON
+
# Initialize libtool
LT_PREREQ([2.2.6])
LT_INIT(disable-static)
@@ -410,6 +412,9 @@ plugins/docinfo/Makefile
plugins/filebrowser/org.gnome.gedit.file-browser.gschema.xml.in
plugins/filebrowser/Makefile
plugins/modelines/Makefile
+plugins/pythonconsole/Makefile
+plugins/pythonconsole/pythonconsole/Makefile
+plugins/pythonconsole/pythonconsole/org.gnome.gedit.pythonconsole.gschema.xml.in
plugins/sort/Makefile
plugins/spell/Makefile
plugins/taglist/Makefile
@@ -426,8 +431,6 @@ osx/Makefile])
#plugins/externaltools/Makefile
#plugins/externaltools/scripts/Makefile
#plugins/externaltools/tools/Makefile
-#plugins/pythonconsole/Makefile
-#plugins/pythonconsole/pythonconsole/Makefile
#plugins/quickopen/Makefile
#plugins/quickopen/quickopen/Makefile
#plugins/snippets/data/lang/Makefile
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 1f66c78..760bf6a 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -4,13 +4,13 @@ DIST_SUBDIRS = \
docinfo \
filebrowser \
modelines \
+ pythonconsole \
sort \
spell \
taglist \
time
# externaltools
-# pythonconsole
# quickopen
# snippets
@@ -19,11 +19,11 @@ SUBDIRS = \
docinfo \
filebrowser \
modelines \
+ pythonconsole \
sort \
taglist \
time
-# pythonconsole
# quickopen
# snippets
diff --git a/plugins/pythonconsole/pythonconsole/Makefile.am b/plugins/pythonconsole/pythonconsole/Makefile.am
index 7aa91fe..9270e61 100644
--- a/plugins/pythonconsole/pythonconsole/Makefile.am
+++ b/plugins/pythonconsole/pythonconsole/Makefile.am
@@ -9,9 +9,18 @@ plugin_PYTHON = \
uidir = $(GEDIT_PLUGINS_DATA_DIR)/pythonconsole/ui
ui_DATA = config.ui
-EXTRA_DIST = $(ui_DATA)
+gsettings_SCHEMAS = org.gnome.gedit.pythonconsole.gschema.xml
-CLEANFILES =
-DISTCLEANFILES =
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
+EXTRA_DIST = \
+ $(ui_DATA) \
+ org.gnome.gedit.plugins.pythonconsole.gschema.xml.in.in
+
+CLEANFILES = $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(gsettings_SCHEMAS)
+
+MAINTAINERCLEANFILES = $(gsettings_SCHEMAS:.xml=.valid)
-include $(top_srcdir)/git.mk
diff --git a/plugins/pythonconsole/pythonconsole/__init__.py b/plugins/pythonconsole/pythonconsole/__init__.py
index 9fa3b1d..4c31c84 100644
--- a/plugins/pythonconsole/pythonconsole/__init__.py
+++ b/plugins/pythonconsole/pythonconsole/__init__.py
@@ -24,56 +24,46 @@
# Bits from gedit Python Console Plugin
# Copyrignt (C), 2005 Raphaël Slinckx
-import gtk
-import gedit
+from gi.repository import GObject, Gtk, Gedit, Peas, PeasUI
from console import PythonConsole
from config import PythonConsoleConfigDialog
-from config import PythonConsoleConfig
PYTHON_ICON = 'gnome-mime-text-x-python'
-class PythonConsolePlugin(gedit.Plugin):
+class PythonConsolePlugin(GObject.Object, Gedit.WindowActivatable, PeasUI.Configurable):
+ __gtype_name__ = "PythonConsolePlugin"
+
def __init__(self):
- gedit.Plugin.__init__(self)
- self.dlg = None
+ GObject.Object.__init__(self)
+ self._dlg = None
- def activate(self, window):
- console = PythonConsole(namespace = {'__builtins__' : __builtins__,
- 'gedit' : gedit,
- 'window' : window})
- console.eval('print "You can access the main window through ' \
- '\'window\' :\\n%s" % window', False)
+ def do_activate(self, window):
+ self._console = PythonConsole(namespace = {'__builtins__' : __builtins__,
+ 'gedit' : Gedit,
+ 'window' : window})
+ self._console.eval('print "You can access the main window through ' \
+ '\'window\' :\\n%s" % window', False)
bottom = window.get_bottom_panel()
- image = gtk.Image()
- image.set_from_icon_name(PYTHON_ICON, gtk.ICON_SIZE_MENU)
- bottom.add_item(console, "GeditPythonConsolePanel",
+ image = Gtk.Image()
+ image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU)
+ bottom.add_item(self._console, "GeditPythonConsolePanel",
_('Python Console'), image)
- window.set_data('PythonConsolePluginInfo', console)
def deactivate(self, window):
- console = window.get_data("PythonConsolePluginInfo")
- console.stop()
- window.set_data("PythonConsolePluginInfo", None)
+ self._console.stop()
bottom = window.get_bottom_panel()
- bottom.remove_item(console)
-
-def create_configure_dialog(self):
+ bottom.remove_item(self._console)
- if not self.dlg:
- self.dlg = PythonConsoleConfigDialog(self.get_data_dir())
+ def do_create_configure_dialog(self):
+ if not self._dlg:
+ self._dlg = PythonConsoleConfigDialog(self.plugin_info.get_data_dir())
- dialog = self.dlg.dialog()
- window = gedit.app_get_default().get_active_window()
- if window:
- dialog.set_transient_for(window)
+ dialog = self._dlg.dialog()
- return dialog
+ app = Gedit.App.get_default()
+ dialog.set_transient_for(app.get_active_window())
-# Here we dynamically insert create_configure_dialog based on if configuration
-# is enabled. This has to be done like this because gedit checks if a plugin
-# is configurable solely on the fact that it has this member defined or not
-if PythonConsoleConfig.enabled():
- PythonConsolePlugin.create_configure_dialog = create_configure_dialog
+ return dialog
# ex:et:ts=4:
diff --git a/plugins/pythonconsole/pythonconsole/config.py b/plugins/pythonconsole/pythonconsole/config.py
index 2afed36..117916b 100644
--- a/plugins/pythonconsole/pythonconsole/config.py
+++ b/plugins/pythonconsole/pythonconsole/config.py
@@ -25,97 +25,46 @@
# Copyrignt (C), 2005 Raphaël Slinckx
import os
-import gtk
+from gi.repository import Gio, Gtk, Gdk
-__all__ = ('PythonConsoleConfig', 'PythonConsoleConfigDialog')
-
-GCONF_KEY_BASE = '/apps/gedit-2/plugins/pythonconsole'
-GCONF_KEY_COMMAND_COLOR = GCONF_KEY_BASE + '/command-color'
-GCONF_KEY_ERROR_COLOR = GCONF_KEY_BASE + '/error-color'
-
-DEFAULT_COMMAND_COLOR = '#314e6c' # Blue Shadow
-DEFAULT_ERROR_COLOR = '#990000' # Accent Red Dark
-
-class PythonConsoleConfig(object):
- try:
- import gconf
- except ImportError:
- gconf = None
-
- def __init__(self):
- pass
-
- @staticmethod
- def enabled():
- return PythonConsoleConfig.gconf != None
-
- @staticmethod
- def add_handler(handler):
- if PythonConsoleConfig.gconf:
- PythonConsoleConfig.gconf.client_get_default().notify_add(GCONF_KEY_BASE, handler)
-
- color_command = property(
- lambda self: self.gconf_get_str(GCONF_KEY_COMMAND_COLOR, DEFAULT_COMMAND_COLOR),
- lambda self, value: self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value))
-
- color_error = property(
- lambda self: self.gconf_get_str(GCONF_KEY_ERROR_COLOR, DEFAULT_ERROR_COLOR),
- lambda self, value: self.gconf_set_str(GCONF_KEY_ERROR_COLOR, value))
-
- @staticmethod
- def gconf_get_str(key, default=''):
- if not PythonConsoleConfig.gconf:
- return default
-
- val = PythonConsoleConfig.gconf.client_get_default().get(key)
- if val is not None and val.type == gconf.VALUE_STRING:
- return val.get_string()
- else:
- return default
-
- @staticmethod
- def gconf_set_str(key, value):
- if not PythonConsoleConfig.gconf:
- return
-
- v = PythonConsoleConfig.gconf.Value(gconf.VALUE_STRING)
- v.set_string(value)
- PythonConsoleConfig.gconf.client_get_default().set(key, v)
+__all__ = ('PythonConsoleConfigDialog')
class PythonConsoleConfigDialog(object):
+ CONSOLE_KEY_BASE = 'org.gnome.gedit.plugins.pythonconsole'
+ CONSOLE_KEY_COMMAND_COLOR = 'command-color'
+ CONSOLE_KEY_ERROR_COLOR = 'error-color'
+
def __init__(self, datadir):
object.__init__(self)
self._dialog = None
self._ui_path = os.path.join(datadir, 'ui', 'config.ui')
- self.config = PythonConsoleConfig()
+ self._settings = Gio.Settings.new(self.CONSOLE_KEY_BASE)
def dialog(self):
if self._dialog is None:
- self._ui = gtk.Builder()
+ self._ui = Gtk.Builder()
self._ui.add_from_file(self._ui_path)
self.set_colorbutton_color(self._ui.get_object('colorbutton-command'),
- self.config.color_command)
+ self._settings.get_string(self.CONSOLE_KEY_COMMAND_COLOR))
self.set_colorbutton_color(self._ui.get_object('colorbutton-error'),
- self.config.color_error)
-
+ self._settings.get_string(self.CONSOLE_KEY_ERROR_COLOR))
+
self._ui.connect_signals(self)
-
+
self._dialog = self._ui.get_object('dialog-config')
self._dialog.show_all()
else:
self._dialog.present()
-
+
return self._dialog
-
+
@staticmethod
def set_colorbutton_color(colorbutton, value):
- try:
- color = gtk.gdk.color_parse(value)
- except ValueError:
- pass # Default color in config.ui used
- else:
+ parsed, color = Gdk.color_parse(value)
+
+ if parsed:
colorbutton.set_color(color)
def on_dialog_config_response(self, dialog, response_id):
@@ -126,9 +75,11 @@ class PythonConsoleConfigDialog(object):
self._ui = None
def on_colorbutton_command_color_set(self, colorbutton):
- self.config.color_command = colorbutton.get_color().to_string()
+ self._settings.set_string(self.CONSOLE_KEY_COMMAND_COLOR,
+ colorbutton.get_color().to_string())
def on_colorbutton_error_color_set(self, colorbutton):
- self.config.color_error = colorbutton.get_color().to_string()
+ self._settings.set_string(self.CONSOLE_KEY_ERROR_COLOR,
+ colorbutton.get_color().to_string())
# ex:et:ts=4:
diff --git a/plugins/pythonconsole/pythonconsole/console.py b/plugins/pythonconsole/pythonconsole/console.py
index b1bdd13..8907915 100755
--- a/plugins/pythonconsole/pythonconsole/console.py
+++ b/plugins/pythonconsole/pythonconsole/console.py
@@ -28,16 +28,12 @@ import string
import sys
import re
import traceback
-import gobject
-import gtk
-import pango
-import gconf
-from config import PythonConsoleConfig
+from gi.repository import GObject, Gio, Gtk, Gdk, Pango
__all__ = ('PythonConsole', 'OutFile')
-class PythonConsole(gtk.ScrolledWindow):
+class PythonConsole(Gtk.ScrolledWindow):
__gsignals__ = {
'grab-focus' : 'override',
@@ -45,38 +41,41 @@ class PythonConsole(gtk.ScrolledWindow):
DEFAULT_FONT = "Monospace 10"
- GCONF_INTERFACE_DIR = "/desktop/gnome/interface"
- GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
+ CONSOLE_KEY_BASE = 'org.gnome.gedit.plugins.pythonconsole'
+ SETTINGS_INTERFACE_DIR = "org.gnome.Desktop.Interface"
+ SETTINGS_PROFILE_DIR = "org.gnome.GnomeTerminal.profiles.Default"
+
+ CONSOLE_KEY_COMMAND_COLOR = 'command-color'
+ CONSOLE_KEY_ERROR_COLOR = 'error-color'
def __init__(self, namespace = {}):
- gtk.ScrolledWindow.__init__(self)
+ Gtk.ScrolledWindow.__init__(self)
+
+ self._settings = Gio.Settings.new(self.CONSOLE_KEY_BASE)
+ self._settings.connect("changed", self.on_color_settings_changed)
- gconf_client.add_dir(self.GCONF_INTERFACE_DIR,
- gconf.CLIENT_PRELOAD_NONE)
- gconf_client.add_dir(self.GCONF_PROFILE_DIR,
- gconf.CLIENT_PRELOAD_NONE)
+ self._interface_settings = Gio.Settings.new(self.SETTINGS_INTERFACE_DIR)
+ self._interface_settings.connect("changed", self.on_settings_changed)
- gconf_client.notify_add(self.GCONF_INTERFACE_DIR,
- self.on_gconf_notification)
- gconf_client.notify_add(self.GCONF_PROFILE_DIR,
- self.on_gconf_notification)
+ self._profile_settings = Gio.Settings.new(self.SETTINGS_PROFILE_DIR)
+ self._profile_settings.connect("changed", self.on_settings_changed)
- self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- self.set_shadow_type(gtk.SHADOW_IN)
- self.view = gtk.TextView()
+ self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ self.set_shadow_type(Gtk.ShadowType.IN)
+ self.view = Gtk.TextView()
self.reconfigure()
self.view.set_editable(True)
- self.view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
+ self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
self.add(self.view)
self.view.show()
- buffer = self.view.get_buffer()
- self.normal = buffer.create_tag("normal")
- self.error = buffer.create_tag("error")
- self.command = buffer.create_tag("command")
+ buf = self.view.get_buffer()
+ self.normal = buf.create_tag("normal")
+ self.error = buf.create_tag("error")
+ self.command = buf.create_tag("command")
- PythonConsoleConfig.add_handler(self.apply_preferences)
- self.apply_preferences()
+ # Load the default settings
+ self.on_color_settings_changed(self._settings, None)
self.__spaces_pattern = re.compile(r'^\s+')
self.namespace = namespace
@@ -84,9 +83,9 @@ class PythonConsole(gtk.ScrolledWindow):
self.block_command = False
# Init first line
- buffer.create_mark("input-line", buffer.get_end_iter(), True)
- buffer.insert(buffer.get_end_iter(), ">>> ")
- buffer.create_mark("input", buffer.get_end_iter(), True)
+ buf.create_mark("input-line", buf.get_end_iter(), True)
+ buf.insert(buf.get_end_iter(), ">>> ")
+ buf.create_mark("input", buf.get_end_iter(), True)
# Init history
self.history = ['']
@@ -100,7 +99,7 @@ class PythonConsole(gtk.ScrolledWindow):
# Signals
self.view.connect("key-press-event", self.__key_press_event_cb)
- buffer.connect("mark-set", self.__mark_set_cb)
+ buf.connect("mark-set", self.__mark_set_cb)
def do_grab_focus(self):
self.view.grab_focus()
@@ -108,16 +107,15 @@ class PythonConsole(gtk.ScrolledWindow):
def reconfigure(self):
# Font
font_desc = None
- system_font = gconf_get_str(self.GCONF_INTERFACE_DIR + "/monospace_font_name",
- self.DEFAULT_FONT)
+ system_font = self._interface_settings.get_string("monospace-font-name")
- if gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_system_font"):
+ if self._profile_settings.get_boolean("use-system-font"):
font_name = system_font
else:
- font_name = gconf_get_str(self.GCONF_PROFILE_DIR + "/font", system_font)
+ font_name = self._profile_settings.get_string("font")
try:
- font_desc = pango.FontDescription(font_name)
+ font_desc = Pango.FontDescription(font_name)
except:
if font_name != self.DEFAULT_FONT:
if font_name != system_font:
@@ -135,67 +133,66 @@ class PythonConsole(gtk.ScrolledWindow):
if font_desc != None:
self.view.modify_font(font_desc)
- def on_gconf_notification(self, client, cnxn_id, entry, what):
+ def on_settings_changed(self, settings, key):
self.reconfigure()
- def apply_preferences(self, *args):
- config = PythonConsoleConfig()
- self.error.set_property("foreground", config.color_error)
- self.command.set_property("foreground", config.color_command)
+ def on_color_settings_changed(self, settings, key):
+ self.error.set_property("foreground", settings.get_string(self.CONSOLE_KEY_ERROR_COLOR))
+ self.command.set_property("foreground", settings.get_string(self.CONSOLE_KEY_COMMAND_COLOR))
def stop(self):
self.namespace = None
def __key_press_event_cb(self, view, event):
- modifier_mask = gtk.accelerator_get_default_mod_mask()
- event_state = event.state & modifier_mask
+ modifier_mask = Gtk.accelerator_get_default_mod_mask()
+ event_state = event.key.state & modifier_mask
- if event.keyval == gtk.keysyms.d and event_state == gtk.gdk.CONTROL_MASK:
+ if event.key.keyval == Gdk.d and event_state == Gdk.ModifierType.CONTROL_MASK:
self.destroy()
- elif event.keyval == gtk.keysyms.Return and event_state == gtk.gdk.CONTROL_MASK:
+ elif event.key.keyval == Gdk.Return and event_state == Gdk.ModifierType.CONTROL_MASK:
# Get the command
- buffer = view.get_buffer()
- inp_mark = buffer.get_mark("input")
- inp = buffer.get_iter_at_mark(inp_mark)
- cur = buffer.get_end_iter()
- line = buffer.get_text(inp, cur)
+ buf = view.get_buffer()
+ inp_mark = buf.get_mark("input")
+ inp = buf.get_it_at_mark(inp_mark)
+ cur = buf.get_end_iter()
+ line = buf.get_text(inp, cur)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
# Prepare the new line
- cur = buffer.get_end_iter()
- buffer.insert(cur, "\n... ")
- cur = buffer.get_end_iter()
- buffer.move_mark(inp_mark, cur)
+ cur = buf.get_end_iter()
+ buf.insert(cur, "\n... ")
+ cur = buf.get_end_iter()
+ buf.move_mark(inp_mark, cur)
# Keep indentation of precendent line
spaces = re.match(self.__spaces_pattern, line)
if spaces is not None:
- buffer.insert(cur, line[spaces.start() : spaces.end()])
- cur = buffer.get_end_iter()
+ buf.insert(cur, line[spaces.start() : spaces.end()])
+ cur = buf.get_end_iter()
- buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ buf.place_cursor(cur)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.Return:
+ elif event.key.keyval == Gdk.Return:
# Get the marks
- buffer = view.get_buffer()
- lin_mark = buffer.get_mark("input-line")
- inp_mark = buffer.get_mark("input")
+ buf = view.get_buffer()
+ lin_mark = buf.get_mark("input-line")
+ inp_mark = buf.get_mark("input")
# Get the command line
- inp = buffer.get_iter_at_mark(inp_mark)
- cur = buffer.get_end_iter()
- line = buffer.get_text(inp, cur)
+ inp = buf.get_iter_at_mark(inp_mark)
+ cur = buf.get_end_iter()
+ line = buf.get_text(inp, cur, False)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
# Make the line blue
- lin = buffer.get_iter_at_mark(lin_mark)
- buffer.apply_tag(self.command, lin, cur)
- buffer.insert(cur, "\n")
+ lin = buf.get_iter_at_mark(lin_mark)
+ buf.apply_tag(self.command, lin, cur)
+ buf.insert(cur, "\n")
cur_strip = self.current_command.rstrip()
@@ -214,103 +211,103 @@ class PythonConsole(gtk.ScrolledWindow):
com_mark = ">>> "
# Prepare the new line
- cur = buffer.get_end_iter()
- buffer.move_mark(lin_mark, cur)
- buffer.insert(cur, com_mark)
- cur = buffer.get_end_iter()
- buffer.move_mark(inp_mark, cur)
- buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ cur = buf.get_end_iter()
+ buf.move_mark(lin_mark, cur)
+ buf.insert(cur, com_mark)
+ cur = buf.get_end_iter()
+ buf.move_mark(inp_mark, cur)
+ buf.place_cursor(cur)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Down or event.keyval == gtk.keysyms.Down:
+ elif event.key.keyval == Gdk.KP_Down or event.key.keyval == Gdk.Down:
# Next entry from history
view.emit_stop_by_name("key_press_event")
self.history_down()
gobject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Up or event.keyval == gtk.keysyms.Up:
+ elif event.key.keyval == Gdk.KP_Up or event.key.keyval == Gdk.Up:
# Previous entry from history
view.emit_stop_by_name("key_press_event")
self.history_up()
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Left or event.keyval == gtk.keysyms.Left or \
- event.keyval == gtk.keysyms.BackSpace:
- buffer = view.get_buffer()
- inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
- cur = buffer.get_iter_at_mark(buffer.get_insert())
+ elif event.key.keyval == Gdk.KP_Left or event.key.keyval == Gdk.Left or \
+ event.key.keyval == Gdk.BackSpace:
+ buf = view.get_buffer()
+ inp = buf.get_iter_at_mark(buf.get_mark("input"))
+ cur = buf.get_iter_at_mark(buf.get_insert())
if inp.compare(cur) == 0:
if not event_state:
- buffer.place_cursor(inp)
+ buf.place_cursor(inp)
return True
return False
# For the console we enable smart/home end behavior incoditionally
# since it is useful when editing python
- elif (event.keyval == gtk.keysyms.KP_Home or event.keyval == gtk.keysyms.Home) and \
- event_state == event_state & (gtk.gdk.SHIFT_MASK|gtk.gdk.CONTROL_MASK):
+ elif (event.key.keyval == Gdk.KP_Home or event.key.keyval == Gdk.Home) and \
+ event_state == event_state & (Gdk.ModifierType.SHIFT_MASK|Gdk.ModifierType.CONTROL_MASK):
# Go to the begin of the command instead of the begin of the line
- buffer = view.get_buffer()
- iter = buffer.get_iter_at_mark(buffer.get_mark("input"))
- ins = buffer.get_iter_at_mark(buffer.get_insert())
+ buf = view.get_buffer()
+ it = buf.get_iter_at_mark(buf.get_mark("input"))
+ ins = buf.get_iter_at_mark(buf.get_insert())
- while iter.get_char().isspace():
- iter.forward_char()
+ while it.get_char().isspace():
+ it.forward_char()
- if iter.equal(ins):
- iter = buffer.get_iter_at_mark(buffer.get_mark("input"))
+ if it.equal(ins):
+ it = buf.get_iter_at_mark(buf.get_mark("input"))
- if event_state & gtk.gdk.SHIFT_MASK:
- buffer.move_mark_by_name("insert", iter)
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
+ buf.move_mark_by_name("insert", it)
else:
- buffer.place_cursor(iter)
+ buf.place_cursor(it)
return True
- elif (event.keyval == gtk.keysyms.KP_End or event.keyval == gtk.keysyms.End) and \
- event_state == event_state & (gtk.gdk.SHIFT_MASK|gtk.gdk.CONTROL_MASK):
+ elif (event.key.keyval == Gdk.KP_End or event.key.keyval == Gdk.End) and \
+ event_state == event_state & (Gdk.ModifierType.SHIFT_MASK|Gdk.ModifierType.CONTROL_MASK):
- buffer = view.get_buffer()
- iter = buffer.get_end_iter()
- ins = buffer.get_iter_at_mark(buffer.get_insert())
+ buf = view.get_buffer()
+ it = buf.get_end_iter()
+ ins = buf.get_iter_at_mark(buf.get_insert())
- iter.backward_char()
+ it.backward_char()
- while iter.get_char().isspace():
- iter.backward_char()
+ while it.get_char().isspace():
+ it.backward_char()
- iter.forward_char()
+ it.forward_char()
- if iter.equal(ins):
- iter = buffer.get_end_iter()
+ if it.equal(ins):
+ it = buf.get_end_iter()
- if event_state & gtk.gdk.SHIFT_MASK:
- buffer.move_mark_by_name("insert", iter)
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
+ buf.move_mark_by_name("insert", it)
else:
- buffer.place_cursor(iter)
+ buf.place_cursor(it)
return True
- def __mark_set_cb(self, buffer, iter, name):
- input = buffer.get_iter_at_mark(buffer.get_mark("input"))
- pos = buffer.get_iter_at_mark(buffer.get_insert())
+ def __mark_set_cb(self, buf, it, name):
+ input = buf.get_iter_at_mark(buf.get_mark("input"))
+ pos = buf.get_iter_at_mark(buf.get_insert())
self.view.set_editable(pos.compare(input) != -1)
def get_command_line(self):
- buffer = self.view.get_buffer()
- inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
- cur = buffer.get_end_iter()
- return buffer.get_text(inp, cur)
+ buf = self.view.get_buffer()
+ inp = buf.get_iter_at_mark(buf.get_mark("input"))
+ cur = buf.get_end_iter()
+ return buf.get_text(inp, cur)
def set_command_line(self, command):
- buffer = self.view.get_buffer()
- mark = buffer.get_mark("input")
- inp = buffer.get_iter_at_mark(mark)
- cur = buffer.get_end_iter()
- buffer.delete(inp, cur)
- buffer.insert(inp, command)
+ buf = self.view.get_buffer()
+ mark = buf.get_mark("input")
+ inp = buf.get_iter_at_mark(mark)
+ cur = buf.get_end_iter()
+ buf.delete(inp, cur)
+ buf.insert(inp, command)
self.view.grab_focus()
def history_add(self, line):
@@ -332,23 +329,28 @@ class PythonConsole(gtk.ScrolledWindow):
self.set_command_line(self.history[self.history_pos])
def scroll_to_end(self):
- iter = self.view.get_buffer().get_end_iter()
- self.view.scroll_to_iter(iter, 0.0)
+ i = self.view.get_buffer().get_end_iter()
+ self.view.scroll_to_iter(i, 0.0, False, 0.5, 0.5)
return False
def write(self, text, tag = None):
- buffer = self.view.get_buffer()
- if tag is None:
- buffer.insert(buffer.get_end_iter(), text)
- else:
- buffer.insert_with_tags(buffer.get_end_iter(), text, tag)
- gobject.idle_add(self.scroll_to_end)
+ buf = self.view.get_buffer()
+ #FIXME
+ #if tag is None:
+ # buf.insert(buf.get_end_iter(), text)
+ #else:
+ # buf.insert_with_tags(buf.get_end_iter(), text, tag)
+ insertion_iter = buf.get_end_iter()
+ buf.insert(insertion_iter, text)
+ if tag is not None:
+ buf.apply_tag(tag, insertion_iter, buf.get_end_iter())
+ GObject.idle_add(self.scroll_to_end)
def eval(self, command, display_command = False):
- buffer = self.view.get_buffer()
- lin = buffer.get_mark("input-line")
- buffer.delete(buffer.get_iter_at_mark(lin),
- buffer.get_end_iter())
+ buf = self.view.get_buffer()
+ lin = buf.get_mark("input-line")
+ buf.delete(buf.get_iter_at_mark(lin),
+ buf.get_end_iter())
if isinstance(command, list) or isinstance(command, tuple):
for c in command:
@@ -360,12 +362,12 @@ class PythonConsole(gtk.ScrolledWindow):
self.write(">>> " + c + "\n", self.command)
self.__run(command)
- cur = buffer.get_end_iter()
- buffer.move_mark_by_name("input-line", cur)
- buffer.insert(cur, ">>> ")
- cur = buffer.get_end_iter()
- buffer.move_mark_by_name("input", cur)
- self.view.scroll_to_iter(buffer.get_end_iter(), 0.0)
+ cur = buf.get_end_iter()
+ buf.move_mark_by_name("input-line", cur)
+ buf.insert(cur, ">>> ")
+ cur = buf.get_end_iter()
+ buf.move_mark_by_name("input", cur)
+ self.view.scroll_to_iter(buf.get_end_iter(), 0.0, False, 0.5, 0.5)
def __run(self, command):
sys.stdout, self.stdout = self.stdout, sys.stdout
@@ -416,21 +418,4 @@ class OutFile:
def tell(self): raise IOError, (29, 'Illegal seek')
truncate = tell
-gconf_client = gconf.client_get_default()
-def gconf_get_bool(key, default = False):
- val = gconf_client.get(key)
-
- if val is not None and val.type == gconf.VALUE_BOOL:
- return val.get_bool()
- else:
- return default
-
-def gconf_get_str(key, default = ""):
- val = gconf_client.get(key)
-
- if val is not None and val.type == gconf.VALUE_STRING:
- return val.get_string()
- else:
- return default
-
# ex:et:ts=4:
diff --git a/plugins/pythonconsole/pythonconsole/org.gnome.gedit.pythonconsole.gschema.xml.in.in b/plugins/pythonconsole/pythonconsole/org.gnome.gedit.pythonconsole.gschema.xml.in.in
new file mode 100644
index 0000000..ca27cf5
--- /dev/null
+++ b/plugins/pythonconsole/pythonconsole/org.gnome.gedit.pythonconsole.gschema.xml.in.in
@@ -0,0 +1,22 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.pythonconsole" path="/apps/gedit/plugins/pythonconsole/">
+ <key name="command-color" type="s">
+ <default>'#314e6c'</default>
+ <_summary>Command Color Text</_summary>
+ <_description>The command color text</_description>
+ </key>
+ <key name="error-color" type="s">
+ <default>'#990000'</default>
+ <_summary>Error Color Text</_summary>
+ <_description>The error color text</_description>
+ </key>
+ </schema>
+ <schema id="org.gnome.GnomeTerminal.profiles.Default" path="/apps/gnome-terminal/profiles/Default/">
+ <key name="use-system-font" type="b">
+ <default>true</default>
+ </key>
+ <key name="font" type="s">
+ <default>'Monospace 10'</default>
+ </key>
+ </schema>
+</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]