def show_popup(self): focus_time = figure_time(self.get_text()) hours = gtk.ListStore(gobject.TYPE_STRING) # populate times i_time = self.start_time or dt.datetime(1900, 1, 1, 0, 0) if focus_time and focus_time < i_time: focus_time += dt.timedelta(days = 1) if self.start_time: end_time = i_time + dt.timedelta(hours = 12) i_time += dt.timedelta(minutes = 15) else: end_time = i_time + dt.timedelta(hours = 24) i, focus_row = 0, None while i_time < end_time: row_text = self._format_time(i_time) if self.start_time: delta = (i_time - self.start_time).seconds / 60 delta_text = format_duration(delta) row_text += " (%s)" % delta_text hours.append([row_text]) if focus_time and i_time <= focus_time <= i_time + \ dt.timedelta(minutes = 30): focus_row = i if self.start_time: i_time += dt.timedelta(minutes = 15) else: i_time += dt.timedelta(minutes = 30) i += 1 self.time_tree.set_model(hours) #focus on row if focus_row != None: self.time_tree.set_cursor(focus_row) self.time_tree.scroll_to_cell(focus_row, use_align = True, row_align = 0.4) #move popup under the widget alloc = self.get_allocation() w = alloc.width if self.start_time: w = w * 2 self.time_tree.set_size_request(w, alloc.height * 5) window = self.get_parent_window() x, y= window.get_origin() self.popup.move(x + alloc.x,y + alloc.y + alloc.height) self.popup.show_all()
def fill_tree(self, facts): day_dict = {} for day, facts in groupby(facts, lambda fact: fact["date"]): day_dict[day] = sorted(list(facts), key=lambda fact:fact["start_time"]) for i in range((self.end_date - self.start_date).days + 1): current_date = self.start_date + dt.timedelta(i) # date format in overview window fact listing # prefix is "o_",letter after prefix is regular python format. you can use all of them fact_date = _("%(o_A)s, %(o_b)s %(o_d)s") % stuff.dateDict(current_date, "o_") day_total = dt.timedelta() for fact in day_dict.get(current_date, []): day_total += fact["delta"] day_row = self.fact_store.append(None, [-1, fact_date, stuff.format_duration(day_total), current_date.strftime('%Y-%m-%d'), "", "", None]) for fact in day_dict.get(current_date, []): self.fact_store.append(day_row, [fact["id"], fact["start_time"].strftime('%H:%M') + " " + fact["name"], stuff.format_duration(fact["delta"]), fact["start_time"].strftime('%Y-%m-%d'), fact["description"], fact["category"], fact ]) self.fact_tree.expand_all()
def _write_fact(self, report, fact): end_time = fact["end_time"] # ongoing task in current day end_time_str = "" if end_time: end_time_str = end_time.strftime('%H:%M') category = "" if fact["category"] != _("Unsorted"): #do not print "unsorted" in list category = fact["category"] description = fact["description"] or "" # fact date column in HTML report report.write("""<tr class="row%d"> <td class="smallCell">%s</td> <td class="largeCell">%s</td> <td class="smallCell">%s</td> <td class="smallCell">%s</td> <td class="smallCell">%s</td> <td class="smallCell">%s</td> <td class="largeCell">%s</td> </tr> """ % (int(self.even_row), _("%(report_b)s %(report_d)s, %(report_Y)s") % stuff.dateDict(fact["start_time"], "report_"), fact["name"], category, fact["start_time"].strftime('%H:%M'), end_time_str, stuff.format_duration(fact["delta"]) or "", description)) self.even_row = not self.even_row # save data for summary table if fact["delta"]: id_string = "<td class=\"smallCell\">%s</td><td class=\"largeCell\">%s</td>" % (fact["category"], fact["name"]) self.sum_time[id_string] = self.sum_time.get(id_string, 0) + fact["delta"]
def plot(self, keys, data): self.data = data bars = dict([(bar.key, bar.normalized) for bar in self.bars]) max_val = float(max(data or [0])) new_bars, new_labels = [], [] for key, value in zip(keys, data): if max_val: normalized = value / max_val else: normalized = 0 bar = Bar(key, "%s (%s)" % ( locale.format(self.value_format, value), stuff.format_duration(value*60), ), normalized, self.label_color) bar.interactive = self.graph_interactive if key in bars: bar.normalized = bars[key] self.tweener.add_tween(bar, normalized=normalized) new_bars.append(bar) label = graphics.Label(stuff.escape_pango(key), size = 8, alignment = pango.ALIGN_RIGHT) new_labels.append(label) self.plot_area.remove_child(*self.bars) self.remove_child(*self.labels) self.bars, self.labels = new_bars, new_labels self.add_child(*self.labels) self.plot_area.add_child(*self.bars) self.show() self.redraw()
def _finish(self, report, facts): report.write("</table>") # summary table report.write("\n<h2>%s</h2>\n" % _("Totals")) report.write("""<table> <tr> <th class="smallCell">""" + _("Category") + """</th> <th class="largeCell">""" + _("Activity") + """</th> <th class="smallCell">""" + _("Duration") + """</th> </tr>\n""") tot_time = 0 even_row = False for key in sorted(self.sum_time.keys()): report.write(" <tr class=\"row%d\">%s<td class=\"smallCell\">%s</td></tr>\n" % (int(even_row), key, stuff.format_duration(self.sum_time[key]))) tot_time += self.sum_time[key] even_row = not even_row report.write(" <tr><th colspan=\"2\" style=\"text-align:right;\">" + _("Total Time") + ":</th><th>%s</th></tr>\n" % (stuff.format_duration(tot_time))) report.write("</table>\n") report.write("</body>\n</html>")