summaryrefslogtreecommitdiff
path: root/plugins/externaltools/tools/capture.py
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-14 15:35:49 +0300
committermonsta <[email protected]>2016-12-19 14:16:30 +0300
commit4ea3ff79c350c9af799ed76e72e5c862af3eb73e (patch)
tree1eeb0c435c0e3adc512efb55c72cb3747cc27a58 /plugins/externaltools/tools/capture.py
parent38c20e460232c5f4ec7bf616180ff777b5d6b3a0 (diff)
downloadpluma-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/capture.py')
-rwxr-xr-xplugins/externaltools/tools/capture.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 2f065761..487c8dbb 100755
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -21,11 +21,10 @@ __all__ = ('Capture', )
import os, sys, signal
import locale
import subprocess
-import gobject
import fcntl
-import glib
+from gi.repository import GObject, GLib
-class Capture(gobject.GObject):
+class Capture(GObject.Object):
CAPTURE_STDOUT = 0x01
CAPTURE_STDERR = 0x02
CAPTURE_BOTH = 0x03
@@ -34,14 +33,14 @@ class Capture(gobject.GObject):
WRITE_BUFFER_SIZE = 0x4000
__gsignals__ = {
- 'stdout-line' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
- 'stderr-line' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
- 'begin-execute': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, tuple()),
- 'end-execute' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,))
+ 'stdout-line' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
+ 'stderr-line' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
+ 'begin-execute': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, tuple()),
+ 'end-execute' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT,))
}
def __init__(self, command, cwd = None, env = {}):
- gobject.GObject.__init__(self)
+ GObject.GObject.__init__(self)
self.pipe = None
self.env = env
self.cwd = cwd
@@ -101,8 +100,8 @@ class Capture(gobject.GObject):
flags = fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK
fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_SETFL, flags)
- gobject.io_add_watch(self.pipe.stdout,
- gobject.IO_IN | gobject.IO_HUP,
+ GLib.io_add_watch(self.pipe.stdout,
+ GObject.IO_IN | GObject.IO_HUP,
self.on_output)
if self.flags & self.CAPTURE_STDERR:
@@ -110,8 +109,8 @@ class Capture(gobject.GObject):
flags = fcntl.fcntl(self.pipe.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK
fcntl.fcntl(self.pipe.stderr.fileno(), fcntl.F_SETFL, flags)
- gobject.io_add_watch(self.pipe.stderr,
- gobject.IO_IN | gobject.IO_HUP,
+ GLib.io_add_watch(self.pipe.stderr,
+ GObject.IO_IN | GObject.IO_HUP,
self.on_output)
# IO
@@ -120,10 +119,10 @@ class Capture(gobject.GObject):
self.write_buffer = str(self.input_text)
if self.idle_write_chunk():
- self.idle_write_id = gobject.idle_add(self.idle_write_chunk)
+ self.idle_write_id = GLib.idle_add(self.idle_write_chunk)
# Wait for the process to complete
- gobject.child_watch_add(self.pipe.pid, self.on_child_end)
+ GLib.child_watch_add(self.pipe.pid, self.on_child_end)
def idle_write_chunk(self):
if not self.pipe:
@@ -153,7 +152,7 @@ class Capture(gobject.GObject):
return False
def on_output(self, source, condition):
- if condition & (glib.IO_IN | glib.IO_PRI):
+ if condition & (GLib.IOCondition.IN | GLib.IOCondition.PRI):
line = source.read()
if len(line) > 0:
@@ -179,7 +178,7 @@ class Capture(gobject.GObject):
else:
self.emit('stderr-line', line)
- if condition & ~(glib.IO_IN | glib.IO_PRI):
+ if condition & ~(GLib.IOCondition.IN | GLib.IOCondition.PRI):
if self.read_buffer:
if source == self.pipe.stdout:
self.emit('stdout-line', self.read_buffer)
@@ -197,7 +196,7 @@ class Capture(gobject.GObject):
def stop(self, error_code = -1):
if self.pipe is not None:
if self.idle_write_id:
- gobject.source_remove(self.idle_write_id)
+ GLib.source_remove(self.idle_write_id)
self.idle_write_id = 0
if not self.tried_killing:
@@ -209,6 +208,6 @@ class Capture(gobject.GObject):
def on_child_end(self, pid, error_code):
# In an idle, so it is emitted after all the std*-line signals
# have been intercepted
- gobject.idle_add(self.emit, 'end-execute', error_code)
+ GLib.idle_add(self.emit, 'end-execute', error_code)
# ex:ts=4:et: