Module ScriptChooser
[hide private]
[frames] | no frames]

Source Code for Module ScriptChooser

  1  ''' 
  2  Defines a gtk dialog L{AEChooser} for loading/unloading 
  3  L{AccessEngine.AEScript}s from a single L{AETier} at runtime. 
  4   
  5  @author: Brett Clippingdale 
  6  @author: Peter Parente 
  7  @organization: IBM Corporation 
  8  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  9  @license: The BSD License 
 10   
 11  @author: Frank Zenker 
 12  @organization: IT Science Center Ruegen gGmbH, Germany 
 13  @copyright: Copyright (c) 2007, 2008 ITSC Ruegen 
 14  @license: The BSD License 
 15   
 16  All rights reserved. This program and the accompanying materials are made  
 17  available under the terms of the BSD license which accompanies 
 18  this distribution, and is available at 
 19  U{http://www.opensource.org/licenses/bsd-license.php} 
 20  ''' 
 21   
 22  import pygtk 
 23  pygtk.require('2.0') 
 24  import gtk, gobject 
 25  import gtk.glade 
 26  from AccessEngine import AEChooser 
 27  from Tools.i18n import _ 
 28  import gettext 
 29  from GTKUIEView import * 
 30   
 31  __uie__ = dict(kind='chooser') 
 32   
33 -class ScriptChooser(AEChooser.AEChooser):
34 ''' 35 Dialog for selecting Scripts to load and unload on-the-fly. 36 37 @ivar dialog: Dialog widget for choosing L{AccessEngine.AEScript}s 38 @type dialog: gtk.Dialog 39 @ivar uie_view: View of the status and order of loaded and unloaded 40 L{AccessEngine.AEScript}s 41 @type uie_view: L{GTKUIEView.UIEView} 42 43 @cvar RAISE: raise load priority (lower in stack) of L{AccessEngine.AEScript} 44 in list of scripts 45 @type RAISE: integer 46 @cvar LOWER: lower load priority (raise in stack) of L{AccessEngine.AEScript} 47 in list of scripts 48 @type LOWER: integer 49 @cvar TO_LOAD: indicates a L{AccessEngine.AEScript} is to be loaded in the 50 current L{AETier}, if OK or APPLY buttons are then selected. 51 @type TO_LOAD: integer 52 @cvar TO_UNLOAD: indicates a L{AccessEngine.AEScript} is to be unloaded from 53 the current L{AETier}, if OK or APPLY buttons are then selected. 54 @type TO_UNLOAD: integer 55 ''' 56 # signal constants pulled from GTKUIEView 57 RAISE = RAISE 58 LOWER = LOWER 59 TO_LOAD = TO_LOAD 60 TO_UNLOAD = TO_UNLOAD 61 APP_SINGLETON = True 62
63 - def init(self, app_name, loaded, unloaded, timestamp, **kwargs):
64 ''' 65 Creates and shows the chooser dialog and its components. 66 67 @param app_name: Name of application for current L{AETier} 68 @type app_name: string 69 @param loaded: Loaded L{AccessEngine.AEScript} class names, human readable 70 names, and descriptions 71 @type loaded: list of 3-tuple of string 72 @param unloaded: Unloaded L{AccessEngine.AEScript} class names, human 73 readable names, and descriptions 74 @type unloaded: list of 3-tuple of string 75 @param timestamp: Time at which input was given indicating the start of 76 this chooser 77 @type timestamp: float 78 ''' 79 # initialize the view to None 80 self.uie_view = None 81 # load the glade file 82 gtk.glade.set_custom_handler(self._createCustomWidget, loaded, unloaded) 83 source = gtk.glade.XML(self._getResource('script_chooser.glade'), 84 'main dialog', 85 gettext.textdomain()) 86 87 # get the dialog widget 88 self.dialog = source.get_widget('main dialog') 89 self.dialog.set_title(self.dialog.get_title() % app_name) 90 91 # set the data 92 self.uie_view.setData(loaded, unloaded) 93 94 # connect all signal handlers 95 source.signal_autoconnect(self) 96 97 self.activate(timestamp, present=False)
98
99 - def activate(self, timestamp, present=True, **kwargs):
100 '''Try to bring the window to the foreground.''' 101 try: 102 # try to bring the window to the foreground if this feature is supported 103 self.dialog.window.set_user_time(timestamp) 104 except AttributeError: 105 pass 106 if present: 107 self.dialog.present()
108
109 - def _createCustomWidget(self, source, name, func, *args):
110 ''' 111 Creates an ordered UIE chooser widget. 112 113 @param source: glade XML parser 114 @type source: gtk.glade.XML 115 @param name: Name of the widget to create 116 @type name: string 117 @param func: Name of the function to call to create this widget 118 @type func: string 119 @return: Custom widget 120 @rtype: gtk.Widget 121 ''' 122 self.uie_view = UIEView(self) 123 return self.uie_view.getWidget()
124
125 - def _onOK(self, widget):
126 ''' 127 Handles 'OK' button 'clicked' events. Gets the current user-configured 128 loaded/unloaded lists, passes them on to DefaultDialogScript in a request to 129 update the loaded L{AccessEngine.AEScript}s for the current L{AETier}, and 130 then closes this L{ScriptChooser} dialog. 131 132 @param widget: source of GUI event 133 @type widget: gtk.Widget 134 ''' 135 # get updated, user-configured loaded/unloaded lists 136 loaded, unloaded = self.uie_view.getCurrentUIEs() 137 # notify DefaultDialogScript 138 self._signal(self.OK, loaded=loaded, unloaded=unloaded) 139 self.close()
140
141 - def _onCancel(self, widget):
142 ''' 143 Handles for 'Cancel' button 'clicked' events. Signals to DefaultDialogScript 144 that this L{AEChooser} will close, then closes this L{ScriptChooser} dialog. 145 146 @param widget: source of GUI event 147 @type widget: gtk.Widget 148 ''' 149 # notify DefaultDialogScript 150 self._signal(self.CANCEL) 151 self.close()
152
153 - def _onApply(self, widget):
154 ''' 155 Handles 'Apply' button 'clicked' events. Gets the current user-configured 156 loaded/unloaded lists, passes them on to DefaultDialogScript in a request to 157 update the loaded L{AccessEngine.AEScript}s for the current L{AETier}. 158 159 @param widget: source of GUI event 160 @type widget: gtk.Widget 161 ''' 162 # get updated, user-configured loaded/unloaded lists 163 loaded, unloaded = self.uie_view.getCurrentUIEs() 164 # notify DefaultDialogScript 165 self._signal(self.APPLY, loaded = loaded, unloaded=unloaded)
166
167 - def close(self):
168 ''' 169 Closes the chooser, preventing further chooser interaction with the user. 170 ''' 171 gtk.glade.set_custom_handler(lambda x: None) 172 self.dialog.destroy()
173
174 - def getName(self):
175 ''' 176 Gets the name of the chooser. 177 178 @return: Human readable name of the chooser 179 @rtype: string 180 ''' 181 return _('Script Chooser')
182