summaryrefslogtreecommitdiff
path: root/plugins/pythonconsole
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-15 12:34:46 +0300
committermonsta <[email protected]>2016-12-19 16:32:30 +0300
commit0bbd1671ab53efe079357689fcf18d10e9d846a4 (patch)
tree96d2bf14d3ac681545608b47efe44909fabf2431 /plugins/pythonconsole
parent4ea3ff79c350c9af799ed76e72e5c862af3eb73e (diff)
downloadpluma-0bbd1671ab53efe079357689fcf18d10e9d846a4.tar.bz2
pluma-0bbd1671ab53efe079357689fcf18d10e9d846a4.tar.xz
pythonconsole plugin: port to gi and libpeas
note: config dialog is broken for ages since it tries to use ancient MateConf, so it's left as is for now. later it can be ported to GSettings and PeasGtk. mostly adapted from: https://git.gnome.org/browse/gedit/commit/?id=4dcd8d84b1a6b11c5254416d9b5ed7af8105f538 https://git.gnome.org/browse/gedit/commit/?id=a9d2ea047401124537e49ef6a2bf9c0f6c4a4f22 https://git.gnome.org/browse/gedit/commit/?id=c2ef43753eaf07d7ea9eecf9221daacff5f2a3b7 https://git.gnome.org/browse/gedit/commit/?id=ad07a02a15ba868bbd5654152f3946350db2dadf
Diffstat (limited to 'plugins/pythonconsole')
-rw-r--r--plugins/pythonconsole/Makefile.am6
-rw-r--r--plugins/pythonconsole/pythonconsole.plugin.desktop.in (renamed from plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in)2
-rwxr-xr-xplugins/pythonconsole/pythonconsole/__init__.py42
-rwxr-xr-xplugins/pythonconsole/pythonconsole/console.py66
4 files changed, 59 insertions, 57 deletions
diff --git a/plugins/pythonconsole/Makefile.am b/plugins/pythonconsole/Makefile.am
index 53361183..0a9ff965 100644
--- a/plugins/pythonconsole/Makefile.am
+++ b/plugins/pythonconsole/Makefile.am
@@ -2,10 +2,10 @@
SUBDIRS = pythonconsole
plugindir = $(PLUMA_PLUGINS_LIBS_DIR)
-plugin_in_files = pythonconsole.pluma-plugin.desktop.in
-%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+plugin_in_files = pythonconsole.plugin.desktop.in
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
index 1d6747e1..50d2a7a7 100644
--- a/plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in
+++ b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Pluma Plugin]
+[Plugin]
Loader=python
Module=pythonconsole
IAge=2
diff --git a/plugins/pythonconsole/pythonconsole/__init__.py b/plugins/pythonconsole/pythonconsole/__init__.py
index 347df0ee..59ac413e 100755
--- a/plugins/pythonconsole/pythonconsole/__init__.py
+++ b/plugins/pythonconsole/pythonconsole/__init__.py
@@ -24,38 +24,42 @@
# Bits from pluma Python Console Plugin
# Copyrignt (C), 2005 Raphaƫl Slinckx
-import gtk
-import pluma
+from gi.repository import GObject, Gtk, Peas, Pluma
from console import PythonConsole
from config import PythonConsoleConfigDialog
from config import PythonConsoleConfig
-PYTHON_ICON = 'mate-mime-text-x-python'
+PYTHON_ICON = 'text-x-python'
+
+class PythonConsolePlugin(GObject.Object, Peas.Activatable):
+ __gtype_name__ = "PythonConsolePlugin"
+
+ object = GObject.Property(type=GObject.Object)
-class PythonConsolePlugin(pluma.Plugin):
def __init__(self):
- pluma.Plugin.__init__(self)
+ GObject.Object.__init__(self)
self.dlg = None
- def activate(self, window):
- console = PythonConsole(namespace = {'__builtins__' : __builtins__,
- 'pluma' : pluma,
+ def do_activate(self):
+ window = self.object
+
+ self._console = PythonConsole(namespace = {'__builtins__' : __builtins__,
+ 'pluma' : Pluma,
'window' : window})
- console.eval('print "You can access the main window through ' \
+ 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, _('Python Console'), image)
- window.set_data('PythonConsolePluginInfo', console)
-
- def deactivate(self, window):
- console = window.get_data("PythonConsolePluginInfo")
- console.stop()
- window.set_data("PythonConsolePluginInfo", None)
+ image = Gtk.Image()
+ image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU)
+ bottom.add_item(self._console, _('Python Console'), image)
+
+ def do_deactivate(self):
+ window = self.object
+
+ self._console.stop()
bottom = window.get_bottom_panel()
- bottom.remove_item(console)
+ bottom.remove_item(self._console)
def create_configure_dialog(self):
diff --git a/plugins/pythonconsole/pythonconsole/console.py b/plugins/pythonconsole/pythonconsole/console.py
index 5a01e311..75f60e4d 100755
--- a/plugins/pythonconsole/pythonconsole/console.py
+++ b/plugins/pythonconsole/pythonconsole/console.py
@@ -28,29 +28,27 @@ import string
import sys
import re
import traceback
-import gobject
-import gtk
-import pango
+from gi.repository import GObject, Gdk, Gtk, Pango
from config import PythonConsoleConfig
__all__ = ('PythonConsole', 'OutFile')
-class PythonConsole(gtk.ScrolledWindow):
+class PythonConsole(Gtk.ScrolledWindow):
__gsignals__ = {
'grab-focus' : 'override',
}
def __init__(self, namespace = {}):
- gtk.ScrolledWindow.__init__(self)
+ Gtk.ScrolledWindow.__init__(self)
- self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- self.set_shadow_type(gtk.SHADOW_IN)
- self.view = gtk.TextView()
- self.view.modify_font(pango.FontDescription('Monospace'))
+ self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ self.set_shadow_type(Gtk.ShadowType.IN)
+ self.view = Gtk.TextView()
+ self.view.modify_font(Pango.font_description_from_string('Monospace'))
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()
@@ -98,19 +96,19 @@ class PythonConsole(gtk.ScrolledWindow):
self.namespace = None
def __key_press_event_cb(self, view, event):
- modifier_mask = gtk.accelerator_get_default_mod_mask()
+ modifier_mask = Gtk.accelerator_get_default_mod_mask()
event_state = event.state & modifier_mask
- if event.keyval == gtk.keysyms.d and event_state == gtk.gdk.CONTROL_MASK:
+ if event.keyval == Gdk.KEY_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.keyval == Gdk.KEY_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)
+ line = buffer.get_text(inp, cur, False)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
@@ -127,10 +125,10 @@ class PythonConsole(gtk.ScrolledWindow):
cur = buffer.get_end_iter()
buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.Return:
+ elif event.keyval == Gdk.KEY_Return:
# Get the marks
buffer = view.get_buffer()
lin_mark = buffer.get_mark("input-line")
@@ -139,7 +137,7 @@ class PythonConsole(gtk.ScrolledWindow):
# Get the command line
inp = buffer.get_iter_at_mark(inp_mark)
cur = buffer.get_end_iter()
- line = buffer.get_text(inp, cur)
+ line = buffer.get_text(inp, cur, False)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
@@ -171,25 +169,25 @@ class PythonConsole(gtk.ScrolledWindow):
cur = buffer.get_end_iter()
buffer.move_mark(inp_mark, cur)
buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Down or event.keyval == gtk.keysyms.Down:
+ elif event.keyval == Gdk.KEY_KP_Down or event.keyval == Gdk.KEY_Down:
# Next entry from history
view.emit_stop_by_name("key_press_event")
self.history_down()
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Up or event.keyval == gtk.keysyms.Up:
+ elif event.keyval == Gdk.KEY_KP_Up or event.keyval == Gdk.KEY_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:
+ elif event.keyval == Gdk.KEY_KP_Left or event.keyval == Gdk.KEY_Left or \
+ event.keyval == Gdk.KEY_BackSpace:
buffer = view.get_buffer()
inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
cur = buffer.get_iter_at_mark(buffer.get_insert())
@@ -202,8 +200,8 @@ class PythonConsole(gtk.ScrolledWindow):
# 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.keyval == Gdk.KEY_KP_Home or event.keyval == Gdk.KEY_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"))
@@ -215,14 +213,14 @@ class PythonConsole(gtk.ScrolledWindow):
if iter.equal(ins):
iter = buffer.get_iter_at_mark(buffer.get_mark("input"))
- if event_state & gtk.gdk.SHIFT_MASK:
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
buffer.move_mark_by_name("insert", iter)
else:
buffer.place_cursor(iter)
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.keyval == Gdk.KEY_KP_End or event.keyval == Gdk.KEY_End) and \
+ event_state == event_state & (Gdk.ModifierType.SHIFT_MASK|Gdk.ModifierType.CONTROL_MASK):
buffer = view.get_buffer()
iter = buffer.get_end_iter()
@@ -238,7 +236,7 @@ class PythonConsole(gtk.ScrolledWindow):
if iter.equal(ins):
iter = buffer.get_end_iter()
- if event_state & gtk.gdk.SHIFT_MASK:
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
buffer.move_mark_by_name("insert", iter)
else:
buffer.place_cursor(iter)
@@ -253,7 +251,7 @@ class PythonConsole(gtk.ScrolledWindow):
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)
+ return buffer.get_text(inp, cur, False)
def set_command_line(self, command):
buffer = self.view.get_buffer()
@@ -284,7 +282,7 @@ class PythonConsole(gtk.ScrolledWindow):
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
def write(self, text, tag = None):
@@ -293,7 +291,7 @@ class PythonConsole(gtk.ScrolledWindow):
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)
+ GObject.idle_add(self.scroll_to_end)
def eval(self, command, display_command = False):
buffer = self.view.get_buffer()
@@ -316,7 +314,7 @@ class PythonConsole(gtk.ScrolledWindow):
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)
+ self.view.scroll_to_iter(buffer.get_end_iter(), 0.0, False, 0.5, 0.5)
def __run(self, command):
sys.stdout, self.stdout = self.stdout, sys.stdout