Created
June 17, 2011 19:13
-
-
Save ixth/1032080 to your computer and use it in GitHub Desktop.
Simple chess clock-like app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import gtk | |
import time | |
import gobject | |
class ChessTimer(gtk.StatusIcon): | |
def __init__(self): | |
gtk.StatusIcon.__init__(self) | |
# Set icon | |
self.set_from_stock(gtk.STOCK_NO) | |
self.set_tooltip('00:00:00') | |
# Init menu | |
actiongroup = gtk.ActionGroup('Actions') | |
actiongroup.add_actions([ | |
('About', gtk.STOCK_ABOUT, | |
'A_bout', None, | |
None, | |
self.on_help | |
), | |
('Exit', None, | |
'E_xit', None, | |
None, | |
self.on_quit | |
) | |
]) | |
manager = gtk.UIManager() | |
manager.insert_action_group(actiongroup) | |
manager.add_ui_from_string(''' | |
<popup> | |
<menuitem action="About" /> | |
<separator /> | |
<menuitem action="Exit" /> | |
</popup> | |
''') | |
self.menu = manager.get_widget('/popup') | |
# Event handlers | |
self.connect('activate', self.on_activate) | |
self.connect('popup-menu', | |
lambda status, button, time: | |
self.menu.popup(None, None, None, button, time) | |
) | |
# Init local variables and start timer update loop | |
self.is_active = False | |
self.cached_time = 0 | |
gobject.timeout_add(990, self.update_timer) | |
def on_help (self, data): | |
dialog = gtk.AboutDialog() | |
dialog.set_name('ChessTimer') | |
dialog.set_version('0.0.1') | |
dialog.set_comments('Check how much time you spend on any actions') | |
dialog.set_website('http://ixth.net/') | |
dialog.run() | |
dialog.destroy() | |
def on_quit (self, data): | |
gtk.main_quit() | |
def on_activate (self, data): | |
self.is_active = not self.is_active | |
self.set_from_stock({True: gtk.STOCK_YES, False: gtk.STOCK_NO}[self.is_active]) | |
if self.is_active: | |
self.initial_time = time.time() | |
else: | |
self.cached_time += time.time() - self.initial_time | |
def update_timer (self): | |
if self.is_active: | |
self.set_tooltip(time.strftime('%H:%M:%S', time.gmtime(time.time() - self.initial_time + self.cached_time))) | |
return True | |
if __name__ == '__main__': | |
ChessTimer() | |
gtk.main() |
Just tabs are not restricted. Combinations of spaces and tabs are not permitted. So fuck'm all!;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, I use tabs and will burn in hell.