Merge lp:~jcsims/pomodoro-timer/rewrite into lp:pomodoro-timer

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
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.
Revision history for this message
Chris Sims (jcsims) wrote :

Approving myself...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pomodorotimer'
--- bin/pomodorotimer 2010-04-04 22:06:22 +0000
+++ bin/pomodorotimer 2010-04-07 04:26:17 +0000
@@ -15,111 +15,225 @@
15#with this program. If not, see <http://www.gnu.org/licenses/>.15#with this program. If not, see <http://www.gnu.org/licenses/>.
16### END LICENSE16### END LICENSE
1717
18import sys18import pygtk
19import os19pygtk.require('2.0')
20import gtk20import gtk, gobject
2121
22# Check if we are working in the source tree or from the installed 22class PomodorotimerWindow():
23# package and mangle the python path accordingly
24if os.path.dirname(sys.argv[0]) != ".":
25 if sys.argv[0][0] == "/":
26 fullPath = os.path.dirname(sys.argv[0])
27 else:
28 fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0])
29else:
30 fullPath = os.getcwd()
31sys.path.insert(0, os.path.dirname(fullPath))
32
33from pomodorotimer import AboutPomodorotimerDialog, PreferencesPomodorotimerDialog
34from pomodorotimer.pomodorotimerconfig import getdatapath
35
36class PomodorotimerWindow(gtk.Window):
37 __gtype_name__ = "PomodorotimerWindow"
3823
39 def __init__(self):24 def __init__(self):
40 """__init__ - This function is typically not called directly.25 # Create the window and set attributes
41 Creation a PomodorotimerWindow requires redeading the associated ui26 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
42 file and parsing the ui definition extrenally,27 self.window.set_title("Pomodoro Timer")
43 and then calling PomodorotimerWindow.finish_initializing().28 self.window.set_border_width(5)
4429 self.window.set_resizable(False)
45 Use the convenience function NewPomodorotimerWindow to create30 self.window.set_size_request(400, 200)
46 PomodorotimerWindow object.31
4732 # Connect the delete_event event to the event handler
48 """33 self.window.connect("delete_event", self.on_destroy)
49 pass34
5035 # Create and add the one VBox that we'll need
51 def finish_initializing(self, builder):36 box1 = gtk.VBox(False, 0)
52 """finish_initalizing should be called after parsing the ui definition37 self.window.add(box1)
53 and creating a PomodorotimerWindow object with it in order to finish38 box1.show()
54 initializing the start of the new PomodorotimerWindow instance.39
5540 # Create the file menu and pack it
56 """41 file_menu = gtk.Menu()
57 #get a reference to the builder and set up the signals42 quit_item = gtk.MenuItem("Quit")
58 self.builder = builder43
59 self.builder.connect_signals(self)44 file_menu.append(quit_item)
6045
61 #uncomment the following code to read in preferences at start up46 # Attach quit menu entry to our exit function
62 #dlg = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog()47 quit_item.connect("activate", self.on_destroy, None)
63 #self.preferences = dlg.get_preferences()48
6449 # And show it
65 #code for other initialization actions should be added here50 quit_item.show()
51
52 # Create the menu bar, pack it, show it
53 menu_bar = gtk.MenuBar()
54 box1.pack_start(menu_bar, False, False, 0)
55 menu_bar.show()
56
57 # Create the visible "File" menu and associate it with our
58 # above created menu
59 file_item = gtk.MenuItem("File")
60 file_item.show()
61 file_item.set_submenu(file_menu)
62
63 # And then append the file menu to our menu bar
64 menu_bar.append(file_item)
65
66 # Create the help menu and pack it
67 help_menu = gtk.Menu()
68 about_item = gtk.MenuItem("About")
69
70 help_menu.append(about_item)
71
72 # Attach about menu entry to our about function
73 about_item.connect("activate", self.about, None)
74
75 # And show it
76 about_item.show()
77
78 # Create the visible "Help" menu and associate it with our
79 # above created menu
80 help_item = gtk.MenuItem("Help")
81 help_item.show()
82 help_item.set_submenu(help_menu)
83
84 # And then append the file menu to our menu bar
85 menu_bar.append(help_item)
86
87 # Create the HBox to hold the buttons and the timer
88 box2 = gtk.HBox(True, 0)
89 box1.pack_start(box2, False, False, 0)
90 box2.show()
91
92 # Create our VBox for the radio buttons and the start button
93 box3 = gtk.VBox(True, 0)
94 box3.set_border_width(10)
95 box2.pack_start(box3, False, False, 5)
96 box3.show()
97
98 # Create the three radio buttons and pack them
99 rbutton1 = gtk.RadioButton(None, "Pomodoro!")
100 rbutton1.connect("toggled", self.pomodoro, None)
101 rbutton1.set_active(True)
102 box3.pack_start(rbutton1, False, False, 5)
103 rbutton1.show()
104
105 rbutton2 = gtk.RadioButton(rbutton1, "Short Break")
106 rbutton2.connect("toggled", self.short_break, None)
107 box3.pack_start(rbutton2, False, False, 5)
108 rbutton2.show()
109
110 rbutton3 = gtk.RadioButton(rbutton1, "Long Break")
111 rbutton3.connect("toggled", self.long_break, None)
112 box3.pack_start(rbutton3, False, False, 5)
113 rbutton3.show()
114
115 # Create a small HBox for our start and stop buttons
116 box4 = gtk.HBox(True, 0)
117 box3.pack_start(box4, False, False, 0)
118 box4.show()
119
120 start_button = gtk.Button("Start!")
121 start_button.connect("clicked", self.start, None)
122 box4.pack_start(start_button, False, False, 5)
123 start_button.show()
124
125 stop_button = gtk.Button("Stop!")
126 stop_button.connect("clicked", self.stop, None)
127 box4.pack_start(stop_button, False, False, 5)
128 stop_button.show()
129
130 # Create the label that will become our countdown timer
131 self.timer = gtk.Label("25:00")
132 box2.pack_start(self.timer, False, False, 5)
133 self.timer.show()
134
135
136 self.window.show()
66137
67 def about(self, widget, data=None):138 def about(self, widget, data=None):
68 """about - display the about box for pomodorotimer """139 """about - display the about box for pomodorotimer """
69 about = AboutPomodorotimerDialog.NewAboutPomodorotimerDialog()140 # Borrowed from Jon Staley, from python-snippets package
70 response = about.run()141 # The AboutDialog has good helper methods which
71 about.destroy()142 # setup the dialog and add the content ensuring all
72143 # about dialog are consistant. Below is a small example
73 def preferences(self, widget, data=None):144
74 """preferences - display the preferences window for pomodorotimer """145 # Create AboutDialog object
75 prefs = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog()146 dialog = gtk.AboutDialog()
76 response = prefs.run()147
77 if response == gtk.RESPONSE_OK:148 # Add the application name to the dialog
78 #TODO: Save changes made to preferences149 dialog.set_name('About Pomodoro Timer')
79 pass150
80 prefs.destroy()151 # Set the application version
81152 dialog.set_version('0.1')
82 def quit(self, widget, data=None):153
83 """quit - signal handler for closing the PomodorotimerWindow"""154 # Pass a list of authors. This is then connected to the 'Credits'
84 self.destroy()155 # button. When clicked the buttons opens a new window showing
156 # each author on their own line.
157 dialog.set_authors(['Chris Sims', 'Steven Nance'])
158
159 # Add a short comment about the application, this appears below the application
160 # name in the dialog
161 dialog.set_comments('A simple pomodoro timer.')
162
163 # Add license information, this is connected to the 'License' button
164 # and is displayed in a new window.
165 dialog.set_license('Distributed under the GPL v3 license.\nhttp://www.gnu.org/licenses/gpl.html')
166
167 # Show the dialog
168 dialog.run()
169
170 # The destroy method must be called otherwise the 'Close' button will
171 # not work.
172 dialog.destroy()
173
174# def preferences(self, widget, data=None):
175# """preferences - display the preferences window for pomodorotimer """
176# prefs = PreferencesPomodorotimerDialog.NewPreferencesPomodorotimerDialog()
177# response = prefs.run()
178# if response == gtk.RESPONSE_OK:
179# #TODO: Save changes made to preferences
180# pass
181# prefs.destroy()
182
183 # Make sure to default our seconds to zero
184 seconds = 0
185
186 def pomodoro(self, widget, data=None):
187 if widget.get_active():
188 self.minutes = 25
189 self.timer.set_label("25:00")
190
191 def short_break(self, widget, data=None):
192 if widget.get_active():
193 self.minutes = 5
194 self.timer.set_label("5:00")
195
196 def long_break(self, widget, data=None):
197 if widget.get_active():
198 self.minutes = 15
199 self.timer.set_label("15:00")
200
201 def start(self, widget, data=None):
202 gobject.timeout_add(1000, self.countdown)
203 self.countdown()
204
205 def countdown(self):
206 if self.seconds>= 0:
207 m = "%02d" % self.minutes
208 s = "%02d" % self.seconds
209 self.timer.set_text(m + ':' + s)
210 self.seconds -= 1
211 return True
212 elif self.minutes > 0:
213 self.minutes -= 1
214 self.seconds = 59
215 return True
216 else:
217 self.timer.set_text("All done!")
218 return False
219
220 def stop(self, widget, data=None):
221 self.minutes = 0
222 self.seconds = 0
223 self.countdown()
85224
86 def on_destroy(self, widget, data=None):225 def on_destroy(self, widget, data=None):
87 """on_destroy - called when the PomodorotimerWindow is close. """226 """on_destroy - called when the PomodorotimerWindow is closed,
227 or when "quit" is selected from the menu. """
88 #TODO: Save any changes to historical data before closing228 #TODO: Save any changes to historical data before closing
89229
90 gtk.main_quit()230 gtk.main_quit()
91231
92def NewPomodorotimerWindow():232 def main(self):
93 """NewPomodorotimerWindow - returns a fully instantiated233 gtk.main()
94 PomodorotimerWindow object. Use this function rather than
95 creating a PomodorotimerWindow directly.
96 """
97
98 #look for the ui file that describes the ui
99 ui_filename = os.path.join(getdatapath(), 'ui', 'PomodorotimerWindow.ui')
100 if not os.path.exists(ui_filename):
101 ui_filename = None
102
103 builder = gtk.Builder()
104 builder.add_from_file(ui_filename)
105 window = builder.get_object("pomodorotimer_window")
106 window.finish_initializing(builder)
107 return window
108234
109if __name__ == "__main__":235if __name__ == "__main__":
110 #support for command line options
111 import logging, optparse
112 parser = optparse.OptionParser(version="%prog %ver")
113 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages")
114 (options, args) = parser.parse_args()
115
116 #set the logging level to show debug messages
117 if options.verbose:
118 logging.basicConfig(level=logging.DEBUG)
119 logging.debug('logging enabled')
120
121 #run the application236 #run the application
122 window = NewPomodorotimerWindow()237 window = PomodorotimerWindow()
123 window.show()238 window.main()
124 gtk.main()
125239

Subscribers

People subscribed via source and target branches

to all changes: