~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to plugins/pythonconsole/pythonconsole.py

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
import sys
37
37
import re
38
38
import traceback
39
 
import gobject
40
39
 
41
 
from gi.repository import Gtk, Gdk, Pango, GConf
 
40
from gi.repository import Gtk, Gdk, GObject, Pango, Peas
42
41
from gi.repository import RB
43
42
 
44
43
try:
60
59
</ui>
61
60
"""
62
61
 
63
 
class PythonConsolePlugin(RB.Plugin):
 
62
class PythonConsolePlugin(GObject.Object, Peas.Activatable):
 
63
        __gtype_name__ = 'PythonConsolePlugin'
 
64
 
 
65
        object = GObject.property (type = GObject.Object)
 
66
 
64
67
        def __init__(self):
65
 
                RB.Plugin.__init__(self)
 
68
                GObject.Object.__init__(self)
66
69
                self.window = None
67
70
                        
68
 
        def activate(self, shell):
 
71
        def do_activate(self):
69
72
                data = dict()
70
 
                manager = shell.get_player().get_property('ui-manager')
 
73
                shell = self.object
 
74
                manager = shell.props.ui_manager
71
75
                
72
76
                data['action_group'] = Gtk.ActionGroup(name='PythonConsolePluginActions')
73
77
 
92
96
                
93
97
                shell.set_data('PythonConsolePluginInfo', data)
94
98
        
95
 
        def deactivate(self, shell):
 
99
        def do_deactivate(self):
 
100
                shell = self.object
96
101
                data = shell.get_data('PythonConsolePluginInfo')
97
102
 
98
 
                manager = shell.get_player().get_property('ui-manager')
 
103
                manager = shell.props.ui_manager
99
104
                manager.remove_ui(data['ui_id'])
100
105
                manager.remove_action_group(data['action_group'])
101
106
                manager.ensure_update()
128
133
                self.window.grab_focus()
129
134
 
130
135
        def enable_debugging(self, action, shell):
131
 
                msg = _("After you press OK, Rhythmbox will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in GConf, it will use the default password ('rhythmbox').")
 
136
                pwd_path = os.path.join(rb.user_data_dir(), "rpdb2_password")
 
137
                msg = _("After you press OK, Rhythmbox will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in the file %s, it will use the default password ('rhythmbox').") % pwd_path
132
138
                dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK_CANCEL, msg)
133
139
                if dialog.run() == Gtk.RESPONSE_OK:
134
 
                        gconfclient = GConf.Client.get_default()
135
 
                        password = gconfclient.get_string('/apps/rhythmbox/plugins/pythonconsole/rpdb2_password') or "rhythmbox"
 
140
                        password = "rhythmbox"
 
141
                        if os.path.exists(pwd_path):
 
142
                                pwd_file = open(pwd_path)
 
143
                                password = pwd_file.read().rstrip()
 
144
                                pwd_file.close()
 
145
 
136
146
                        def start_debugger(password):
137
147
                                rpdb2.start_embedded_debugger(password)
138
148
                                return False
139
149
 
140
 
                        gobject.idle_add(start_debugger, password)
 
150
                        GObject.idle_add(start_debugger, password)
141
151
                dialog.destroy()
142
152
        
143
153
        def destroy_console(self, *args):
227
237
                                cur = self.get_end_iter()
228
238
                                
229
239
                        buffer.place_cursor(cur)
230
 
                        gobject.idle_add(self.scroll_to_end)
 
240
                        GObject.idle_add(self.scroll_to_end)
231
241
                        return True
232
242
                
233
243
                elif event.keyval == Gdk.KEY_Return:
271
281
                        cur = self.get_end_iter()
272
282
                        buffer.move_mark(inp_mark, cur)
273
283
                        buffer.place_cursor(cur)
274
 
                        gobject.idle_add(self.scroll_to_end)
 
284
                        GObject.idle_add(self.scroll_to_end)
275
285
                        return True
276
286
 
277
287
                elif event.keyval == Gdk.KEY_KP_Down or \
279
289
                        # Next entry from history
280
290
                        view.emit_stop_by_name("key_press_event")
281
291
                        self.history_down()
282
 
                        gobject.idle_add(self.scroll_to_end)
 
292
                        GObject.idle_add(self.scroll_to_end)
283
293
                        return True
284
294
 
285
295
                elif event.keyval == Gdk.KEY_KP_Up or \
287
297
                        # Previous entry from history
288
298
                        view.emit_stop_by_name("key_press_event")
289
299
                        self.history_up()
290
 
                        gobject.idle_add(self.scroll_to_end)
 
300
                        GObject.idle_add(self.scroll_to_end)
291
301
                        return True
292
302
 
293
303
                elif event.keyval == Gdk.KEY_KP_Left or \
366
376
                        start_iter = Gtk.TextIter()
367
377
                        start_iter = buffer.get_iter_at_offset(offset)
368
378
                        buffer.apply_tag(tag, start_iter, self.get_end_iter())
369
 
                gobject.idle_add(self.scroll_to_end)
 
379
                GObject.idle_add(self.scroll_to_end)
370
380
        
371
381
        def eval(self, command, display_command = False):
372
382
                buffer = self.view.get_buffer()