1''' 2IPython console plugin. 3 4@author: Eitan Isaacson 5@organization: IBM Corporation 6@copyright: Copyright (c) 2007 IBM Corporation 7@license: BSD 8 9All rights reserved. This program and the accompanying materials are made 10available under the terms of the BSD which accompanies this distribution, and 11is available at U{http://www.opensource.org/licenses/bsd-license.php} 12''' 13 14import gi 15 16from gi.repository import Gtk as gtk 17 18from accerciser.plugin import ViewportPlugin 19from accerciser.i18n import N_, _ 20import os 21import pyatspi 22import ipython_view 23 24if ipython_view.IPython == None: 25 raise RuntimeError('The IPython module is required for the IPython console') 26 27 28class Console(ViewportPlugin): 29 ''' 30 Plugin class for IPython console. 31 ''' 32 plugin_name = N_('IPython Console') 33 plugin_name_localized = _(plugin_name) 34 plugin_description = \ 35 N_('Interactive console for manipulating currently selected accessible') 36 def init(self): 37 ''' 38 Initialize plugin. 39 ''' 40 sw = gtk.ScrolledWindow() 41 self.plugin_area.add(sw) 42 self.ipython_view = ipython_view.IPythonView() 43 self.ipython_view.updateNamespace({'acc': None}) 44 self.ipython_view.updateNamespace(pyatspi.__dict__) 45 self.ipython_view.updateNamespace({'desktop': 46 pyatspi.Registry.getDesktop(0)}) 47 self.ipython_view.updateNamespace({'show': self._showAcc}) 48 sw.add(self.ipython_view) 49 50 def onAccChanged(self, acc): 51 ''' 52 Update 'acc' variable in console namespace with currently 53 selected accessible. 54 55 @param acc: The currently selected accessible. 56 @type acc: Accessibility.Accessible 57 ''' 58 self.ipython_view.updateNamespace({'acc': acc}) 59 60 def _showAcc(self, acc): 61 ''' 62 A method that is exposed in the console's namespace that allows the user 63 to show a given accessible in the main application. 64 65 @param acc: Accessible to show. 66 @type acc: Accessibility.Accessible 67 ''' 68 self.node.update(acc) 69