[totem/wip/python3: 4/5] Port python console to python 3
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/python3: 4/5] Port python console to python 3
- Date: Mon, 29 Apr 2013 15:43:07 +0000 (UTC)
commit 755334e420df37b6649c4551534f10948fb899eb
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Apr 29 17:39:57 2013 +0200
Port python console to python 3
src/plugins/pythonconsole/console.py | 48 ++++++++++----------
src/plugins/pythonconsole/pythonconsole.plugin.in | 2 +-
src/plugins/pythonconsole/pythonconsole.py | 38 +++++++---------
3 files changed, 41 insertions(+), 47 deletions(-)
---
diff --git a/src/plugins/pythonconsole/console.py b/src/plugins/pythonconsole/console.py
index 8bbfb9f..2571377 100644
--- a/src/plugins/pythonconsole/console.py
+++ b/src/plugins/pythonconsole/console.py
@@ -36,7 +36,7 @@ import string
import sys
import re
import traceback
-from gi.repository import GObject, Pango, Gtk, Gdk # pylint: disable-msg=E0611
+from gi.repository import GLib, Pango, Gtk, Gdk # pylint: disable-msg=E0611
class PythonConsole(Gtk.ScrolledWindow):
def __init__(self, namespace = {}, destroy_cb = None):
@@ -59,7 +59,7 @@ class PythonConsole(Gtk.ScrolledWindow):
self.command = buffer.create_tag("command")
self.command.set_property("foreground", "blue")
- self.__spaces_pattern = re.compile(r'^\s+')
+ self.__spaces_pattern = re.compile(r'^\s+')
self.namespace = namespace
self.block_command = False
@@ -82,8 +82,8 @@ class PythonConsole(Gtk.ScrolledWindow):
# Signals
self.view.connect("key-press-event", self.__key_press_event_cb)
buffer.connect("mark-set", self.__mark_set_cb)
-
-
+
+
def __key_press_event_cb(self, view, event):
modifier_mask = Gtk.accelerator_get_default_mod_mask()
event_state = event.state & modifier_mask
@@ -114,7 +114,7 @@ class PythonConsole(Gtk.ScrolledWindow):
cur = buffer.get_end_iter()
buffer.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:
@@ -158,21 +158,21 @@ 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)
+ 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 \
@@ -243,22 +243,22 @@ class PythonConsole(Gtk.ScrolledWindow):
else:
buf.insert_with_tags(buf.get_end_iter(), text, tag)
- GObject.idle_add(self.scroll_to_end)
-
- def eval(self, command, display_command = False):
+ GLib.idle_add(self.scroll_to_end)
+
+ def eval(self, command, display_command = False):
buffer = self.view.get_buffer()
lin = buffer.get_mark("input-line")
buffer.delete(buffer.get_iter_at_mark(lin),
buffer.get_end_iter())
-
+
if isinstance(command, list) or isinstance(command, tuple):
- for c in command:
- if display_command:
- self.write(">>> " + c + "\n", self.command)
- self.__run(c)
+ for c in command:
+ if display_command:
+ self.write(">>> " + c + "\n", self.command)
+ self.__run(c)
else:
- if display_command:
- self.write(">>> " + c + "\n", self.command)
+ if display_command:
+ self.write(">>> " + c + "\n", self.command)
self.__run(command)
cur = buffer.get_end_iter()
@@ -268,17 +268,17 @@ class PythonConsole(Gtk.ScrolledWindow):
buffer.move_mark_by_name("input", cur)
self.view.scroll_to_iter(buffer.get_end_iter(), 0.0, False, 0.5, 0.5)
- def __run(self, command):
+ def __run(self, command):
sys.stdout, self.stdout = self.stdout, sys.stdout
sys.stderr, self.stderr = self.stderr, sys.stderr
-
+
try:
try:
r = eval(command, self.namespace, self.namespace)
if r is not None:
- print `r`
+ print(r)
except SyntaxError:
- exec command in self.namespace
+ exec(command, self.namespace)
except:
if hasattr(sys, 'last_type') and sys.last_type == SystemExit:
self.destroy()
@@ -308,6 +308,6 @@ class OutFile:
def readlines(self): return []
def write(self, s): self.console.write(s, self.tag)
def writelines(self, l): self.console.write(l, self.tag)
- def seek(self, a): raise IOError, (29, 'Illegal seek')
- def tell(self): raise IOError, (29, 'Illegal seek')
+ def seek(self, a): raise IOError((29, 'Illegal seek'))
+ def tell(self): raise IOError((29, 'Illegal seek'))
truncate = tell
diff --git a/src/plugins/pythonconsole/pythonconsole.plugin.in
b/src/plugins/pythonconsole/pythonconsole.plugin.in
index 9813896..b384c4a 100644
--- a/src/plugins/pythonconsole/pythonconsole.plugin.in
+++ b/src/plugins/pythonconsole/pythonconsole.plugin.in
@@ -1,5 +1,5 @@
[Plugin]
-Loader=python
+Loader=python3
Module=pythonconsole
IAge=1
_Name=Python Console
diff --git a/src/plugins/pythonconsole/pythonconsole.py b/src/plugins/pythonconsole/pythonconsole.py
index 40d6a78..780ad36 100644
--- a/src/plugins/pythonconsole/pythonconsole.py
+++ b/src/plugins/pythonconsole/pythonconsole.py
@@ -82,37 +82,35 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
data = dict ()
manager = self.totem.get_ui_manager ()
- data['action_group'] = Gtk.ActionGroup (name = 'Python')
+ self.action_group = Gtk.ActionGroup (name = 'Python')
action = Gtk.Action (name = 'Python', label = 'Python',
- tooltip = _(u'Python Console Menu'),
+ tooltip = _('Python Console Menu'),
stock_id = None)
- data['action_group'].add_action (action)
+ self.action_group.add_action (action)
action = Gtk.Action (name = 'PythonConsole',
- label = _(u'_Python Console'),
- tooltip = _(u"Show Totem's Python console"),
+ label = _('_Python Console'),
+ tooltip = _("Show Totem's Python console"),
stock_id = 'gnome-mime-text-x-python')
action.connect ('activate', self._show_console)
- data['action_group'].add_action (action)
+ self.action_group.add_action (action)
action = Gtk.Action (name = 'PythonDebugger',
- label = _(u'Python Debugger'),
- tooltip = _(u"Enable remote Python debugging "\
+ label = _('Python Debugger'),
+ tooltip = _("Enable remote Python debugging "\
"with rpdb2"),
stock_id = None)
if HAVE_RPDB2:
action.connect ('activate', self._enable_debugging)
else:
action.set_visible (False)
- data['action_group'].add_action (action)
+ self.action_group.add_action (action)
- manager.insert_action_group (data['action_group'], 0)
- data['ui_id'] = manager.add_ui_from_string (UI_STR)
+ manager.insert_action_group (self.action_group, 0)
+ self.ui_id = manager.add_ui_from_string (UI_STR)
manager.ensure_update ()
- self.totem.set_data ('PythonConsolePluginInfo', data)
-
def _show_console (self, _action):
if not self.window:
console = PythonConsole (namespace = {
@@ -122,11 +120,11 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
}, destroy_cb = self._destroy_console)
console.set_size_request (600, 400) # pylint: disable-msg=E1101
- console.eval ('print "%s" %% totem_object' % _(u"You can access "\
+ console.eval ('print("%s" %% totem_object)' % _("You can access "\
"the Totem.Object through \'totem_object\' :\\n%s"), False)
self.window = Gtk.Window ()
- self.window.set_title (_(u'Totem Python Console'))
+ self.window.set_title (_('Totem Python Console'))
self.window.add (console)
self.window.connect ('destroy', self._destroy_console)
self.window.show_all ()
@@ -136,7 +134,7 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
@classmethod
def _enable_debugging (cls, _action):
- msg = _(u"After you press OK, Totem will wait until you connect to it "\
+ msg = _("After you press OK, Totem will wait until you connect to it "\
"with winpdb or rpdb2. If you have not set a debugger "\
"password in DConf, it will use the default password "\
"('totem').")
@@ -158,14 +156,10 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
self.window = None
def do_deactivate (self):
- data = self.totem.get_data ('PythonConsolePluginInfo')
-
manager = self.totem.get_ui_manager ()
- manager.remove_ui (data['ui_id'])
- manager.remove_action_group (data['action_group'])
+ manager.remove_ui (self.ui_id)
+ manager.remove_action_group (self.action_group)
manager.ensure_update ()
- self.totem.set_data ('PythonConsolePluginInfo', None)
-
if self.window is not None:
self.window.destroy ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]