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
24 menu
= Menu
.Menu('main', [
25 ("/Show Main Window", "show_main", "", ""),
26 ("/Set Time", "set_time", "<StockItem>", "", g
.STOCK_PROPERTIES
),
27 ("/Help", "show_help", "<StockItem>", "", g
.STOCK_HELP
),
28 ("/Options", "options", "<StockItem>", "", g
.STOCK_PREFERENCES
),
29 ("/Quit", "quit", "<StockItem>", "", g
.STOCK_QUIT
)
32 set_prog
= options
.Option('set_program', "gksu time-admin")
34 line1
= options
.Option("line1", "%X")
35 line2
= options
.Option("line2", "%x")
36 tip
= options
.Option("tip", "%c")
38 line1_font
= options
.Option("line1_font", None)
39 line1_color
= options
.Option("line1_color", "#000000")
41 line2_font
= options
.Option("line2_font", None)
42 line2_color
= options
.Option("line2_color", "#000000")
46 self
.tooltip
= g
.Tooltips()
47 if tip
.value
== "": self
.tooltip
.disable()
48 self
.vbox
= g
.VBox(spacing
= 2)
50 self
.line1_label
= g
.Label("")
52 self
.vbox
.add(self
.line1_label
)
54 self
.line2_label
= g
.Label("")
56 self
.vbox
.add(self
.line2_label
)
58 self
.set_border_width(5)
61 rox
.app_options
.add_notify(self
.options_changed
)
63 self
.add_events(g
.gdk
.BUTTON_PRESS_MASK
)
64 self
.connect("button-press-event", self
.button_press
)
66 self
.connect("destroy", self
.destroyed
)
69 self
.timeout
= gobject
.timeout_add(1000, self
.update_clock
)
73 def update_clock(self
):
74 self
.line1_label
.set_text(time
.strftime(line1
.value
))
75 self
.line2_label
.set_text(time
.strftime(line2
.value
))
78 self
.tooltip
.set_tip(self
, time
.strftime(tip
.value
))
81 def update_font(self
):
82 new_font1
= pango
.FontDescription(line1_font
.value
)
83 new_font2
= pango
.FontDescription(line2_font
.value
)
85 self
.line1_label
.modify_font(new_font1
)
87 self
.line2_label
.modify_font(new_font2
)
89 def update_color(self
):
90 new_color1
= g
.gdk
.color_parse(line1_color
.value
)
91 new_color2
= g
.gdk
.color_parse(line2_color
.value
)
93 self
.line1_label
.modify_fg(g
.STATE_NORMAL
, new_color1
)
95 self
.line2_label
.modify_fg(g
.STATE_NORMAL
, new_color2
)
97 def destroyed(self
, window
):
98 gobject
.source_remove(self
.timeout
)
99 main
.main_window
.destroy()
101 def button_press(self
, window
, event
):
102 if event
.button
== 3:
103 menu
.popup(window
, event
)
105 def options_changed(self
):
106 if line1
.has_changed
:
107 if line1
.value
== '':
108 self
.vbox
.remove(self
.line1_label
)
110 self
.vbox
.add(self
.line1_label
)
112 self
.vbox
.remove(self
.line2_label
)
113 self
.vbox
.add(self
.line2_label
)
115 if line2
.has_changed
:
116 if line2
.value
== '':
117 self
.vbox
.remove(self
.line2_label
)
119 self
.vbox
.add(self
.line2_label
)
123 self
.tooltip
.disable()
125 self
.tooltip
.enable()
127 if line1_font
.has_changed
or line2_font
.has_changed
:
129 if line1_color
.has_changed
or line2_color
.has_changed
:
138 filer
.open_dir(os
.path
.join(rox
.app_dir
, 'Help'))
144 rox
.processes
.PipeThroughCommand(set_prog
.value
, None, None).wait()
147 if main
.main_window
.get_property('visible'):
148 main
.main_window
.hide()
150 main
.main_window
.set_decorated(False) #should be done only once?
151 self
.position_window(main
.main_window
)
152 main
.main_window
.present()
154 class ClockApplet(applet
.Applet
, Clock
):
156 applet
.Applet
.__init
__(self
, sys
.argv
[1])
158 main
.main_window
.memo_list
.watchers
.append(self
.memo_list_changed
)
160 def button_press(self
, window
, event
):
161 if event
.type != g
.gdk
.BUTTON_PRESS
: return
162 if event
.button
== 1:
164 elif event
.button
== 3:
165 menu
.popup(window
, event
, self
.position_menu
)
167 def get_panel_orientation(self
):
168 """Return the panel orientation ('Top', 'Bottom', 'Left', 'Right')
169 and the margin for displaying a popup menu"""
170 pos
= self
.socket
.property_get('_ROX_PANEL_MENU_POS', 'STRING', False)
173 side
, margin
= pos
.split(',')
176 side
, margin
= None, 2
179 def memo_list_changed(self
):
181 if main
.main_window
.get_property('visible'):
182 self
.position_window(main
.main_window
)
183 # Give the window a chance to resize itself first...
184 gobject
.idle_add(reposition
)
186 def position_window(self
, win
):
187 """Set the position of the popup"""
188 side
, margin
= self
.get_panel_orientation()
189 x
, y
= self
.socket
.get_origin()
190 w
, h
= win
.size_request()
192 # widget (x, y, w, h, bits)
193 geometry
= self
.socket
.get_geometry()
198 win
.move(x
, y
+geometry
[3])
200 win
.move(x
+geometry
[2], y
)
201 elif side
== 'Right':