diff options
author | monsta <[email protected]> | 2016-12-14 15:35:49 +0300 |
---|---|---|
committer | monsta <[email protected]> | 2016-12-19 14:16:30 +0300 |
commit | 4ea3ff79c350c9af799ed76e72e5c862af3eb73e (patch) | |
tree | 1eeb0c435c0e3adc512efb55c72cb3747cc27a58 /plugins/externaltools/tools/outputpanel.py | |
parent | 38c20e460232c5f4ec7bf616180ff777b5d6b3a0 (diff) | |
download | pluma-4ea3ff79c350c9af799ed76e72e5c862af3eb73e.tar.bz2 pluma-4ea3ff79c350c9af799ed76e72e5c862af3eb73e.tar.xz |
externaltools plugin: port to gi and libpeas
note: tools manager dialog can now be invoked only via Pluma's menu.
Preferences button in plugin manager is inactive. re-enabling it would
mean introducing even more complexity, because we would need to pass
a configure widget to libpeas, not the whole dialog.
mostly adapted from:
https://git.gnome.org/browse/gedit/commit/?id=8b6d353e0ab94ad52ce6119759db5e14b281fbba
https://git.gnome.org/browse/gedit/commit/?id=2aa6071912dac227f04f44c07e07f159b77be7ff
https://git.gnome.org/browse/gedit/commit/?id=09738cd6f5f24a37cb7dd85dfca7a5099529e5d2
https://git.gnome.org/browse/gedit/commit/?id=f08e9d2953fa213f77dce635127c3a0131fba02f
https://git.gnome.org/browse/gedit/commit/?id=d09a703e84f818dcadd7bd1c16c2091305a691c2
https://git.gnome.org/browse/gedit/commit/?id=985f3908abe3f2ade53db1364dccf0d1fd61ec1b
https://git.gnome.org/browse/gedit/commit/?id=b6086cab8c664d2cfb3e5b4a6d33c215d1b207da
https://git.gnome.org/browse/gedit/commit/?id=befd854563e4691a6b75b03695d6a7c458836312
https://git.gnome.org/browse/gedit/commit/?id=cf7549c8e5944a3fbf9d18170b6e45a552071b4c
https://git.gnome.org/browse/gedit/commit/?id=6c95d28a13ae87232346583a86ae525a22fcc651
https://git.gnome.org/browse/gedit/commit/?id=c70319048b42b898fd6c2f6ee37e98e54cea54be
Diffstat (limited to 'plugins/externaltools/tools/outputpanel.py')
-rwxr-xr-x | plugins/externaltools/tools/outputpanel.py | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py index 9d1da65f..9613d78c 100755 --- a/plugins/externaltools/tools/outputpanel.py +++ b/plugins/externaltools/tools/outputpanel.py @@ -19,17 +19,13 @@ __all__ = ('OutputPanel', 'UniqueById') -import gtk, pluma -import pango -import gobject import os from weakref import WeakKeyDictionary from capture import * -from gtk import gdk import re -import gio import linkparsing import filelookup +from gi.repository import GLib, Gdk, Gtk, Pango, Pluma class UniqueById: __shared_state = WeakKeyDictionary() @@ -58,12 +54,12 @@ class OutputPanel(UniqueById): } self.window = window - self.ui = gtk.Builder() + self.ui = Gtk.Builder() self.ui.add_from_file(os.path.join(datadir, 'ui', 'outputpanel.ui')) self.ui.connect_signals(callbacks) self.panel = self["output-panel"] - self['view'].modify_font(pango.FontDescription('Monospace')) + self['view'].override_font(Pango.font_description_from_string('Monospace')) buffer = self['view'].get_buffer() @@ -73,18 +69,18 @@ class OutputPanel(UniqueById): self.error_tag.set_property('foreground', 'red') self.italic_tag = buffer.create_tag('italic') - self.italic_tag.set_property('style', pango.STYLE_OBLIQUE) + self.italic_tag.set_property('style', Pango.Style.OBLIQUE) self.bold_tag = buffer.create_tag('bold') - self.bold_tag.set_property('weight', pango.WEIGHT_BOLD) + self.bold_tag.set_property('weight', Pango.Weight.BOLD) self.invalid_link_tag = buffer.create_tag('invalid_link') self.link_tag = buffer.create_tag('link') - self.link_tag.set_property('underline', pango.UNDERLINE_SINGLE) + self.link_tag.set_property('underline', Pango.Underline.SINGLE) - self.link_cursor = gdk.Cursor(gdk.HAND2) - self.normal_cursor = gdk.Cursor(gdk.XTERM) + self.link_cursor = Gdk.Cursor.new(Gdk.CursorType.HAND2) + self.normal_cursor = Gdk.Cursor.new(Gdk.CursorType.XTERM) self.process = None @@ -108,7 +104,7 @@ class OutputPanel(UniqueById): def scroll_to_end(self): iter = self['view'].get_buffer().get_end_iter() - self['view'].scroll_to_iter(iter, 0.0) + self['view'].scroll_to_iter(iter, 0.0, False, 0.5, 0.5) return False # don't requeue this handler def clear(self): @@ -153,7 +149,7 @@ class OutputPanel(UniqueById): buffer.apply_tag(tag, start_iter, end_iter) buffer.delete_mark(insert) - gobject.idle_add(self.scroll_to_end) + GLib.idle_add(self.scroll_to_end) def show(self): panel = self.window.get_bottom_panel() @@ -166,16 +162,16 @@ class OutputPanel(UniqueById): else: cursor = self.normal_cursor - view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor) + view.get_window(Gtk.TextWindowType.TEXT).set_cursor(cursor) def on_view_motion_notify_event(self, view, event): - if event.window == view.get_window(gtk.TEXT_WINDOW_TEXT): + if event.window == view.get_window(Gtk.TextWindowType.TEXT): self.update_cursor_style(view, int(event.x), int(event.y)) return False def on_view_visibility_notify_event(self, view, event): - if event.window == view.get_window(gtk.TEXT_WINDOW_TEXT): + if event.window == view.get_window(Gtk.TextWindowType.TEXT): x, y, m = event.window.get_pointer() self.update_cursor_style(view, x, y) @@ -192,9 +188,17 @@ class OutputPanel(UniqueById): """ # get the offset within the buffer from the x,y coordinates - buff_x, buff_y = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, + buff_x, buff_y = view.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x, y) - iter_at_xy = view.get_iter_at_location(buff_x, buff_y) + # usual API breakage in GTK+3, nothing new... + # see https://bugzilla.gnome.org/768793 + if Gtk.get_minor_version() >= 20: + (over_text, iter_at_xy) = view.get_iter_at_location(buff_x, buff_y) + if not over_text: + return None + else: + iter_at_xy = view.get_iter_at_location(buff_x, buff_y) + offset = iter_at_xy.get_offset() # find the first link that contains the offset @@ -206,8 +210,8 @@ class OutputPanel(UniqueById): return None def on_view_button_press_event(self, view, event): - if event.button != 1 or event.type != gdk.BUTTON_PRESS or \ - event.window != view.get_window(gtk.TEXT_WINDOW_TEXT): + if event.button != 1 or event.type != Gdk.EventType.BUTTON_PRESS or \ + event.window != view.get_window(Gtk.TextWindowType.TEXT): return False link = self.get_link_at_location(view, int(event.x), int(event.y)) @@ -217,8 +221,8 @@ class OutputPanel(UniqueById): gfile = self.file_lookup.lookup(link.path) if gfile: - pluma.commands.load_uri(self.window, gfile.get_uri(), None, + Pluma.commands.load_uri(self.window, gfile.get_uri(), None, link.line_nr) - gobject.idle_add(self.idle_grab_focus) + GLib.idle_add(self.idle_grab_focus) # ex:ts=4:et: |