home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / totem / plugins / pythonconsole / pythonconsole.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.5 KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from console import PythonConsole
  5. __all__ = ('PythonConsole', 'OutFile')
  6. import gtk
  7. import totem
  8. import gconf
  9. import gobject
  10.  
  11. try:
  12.     import rpdb2
  13.     have_rpdb2 = True
  14. except:
  15.     have_rpdb2 = False
  16.  
  17. ui_str = '\n<ui>\n  <menubar name="tmw-menubar">\n    <menu name="Python" action="Python">\n      <placeholder name="ToolsOps_5">\n        <menuitem name="PythonConsole" action="PythonConsole"/>\n        <menuitem name="PythonDebugger" action="PythonDebugger"/>\n      </placeholder>\n    </menu>\n  </menubar>\n</ui>\n'
  18.  
  19. class PythonConsolePlugin(totem.Plugin):
  20.     
  21.     def __init__(self):
  22.         totem.Plugin.__init__(self)
  23.         self.window = None
  24.  
  25.     
  26.     def activate(self, totem_object):
  27.         data = dict()
  28.         manager = totem_object.get_ui_manager()
  29.         data['action_group'] = gtk.ActionGroup('Python')
  30.         action = gtk.Action('Python', 'Python', _('Python Console Menu'), None)
  31.         data['action_group'].add_action(action)
  32.         action = gtk.Action('PythonConsole', _('_Python Console'), _("Show Totem's Python console"), 'gnome-mime-text-x-python')
  33.         action.connect('activate', self.show_console, totem_object)
  34.         data['action_group'].add_action(action)
  35.         action = gtk.Action('PythonDebugger', _('Python Debugger'), _('Enable remote Python debugging with rpdb2'), None)
  36.         if have_rpdb2:
  37.             action.connect('activate', self.enable_debugging, totem_object)
  38.         else:
  39.             action.set_visible(False)
  40.         data['action_group'].add_action(action)
  41.         manager.insert_action_group(data['action_group'], 0)
  42.         data['ui_id'] = manager.add_ui_from_string(ui_str)
  43.         manager.ensure_update()
  44.         totem_object.set_data('PythonConsolePluginInfo', data)
  45.  
  46.     
  47.     def show_console(self, action, totem_object):
  48.         if not self.window:
  49.             console = PythonConsole(namespace = {
  50.                 '__builtins__': __builtins__,
  51.                 'totem': totem,
  52.                 'totem_object': totem_object }, destroy_cb = self.destroy_console)
  53.             console.set_size_request(600, 400)
  54.             console.eval('print "%s" %% totem_object' % _("You can access the totem object through 'totem_object' :\\n%s"), False)
  55.             self.window = gtk.Window()
  56.             self.window.set_title(_('Totem Python Console'))
  57.             self.window.add(console)
  58.             self.window.connect('destroy', self.destroy_console)
  59.             self.window.show_all()
  60.         else:
  61.             self.window.show_all()
  62.             self.window.grab_focus()
  63.  
  64.     
  65.     def enable_debugging(self, action, totem_object):
  66.         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 GConf, it will use the default password ('totem').")
  67.         dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK_CANCEL, msg)
  68.         if dialog.run() == gtk.RESPONSE_OK:
  69.             gconfclient = gconf.client_get_default()
  70.             if not gconfclient.get_string('/apps/totem/plugins/pythonconsole/rpdb2_password'):
  71.                 pass
  72.             password = 'totem'
  73.             
  74.             def start_debugger(password):
  75.                 rpdb2.start_embedded_debugger(password)
  76.                 return False
  77.  
  78.             gobject.idle_add(start_debugger, password)
  79.         
  80.         dialog.destroy()
  81.  
  82.     
  83.     def destroy_console(self, *args):
  84.         self.window.destroy()
  85.         self.window = None
  86.  
  87.     
  88.     def deactivate(self, totem_object):
  89.         data = totem_object.get_data('PythonConsolePluginInfo')
  90.         manager = totem_object.get_ui_manager()
  91.         manager.remove_ui(data['ui_id'])
  92.         manager.remove_action_group(data['action_group'])
  93.         manager.ensure_update()
  94.         totem_object.set_data('PythonConsolePluginInfo', None)
  95.         if self.window is not None:
  96.             self.window.destroy()
  97.         
  98.  
  99.  
  100.