<s> import sys <EOL> import gtk <EOL> from datetime import datetime <EOL> import gobject <EOL> from threading import Thread <EOL> class uiSignalHelpers ( object ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( uiSignalHelpers , self ) . __init__ ( * args , ** kwargs ) <EOL> def callback ( self , * args , ** kwargs ) : <EOL> super ( uiSignalHelpers , self ) . callback ( * args , ** kwargs ) <EOL> def gtk_widget_show ( self , w , e = None ) : <EOL> w . show ( ) <EOL> return True <EOL> def gtk_widget_hide ( self , w , e = None ) : <EOL> w . hide ( ) <EOL> return True <EOL> def information_message ( self , widget , message , cb = None ) : <EOL> self . attention = "<STR_LIT>" % message <EOL> messagedialog = gtk . MessageDialog ( widget , gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT , gtk . MESSAGE_INFO , gtk . BUTTONS_OK , message ) <EOL> messagedialog . connect ( "<STR_LIT>" , lambda w , e : w . hide ( ) or True ) <EOL> if cb : <EOL> messagedialog . connect ( "<STR_LIT>" , cb ) <EOL> messagedialog . set_default_response ( gtk . RESPONSE_OK ) <EOL> messagedialog . show ( ) <EOL> messagedialog . present ( ) <EOL> return messagedialog <EOL> def error_message ( self , widget , message ) : <EOL> self . attention = "<STR_LIT>" % message <EOL> messagedialog = gtk . MessageDialog ( widget , gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT , gtk . MESSAGE_ERROR , gtk . BUTTONS_CANCEL , message ) <EOL> messagedialog . run ( ) <EOL> messagedialog . destroy ( ) <EOL> def warning_message ( self , widget , message ) : <EOL> self . attention = "<STR_LIT>" % message <EOL> messagedialog = gtk . MessageDialog ( widget , gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT , gtk . MESSAGE_WARNING , gtk . BUTTONS_OK_CANCEL , message ) <EOL> messagedialog . show ( ) <EOL> messagedialog . present ( ) <EOL> messagedialog . run ( ) <EOL> messagedialog . destroy ( ) <EOL> def question_message ( self , widget , message , cb = None ) : <EOL> self . attention = "<STR_LIT>" % message <EOL> messagedialog = gtk . MessageDialog ( widget , gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT , gtk . MESSAGE_QUESTION , gtk . BUTTONS_YES_NO , message ) <EOL> messagedialog . connect ( "<STR_LIT>" , lambda w , e : w . hide ( ) or True ) <EOL> if cb : <EOL> messagedialog . connect ( "<STR_LIT>" , cb ) <EOL> messagedialog . set_default_response ( gtk . RESPONSE_YES ) <EOL> messagedialog . show ( ) <EOL> messagedialog . present ( ) <EOL> return messagedialog <EOL> def interval_dialog ( self , message ) : <EOL> if not self . interval_dialog_showing : <EOL> if not self . timetracker_window . is_active ( ) : <EOL> self . timetracker_window . show ( ) <EOL> self . timetracker_window . present ( ) <EOL> self . interval_dialog_showing = True <EOL> return self . question_message ( self . timetracker_window , message , self . on_interval_dialog ) <EOL> return None <EOL> def stop_interval_dialog ( self , message ) : <EOL> if not self . stop_interval_dialog_showing : <EOL> if not self . timetracker_window . is_active ( ) : <EOL> self . timetracker_window . show ( ) <EOL> self . timetracker_window . present ( ) <EOL> self . stop_interval_dialog_showing = True <EOL> return self . information_message ( self . timetracker_window , message , self . on_stopped ) <EOL> return None <EOL> def set_custom_label ( self , widget , text ) : <EOL> Label = widget . get_children ( ) [ <NUM_LIT:0> ] <EOL> Label = Label . get_children ( ) [ <NUM_LIT:0> ] . get_children ( ) [ <NUM_LIT:1> ] <EOL> Label = Label . set_label ( text ) <EOL> def window_state ( self , widget , state ) : <EOL> self . timetracker_window_state = state . new_window_state <EOL> class uiSignals ( uiSignalHelpers ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( uiSignals , self ) . __init__ ( * args , ** kwargs ) <EOL> self . preferences_window . connect ( '<STR_LIT>' , lambda w , e : w . hide ( ) or True ) <EOL> self . timetracker_window . connect ( '<STR_LIT>' , lambda w , e : w . hide ( ) or True ) <EOL> self . timetracker_window . connect ( '<STR_LIT>' , lambda w , e : w . hide ( ) or True ) <EOL> self . timetracker_window . connect ( "<STR_LIT>" , self . window_state ) <EOL> self . about_dialog . connect ( "<STR_LIT>" , lambda w , e : w . hide ( ) or True ) <EOL> self . about_dialog . connect ( "<STR_LIT>" , lambda w , e : w . hide ( ) or True ) <EOL> self . notes_textview . connect ( '<STR_LIT>' , self . on_textview_ctrl_enter ) <EOL> def callback ( self , * args , ** kwargs ) : <EOL> super ( uiSignals , self ) . callback ( * args , ** kwargs ) <EOL> self . icon . connect ( '<STR_LIT>' , self . left_click ) <EOL> self . icon . connect ( "<STR_LIT>" , self . right_click ) <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> from gtkwin32 import GTKWin32Ext <EOL> self . timetracker_window . realize ( ) <EOL> self . win32ext = GTKWin32Ext ( self . timetracker_window ) <EOL> self . win32ext . add_notify_icon ( ) <EOL> def before_init ( self ) : <EOL> pass <EOL> def after_init ( self ) : <EOL> self . project_combobox_handler = self . project_combobox . connect ( '<STR_LIT>' , self . on_project_combobox_changed ) <EOL> self . task_combobox_handler = self . task_combobox . connect ( '<STR_LIT>' , self . on_task_combobox_changed ) <EOL> def on_show_about_dialog ( self , widget ) : <EOL> self . about_dialog . show ( ) <EOL> def on_interval_dialog ( self , dialog , a ) : <EOL> if a == gtk . RESPONSE_NO : <EOL> self . refresh_and_show ( ) <EOL> else : <EOL> self . running = True <EOL> self . current_selected_project_id = self . last_project_id <EOL> self . current_selected_task_id = self . last_task_id <EOL> self . current_notes = self . get_notes ( self . last_notes ) <EOL> self . current_hours = "<STR_LIT>" % round ( float ( self . last_hours ) + float ( self . interval ) , <NUM_LIT:2> ) <EOL> self . current_text = self . last_text <EOL> self . current_entry_id = self . last_entry_id <EOL> entry = self . harvest . update ( self . current_entry_id , { <EOL> '<STR_LIT>' : self . current_notes , <EOL> '<STR_LIT>' : self . current_hours , <EOL> '<STR_LIT>' : self . current_project_id , <EOL> '<STR_LIT>' : self . current_task_id <EOL> } ) <EOL> self . refresh_and_show ( ) <EOL> self . timetracker_window . hide ( ) <EOL> dialog . destroy ( ) <EOL> self . attention = None <EOL> self . interval_dialog_showing = False <EOL> def on_textview_ctrl_enter ( self , widget , event ) : <EOL> '''<STR_LIT>''' <EOL> if event . state == gtk . gdk . CONTROL_MASK and gtk . gdk . keyval_name ( event . keyval ) == "<STR_LIT>" : <EOL> self . submit_button . emit ( '<STR_LIT>' ) <EOL> def on_stopped ( self , dialog ) : <EOL> if not self . timetracker_window . is_active ( ) : <EOL> self . timetracker_window . show ( ) <EOL> self . timetracker_window . present ( ) <EOL> dialog . destroy ( ) <EOL> self . attention = None <EOL> self . stop_interval_dialog_showing = False <EOL> def on_save_preferences_button_clicked ( self , widget ) : <EOL> if self . running : <EOL> if self . interval_dialog_instance : <EOL> self . interval_dialog_instance . hide ( ) <EOL> self . stop_and_refactor_time ( ) <EOL> self . get_prefs ( ) <EOL> if self . connect_to_harvest ( ) : <EOL> self . preferences_window . hide ( ) <EOL> self . timetracker_window . show ( ) <EOL> self . timetracker_window . present ( ) <EOL> def on_task_combobox_changed ( self , widget ) : <EOL> new_idx = widget . get_active ( ) <EOL> if new_idx != - <NUM_LIT:1> : <EOL> if new_idx != self . current_selected_task_idx : <EOL> self . current_selected_task_id = self . get_combobox_selection ( widget ) <EOL> self . current_selected_task_idx = new_idx <EOL> self . refresh_comboboxes ( ) <EOL> def on_project_combobox_changed ( self , widget ) : <EOL> self . current_selected_project_id = self . get_combobox_selection ( widget ) <EOL> new_idx = widget . get_active ( ) <EOL> if new_idx != - <NUM_LIT:1> : <EOL> self . current_selected_project_idx = new_idx <EOL> self . current_selected_task_id = None <EOL> self . current_selected_task_idx = <NUM_LIT:0> <EOL> self . refresh_comboboxes ( ) <EOL> def on_show_preferences ( self , widget ) : <EOL> self . preferences_window . show ( ) <EOL> self . preferences_window . present ( ) <EOL> def on_away_from_desk ( self , widget ) : <EOL> if self . running : <EOL> self . away_from_desk = True if not self . away_from_desk else False <EOL> def on_check_for_updates ( self , widget ) : <EOL> pass <EOL> def on_top ( self , widget ) : <EOL> self . always_on_top = False if self . always_on_top else True <EOL> self . timetracker_window . set_keep_above ( self . always_on_top ) <EOL> def on_submit_button_clicked ( self , widget ) : <EOL> self . away_from_desk = False <EOL> self . attention = None <EOL> self . append_add_entry ( ) <EOL> self . set_textview_text ( self . notes_textview , "<STR_LIT>" ) <EOL> self . notes_textview . grab_focus ( ) <EOL> def on_stop_timer ( self , widget ) : <EOL> self . stop_and_refactor_time ( ) <EOL> def on_quit ( self , widget ) : <EOL> if self . running and self . harvest : <EOL> self . harvest . toggle_timer ( self . current_entry_id ) <EOL> gtk . main_quit ( ) <EOL> def refresh_and_show ( self ) : <EOL> self . set_entries ( ) <EOL> self . timetracker_window . show ( ) <EOL> self . timetracker_window . present ( ) <EOL> self . notes_textview . grab_focus ( ) <EOL> def on_refresh ( self , widget ) : <EOL> self . refresh_and_show ( ) <EOL> def left_click ( self , widget ) : <EOL> self . refresh_and_show ( ) <EOL> def right_click ( self , widget , button , time ) : <EOL> menu = gtk . Menu ( ) <EOL> refresh = gtk . ImageMenuItem ( gtk . STOCK_REFRESH ) <EOL> refresh . connect ( "<STR_LIT>" , self . on_refresh ) <EOL> menu . append ( refresh ) <EOL> if self . running : <EOL> stop_timer = gtk . MenuItem ( "<STR_LIT>" ) <EOL> stop_timer . connect ( "<STR_LIT>" , self . on_stop_timer ) <EOL> menu . append ( stop_timer ) <EOL> if not self . away_from_desk : <EOL> away = gtk . ImageMenuItem ( gtk . STOCK_NO ) <EOL> away . set_label ( "<STR_LIT>" ) <EOL> else : <EOL> away = gtk . ImageMenuItem ( gtk . STOCK_YES ) <EOL> away . set_label ( "<STR_LIT>" ) <EOL> away . connect ( "<STR_LIT>" , self . on_away_from_desk ) <EOL> menu . append ( away ) <EOL> top = gtk . MenuItem ( "<STR_LIT>" ) <EOL> prefs = gtk . MenuItem ( "<STR_LIT>" ) <EOL> about = gtk . MenuItem ( "<STR_LIT>" ) <EOL> quit = gtk . MenuItem ( "<STR_LIT>" ) <EOL> top . connect ( "<STR_LIT>" , self . on_top ) <EOL> prefs . connect ( "<STR_LIT>" , self . on_show_preferences ) <EOL> about . connect ( "<STR_LIT>" , self . on_show_about_dialog ) <EOL> quit . connect ( "<STR_LIT>" , self . on_quit ) <EOL> menu . append ( prefs ) <EOL> menu . append ( top ) <EOL> menu . append ( about ) <EOL> menu . append ( quit ) <EOL> menu . show_all ( ) <EOL> menu . popup ( None , None , gtk . status_icon_position_menu , button , time , self . icon ) </s>
