def __init__(self, parent_window): super(HistoryView, self).__init__() self.parent_window = parent_window self.calendar = gtk.Calendar() self.tomato_view = self._create_tomato_view() self.tomato_model = self.tomato_view.get_model() self.stat_model = WeeklyStatisticsModel() self.stat_graph = WeeklyBarChart(self.stat_model) tomato_wnd = gtk.ScrolledWindow() tomato_wnd.add(self.tomato_view) tomato_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) tomato_view = gtk.Viewport() tomato_view.add(tomato_wnd) top_hbox = gtk.HBox(False, 0) top_hbox.pack_start(self.calendar, False, False, padding=5) top_hbox.pack_start(tomato_view, True, True, padding=5) top_vbox = gtk.VBox(False, 0) top_vbox.pack_start(top_hbox, True, True, padding=5) self.pack1(top_vbox, shrink=False) self.pack2(self.stat_graph, shrink=False) self._on_day_changed(self.calendar) self.calendar.connect('day-selected', self._on_day_changed)
class HistoryView(gtk.VPaned): """Activity history view""" def __init__(self, parent_window): super(HistoryView, self).__init__() self.parent_window = parent_window self.calendar = gtk.Calendar() self.tomato_view = self._create_tomato_view() self.tomato_model = self.tomato_view.get_model() self.stat_model = WeeklyStatisticsModel() self.stat_graph = WeeklyBarChart(self.stat_model) tomato_wnd = gtk.ScrolledWindow() tomato_wnd.add(self.tomato_view) tomato_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) tomato_view = gtk.Viewport() tomato_view.add(tomato_wnd) top_hbox = gtk.HBox(False, 0) top_hbox.pack_start(self.calendar, False, False, padding=5) top_hbox.pack_start(tomato_view, True, True, padding=5) top_vbox = gtk.VBox(False, 0) top_vbox.pack_start(top_hbox, True, True, padding=5) self.pack1(top_vbox, shrink=False) self.pack2(self.stat_graph, shrink=False) self._on_day_changed(self.calendar) self.calendar.connect('day-selected', self._on_day_changed) def _create_tomato_view(self): def _set_bg(col, renderer, model, iter, user_data=None): interrupted = model.get_value(iter, 2) bgcolor = interrupted and '#F79292' or '#92F792' renderer.set_property('cell-background', bgcolor) view = gtk.TreeView() model = FinishedTomatoModel() view.set_model(model) time_renderer = gtk.CellRendererText() time_col = gtk.TreeViewColumn(_('Time Range'), time_renderer, text=0) time_col.set_cell_data_func(time_renderer, _set_bg) time_col.set_resizable(True) time_col.set_expand(True) activity_renderer = gtk.CellRendererText() activity_col = gtk.TreeViewColumn(_('Activity'), activity_renderer, text=1) activity_col.set_cell_data_func(activity_renderer, _set_bg) activity_col.set_resizable(True) activity_col.set_expand(True) view.append_column(time_col) view.append_column(activity_col) return view def refresh(self): self._on_day_changed(self.calendar, force=True) def _on_day_changed(self, calendar, force=False): y, m, d = calendar.get_date() #The month is 0-based, so we need to add 1 to it selected_day = date(y, m + 1, d) tomato_count, interruption_count = self.tomato_model.load_finished_tomatoes(selected_day) self.stat_model.reload_data(selected_day, force=force)
class HistoryView(gtk.VPaned): """Activity history view""" def __init__(self, parent_window): super(HistoryView, self).__init__() self.parent_window = parent_window self.calendar = gtk.Calendar() self.tomato_view = self._create_tomato_view() self.tomato_model = self.tomato_view.get_model() self.stat_model = WeeklyStatisticsModel() self.stat_graph = WeeklyBarChart(self.stat_model) tomato_wnd = gtk.ScrolledWindow() tomato_wnd.add(self.tomato_view) tomato_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) tomato_view = gtk.Viewport() tomato_view.add(tomato_wnd) top_hbox = gtk.HBox(False, 0) top_hbox.pack_start(self.calendar, False, False, padding=5) top_hbox.pack_start(tomato_view, True, True, padding=5) top_vbox = gtk.VBox(False, 0) top_vbox.pack_start(top_hbox, True, True, padding=5) self.pack1(top_vbox, shrink=False) self.pack2(self.stat_graph, shrink=False) self._on_day_changed(self.calendar) self.calendar.connect('day-selected', self._on_day_changed) def _create_tomato_view(self): def _set_bg(col, renderer, model, iter, user_data=None): interrupted = model.get_value(iter, 2) bgcolor = interrupted and '#F79292' or '#92F792' renderer.set_property('cell-background', bgcolor) view = gtk.TreeView() model = FinishedTomatoModel() view.set_model(model) time_renderer = gtk.CellRendererText() time_col = gtk.TreeViewColumn(_('Time Range'), time_renderer, text=0) time_col.set_cell_data_func(time_renderer, _set_bg) time_col.set_resizable(True) time_col.set_expand(True) activity_renderer = gtk.CellRendererText() activity_col = gtk.TreeViewColumn(_('Activity'), activity_renderer, text=1) activity_col.set_cell_data_func(activity_renderer, _set_bg) activity_col.set_resizable(True) activity_col.set_expand(True) view.append_column(time_col) view.append_column(activity_col) return view def refresh(self): self._on_day_changed(self.calendar, force=True) def _on_day_changed(self, calendar, force=False): y, m, d = calendar.get_date() #The month is 0-based, so we need to add 1 to it selected_day = date(y, m + 1, d) tomato_count, interruption_count = self.tomato_model.load_finished_tomatoes( selected_day) self.stat_model.reload_data(selected_day, force=force)