Changeset 4503
- Timestamp:
- 04/14/09 11:47:09 (4 years ago)
- Location:
- branch/UmitPlugins/source-plugins/tray-icon
- Files:
-
- 3 added
- 2 modified
-
setup.py (modified) (1 diff)
-
sources/main.py (modified) (8 diffs)
-
sources/notification (added)
-
sources/notification/__init__.py (added)
-
sources/notification/win32.py (added)
Legend:
- Unmodified
- Added
- Removed
-
branch/UmitPlugins/source-plugins/tray-icon/setup.py
r4364 r4503 23 23 setup( 24 24 name='Tray Icon', 25 version=' 1.0',25 version='2.0', 26 26 author='Francesco Piccinno', 27 url='http:// snippets.pornosecurity.org',27 url='http://blog.archpwn.org', 28 28 start_file='main', 29 provides='=tray- 1.0',29 provides='=tray-2.0', 30 30 description='A simple tray icon for Umit', 31 31 scripts=['sources/main.py'], 32 32 data_files=[('data', ['dist/logo.png', 'dist/preferences.xml'])], 33 package_dir={'notification' : 'sources/notification'}, 34 packages=['notification'], 35 license='GPL', 33 36 output='TrayIcon.ump' 34 37 ) -
branch/UmitPlugins/source-plugins/tray-icon/sources/main.py
r4499 r4503 34 34 from umit.plugin.Parser import Parser 35 35 36 WIN32_PRESENT = False 37 38 if os.name == 'nt': 39 try: 40 from notification.win32 import StatusIcon 41 WIN32_PRESENT = True 42 except ImportError: 43 raise Exception('If you are using Windows you need Win32 Extensions package for python to use that plugin.\nDownload a copy from\n\nhttp://starship.python.net/crew/mhammond/win32/\n\nand reenable the plugin.') 44 45 try: 46 import pynotify 47 NOTIFY_PRESENT = True 48 except ImportError: 49 NOTIFY_PRESENT = False 50 36 51 class Preferences(object): 37 52 def __init__(self): … … 76 91 self.change_cb(self.parser['notifications']['type'].value) 77 92 78 tray_prefs = Preferences() 93 if not WIN32_PRESENT: 94 tray_prefs = Preferences() 79 95 80 96 class TrayPlugin(Plugin): 81 97 TYPE_LIBNOTIFY = 0 82 98 TYPE_HIGTOOLTIP = 1 99 TYPE_WINDOWS = 2 83 100 84 101 def start(self, reader): … … 86 103 self.toggle_visibility = True 87 104 105 self.icon = None 106 88 107 self.menu = gtk.Menu() 89 108 self.menu.show() … … 97 116 self.menu.append(item) 98 117 99 logo = os.path.join(Path.icons_dir, 'umit_16.ico') 100 log.debug('Creating status icon with %s as logo' % logo) 101 102 self.icon = gtk.status_icon_new_from_file(logo) 118 self.type = self.notifier = None 119 120 # Force to use win32 module 121 if WIN32_PRESENT: 122 self.set_type(TrayPlugin.TYPE_WINDOWS) 123 else: 124 self.set_type(tray_prefs.parser['notifications']['type'].value) 125 tray_prefs.parser['notifications']['type'].value = self.type 126 127 logo = os.path.join(Path.icons_dir, 'umit_16.ico') 128 log.debug('Creating status icon with %s as logo' % logo) 129 130 self.icon = gtk.status_icon_new_from_file(logo) 131 tray_prefs.change_cb = self.set_type 132 103 133 self.icon.connect('popup-menu', self.__on_right_click) 104 134 self.icon.connect('activate', self.__on_activate) 105 135 106 self.type = self.notifier = None107 108 self.set_type(tray_prefs.parser['notifications']['type'].value)109 tray_prefs.parser['notifications']['type'].value = self.type110 111 tray_prefs.change_cb = self.set_type112 113 136 def set_type(self, typo): 114 if typo == TrayPlugin.TYPE_LIBNOTIFY: 115 try: 116 # Try to use libnotify for notifications 117 import pynotify 118 137 log.debug('called with type = %d' % typo) 138 139 if typo == TrayPlugin.TYPE_WINDOWS and WIN32_PRESENT: 140 141 self.icon = StatusIcon() 142 self.type = TrayPlugin.TYPE_WINDOWS 143 144 log.debug('Now notifications will use win32 api') 145 146 elif typo == TrayPlugin.TYPE_LIBNOTIFY and NOTIFY_PRESENT: 147 148 if pynotify.init('UMIT'): 149 self.notifier = pynotify.Notification 119 150 self.type = TrayPlugin.TYPE_LIBNOTIFY 120 151 121 if pynotify.init('UMIT'): 122 self.notifier = pynotify.Notification 123 log.debug('Now notifications will use LibNotify') 124 else: 125 self.set_type(TrayPlugin.TYPE_HIGTOOLTIP) 126 except ImportError: 152 log.debug('Now notifications will use LibNotify') 153 else: 127 154 self.set_type(TrayPlugin.TYPE_HIGTOOLTIP) 128 155 else: 156 129 157 self.type = TrayPlugin.TYPE_HIGTOOLTIP 130 158 self.notifier = HIGTooltip() … … 132 160 log.debug('Now notifications will use HIGTooltip') 133 161 162 def remove_status_icon(self): 163 if not self.icon: 164 return 165 166 if self.type == TrayPlugin.TYPE_WINDOWS: 167 self.icon.remove() 168 else: 169 self.icon.set_visible(False) 170 del self.icon 171 172 self.icon = None 173 134 174 def stop(self): 135 self.icon.set_visible(False) 136 self.icon = None 175 self.remove_status_icon() 137 176 138 177 def __on_right_click(self, w, evt, evt_time): 139 self.popup_menu.popup(None, None, gtk.status_icon_position_menu, evt, \ 178 self.popup_menu.popup(None, None, 179 (self.type != TrayPlugin.TYPE_WINDOWS) and \ 180 (gtk.status_icon_position_menu)or (None), evt, \ 140 181 evt_time, w) 141 182 … … 166 207 (pass None for persistent notification) 167 208 """ 168 rect = self.icon.get_geometry() 169 170 if rect is not None: 171 rect = rect[1] 172 else: 173 return 174 175 if self.type == TrayPlugin.TYPE_HIGTOOLTIP: 209 210 if self.type == TrayPlugin.TYPE_WINDOWS: 211 if self.icon.notify_icon: 212 title = pango.parse_markup(title)[1] 213 msg = pango.parse_markup(msg)[1] 214 self.icon.notify_icon.show_balloon(title, msg, 215 (timeout is None) and (0) or (timeout), stock) 216 217 elif self.type == TrayPlugin.TYPE_HIGTOOLTIP: 218 rect = self.icon.get_geometry() 219 220 if rect is not None: 221 rect = rect[1] 222 else: 223 return 224 176 225 data = HIGTooltipData(msg, title, stock, fname) 177 226 self.notifier.show_at(self.icon, data, rect.x, rect.y, timeout) … … 225 274 # Adjusting to the current preferences 226 275 227 btn = (tray_prefs.parser['notifications']['type'].value == 0) and \ 228 (self.typenot) or (self.typehig) 229 btn.set_active(True) 230 231 try: 232 import pynotify 233 except ImportError: 276 if tray_prefs.parser['notifications']['type'].value == 0: 277 self.typenot.set_active(True) 278 else: 279 self.typehig.set_active(True) 280 281 if not NOTIFY_PRESENT: 234 282 self.typenot.set_sensitive(False) 235 283 self.typehig.set_active(True) … … 254 302 255 303 __plugins__ = [TrayPlugin] 256 __pref_func__ = show_preferences 304 305 # No preferences if you are using windows 306 if os.name != 'nt': 307 __pref_func__ = show_preferences
