1 # Based on code in MiniClock v. 2.0.0 - a very very simple clock
2 # Copyright (C) 2005 Edoardo Spadolini <pedonzolo@email.it>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 import rox
, time
, sys
, os
19 from rox
import g
, applet
, Menu
, options
, processes
, filer
20 from MenuWindow
import MenuWindow
27 ("/Main Window", "toggle_main", "", ""),
30 ('/', "", "<Separator>" ),
31 (_('/Set Time'), "set_time", "<StockItem>", "", g
.STOCK_PROPERTIES
),
34 set_prog
= options
.Option('set_program', "gksu time-admin")
36 line1
= options
.Option("line1", "%X")
37 line2
= options
.Option("line2", "%x")
38 tip
= options
.Option("tip", "%c")
40 line1_font
= options
.Option("line1_font", None)
41 line1_color
= options
.Option("line1_color", "#000000")
43 line2_font
= options
.Option("line2_font", None)
44 line2_color
= options
.Option("line2_color", "#000000")
48 self
.tooltip
= g
.Tooltips()
49 if tip
.value
== "": self
.tooltip
.disable()
50 self
.vbox
= g
.VBox(spacing
= 2)
52 self
.line1_label
= g
.Label("")
54 self
.vbox
.add(self
.line1_label
)
56 self
.line2_label
= g
.Label("")
58 self
.vbox
.add(self
.line2_label
)
60 self
.set_border_width(5)
63 rox
.app_options
.add_notify(self
.options_changed
)
65 self
.add_events(g
.gdk
.BUTTON_PRESS_MASK
)
66 self
.connect("button-press-event", self
.button_press
)
68 self
.connect("destroy", self
.destroyed
)
71 self
.timeout
= gobject
.timeout_add(1000, self
.update_clock
)
75 def update_clock(self
):
76 self
.line1_label
.set_text(time
.strftime(line1
.value
))
77 self
.line2_label
.set_text(time
.strftime(line2
.value
))
80 self
.tooltip
.set_tip(self
, time
.strftime(tip
.value
))
83 def update_font(self
):
84 new_font1
= pango
.FontDescription(line1_font
.value
)
85 new_font2
= pango
.FontDescription(line2_font
.value
)
87 self
.line1_label
.modify_font(new_font1
)
89 self
.line2_label
.modify_font(new_font2
)
91 def update_color(self
):
92 new_color1
= g
.gdk
.color_parse(line1_color
.value
)
93 new_color2
= g
.gdk
.color_parse(line2_color
.value
)
95 self
.line1_label
.modify_fg(g
.STATE_NORMAL
, new_color1
)
97 self
.line2_label
.modify_fg(g
.STATE_NORMAL
, new_color2
)
99 def destroyed(self
, window
):
100 gobject
.source_remove(self
.timeout
)
101 main
.main_window
.destroy()
103 def button_press(self
, window
, event
):
104 if event
.button
== 3:
105 self
.popup_menu(event
)
107 def options_changed(self
):
108 if line1
.has_changed
:
109 if line1
.value
== '':
110 self
.vbox
.remove(self
.line1_label
)
112 self
.vbox
.add(self
.line1_label
)
114 self
.vbox
.remove(self
.line2_label
)
115 self
.vbox
.add(self
.line2_label
)
117 if line2
.has_changed
:
118 if line2
.value
== '':
119 self
.vbox
.remove(self
.line2_label
)
121 self
.vbox
.add(self
.line2_label
)
125 self
.tooltip
.disable()
127 self
.tooltip
.enable()
129 if line1_font
.has_changed
or line2_font
.has_changed
:
131 if line1_color
.has_changed
or line2_color
.has_changed
:
137 rox
.processes
.PipeThroughCommand(set_prog
.value
, None, None).wait()
139 def toggle_main(self
):
140 if main
.main_window
.get_property('visible'):
141 main
.main_window
.hide()
143 main
.main_window
.set_decorated(False) #should be done only once?
144 self
.position_window(main
.main_window
)
145 main
.main_window
.present()
147 class ClockApplet(applet
.Applet
, Clock
, MenuWindow
):
149 applet
.Applet
.__init
__(self
, sys
.argv
[1])
151 MenuWindow
.__init
__(self
, attach
=False, additions
=menuAdditions
)
152 main
.main_window
.memo_list
.connect("MemoListChanged", self
.memo_list_changed
)
154 def button_press(self
, window
, event
):
155 if event
.type != g
.gdk
.BUTTON_PRESS
: return
156 if event
.button
== 1:
158 elif event
.button
== 3:
159 self
.popup_menu(event
, self
.position_menu
)
161 def get_panel_orientation(self
):
162 """Return the panel orientation ('Top', 'Bottom', 'Left', 'Right')
163 and the margin for displaying a popup menu"""
164 pos
= self
.socket
.property_get('_ROX_PANEL_MENU_POS', 'STRING', False)
167 side
, margin
= pos
.split(',')
170 side
, margin
= None, 2
173 def memo_list_changed(self
, memo_list
= None):
175 if main
.main_window
.get_property('visible'):
176 self
.position_window(main
.main_window
)
177 # Give the window a chance to resize itself first...
178 gobject
.idle_add(reposition
)
180 def position_window(self
, win
):
181 """Set the position of the popup"""
182 side
, margin
= self
.get_panel_orientation()
183 x
, y
= self
.socket
.get_origin()
184 w
, h
= win
.size_request()
186 # widget (x, y, w, h, bits)
187 geometry
= self
.socket
.get_geometry()
192 win
.move(x
, y
+geometry
[3])
194 win
.move(x
+geometry
[2], y
)
195 elif side
== 'Right':