<commit_before>#!/usr/bin/env python

import gtk
import gtk.glade
import gobject

#

import string
import thread
import time

#

import timer

class SteepTimer:
    def __init__(self):
        gobject.threads_init()
        self._ticks = 0
        self._remaining = 0
        self._timer = timer.Timer(1, self.tick)

        # set up UI via Glade
        
        wtree = gtk.glade.XML('steep.glade')
        wtree.signal_autoconnect(self)
        
        for w in wtree.get_widget_prefix(''):
            name = w.get_name()
            assert not hasattr(self, name)
            setattr(self, name, w)
            
        self.wnd_main.show()

        #

        self.on_btn_reset_clicked()
        
    def on_btn_start_clicked(self, widget = None, data = None):
        self.init_timer(self._ticks)

        print "Starting."
        self.update_timer_display()
        self._timer.start()

    def on_btn_stop_clicked(self, widget = None, data = None):
        print "Stopping."
        self._timer.stop()
        self.update_timer_display()

    def on_btn_reset_clicked(self, widget = None, data = None):
        print "Resetting."
        self.on_btn_stop_clicked()
        self._remaining = self._ticks
        self.update_timer_display()
        
    def on_tea_selected(self, widget, data = None):
        if self.rb_blacktea.get_active():
            seconds = 5 * 60
        elif self.rb_greentea.get_active():
            seconds = 3 * 60
        elif self.rb_herbaltea.get_active():
            seconds = 7 * 60
        
        self.on_btn_stop_clicked()
        self.init_timer(seconds)
    
    def on_wnd_main_delete_event(self, widget, event, data=None):
        print "delete event"
        return False

    def on_wnd_main_destroy(self, widget, data=None):
        gtk.main_quit()

    def init_timer(self, seconds):
        self._ticks = seconds
        self._remaining = self._ticks
        
        self.pb_progressbar.set_fraction(0)
        self.update_timer_display()
        
    def update_timer_display(self):
        formatted_time_string = '%d:%02d' % (self._remaining / 60, self._remaining % 60)
        self.lbl_remaining.set_text(formatted_time_string)
        
    def tick(self):
        print "tick."
        self._remaining = self._remaining - 1
        self.update_timer_display()
        self.pb_progressbar.set_fraction(1 - float(self._remaining) / self._ticks)
        self.pb_progressbar.set_text(self.lbl_remaining.get_text())
        if self._remaining <= 0:
            print "done."
            #msgdlg = gtk.MessageDialog(self.wnd_main, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, 'Tea is ready.')
            #msgdlg.run()
            self.on_btn_stop_clicked()
        
    def main(self):
        gtk.main()

if __name__ == "__main__":
    obj = SteepTimer()
    obj.main()

<commit_msg>* Added message dialog notification that the timer has elapsed. * Use logging module for printing debug stuff instead of printing directly.<commit_after>#!/usr/bin/env python

import gtk
import gtk.glade
import gobject

#

import logging
import string
import thread
import time

#

import timer

class SteepMain:
    def __init__(self):
        logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", level=logging.DEBUG)
        gobject.threads_init()
        self._ticks = 0
        self._remaining = 0
        self._timer = timer.Timer(1, self.tick)

        # set up UI via Glade
        
        wtree = gtk.glade.XML('steep.glade')
        wtree.signal_autoconnect(self)
        
        for w in wtree.get_widget_prefix(''):
            name = w.get_name()
            assert not hasattr(self, name)
            setattr(self, name, w)
            
        self.wnd_main.show()

        #

        self.on_tea_selected()
        self.reset_timer()
        
    def on_btn_start_clicked(self, widget = None, data = None):
        self.on_tea_selected()
        logging.debug("Starting.");
        self.update_timer_display()
        self._timer.start()

    def on_btn_stop_clicked(self, widget = None, data = None):
        if not self._timer.is_running():
            return
        
        logging.debug("Stopping.")
        self._timer.stop()
        self.update_timer_display()

    def reset_timer(self):
        logging.debug("Resetting.")
        self.on_btn_stop_clicked()
        self._remaining = self._ticks
        self.update_timer_display()
        
    def on_tea_selected(self, widget = None, data = None):
        self.on_btn_stop_clicked()

        if self.rb_blacktea.get_active():
            seconds = 5 * 60
        elif self.rb_greentea.get_active():
            seconds = 3 * 60
        elif self.rb_herbaltea.get_active():
            seconds = 7 * 60
        
        self.init_timer(seconds)
    
    def on_wnd_main_delete_event(self, widget, event, data=None):
        return False

    def on_wnd_main_destroy(self, widget, data=None):
        gtk.main_quit()

    def init_timer(self, seconds):
        self._ticks = seconds
        self._remaining = self._ticks
        self.pb_progressbar.set_fraction(0)
        self.update_timer_display()
        
    def update_timer_display(self):
        formatted_time_string = '%d:%02d' % (self._remaining / 60, self._remaining % 60)
        self.pb_progressbar.set_text(formatted_time_string)
        
        if 0 != self._ticks:
            self.pb_progressbar.set_fraction(float(self._remaining) / self._ticks)

    def tick(self):
        logging.debug("tick (" + str(self._remaining) + ").")
        self._remaining = self._remaining - 1
        self.update_timer_display()

        if self._remaining <= 0:
            logging.debug("done.")
            self.on_btn_stop_clicked()
            gobject.idle_add(self.timer_elapsed)
            
    def timer_elapsed(self):
        dlg = gtk.MessageDialog(self.wnd_main, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, 'Tea is ready.')
        dlg.run()
        dlg.destroy()
        
        
    def main(self):
        gtk.main()

if __name__ == "__main__":
    obj = SteepMain()
    gtk.main()


{'fraction_non_alphanumeric': 0.10324483775811209, 'fraction_numerical': 0.007210750573582432, 'mean_word_length': 2.1106014271151885, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1704768', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1945, 'n_words': 376}