2 from rox
import g
, options
, app_options
3 from MenuWindow
import MenuWindow
11 systrayEnable
= options
.Option('systray_enable', True)
12 systrayHideOnStartup
= options
.Option('systray_hide_on_startup', False)
13 systrayWorkaround
= options
.Option('systray_workaround', False)
15 # Require gtk version 2.10.x or better for the 'StatusIcon' widget
16 assert( g
.gtk_version
>= (2,10,0) )
20 ("/Main Window", "toggle_main", "", ""),
24 mainAdditions
= { 'topMain': [
25 (_('Hide Main Window'), "hide", "")
28 class Systray(g
.StatusIcon
, MenuWindow
):
29 def __init__(self
, showOnStartup
= None):
30 g
.StatusIcon
.__init
__(self
)
31 MenuWindow
.__init
__(self
, attach
=False, additions
=menuAdditions
)
32 icon
= os
.path
.join(rox
.app_dir
, '.DirIcon')
33 self
.set_from_file(icon
)
34 self
.firstChange
= True
35 self
.showOnStartup
= showOnStartup
36 self
.was_embedded
= None
37 main
.memo_list
.connect( "MemoListChanged", self
.tooltip_refresh
)
38 self
.tooltip_refresh( main
.memo_list
)
39 self
.connect("popup-menu", self
.popup
)
40 self
.connect("activate", self
.toggle_main
)
41 self
.connect("notify::visible", self
.visibility
)
42 if g
.gtk_version
>= (2,12,0):
43 self
.connect("notify::embedded", self
.check_embed
)
45 self
.connect("size-changed", self
.size_change
)
46 self
.timeout
= gobject
.timeout_add(500, self
.check_embed
)
48 def tooltip_refresh(self
, memo_list
):
49 (all
, hidden
) = memo_list
.count_today()
54 self
.set_tooltip("Memo - %d reminder%s today" % (visible
, vplural
) )
56 def position_menu(self
, menu
):
57 return g
.status_icon_position_menu(menu
, self
)
59 def popup(self
, status_icon
, button
, activate_time
):
60 # Rox's 'menu' class doesn't actually need a 'gtk.gdk.Event', just an object
61 # with 'button' and 'time' parameters - Which is good, since gtk.gdk.Event
62 # won't accept a 'long' value, which is what both 'button' and
63 # 'activate_time' are (plus activate_time is usually too large to properly
64 # cast into a signed python 'int' type
68 event
.time
= activate_time
69 self
.popup_menu(event
, self
.position_menu
)
71 def size_change(self
, icon
= None, size
= None):
75 return self
.is_embedded
and self
.get_visible()
77 def visibility(self
, object=None, property=None):
78 if self
.get_visible():
84 # Systray present, allow main window to hide
85 main
.main_window
.addAdditions( mainAdditions
)
87 def _unembedded(self
):
88 # Systray no longer present, show the main window, and disallow hiding
89 main
.main_window
.removeAdditions( mainAdditions
)
90 if not main
.main_window
.get_property('visible'):
91 main
.main_window
.present()
93 def check_embed(self
, object = None, property = None):
94 if self
.is_embedded() and (not self
.was_embedded
or self
.firstChange
):
96 # Check for "hide on startup" flag
97 if self
.showOnStartup
is not None:
98 if not self
.showOnStartup
:
99 main
.main_window
.hide()
101 if not main
.main_window
.get_property('visible'):
102 main
.main_window
.present()
103 self
.was_embedded
= True
104 elif not self
.is_embedded() and (self
.was_embedded
or self
.firstChange
):
106 self
.was_embedded
= False
107 self
.firstChange
= False
110 def toggle_main(self
, event
= None):
111 if main
.main_window
.get_property('visible'):
112 main
.main_window
.hide()
114 main
.main_window
.present()
116 def quit(self
, event
= None):
117 main
.main_window
.destroy()
119 class HideableSystray(object):
121 if systrayEnable
.int_value
:
122 self
.icon
= Systray( showOnStartup
= not systrayHideOnStartup
.int_value
)
125 main
.main_window
.present()
126 app_options
.add_notify(self
.options_changed
)
128 def options_changed(self
):
129 if systrayEnable
.has_changed
:
130 if systrayEnable
.int_value
:
134 if systrayWorkaround
.has_changed
:
135 if systrayEnable
.int_value
and systrayWorkaround
.int_value
:
141 self
.icon
= Systray()
143 self
.icon
.set_visible(True)
147 self
.icon
.set_visible(False)
148 # Workaround for broken systrays (like older fluxbox versions) which
149 # may not support set_visible(True) - Delete the systray icon (which
150 # will be re-created at 'show' time.
151 if systrayWorkaround
.int_value
:
155 def is_embedded(self
):
157 return self
.icon
.is_embedded()
160 def get_visible(self
):
162 return self
.icon
.get_visible()
165 def is_present(self
):
167 return self
.icon
.is_present()