[gedit/wip/python3] Try to fix external tools
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/python3] Try to fix external tools
- Date: Sun, 28 Oct 2012 17:31:37 +0000 (UTC)
commit 0e3cb9c7e4b0ea640f7e548c38b5133238072bf7
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun Oct 28 18:31:25 2012 +0100
Try to fix external tools
plugins/externaltools/tools/capture.py | 32 ++++++++++++-----------
plugins/externaltools/tools/outputpanel.py | 6 ++--
plugins/pythonconsole/pythonconsole/console.py | 12 ++++----
3 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 27ffc9b..1614f5b 100644
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -22,7 +22,7 @@ import os, sys, signal
import locale
import subprocess
import fcntl
-from gi.repository import GObject
+from gi.repository import GLib, GObject
class Capture(GObject.Object):
CAPTURE_STDOUT = 0x01
@@ -100,18 +100,22 @@ class Capture(GObject.Object):
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 | GObject.IO_ERR,
- self.on_output)
+ channel = GLib.IOChannel.unix_new(self.pipe.stdout.fileno())
+ GLib.io_add_watch(channel,
+ GLib.PRIORITY_DEFAULT,
+ GLib.IOCondition.IN | GLib.IOCondition.HUP | GLib.IOCondition.ERR,
+ self.on_output)
if self.flags & self.CAPTURE_STDERR:
# Set non blocking
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 | GObject.IO_ERR,
- self.on_output)
+ channel = GLib.IOChannel.unix_new(self.pipe.stderr.fileno())
+ GLib.io_add_watch(channel,
+ GLib.PRIORITY_DEFAULT,
+ GLib.IOCondition.IN | GLib.IOCondition.HUP | GLib.IOCondition.ERR,
+ self.on_output)
# IO
if self.input_text is not None:
@@ -119,10 +123,10 @@ class Capture(GObject.Object):
self.write_buffer = self.input_text.encode('utf-8')
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:
@@ -166,11 +170,9 @@ class Capture(GObject.Object):
if len(line) > 0:
try:
- line = unicode(line, 'utf-8')
+ line = line
except:
- line = unicode(line,
- locale.getdefaultlocale()[1],
- 'replace')
+ line = line.encode(locale.getdefaultlocale()[1])
self.read_buffer += line
lines = self.read_buffer.splitlines(True)
@@ -204,7 +206,7 @@ class Capture(GObject.Object):
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:
@@ -220,6 +222,6 @@ class Capture(GObject.Object):
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:
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index cf24a33..e22ed73 100644
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -25,7 +25,7 @@ from .capture import *
import re
from . import linkparsing
from . import filelookup
-from gi.repository import GObject, Gio, Gdk, Gtk, Pango, Gedit
+from gi.repository import GLib, Gio, Gdk, Gtk, Pango, Gedit
class UniqueById:
__shared_state = WeakKeyDictionary()
@@ -168,7 +168,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()
@@ -233,6 +233,6 @@ class OutputPanel(UniqueById):
if gfile:
Gedit.commands_load_location(self.window, gfile, None, link.line_nr, link.col_nr)
- GObject.idle_add(self.idle_grab_focus)
+ GLib.idle_add(self.idle_grab_focus)
# ex:ts=4:et:
diff --git a/plugins/pythonconsole/pythonconsole/console.py b/plugins/pythonconsole/pythonconsole/console.py
index 50d48a7..f6540d2 100644
--- a/plugins/pythonconsole/pythonconsole/console.py
+++ b/plugins/pythonconsole/pythonconsole/console.py
@@ -29,7 +29,7 @@ import sys
import re
import traceback
-from gi.repository import GObject, Gio, Gtk, Gdk, Pango
+from gi.repository import GLib, Gio, Gtk, Gdk, Pango
__all__ = ('PythonConsole', 'OutFile')
@@ -177,7 +177,7 @@ class PythonConsole(Gtk.ScrolledWindow):
cur = buf.get_end_iter()
buf.place_cursor(cur)
- GObject.idle_add(self.scroll_to_end)
+ GLib.idle_add(self.scroll_to_end)
return True
elif event.keyval == Gdk.KEY_Return:
@@ -221,21 +221,21 @@ class PythonConsole(Gtk.ScrolledWindow):
cur = buf.get_end_iter()
buf.move_mark(inp_mark, cur)
buf.place_cursor(cur)
- GObject.idle_add(self.scroll_to_end)
+ GLib.idle_add(self.scroll_to_end)
return True
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)
+ GLib.idle_add(self.scroll_to_end)
return True
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)
+ GLib.idle_add(self.scroll_to_end)
return True
elif event.keyval == Gdk.KEY_KP_Left or event.keyval == Gdk.KEY_Left or \
@@ -344,7 +344,7 @@ class PythonConsole(Gtk.ScrolledWindow):
else:
buf.insert_with_tags(buf.get_end_iter(), text, tag)
- GObject.idle_add(self.scroll_to_end)
+ GLib.idle_add(self.scroll_to_end)
def eval(self, command, display_command = False):
buf = self.view.get_buffer()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]