Ejemplo n.º 1
0
 def tip(self):
     """Compute tooltip text."""
     current_task = self.gtimelog_window.task_entry.get_text()
     if not current_task:
         current_task = 'nothing'
     tip = 'GTimeLog: working on {0}'.format(current_task)
     total_work, total_slacking = self.timelog.window.totals()
     tip += '\nWork done today: {0}'.format(format_duration(total_work))
     time_left = self.gtimelog_window.time_left_at_work(total_work)
     if time_left is not None:
         if time_left < datetime.timedelta(0):
             time_left = datetime.timedelta(0)
         tip += '\nTime left at work: {0}'.format(
             format_duration(time_left))
     return tip
Ejemplo n.º 2
0
 def tick(self, force_update=False):
     """Tick every second."""
     if self.timelog.check_reload():
         self.populate_log()
         self.set_up_history()
         force_update = True
     if self.task_pane.get_property('visible'):
         if self.tasks.check_reload():
             self.set_up_task_list()
     now = datetime.datetime.now().replace(second=0, microsecond=0)
     if now == self.last_tick and not force_update:
         # Do not eat CPU unnecessarily: update the time ticker only when
         # the minute changes.
         return True
     self.last_tick = now
     last_time = self.timelog.window.last_time()
     if last_time is None:
         self.time_label.set_text(now.strftime('%H:%M'))
     else:
         self.time_label.set_text(format_duration(now - last_time))
         # Update "time left to work"
         if not self.lock and self.looking_at_date is None:
             self.delete_footer()
             self.add_footer()
     return True
Ejemplo n.º 3
0
 def tick(self, force_update=False):
     """Tick every second."""
     if self.timelog.check_reload():
         self.populate_log()
         self.set_up_history()
         force_update = True
     if self.task_pane.get_property('visible'):
         if self.tasks.check_reload():
             self.set_up_task_list()
     now = datetime.datetime.now().replace(second=0, microsecond=0)
     if now == self.last_tick and not force_update:
         # Do not eat CPU unnecessarily: update the time ticker only when
         # the minute changes.
         return True
     self.last_tick = now
     last_time = self.timelog.window.last_time()
     if last_time is None:
         self.time_label.set_text(now.strftime('%H:%M'))
     else:
         self.time_label.set_text(format_duration(now - last_time))
         # Update "time left to work"
         if not self.lock and self.looking_at_date is None:
             self.delete_footer()
             self.add_footer()
     return True
Ejemplo n.º 4
0
 def tip(self):
     """Compute tooltip text."""
     # NB: returns UTF-8 text instead of Unicode on Python 2.  This
     # seems to be harmless for now.
     current_task = self.gtimelog_window.task_entry.get_text()
     if not current_task:
         current_task = 'nothing'
     tip = 'GTimeLog: working on {0}'.format(current_task)
     total_work, total_slacking = self.timelog.window.totals()
     tip += '\nWork done today: {0}'.format(format_duration(total_work))
     time_left = self.gtimelog_window.time_left_at_work(total_work)
     if time_left is not None:
         if time_left < datetime.timedelta(0):
             time_left = datetime.timedelta(0)
         tip += '\nTime left at work: {0}'.format(
             format_duration(time_left))
     return tip
Ejemplo n.º 5
0
 def tip(self):
     """Compute tooltip text."""
     # NB: returns UTF-8 text instead of Unicode on Python 2.  This
     # seems to be harmless for now.
     current_task = self.gtimelog_window.task_entry.get_text()
     if not current_task:
         current_task = 'nothing'
     tip = 'GTimeLog: working on {0}'.format(current_task)
     total_work, total_slacking = self.timelog.window.totals()
     tip += '\nWork done today: {0}'.format(format_duration(total_work))
     time_left = self.gtimelog_window.time_left_at_work(total_work)
     if time_left is not None:
         if time_left < datetime.timedelta(0):
             time_left = datetime.timedelta(0)
         tip += '\nTime left at work: {0}'.format(
             format_duration(time_left))
     return tip
Ejemplo n.º 6
0
 def write_item(self, item):
     buffer = self.log_buffer
     start, stop, duration, tags, entry = item
     self.w(format_duration(duration), 'duration')
     period = '\t({0}-{1})\t'.format(
         start.strftime('%H:%M'), stop.strftime('%H:%M'))
     self.w(period, 'time')
     tag = ('slacking' if '**' in entry else None)
     self.w(entry + '\n', tag)
     where = buffer.get_end_iter()
     where.backward_cursor_position()
     buffer.place_cursor(where)
Ejemplo n.º 7
0
 def write_item(self, item):
     buffer = self.log_buffer
     start, stop, duration, entry = item
     self.w(format_duration(duration), 'duration')
     period = '\t({0}-{1})\t'.format(
         start.strftime('%H:%M'), stop.strftime('%H:%M'))
     self.w(period, 'time')
     tag = ('slacking' if '**' in entry else None)
     self.w(entry + '\n', tag)
     where = buffer.get_end_iter()
     where.backward_cursor_position()
     buffer.place_cursor(where)
Ejemplo n.º 8
0
 def write_group(self, entry, duration):
     self.w(format_duration(duration), 'duration')
     tag = ('slacking' if '**' in entry else None)
     self.w('\t' + entry + '\n', tag)
Ejemplo n.º 9
0
    def add_footer(self):
        buffer = self.log_buffer
        self.footer_mark = buffer.create_mark(
            'footer', buffer.get_end_iter(), True)
        window = self.daily_window(self.looking_at_date)
        total_work, total_slacking = window.totals()
        weekly_window = self.weekly_window(self.looking_at_date)
        week_total_work, week_total_slacking = weekly_window.totals()
        work_days_this_week = weekly_window.count_days()

        self.w('\n')
        self.w('Total work done: ')
        self.w(format_duration(total_work), 'duration')
        self.w(' (')
        self.w(format_duration(week_total_work), 'duration')
        self.w(' this week')
        if work_days_this_week:
            per_diem = week_total_work / work_days_this_week
            self.w(', ')
            self.w(format_duration(per_diem), 'duration')
            self.w(' per day')
        self.w(')\n')
        self.w('Total slacking: ')
        self.w(format_duration(total_slacking), 'duration')
        self.w(' (')
        self.w(format_duration(week_total_slacking), 'duration')
        self.w(' this week')
        if work_days_this_week:
            per_diem = week_total_slacking / work_days_this_week
            self.w(', ')
            self.w(format_duration(per_diem), 'duration')
            self.w(' per day')
        self.w(')\n')

        if self.looking_at_date is None:
            time_left = self.time_left_at_work(total_work)
        else:
            time_left = None
        if time_left is not None:
            time_to_leave = datetime.datetime.now() + time_left
            if time_left < datetime.timedelta(0):
                time_left = datetime.timedelta(0)
            self.w('Time left at work: ')
            self.w(format_duration(time_left), 'duration')
            self.w(' (till ')
            self.w(time_to_leave.strftime('%H:%M'), 'time')
            self.w(')')

        if self.settings.show_office_hours and self.looking_at_date is None:
            self.w('\nAt office today: ')
            hours = datetime.timedelta(hours=self.settings.hours)
            total = total_slacking + total_work
            self.w("%s " % format_duration(total), 'duration')
            self.w('(')
            if total > hours:
                self.w(format_duration(total - hours), 'duration')
                self.w(' overtime')
            else:
                self.w(format_duration(hours - total), 'duration')
                self.w(' left')
            self.w(')')
Ejemplo n.º 10
0
 def write_group(self, entry, duration):
     self.w(format_duration(duration), 'duration')
     tag = ('slacking' if '**' in entry else None)
     self.w('\t' + entry + '\n', tag)
Ejemplo n.º 11
0
    def add_footer(self):
        buffer = self.log_buffer
        self.footer_mark = buffer.create_mark(
            'footer', buffer.get_end_iter(), True)
        window = self.daily_window(self.looking_at_date)
        total_work, total_slacking = window.totals()
        weekly_window = self.weekly_window(self.looking_at_date)
        week_total_work, week_total_slacking = weekly_window.totals()
        work_days_this_week = weekly_window.count_days()

        self.w('\n')
        self.w('Total work done: ')
        self.w(format_duration(total_work), 'duration')
        self.w(' (')
        self.w(format_duration(week_total_work), 'duration')
        self.w(' this week')
        if work_days_this_week:
            per_diem = week_total_work / work_days_this_week
            self.w(', ')
            self.w(format_duration(per_diem), 'duration')
            self.w(' per day')
        self.w(')\n')
        self.w('Total slacking: ')
        self.w(format_duration(total_slacking), 'duration')
        self.w(' (')
        self.w(format_duration(week_total_slacking), 'duration')
        self.w(' this week')
        if work_days_this_week:
            per_diem = week_total_slacking / work_days_this_week
            self.w(', ')
            self.w(format_duration(per_diem), 'duration')
            self.w(' per day')
        self.w(')\n')

        if self.looking_at_date is None:
            time_left = self.time_left_at_work(total_work)
        else:
            time_left = None
        if time_left is not None:
            time_to_leave = datetime.datetime.now() + time_left
            if time_left < datetime.timedelta(0):
                time_left = datetime.timedelta(0)
            self.w('Time left at work: ')
            self.w(format_duration(time_left), 'duration')
            self.w(' (till ')
            self.w(time_to_leave.strftime('%H:%M'), 'time')
            self.w(')')

        if self.settings.show_office_hours and self.looking_at_date is None:
            self.w('\nAt office today: ')
            hours = datetime.timedelta(hours=self.settings.hours)
            total = total_slacking + total_work
            self.w("%s " % format_duration(total), 'duration')
            self.w('(')
            if total > hours:
                self.w(format_duration(total - hours), 'duration')
                self.w(' overtime')
            else:
                self.w(format_duration(hours - total), 'duration')
                self.w(' left')
            self.w(')')