[gedit-plugins] Port terminal to gtk3/libpeas.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] Port terminal to gtk3/libpeas.
- Date: Mon, 27 Dec 2010 19:52:20 +0000 (UTC)
commit ac071da1a4cadfcc7725d19386dda659b92e5dc3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Dec 23 15:21:05 2010 +0100
Port terminal to gtk3/libpeas.
configure.ac | 27 +--
plugins/terminal/Makefile.am | 11 +-
....gnome.gedit.plugins.terminal.gschema.xml.in.in | 147 ++++++++++
plugins/terminal/terminal.py | 305 +++++++-------------
4 files changed, 263 insertions(+), 227 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a280882..e3bb872 100644
--- a/configure.ac
+++ b/configure.ac
@@ -243,32 +243,6 @@ then
fi
fi
-# ================================================================
-# Terminal plugin vte check
-# ================================================================
-plugin_defined terminal
-if test "$?" = 1
-then
- PYVTE_REQUIRED=0.19.4
- PKG_CHECK_MODULES([PYVTE],
- [pyvte >= $PYVTE_REQUIRED],
- [have_pyvte=yes],[have_pyvte=no])
-
- AC_SUBST([PYVTE_CFLAGS])
- AC_SUBST([PYVTE_LIBS])
-
- if test "x$have_pyvte" = "xno"; then
- plugin_defined_explicit terminal
- if test "$?" = 1
- then
- AC_MSG_ERROR([pyvte could not be found, needed to built terminal plugin])
- else
- AC_MSG_WARN([pyvte could not be found, terminal plugin will be disabled])
- undef_plugin terminal "pyvte not found"
- fi
- fi
-fi
-
if test -z "$disabled_plugins"
then
disabled_plugins="none"
@@ -353,6 +327,7 @@ plugins/synctex/synctex/Makefile
plugins/taglist/taglist.plugin.desktop.in
plugins/taglist/Makefile
plugins/terminal/Makefile
+plugins/terminal/org.gnome.gedit.plugins.terminal.gschema.xml.in
plugins/terminal/terminal.plugin.desktop.in
plugins/textsize/Makefile
plugins/textsize/textsize.plugin.desktop.in
diff --git a/plugins/terminal/Makefile.am b/plugins/terminal/Makefile.am
index ab329f6..d4b3251 100644
--- a/plugins/terminal/Makefile.am
+++ b/plugins/terminal/Makefile.am
@@ -8,9 +8,14 @@ plugin_in_files = terminal.plugin.desktop.in
plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
-EXTRA_DIST = $(plugin_in_files)
+gsettings_SCHEMAS = org.gnome.gedit.plugins.terminal.gschema.xml
-CLEANFILES = $(plugin_DATA)
-DISTCLEANFILES = $(plugin_DATA)
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
+EXTRA_DIST = $(plugin_in_files) org.gnome.gedit.plugins.terminal.gschema.xml.in.in
+
+CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS)
-include $(top_srcdir)/git.mk
diff --git a/plugins/terminal/org.gnome.gedit.plugins.terminal.gschema.xml.in.in b/plugins/terminal/org.gnome.gedit.plugins.terminal.gschema.xml.in.in
new file mode 100644
index 0000000..5d77632
--- /dev/null
+++ b/plugins/terminal/org.gnome.gedit.plugins.terminal.gschema.xml.in.in
@@ -0,0 +1,147 @@
+<schemalist>
+ <enum id='org.gnome.gedit.plugins.terminal.VteTerminalCursorBlinkMode'>
+ <value nick='system' value='0'/>
+ <value nick='on' value='1'/>
+ <value nick='off' value='2'/>
+ </enum>
+ <enum id='org.gnome.gedit.plugins.terminal.VteTerminalCursorShape'>
+ <value nick='block' value='0'/>
+ <value nick='ibeam' value='1'/>
+ <value nick='underline' value='2'/>
+ </enum>
+
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.terminal" path="/apps/gedit/plugins/terminal/">
+ <key name="silent-bell" type="b">
+ <default>true</default>
+ <_summary>Whether to silence terminal bell</_summary>
+ <_description>
+ If true, don't make a noise when applications send the
+ escape sequence for the terminal bell.
+ </_description>
+ </key>
+ <key name="scrollback-lines" type="i">
+ <default>100</default>
+ <_summary>Number of lines to keep in scrollback</_summary>
+ <_description>
+ Number of scrollback lines to keep around. You can
+ scroll back in the terminal by this number of lines;
+ lines that don't fit in the scrollback are discarded.
+ If scrollback-unlimited is true, this value is ignored.
+ </_description>
+ </key>
+ <key name="scrollback-unlimited" type="b">
+ <default>false</default>
+ <_summary>
+ Whether an unlimited number of lines should be kept in scrollback
+ </_summary>
+ <_description>
+ If true, scrollback lines will never be discarded. The scrollback
+ history is stored on disk temporarily, so this may cause the system
+ to run out of disk space if there is a lot of output to the
+ terminal.
+ </_description>
+ </key>
+ <key name="scrollback-on-keystroke" type="b">
+ <default>true</default>
+ <_summary>Whether to scroll to the bottom when a key is pressed</_summary>
+ <_description>
+ If true, pressing a key jumps the scrollbar to the bottom.
+ </_description>
+ </key>
+ <key name="scrollback-on-output" type="b">
+ <default>false</default>
+ <_summary>Whether to scroll to the bottom when there's new output</_summary>
+ <_description>
+ If true, whenever there's new output the terminal will scroll
+ to the bottom.
+ </_description>
+ </key>
+ <key name="allow-bold" type="b">
+ <default>true</default>
+ <_summary>Whether to allow bold text</_summary>
+ <_description>
+ If true, allow applications in the terminal to make text boldface.
+ </_description>
+ </key>
+ <key name="word-chars" type="s">
+ <default>'-A-Za-z0-9,./?%&#:_'</default>
+ <_summary>Characters that are considered "part of a word"</_summary>
+ <_description>
+ When selecting text by word, sequences of these characters
+ are considered single words. Ranges can be given as
+ "A-Z". Literal hyphen (not expressing a range) should be
+ the first character given.
+ </_description>
+ </key>
+ <key name="foreground-color" type="s">
+ <default>'#000000'</default>
+ <_summary>Default color of text in the terminal</_summary>
+ <_description>
+ Default color of text in the terminal, as a color
+ specification (can be HTML-style hex digits, or
+ a color name such as "red").
+ </_description>
+ </key>
+ <key name="background-color" type="s">
+ <default>'#FFFFDD'</default>
+ <_summary>Default color of terminal background</_summary>
+ <_description>
+ Default color of terminal background, as a color
+ specification (can be HTML-style hex digits, or
+ a color name such as "red").
+ </_description>
+ </key>
+ <key name="palette" type="s">
+ <default>'#2E2E34343636:#CCCC00000000:#4E4E9A9A0606:#C4C4A0A00000:#34346565A4A4:#757550507B7B:#060698209A9A:#D3D3D7D7CFCF:#555557575353:#EFEF29292929:#8A8AE2E23434:#FCFCE9E94F4F:#72729F9FCFCF:#ADAD7F7FA8A8:#3434E2E2E2E2:#EEEEEEEEECEC'</default>
+ <_summary>Palette for terminal applications</_summary>
+ <_description>
+ Terminals have a 16-color palette that applications inside
+ the terminal can use. This is that palette, in the form
+ of a colon-separated list of color names. Color names
+ should be in hex format e.g. "#FF00FF"
+ </_description>
+ </key>
+ <key name="use-theme-colors" type="b">
+ <default>true</default>
+ <_summary>
+ Whether to use the colors from the theme for the terminal widget
+ </_summary>
+ <_description>
+ If true, the theme color scheme used for text entry boxes will
+ be used for the terminal, instead of colors provided by the user.
+ </_description>
+ </key>
+ <key name="cursor-blink-mode" enum="org.gnome.gedit.plugins.terminal.VteTerminalCursorBlinkMode">
+ <default>'system'</default>
+ <_summary>Whether to blink the cursor</_summary>
+ <_description>
+ The possible values are "system" to use the global cursor blinking
+ settings, or "on" or "off" to set the mode explicitly.
+ </_description>
+ </key>
+ <key name="cursor-shape" enum="org.gnome.gedit.plugins.terminal.VteTerminalCursorShape">
+ <default>'block'</default>
+ <_summary>The cursor appearance</_summary>
+ <_description>
+ The possible values are "block" to use a block cursor, "ibeam" to
+ use a vertical line cursor, or "underline" to use an underline cursor.
+ </_description>
+ </key>
+ <key name="use-system-font" type="b">
+ <default>true</default>
+ <_summary>Whether to use the system font</_summary>
+ <_description>
+ If true, the terminal will use the desktop-global standard
+ font if it's monospace (and the most similar font it can
+ come up with otherwise).
+ </_description>
+ </key>
+ <key name="font" type="s">
+ <default>'Monospace 10'</default>
+ <_summary>Font</_summary>
+ <_description>
+ A Pango font name. Examples are "Sans 12" or "Monospace Bold 14".
+ </_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/plugins/terminal/terminal.py b/plugins/terminal/terminal.py
index 036e4bf..d941a60 100644
--- a/plugins/terminal/terminal.py
+++ b/plugins/terminal/terminal.py
@@ -20,16 +20,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA
-import gedit
-import gedit.utils
-import pango
-import gtk
-import gobject
-import vte
-import gconf
+from gi.repository import GObject, GLib, Gio, Pango, Gdk, Gtk, Gedit, Vte
import gettext
import os
-import gio
+
+"""
from gpdefs import *
try:
@@ -37,203 +32,155 @@ try:
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
except:
_ = lambda s: s
+"""
-class GeditTerminal(gtk.HBox):
+class GeditTerminal(Gtk.Box):
"""VTE terminal which follows gnome-terminal default profile options"""
__gsignals__ = {
"populate-popup": (
- gobject.SIGNAL_RUN_LAST,
+ GObject.SIGNAL_RUN_LAST,
None,
- (gobject.TYPE_OBJECT,)
+ (GObject.TYPE_OBJECT,)
)
}
- GCONF_INTERFACE_DIR = "/desktop/gnome/interface"
- GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
-
defaults = {
- 'allow_bold' : True,
- 'audible_bell' : False,
- 'background' : None,
- 'backspace_binding' : 'ascii-del',
- 'cursor_blink_mode' : vte.CURSOR_BLINK_SYSTEM,
- 'cursor_shape' : vte.CURSOR_SHAPE_BLOCK,
'emulation' : 'xterm',
- 'font_name' : 'Monospace 10',
- 'scroll_on_keystroke' : False,
- 'scroll_on_output' : False,
- 'scrollback_lines' : 100,
'visible_bell' : False,
- 'word_chars' : '-A-Za-z0-9,./?%&#:_'
}
def __init__(self):
- gtk.HBox.__init__(self, False, 4)
-
- gconf_client.add_dir(self.GCONF_INTERFACE_DIR,
- gconf.CLIENT_PRELOAD_NONE)
- gconf_client.add_dir(self.GCONF_PROFILE_DIR,
- gconf.CLIENT_PRELOAD_RECURSIVE)
+ Gtk.Box.__init__(self)
- 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 = self.get_profile_settings()
+ self.profile_settings.connect("changed", self.on_profile_settings_changed)
+ self.system_settings = Gio.Settings.new("org.gnome.desktop.interface")
+ self.system_settings.connect("changed::monospace-font-name", self.font_changed)
- self._vte = vte.Terminal()
+ self._vte = Vte.Terminal()
self.reconfigure_vte()
self._vte.set_size(self._vte.get_column_count(), 5)
self._vte.set_size_request(200, 50)
self._vte.show()
- self.pack_start(self._vte)
+ self.pack_start(self._vte, True, True, 0)
- self._scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
- self._scrollbar.show()
- self.pack_start(self._scrollbar, False, False, 0)
+ scrollbar = Gtk.VScrollbar.new(self._vte.get_vadjustment())
+ scrollbar.show()
+ self.pack_start(scrollbar, False, False, 0)
# we need to reconf colors if the style changes
- self._vte.connect("style-set", lambda term, oldstyle: self.reconfigure_vte())
+ #FIXME: why?
+ #self._vte.connect("style-update", lambda term, oldstyle: self.reconfigure_vte())
self._vte.connect("key-press-event", self.on_vte_key_press)
self._vte.connect("button-press-event", self.on_vte_button_press)
self._vte.connect("popup-menu", self.on_vte_popup_menu)
- self._vte.connect("child-exited", lambda term: term.fork_command())
+ self._vte.connect("child-exited", self.on_child_exited)
self._accel_base = '<gedit>/plugins/terminal'
self._accels = {
- 'copy-clipboard': [gtk.keysyms.C, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK, self.copy_clipboard],
- 'paste-clipboard': [gtk.keysyms.V, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK, self.paste_clipboard]
+ 'copy-clipboard': [Gdk.KEY_C, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, self.copy_clipboard],
+ 'paste-clipboard': [Gdk.KEY_V, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, self.paste_clipboard]
}
for name in self._accels:
path = self._accel_base + '/' + name
- accel = gtk.accel_map_lookup_entry(path)
+ accel = Gtk.AccelMap.lookup_entry(path)
if accel == None:
- gtk.accel_map_add_entry(path, self._accels[name][0], self._accels[name][1])
+ Gtk.AccelMap.add_entry(path, self._accels[name][0], self._accels[name][1])
- self._vte.fork_command()
+ #FIXME
+ #self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [], None, GLib.SpawnFlags.CHILD_INHERITS_STDIN | GLib.SpawnFlags.SEARCH_PATH, None, None)
+
+ def on_child_exited(self):
+ return None
+ #self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [], None, GLib.SpawnFlags.CHILD_INHERITS_STDIN | GLib.SpawnFlags.SEARCH_PATH, None, None)
def do_grab_focus(self):
self._vte.grab_focus()
- def reconfigure_vte(self):
- # Fonts
- font_desc = None
- system_font = gconf_get_str(self.GCONF_INTERFACE_DIR + "/monospace_font_name",
- self.defaults["font_name"])
+ def get_profile_settings(self):
+ #FIXME return either the gnome-terminal settings or the gedit one
+ return Gio.Settings.new("org.gnome.gedit.plugins.terminal")
- if gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_system_font"):
- font_name = system_font
+ def get_font(self):
+ if self.profile_settings.get_boolean("use-system-font"):
+ font = self.system_settings.get_string("monospace-font-name")
else:
- font_name = gconf_get_str(self.GCONF_PROFILE_DIR + "/font", system_font)
-
- try:
- font_desc = pango.FontDescription(font_name)
- except:
- if font_name != self.DEFAULT_FONT:
- if font_name != system_font:
- try:
- font_desc = pango.FontDescription(system_font)
- except:
- pass
-
- if font_desc == None:
- try:
- font_desc = pango.FontDescription(self.defaults["font_name"])
- except:
- pass
-
- if font_desc != None:
- self._vte.set_font(font_desc)
+ font = self.profile_settings.get_string("font")
+
+ return font
+
+ def font_changed(self, settings=None, key=None):
+ font = self.get_font()
+ font_desc = Pango.font_description_from_string(font)
+
+ self._vte.set_font(font_desc)
+
+ def reconfigure_vte(self):
+ # Fonts
+ self.font_changed()
# colors
- self._vte.ensure_style()
- style = self._vte.get_style()
- fg = style.text[gtk.STATE_NORMAL]
- bg = style.base[gtk.STATE_NORMAL]
+ context = self._vte.get_style_context()
+ fg = context.get_color(0)
+ bg = context.get_background_color(0)
palette = []
- if not gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_theme_colors"):
- fg_color = gconf_get_str(self.GCONF_PROFILE_DIR + "/foreground_color", None)
- if (fg_color):
- fg = gtk.gdk.color_parse (fg_color)
- bg_color = gconf_get_str(self.GCONF_PROFILE_DIR + "/background_color", None)
- if (bg_color):
- bg = gtk.gdk.color_parse (bg_color)
- str_colors = gconf_get_str(self.GCONF_PROFILE_DIR + "/palette", None)
- if (str_colors):
+ if not self.profile_settings.get_boolean("use-theme-colors"):
+ fg_color = self.profile_settings.get_string("foreground-color")
+ if fg_color != "":
+ fg = Gdk.color_parse (fg_color)
+ bg_color = self.profile_settings.get_string("background-color")
+ if (bg_color != ""):
+ bg = Gdk.color_parse (bg_color)
+ str_colors = self.profile_settings.get_string("palette")
+ if (str_colors != ""):
for str_color in str_colors.split(':'):
try:
- palette.append(gtk.gdk.color_parse(str_color))
+ palette.append(Gdk.color_parse(str_color))
except:
palette = []
break
if (len(palette) not in (0, 8, 16, 24)):
palette = []
- self._vte.set_colors(fg, bg, palette)
-
- # cursor blink
- blink_mode = gconf_get_str(self.GCONF_PROFILE_DIR + "/cursor_blink_mode")
- if blink_mode.lower() == "system":
- blink = vte.CURSOR_BLINK_SYSTEM
- elif blink_mode.lower() == "on":
- blink = vte.CURSOR_BLINK_ON
- elif blink_mode.lower() == "off":
- blink = vte.CURSOR_BLINK_OFF
- else:
- blink = self.defaults['cursor_blink_mode']
- self._vte.set_cursor_blink_mode(blink)
-
- # cursor shape
- cursor_shape = gconf_get_str(self.GCONF_PROFILE_DIR + "/cursor_shape")
- if cursor_shape.lower() == "block":
- shape = vte.CURSOR_SHAPE_BLOCK
- elif cursor_shape.lower() == "ibeam":
- shape = vte.CURSOR_SHAPE_IBEAM
- elif cursor_shape.lower() == "underline":
- shape = vte.CURSOR_SHAPE_UNDERLINE
- else:
- shape = self.defaults['cursor_shape']
- self._vte.set_cursor_shape(shape)
-
- self._vte.set_audible_bell(not gconf_get_bool(self.GCONF_PROFILE_DIR + "/silent_bell",
- not self.defaults['audible_bell']))
-
- self._vte.set_scrollback_lines(gconf_get_int(self.GCONF_PROFILE_DIR + "/scrollback_lines",
- self.defaults['scrollback_lines']))
-
- self._vte.set_allow_bold(gconf_get_bool(self.GCONF_PROFILE_DIR + "/allow_bold",
- self.defaults['allow_bold']))
-
- self._vte.set_scroll_on_keystroke(gconf_get_bool(self.GCONF_PROFILE_DIR + "/scroll_on_keystroke",
- self.defaults['scroll_on_keystroke']))
- self._vte.set_scroll_on_output(gconf_get_bool(self.GCONF_PROFILE_DIR + "/scroll_on_output",
- self.defaults['scroll_on_output']))
-
- self._vte.set_word_chars(gconf_get_str(self.GCONF_PROFILE_DIR + "/word_chars",
- self.defaults['word_chars']))
+ # FIXME: we need the version of this method in rgba
+ #self._vte.set_colors(fg, bg, palette)
+ self._vte.set_cursor_blink_mode(self.profile_settings.get_enum("cursor-blink-mode"))
+ self._vte.set_cursor_shape(self.profile_settings.get_enum("cursor-shape"))
+ self._vte.set_audible_bell(not self.profile_settings.get_boolean("silent-bell"))
+ self._vte.set_allow_bold(self.profile_settings.get_boolean("allow-bold"))
+ self._vte.set_scroll_on_keystroke(self.profile_settings.get_boolean("scrollback-on-keystroke"))
+ self._vte.set_scroll_on_output(self.profile_settings.get_boolean("scrollback-on-output"))
+ self._vte.set_word_chars(self.profile_settings.get_string("word-chars"))
self._vte.set_emulation(self.defaults['emulation'])
self._vte.set_visible_bell(self.defaults['visible_bell'])
- def on_gconf_notification(self, client, cnxn_id, entry, what):
+ if self.profile_settings.get_boolean("scrollback-unlimited"):
+ lines = -1
+ else:
+ lines = self.profile_settings.get_int("scrollback-lines")
+ self._vte.set_scrollback_lines(lines)
+
+ def on_profile_settings_changed(self, settings, key):
self.reconfigure_vte()
def on_vte_key_press(self, term, event):
- modifiers = event.state & gtk.accelerator_get_default_mod_mask()
- if event.keyval in (gtk.keysyms.Tab, gtk.keysyms.KP_Tab, gtk.keysyms.ISO_Left_Tab):
- if modifiers == gtk.gdk.CONTROL_MASK:
- self.get_toplevel().child_focus(gtk.DIR_TAB_FORWARD)
+ modifiers = event.state & Gtk.accelerator_get_default_mod_mask()
+ if event.keyval in (Gdk.KEY_Tab, Gdk.KEY_KP_Tab, Gdk.KEY_ISO_Left_Tab):
+ if modifiers == Gdk.ModifierType.CONTROL_MASK:
+ self.get_toplevel().child_focus(Gtk.DirectionType.TAB_FORWARD)
return True
- elif modifiers == gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK:
- self.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
+ elif modifiers == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK:
+ self.get_toplevel().child_focus(Gtk.DirectionType.TAB_BACKWARD)
return True
for name in self._accels:
path = self._accel_base + '/' + name
- entry = gtk.accel_map_lookup_entry(path)
+ entry = Gtk.AccelMap.lookup_entry(path)
if entry and entry[0] == event.keyval and entry[1] == modifiers:
self._accels[name][2]()
@@ -251,15 +198,15 @@ class GeditTerminal(gtk.HBox):
self.do_popup()
def create_popup_menu(self):
- menu = gtk.Menu()
+ menu = Gtk.Menu()
- item = gtk.ImageMenuItem(gtk.STOCK_COPY)
+ item = Gtk.ImageMenuItem(Gtk.Stock.COPY)
item.connect("activate", lambda menu_item: self.copy_clipboard())
item.set_accel_path(self._accel_base + '/copy-clipboard')
item.set_sensitive(self._vte.get_has_selection())
menu.append(item)
- item = gtk.ImageMenuItem(gtk.STOCK_PASTE)
+ item = Gtk.ImageMenuItem(Gtk.Stock.PASTE)
item.connect("activate", lambda menu_item: self.paste_clipboard())
item.set_accel_path(self._accel_base + '/paste-clipboard')
menu.append(item)
@@ -275,8 +222,8 @@ class GeditTerminal(gtk.HBox):
menu.popup(None, None, None, event.button, event.time)
else:
menu.popup(None, None,
- lambda m: gedit.utils.menu_position_under_widget(m, self),
- 0, gtk.get_current_event_time())
+ lambda m: Gedit.utils_menu_position_under_widget(m, self),
+ 0, Gtk.get_current_event_time())
menu.select_first(False)
def copy_clipboard(self):
@@ -292,86 +239,48 @@ class GeditTerminal(gtk.HBox):
self._vte.feed_child('cd "%s"\n' % path)
self._vte.grab_focus()
-class TerminalWindowHelper(object):
- def __init__(self, window):
- self._window = window
+class TerminalPlugin(GObject.Object, Gedit.WindowActivatable):
+ __gtype_name__ = "TerminalPlugin"
+ window = GObject.property(type=GObject.Object)
+
+ def __init__(self):
+ GObject.Object.__init__(self)
+
+ def do_activate(self):
self._panel = GeditTerminal()
self._panel.connect("populate-popup", self.on_panel_populate_popup)
self._panel.show()
- image = gtk.Image()
- image.set_from_icon_name("utilities-terminal", gtk.ICON_SIZE_MENU)
+ image = Gtk.Image.new_from_icon_name("utilities-terminal", Gtk.IconSize.MENU)
- bottom = window.get_bottom_panel()
+ bottom = self.window.get_bottom_panel()
bottom.add_item(self._panel, "GeditTerminalPanel", _("Terminal"), image)
- def deactivate(self):
- bottom = self._window.get_bottom_panel()
+ def do_deactivate(self):
+ bottom = self.window.get_bottom_panel()
bottom.remove_item(self._panel)
- def update_ui(self):
+ def do_update_state(self):
pass
def get_active_document_directory(self):
- doc = self._window.get_active_document()
+ doc = self.window.get_active_document()
if doc is None:
return None
location = doc.get_location()
- if location is not None and gedit.utils.location_has_file_scheme(location):
+ if location is not None and Gedit.utils_location_has_file_scheme(location):
directory = location.get_parent()
return directory.get_path()
return None
def on_panel_populate_popup(self, panel, menu):
- menu.prepend(gtk.SeparatorMenuItem())
+ menu.prepend(Gtk.SeparatorMenuItem())
path = self.get_active_document_directory()
- item = gtk.MenuItem(_("C_hange Directory"))
+ item = Gtk.MenuItem(_("C_hange Directory"))
item.connect("activate", lambda menu_item: panel.change_directory(path))
item.set_sensitive(path is not None)
menu.prepend(item)
-class TerminalPlugin(gedit.Plugin):
- WINDOW_DATA_KEY = "TerminalPluginWindowData"
-
- def __init__(self):
- gedit.Plugin.__init__(self)
-
- def activate(self, window):
- helper = TerminalWindowHelper(window)
- window.set_data(self.WINDOW_DATA_KEY, helper)
-
- def deactivate(self, window):
- window.get_data(self.WINDOW_DATA_KEY).deactivate()
- window.set_data(self.WINDOW_DATA_KEY, None)
-
- def update_ui(self, window):
- window.get_data(self.WINDOW_DATA_KEY).update_ui()
-
-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
-
-def gconf_get_int(key, default = 0):
- val = gconf_client.get(key)
-
- if val is not None and val.type == gconf.VALUE_INT:
- return val.get_int()
- else:
- return default
-
# Let's conform to PEP8
# ex:ts=4:et:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]