Merge lp:~jcsims/pomodoro-timer/rewrite into lp:pomodoro-timer
- rewrite
- Merge into main
Proposed by
Chris Sims
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~jcsims/pomodoro-timer/rewrite |
Merge into: | lp:pomodoro-timer |
Diff against target: |
322 lines (+208/-94) 1 file modified
bin/pomodorotimer (+208/-94) |
To merge this branch: | bzr merge lp:~jcsims/pomodoro-timer/rewrite |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Sims | Approve | ||
Review via email: mp+22923@code.launchpad.net |
Commit message
New direction.
Description of the change
A rewrite of the original Quickly base program. Window created and packed using pyGTK. Basic logic for various timer functions, countdown, display of time.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/pomodorotimer' |
2 | --- bin/pomodorotimer 2010-04-04 22:06:22 +0000 |
3 | +++ bin/pomodorotimer 2010-04-07 04:26:17 +0000 |
4 | @@ -15,111 +15,225 @@ |
5 | #with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | ### END LICENSE |
7 | |
8 | -import sys |
9 | -import os |
10 | -import gtk |
11 | - |
12 | -# Check if we are working in the source tree or from the installed |
13 | -# package and mangle the python path accordingly |
14 | -if os.path.dirname(sys.argv[0]) != ".": |
15 | - if sys.argv[0][0] == "/": |
16 | - fullPath = os.path.dirname(sys.argv[0]) |
17 | - else: |
18 | - fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0]) |
19 | -else: |
20 | - fullPath = os.getcwd() |
21 | -sys.path.insert(0, os.path.dirname(fullPath)) |
22 | - |
23 | -from pomodorotimer import AboutPomodorotimerDialog, PreferencesPomodorotimerDialog |
24 | -from pomodorotimer.pomodorotimerconfig import getdatapath |
25 | - |
26 | -class PomodorotimerWindow(gtk.Window): |
27 | - __gtype_name__ = "PomodorotimerWindow" |
28 | +import pygtk |
29 | +pygtk.require('2.0') |
30 | +import gtk, gobject |
31 | + |
32 | +class PomodorotimerWindow(): |
33 | |
34 | def __init__(self): |
35 | - """__init__ - This function is typically not called directly. |
36 | - Creation a PomodorotimerWindow requires redeading the associated ui |
37 | - file and parsing the ui definition extrenally, |
38 | - and then calling PomodorotimerWindow.finish_initializing(). |
39 | - |
40 | - Use the convenience function NewPomodorotimerWindow to create |
41 | - PomodorotimerWindow object. |
42 | - |
43 | - """ |
44 | - pass |
45 | - |
46 | - def finish_initializing(self, builder): |
47 | - """finish_initalizing should be called after parsing the ui definition |
48 | - and creating a PomodorotimerWindow object with it in order to finish |
49 | - initializing the start of the new PomodorotimerWindow instance. |
50 | - |
51 | - """ |
52 | - #get a reference to the builder and set up the signals |
53 | - self.builder = builder |
54 | - self.builder.connect_signals(self) |
55 | - |
56 | - #uncomment the following code to read in preferences at start up |
57 | - #dlg = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog() |
58 | - #self.preferences = dlg.get_preferences() |
59 | - |
60 | - #code for other initialization actions should be added here |
61 | + # Create the window and set attributes |
62 | + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) |
63 | + self.window.set_title("Pomodoro Timer") |
64 | + self.window.set_border_width(5) |
65 | + self.window.set_resizable(False) |
66 | + self.window.set_size_request(400, 200) |
67 | + |
68 | + # Connect the delete_event event to the event handler |
69 | + self.window.connect("delete_event", self.on_destroy) |
70 | + |
71 | + # Create and add the one VBox that we'll need |
72 | + box1 = gtk.VBox(False, 0) |
73 | + self.window.add(box1) |
74 | + box1.show() |
75 | + |
76 | + # Create the file menu and pack it |
77 | + file_menu = gtk.Menu() |
78 | + quit_item = gtk.MenuItem("Quit") |
79 | + |
80 | + file_menu.append(quit_item) |
81 | + |
82 | + # Attach quit menu entry to our exit function |
83 | + quit_item.connect("activate", self.on_destroy, None) |
84 | + |
85 | + # And show it |
86 | + quit_item.show() |
87 | + |
88 | + # Create the menu bar, pack it, show it |
89 | + menu_bar = gtk.MenuBar() |
90 | + box1.pack_start(menu_bar, False, False, 0) |
91 | + menu_bar.show() |
92 | + |
93 | + # Create the visible "File" menu and associate it with our |
94 | + # above created menu |
95 | + file_item = gtk.MenuItem("File") |
96 | + file_item.show() |
97 | + file_item.set_submenu(file_menu) |
98 | + |
99 | + # And then append the file menu to our menu bar |
100 | + menu_bar.append(file_item) |
101 | + |
102 | + # Create the help menu and pack it |
103 | + help_menu = gtk.Menu() |
104 | + about_item = gtk.MenuItem("About") |
105 | + |
106 | + help_menu.append(about_item) |
107 | + |
108 | + # Attach about menu entry to our about function |
109 | + about_item.connect("activate", self.about, None) |
110 | + |
111 | + # And show it |
112 | + about_item.show() |
113 | + |
114 | + # Create the visible "Help" menu and associate it with our |
115 | + # above created menu |
116 | + help_item = gtk.MenuItem("Help") |
117 | + help_item.show() |
118 | + help_item.set_submenu(help_menu) |
119 | + |
120 | + # And then append the file menu to our menu bar |
121 | + menu_bar.append(help_item) |
122 | + |
123 | + # Create the HBox to hold the buttons and the timer |
124 | + box2 = gtk.HBox(True, 0) |
125 | + box1.pack_start(box2, False, False, 0) |
126 | + box2.show() |
127 | + |
128 | + # Create our VBox for the radio buttons and the start button |
129 | + box3 = gtk.VBox(True, 0) |
130 | + box3.set_border_width(10) |
131 | + box2.pack_start(box3, False, False, 5) |
132 | + box3.show() |
133 | + |
134 | + # Create the three radio buttons and pack them |
135 | + rbutton1 = gtk.RadioButton(None, "Pomodoro!") |
136 | + rbutton1.connect("toggled", self.pomodoro, None) |
137 | + rbutton1.set_active(True) |
138 | + box3.pack_start(rbutton1, False, False, 5) |
139 | + rbutton1.show() |
140 | + |
141 | + rbutton2 = gtk.RadioButton(rbutton1, "Short Break") |
142 | + rbutton2.connect("toggled", self.short_break, None) |
143 | + box3.pack_start(rbutton2, False, False, 5) |
144 | + rbutton2.show() |
145 | + |
146 | + rbutton3 = gtk.RadioButton(rbutton1, "Long Break") |
147 | + rbutton3.connect("toggled", self.long_break, None) |
148 | + box3.pack_start(rbutton3, False, False, 5) |
149 | + rbutton3.show() |
150 | + |
151 | + # Create a small HBox for our start and stop buttons |
152 | + box4 = gtk.HBox(True, 0) |
153 | + box3.pack_start(box4, False, False, 0) |
154 | + box4.show() |
155 | + |
156 | + start_button = gtk.Button("Start!") |
157 | + start_button.connect("clicked", self.start, None) |
158 | + box4.pack_start(start_button, False, False, 5) |
159 | + start_button.show() |
160 | + |
161 | + stop_button = gtk.Button("Stop!") |
162 | + stop_button.connect("clicked", self.stop, None) |
163 | + box4.pack_start(stop_button, False, False, 5) |
164 | + stop_button.show() |
165 | + |
166 | + # Create the label that will become our countdown timer |
167 | + self.timer = gtk.Label("25:00") |
168 | + box2.pack_start(self.timer, False, False, 5) |
169 | + self.timer.show() |
170 | + |
171 | + |
172 | + self.window.show() |
173 | |
174 | def about(self, widget, data=None): |
175 | """about - display the about box for pomodorotimer """ |
176 | - about = AboutPomodorotimerDialog.NewAboutPomodorotimerDialog() |
177 | - response = about.run() |
178 | - about.destroy() |
179 | - |
180 | - def preferences(self, widget, data=None): |
181 | - """preferences - display the preferences window for pomodorotimer """ |
182 | - prefs = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog() |
183 | - response = prefs.run() |
184 | - if response == gtk.RESPONSE_OK: |
185 | - #TODO: Save changes made to preferences |
186 | - pass |
187 | - prefs.destroy() |
188 | - |
189 | - def quit(self, widget, data=None): |
190 | - """quit - signal handler for closing the PomodorotimerWindow""" |
191 | - self.destroy() |
192 | + # Borrowed from Jon Staley, from python-snippets package |
193 | + # The AboutDialog has good helper methods which |
194 | + # setup the dialog and add the content ensuring all |
195 | + # about dialog are consistant. Below is a small example |
196 | + |
197 | + # Create AboutDialog object |
198 | + dialog = gtk.AboutDialog() |
199 | + |
200 | + # Add the application name to the dialog |
201 | + dialog.set_name('About Pomodoro Timer') |
202 | + |
203 | + # Set the application version |
204 | + dialog.set_version('0.1') |
205 | + |
206 | + # Pass a list of authors. This is then connected to the 'Credits' |
207 | + # button. When clicked the buttons opens a new window showing |
208 | + # each author on their own line. |
209 | + dialog.set_authors(['Chris Sims', 'Steven Nance']) |
210 | + |
211 | + # Add a short comment about the application, this appears below the application |
212 | + # name in the dialog |
213 | + dialog.set_comments('A simple pomodoro timer.') |
214 | + |
215 | + # Add license information, this is connected to the 'License' button |
216 | + # and is displayed in a new window. |
217 | + dialog.set_license('Distributed under the GPL v3 license.\nhttp://www.gnu.org/licenses/gpl.html') |
218 | + |
219 | + # Show the dialog |
220 | + dialog.run() |
221 | + |
222 | + # The destroy method must be called otherwise the 'Close' button will |
223 | + # not work. |
224 | + dialog.destroy() |
225 | + |
226 | +# def preferences(self, widget, data=None): |
227 | +# """preferences - display the preferences window for pomodorotimer """ |
228 | +# prefs = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog() |
229 | +# response = prefs.run() |
230 | +# if response == gtk.RESPONSE_OK: |
231 | +# #TODO: Save changes made to preferences |
232 | +# pass |
233 | +# prefs.destroy() |
234 | + |
235 | + # Make sure to default our seconds to zero |
236 | + seconds = 0 |
237 | + |
238 | + def pomodoro(self, widget, data=None): |
239 | + if widget.get_active(): |
240 | + self.minutes = 25 |
241 | + self.timer.set_label("25:00") |
242 | + |
243 | + def short_break(self, widget, data=None): |
244 | + if widget.get_active(): |
245 | + self.minutes = 5 |
246 | + self.timer.set_label("5:00") |
247 | + |
248 | + def long_break(self, widget, data=None): |
249 | + if widget.get_active(): |
250 | + self.minutes = 15 |
251 | + self.timer.set_label("15:00") |
252 | + |
253 | + def start(self, widget, data=None): |
254 | + gobject.timeout_add(1000, self.countdown) |
255 | + self.countdown() |
256 | + |
257 | + def countdown(self): |
258 | + if self.seconds>= 0: |
259 | + m = "%02d" % self.minutes |
260 | + s = "%02d" % self.seconds |
261 | + self.timer.set_text(m + ':' + s) |
262 | + self.seconds -= 1 |
263 | + return True |
264 | + elif self.minutes > 0: |
265 | + self.minutes -= 1 |
266 | + self.seconds = 59 |
267 | + return True |
268 | + else: |
269 | + self.timer.set_text("All done!") |
270 | + return False |
271 | + |
272 | + def stop(self, widget, data=None): |
273 | + self.minutes = 0 |
274 | + self.seconds = 0 |
275 | + self.countdown() |
276 | |
277 | def on_destroy(self, widget, data=None): |
278 | - """on_destroy - called when the PomodorotimerWindow is close. """ |
279 | + """on_destroy - called when the PomodorotimerWindow is closed, |
280 | + or when "quit" is selected from the menu. """ |
281 | #TODO: Save any changes to historical data before closing |
282 | |
283 | gtk.main_quit() |
284 | - |
285 | -def NewPomodorotimerWindow(): |
286 | - """NewPomodorotimerWindow - returns a fully instantiated |
287 | - PomodorotimerWindow object. Use this function rather than |
288 | - creating a PomodorotimerWindow directly. |
289 | - """ |
290 | - |
291 | - #look for the ui file that describes the ui |
292 | - ui_filename = os.path.join(getdatapath(), 'ui', 'PomodorotimerWindow.ui') |
293 | - if not os.path.exists(ui_filename): |
294 | - ui_filename = None |
295 | - |
296 | - builder = gtk.Builder() |
297 | - builder.add_from_file(ui_filename) |
298 | - window = builder.get_object("pomodorotimer_window") |
299 | - window.finish_initializing(builder) |
300 | - return window |
301 | + |
302 | + def main(self): |
303 | + gtk.main() |
304 | |
305 | if __name__ == "__main__": |
306 | - #support for command line options |
307 | - import logging, optparse |
308 | - parser = optparse.OptionParser(version="%prog %ver") |
309 | - parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages") |
310 | - (options, args) = parser.parse_args() |
311 | - |
312 | - #set the logging level to show debug messages |
313 | - if options.verbose: |
314 | - logging.basicConfig(level=logging.DEBUG) |
315 | - logging.debug('logging enabled') |
316 | - |
317 | #run the application |
318 | - window = NewPomodorotimerWindow() |
319 | - window.show() |
320 | - gtk.main() |
321 | + window = PomodorotimerWindow() |
322 | + window.main() |
323 |
Approving myself...