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
19 from rox
import g
, applet
, Menu
, options
, processes
23 menu
= Menu
.Menu('main', [
24 ("/Show Main Window", "show_main", "", ""),
25 ("/Set Time", "set_time", "<StockItem>", "", g
.STOCK_PROPERTIES
),
26 ("/Options", "options", "<StockItem>", "", g
.STOCK_PREFERENCES
),
27 ("/Quit", "quit", "<StockItem>", "", g
.STOCK_QUIT
)
30 clocktype
= options
.Option("clocktype", "2lines")
31 showtip
= options
.Option("showtip", True)
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")
40 self
.tooltip
= g
.Tooltips()
41 if showtip
.value
== "False": self
.tooltip
.disable()
42 self
.vbox
= g
.VBox(spacing
= 2)
44 self
.line1_label
= g
.Label("")
45 self
.vbox
.add(self
.line1_label
)
47 self
.line2_label
= g
.Label("")
48 if clocktype
.value
== "2lines":
49 self
.vbox
.add(self
.line2_label
)
51 self
.set_border_width(5)
54 rox
.app_options
.add_notify(self
.options_changed
)
56 self
.add_events(g
.gdk
.BUTTON_PRESS_MASK
)
57 self
.connect("button-press-event", self
.button_press
)
59 self
.connect("destroy", self
.destroyed
)
62 self
.timeout
= gobject
.timeout_add(1000, self
.update_clock
)
66 def update_clock(self
):
67 self
.line1_label
.set_text(time
.strftime(line1
.value
))
68 self
.line2_label
.set_text(time
.strftime(line2
.value
))
69 self
.tooltip
.set_tip(self
, time
.strftime(tip
.value
))
72 def destroyed(self
, window
):
73 gobject
.source_remove(self
.timeout
)
74 main
.main_window
.destroy()
76 def button_press(self
, window
, event
):
78 menu
.popup(window
, event
)
80 def options_changed(self
):
81 if clocktype
.has_changed
:
82 if clocktype
.value
== "1line":
83 self
.vbox
.remove(self
.line2_label
)
85 self
.vbox
.add(self
.line2_label
)
87 if showtip
.has_changed
:
88 if showtip
.value
== "True":
91 self
.tooltip
.disable()
102 rox
.processes
.PipeThroughCommand(set_prog
.value
, None, None).wait()
105 if main
.main_window
.get_property('visible'):
106 main
.main_window
.hide()
108 main
.main_window
.set_decorated(False) #should be done only once?
109 self
.position_window(main
.main_window
)
110 main
.main_window
.present()
112 class ClockApplet(applet
.Applet
, Clock
):
114 applet
.Applet
.__init
__(self
, sys
.argv
[1])
117 def button_press(self
, window
, event
):
118 if event
.type != g
.gdk
.BUTTON_PRESS
: return
119 if event
.button
== 1:
121 elif event
.button
== 3:
122 menu
.popup(window
, event
, self
.position_menu
)
124 def get_panel_orientation(self
):
125 """Return the panel orientation ('Top', 'Bottom', 'Left', 'Right')
126 and the margin for displaying a popup menu"""
127 pos
= self
.socket
.property_get('_ROX_PANEL_MENU_POS', 'STRING', False)
130 side
, margin
= pos
.split(',')
133 side
, margin
= None, 2
136 def position_window(self
, win
):
137 """Set the position of the popup"""
138 side
, margin
= self
.get_panel_orientation()
139 x
, y
= self
.socket
.get_origin()
140 w
, h
= win
.get_size()
142 # widget (x, y, w, h, bits)
143 geometry
= self
.socket
.get_geometry()
148 win
.move(x
, y
+geometry
[3])
150 win
.move(x
+geometry
[2], y
)
151 elif side
== 'Right':