def __init__(self, ui, plugin): # Visible, MCOL_CODE, MCOL_CITA, MCOL_PAGE, MCOL_NCIT, MCOL_RGID, MCOL_TAGS self.real_model = gtk.TreeStore(bool, str, str, str, str, int, object) model = self.real_model.filter_new() model.set_visible_column(self.MCOL_VISI) model = gtk.TreeModelSort(model) BrowserTreeView.__init__(self, model) self.ui = ui self.plugin = plugin self.filter = None self.tag_filter = None self.label_filter = None self._tags = {} self._labels = {} # Description column cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn(_('QdaCode'), cell_renderer, markup=self.MCOL_CODE) column.set_resizable(True) column.set_sort_column_id(self.MCOL_CODE) column.set_expand(True) column.set_min_width(200) self.append_column(column) self.set_expander_column(column) # Citation column cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Text'), cell_renderer, text=self.MCOL_CITA) column.set_resizable(True) column.set_sort_column_id(self.MCOL_CITA) column.set_min_width(200) column.set_max_width(300) self.append_column(column) # Rendering for page name column cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.MCOL_PAGE) column.set_sort_column_id(self.MCOL_PAGE) self.append_column(column) # Nro Citation in the page cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_(' # '), cell_renderer, text=self.MCOL_NCIT) column.set_sort_column_id(self.MCOL_NCIT) self.append_column(column) # Finalize self.refresh() # HACK because we can not register ourselves :S self.connect('row_activated', self.__class__.do_row_activated)
def __init__(self, ui): model = gtk.ListStore(str, int, object) # NAME_COL, SCORE_COL, PATH_COL BrowserTreeView.__init__(self, model) self.ui = ui self.query = None self.selection = SearchSelection(ui.notebook) self.cancelled = False cell_renderer = gtk.CellRendererText() for name, i in ( (_('Page'), 0), # T: Column header search dialog (_('Score'), 1), # T: Column header search dialog ): column = gtk.TreeViewColumn(name, cell_renderer, text=i) column.set_sort_column_id(i) if i == 0: column.set_expand(True) self.append_column(column) model.set_sort_column_id(1, gtk.SORT_DESCENDING) # By default sort by score self.connect('row-activated', self._do_open_page) self.connect('destroy', self.__class__._cancel)
def __init__(self): BrowserTreeView.__init__(self, ToCTreeModel()) self.set_headers_visible(False) self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) # Allow select multiple cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn('_heading_', cell_renderer, text=TEXT_COL) self.append_column(column)
def __init__(self): BrowserTreeView.__init__(self, LinksTreeModel()) self.set_headers_visible(False) cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn('_page_', cell_renderer, text=TEXT_COL) self.append_column(column) if gtk.gtk_version >= (2, 12, 0): self.set_tooltip_column(TEXT_COL)
def __init__(self): BrowserTreeView.__init__(self) model = gtk.TreeStore(str, object, object) # BASENAME_COL, FILE_COL, DEFAULT_COL self.set_model(model) self.set_headers_visible(False) cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn('_template_', cell_renderer, text=self.BASENAME_COL) self.append_column(column) self.refresh()
def __init__(self, ui): BrowserTreeView.__init__(self) model = PluginsTreeModel(ui) self.set_model(model) cellrenderer = gtk.CellRendererToggle() cellrenderer.connect('toggled', lambda o, p: model.do_toggle_path(p)) self.append_column( gtk.TreeViewColumn(_('Enabled'), cellrenderer, active=0)) # T: Column in plugin tab self.append_column( gtk.TreeViewColumn(_('Plugin'), gtk.CellRendererText(), text=1))
def __init__(self, ellipsis): BrowserTreeView.__init__(self, ToCTreeModel()) self.set_headers_visible(False) self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) # Allow select multiple cell_renderer = gtk.CellRendererText() if ellipsis: cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn('_heading_', cell_renderer, text=TEXT_COL) column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) # Without this sizing, column width only grows and never shrinks self.append_column(column)
def __init__(self): model = Gtk.ListStore(str, float) # NAME_COL, MODIFIED_COL BrowserTreeView.__init__(self, model) cell_renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.NAME_COL) # T: Column header column.set_sort_column_id(self.NAME_COL) column.set_expand(True) self.append_column(column) today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) def render_date(col, cell, model, i, data): mtime = model.get_value(i, self.MODIFIED_COL) if mtime: dt = datetime.datetime.fromtimestamp(mtime) date = dt.date() if date == today: text = _('Today') + datetime.strftime(' %H:%M', dt) # T: label for modified time elif date == yesterday: text = _('Yesterday') + datetime.strftime(' %H:%M', dt) # T: label for modified time elif date.year == today.year: text = datetime.strftime( '%a %d %b %H:%M', dt) # TODO allow config for format ? else: text = datetime.strftime( '%a %d %b %Y %H:%M', dt) # TODO allow config for format ? else: text = '' cell.set_property('text', text) cell_renderer = Gtk.CellRendererText() #cell_renderer.set_property('font', 'mono') column = Gtk.TreeViewColumn(_('Last Modified'), cell_renderer) # T: Column header column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.MODIFIED_COL) self.append_column(column)
def __init__(self, ui, model=None): '''Constructor @param ui: the L{GtkInterface} object @param model: a L{PageTreeStore} object ''' BrowserTreeView.__init__(self) self.set_name('zim-pageindex') self.ui = ui self._cleanup = None # temporary created path that needs to be removed later column = gtk.TreeViewColumn('_pages_') self.append_column(column) cr1 = gtk.CellRendererText() cr1.set_property('ellipsize', pango.ELLIPSIZE_END) column.pack_start(cr1, True) column.set_attributes(cr1, text=NAME_COL, style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL) cr2 = self.get_cell_renderer_number_of_items() column.pack_start(cr2, False) column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL) if gtk.gtk_version >= (2, 12) \ and gtk.pygtk_version >= (2, 12): self.set_tooltip_column(TIP_COL) self.set_headers_visible(False) self.set_enable_search(True) self.set_search_column(0) self.enable_model_drag_source( gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET,), gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE ) self.enable_model_drag_dest( (INTERNAL_PAGELIST_TARGET,), gtk.gdk.ACTION_MOVE ) if ui_environment['platform'] == 'maemo': # Maemo gtk UI bugfix: expanders are hidden by default self.set_property('level-indentation', 0) self.set_property('show-expanders', 1) if model: self.set_model(model)
def _PageTreeView_init_(self, ui): ''' This is a slightly modified copy of PageTreeView constructor with one additional column for icons. ''' BrowserTreeView.__init__(self) self.set_name('zim-pageindex') self.ui = ui self._cleanup = None # temporary created path that needs to be removed later column = gtk.TreeViewColumn('_pages_') self.append_column(column) # Added Icon column. cr0 = gtk.CellRendererPixbuf() column.pack_start(cr0, expand=False) column.set_attributes(cr0, pixbuf=ICON_COL) cr1 = gtk.CellRendererText() cr1.set_property('ellipsize', pango.ELLIPSIZE_END) column.pack_start(cr1, True) column.set_attributes(cr1, text=NAME_COL, style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL) cr2 = self.get_cell_renderer_number_of_items() column.pack_start(cr2, False) column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL) if gtk.gtk_version >= (2, 12) \ and gtk.pygtk_version >= (2, 12): self.set_tooltip_column(TIP_COL) self.set_headers_visible(False) self.set_enable_search(True) self.set_search_column(0) self.enable_model_drag_source( gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET, ), gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE) self.enable_model_drag_dest((INTERNAL_PAGELIST_TARGET, ), gtk.gdk.ACTION_MOVE)
def __init__(self, ui): model = gtk.ListStore(str, str) # NAME_COL, MODIFIED_COL BrowserTreeView.__init__(self, model) self.ui = ui cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.NAME_COL) # T: Column header column.set_sort_column_id(self.NAME_COL) column.set_expand(True) self.append_column(column) today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) def render_date(col, cell, model, i): utime = model.get_value(i, self.MODIFIED_COL) if utime: utime = float(utime) dt = datetime.datetime.fromtimestamp(utime) date = dt.date() if date == today: text = _('Today') + dt.strftime(' %H:%M') # T: label for modified time elif date == yesterday: text = _('Yesterday') + dt.strftime(' %H:%M') # T: label for modified time elif date.year == today.year: text = dt.strftime('%a %d %b %H:%M') # TODO allow config for format ? else: text = dt.strftime('%a %d %b, %Y %H:%M') # TODO allow config for format ? else: text = '' cell.set_property('text', text) cell_renderer = gtk.CellRendererText() #cell_renderer.set_property('font', 'mono') column = gtk.TreeViewColumn(_('Last Modified'), cell_renderer, text=self.MODIFIED_COL) # T: Column header column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.MODIFIED_COL) self.append_column(column) self.connect('row-activated', self._do_open_page)
def __init__(self, ui, model=None): '''Constructor @param ui: the L{GtkInterface} object @param model: a L{PageTreeStore} object ''' BrowserTreeView.__init__(self) self.set_name('zim-pageindex') self.ui = ui column = gtk.TreeViewColumn('_pages_') self.append_column(column) cr1 = gtk.CellRendererText() cr1.set_property('ellipsize', pango.ELLIPSIZE_END) column.pack_start(cr1, True) column.set_attributes(cr1, text=NAME_COL, style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL) cr2 = self.get_cell_renderer_number_of_items() column.pack_start(cr2, False) column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL) if gtk.gtk_version >= (2, 12) \ and gtk.pygtk_version >= (2, 12): self.set_tooltip_column(TIP_COL) self.set_headers_visible(False) self.set_enable_search(True) self.set_search_column(0) self.enable_model_drag_source( gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET, ), gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE) self.enable_model_drag_dest((INTERNAL_PAGELIST_TARGET, ), gtk.gdk.ACTION_MOVE) if model: self.set_model(model)
def _PageTreeView_init_(self, ui): ''' This is a slightly modified copy of PageTreeView constructor with one additional column for icons. ''' BrowserTreeView.__init__(self) self.set_name('zim-pageindex') self.ui = ui self._cleanup = None # temporary created path that needs to be removed later column = gtk.TreeViewColumn('_pages_') self.append_column(column) # Added Icon column. cr0 = gtk.CellRendererPixbuf() column.pack_start(cr0, expand = False) column.set_attributes(cr0, pixbuf = ICON_COL) cr1 = gtk.CellRendererText() cr1.set_property('ellipsize', pango.ELLIPSIZE_END) column.pack_start(cr1, True) column.set_attributes(cr1, text=NAME_COL, style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL) cr2 = self.get_cell_renderer_number_of_items() column.pack_start(cr2, False) column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL) if gtk.gtk_version >= (2, 12) \ and gtk.pygtk_version >= (2, 12): self.set_tooltip_column(TIP_COL) self.set_headers_visible(False) self.set_enable_search(True) self.set_search_column(0) self.enable_model_drag_source( gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET,), gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE ) self.enable_model_drag_dest( (INTERNAL_PAGELIST_TARGET,), gtk.gdk.ACTION_MOVE )
def __init__(self, notebook, navigation, model=None): BrowserTreeView.__init__(self) self.set_name('zim-pageindex') self.notebook = notebook self.navigation = navigation column = Gtk.TreeViewColumn('_pages_') column.set_expand(True) self.append_column(column) cr1 = Gtk.CellRendererText() cr1.set_property('ellipsize', Pango.EllipsizeMode.END) column.pack_start(cr1, True) column.set_attributes(cr1, text=NAME_COL, style=STYLE_COL, sensitive=EXISTS_COL, weight=WEIGHT_COL) column = Gtk.TreeViewColumn('_n_items_') self.append_column(column) cr2 = self.get_cell_renderer_number_of_items() column.pack_start(cr2, False) column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL) self.set_tooltip_column(TIP_COL) self.set_headers_visible(False) self.set_enable_search(True) self.set_search_column(0) self.enable_model_drag_source( Gdk.ModifierType.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET, ), Gdk.DragAction.LINK | Gdk.DragAction.MOVE) self.enable_model_drag_dest((INTERNAL_PAGELIST_TARGET, ), Gdk.DragAction.MOVE) if model: self.set_model(model)
def __init__(self, ui): model = gtk.ListStore(str, int) # page, rank BrowserTreeView.__init__(self, model) self.ui = ui self.searcher = Searcher(ui.notebook) cell_renderer = gtk.CellRendererText() for name, i in ( (_('Page'), 0), # T: Column header search dialog (_('Score'), 1), # T: Column header search dialog ): column = gtk.TreeViewColumn(name, cell_renderer, text=i) column.set_sort_column_id(i) if i == 0: column.set_expand(True) self.append_column(column) model.set_sort_column_id(1, gtk.SORT_DESCENDING) # By default sort by score self.connect('row-activated', self._do_open_page) # FIXME
def __init__(self, tasksview, opener, task_labels, nonactionable_tags=(), filter_actionable=False, tag_by_page=False, use_workweek=False, compact=False, flatlist=False, sort_column=PRIO_COL, sort_order=Gtk.SortType.DESCENDING): self.real_model = Gtk.TreeStore(bool, bool, int, str, str, object, str, str, int, int, str) # VIS_COL, ACT_COL, PRIO_COL, START_COL, DUE_COL, TAGS_COL, DESC_COL, PAGE_COL, TASKID_COL, PRIO_SORT_COL, PRIO_SORT_LABEL_COL model = self.real_model.filter_new() model.set_visible_column(self.VIS_COL) model = Gtk.TreeModelSort(model) model.set_sort_column_id(sort_column, sort_order) BrowserTreeView.__init__(self, model) self.tasksview = tasksview self.opener = opener self.filter = None self.tag_filter = None self.label_filter = None self.filter_actionable = filter_actionable self.nonactionable_tags = tuple( t.strip('@').lower() for t in nonactionable_tags) self.tag_by_page = tag_by_page self.task_labels = task_labels self._tags = {} self._labels = {} self.flatlist = flatlist # Add some rendering for the Prio column def render_prio(col, cell, model, i, data): prio = model.get_value(i, self.PRIO_COL) text = model.get_value(i, self.PRIO_SORT_LABEL_COL) if text.startswith('>'): text = '<span color="darkgrey">%s</span>' % text bg = None else: bg = COLORS[min(prio, 3)] cell.set_property('markup', text) cell.set_property('cell-background', bg) cell_renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn('!', cell_renderer) column.set_cell_data_func(cell_renderer, render_prio) column.set_sort_column_id(self.PRIO_SORT_COL) self.append_column(column) # Rendering for task description column cell_renderer = Gtk.CellRendererText() cell_renderer.set_property('ellipsize', Pango.EllipsizeMode.END) column = Gtk.TreeViewColumn(_('Task'), cell_renderer, markup=self.DESC_COL) # T: Column header Task List dialog column.set_resizable(True) column.set_sort_column_id(self.DESC_COL) column.set_expand(True) if compact: column.set_min_width(100) else: column.set_min_width(300) # don't let this column get too small self.append_column(column) self.set_expander_column(column) # custom tooltip self.props.has_tooltip = True self.connect("query-tooltip", self._query_tooltip_cb) # Rendering of the Date column day_of_week = datetime.date.today().isoweekday() if use_workweek and day_of_week == 4: # Today is Thursday - 2nd day ahead is after the weekend delta1, delta2 = 1, 3 elif use_workweek and day_of_week == 5: # Today is Friday - next day ahead is after the weekend delta1, delta2 = 3, 4 else: delta1, delta2 = 1, 2 today = str(datetime.date.today()) tomorrow = str(datetime.date.today() + datetime.timedelta(days=delta1)) dayafter = str(datetime.date.today() + datetime.timedelta(days=delta2)) def render_date(col, cell, model, i, data): date = model.get_value(i, self.DUE_COL) if date == _MAX_DUE_DATE: cell.set_property('text', '') else: cell.set_property('text', date) # TODO allow strftime here if date <= today: color = HIGH_COLOR elif date <= tomorrow: color = MEDIUM_COLOR elif date <= dayafter: color = ALERT_COLOR # "<=" because tomorrow and/or dayafter can be after the weekend else: color = None cell.set_property('cell-background', color) if not compact: cell_renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_('Date'), cell_renderer) # T: Column header Task List dialog column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.DUE_COL) self.append_column(column) # Rendering for page name column if not compact: cell_renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.PAGE_COL) # T: Column header Task List dialog column.set_sort_column_id(self.PAGE_COL) self.append_column(column) # Finalize self.refresh() # HACK because we can not register ourselves :S self.connect('row_activated', self.__class__.do_row_activated) self.connect('focus-in-event', self.__class__.do_focus_in_event)
def __init__(self, index_ext, opener): self.real_model = gtk.TreeStore(bool, int, str, str, str, str) # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, TASKID_COL, DESCR_COL model = self.real_model.filter_new() model.set_visible_column(self.VIS_COL) model = gtk.TreeModelSort(model) model.set_sort_column_id(self.PRIO_COL, gtk.SORT_DESCENDING) BrowserTreeView.__init__(self, model) self.index_ext = index_ext self.opener = opener self.filter = None # Add some rendering for the Prio column def render_prio(col, cell, model, i): prio = model.get_value(i, self.PRIO_COL) cell.set_property('text', str(prio)) if prio >= 3: color = HIGH_COLOR elif prio == 2: color = MEDIUM_COLOR elif prio == 1: color = ALERT_COLOR else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() #~ column = gtk.TreeViewColumn(_('Prio'), cell_renderer) # T: Column header Task List dialog column = gtk.TreeViewColumn(' ! ', cell_renderer) column.set_cell_data_func(cell_renderer, render_prio) column.set_sort_column_id(self.PRIO_COL) self.append_column(column) # Rendering for task summary column cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn(_('Task'), cell_renderer, markup=self.TASK_COL) # T: Column header Task List dialog column.set_resizable(True) column.set_sort_column_id(self.TASK_COL) column.set_expand(True) if ui_environment['platform'] == 'maemo': column.set_min_width(250) # don't let this column get too small else: column.set_min_width(300) # don't let this column get too small self.append_column(column) self.set_expander_column(column) if gtk.gtk_version >= (2, 12, 0): self.set_tooltip_column(self.TASK_COL) day_of_week = datetime.date.today().isoweekday() delta1, delta2 = 1, 2 today = str( datetime.date.today() ) tomorrow = str( datetime.date.today() + datetime.timedelta(days=delta1)) dayafter = str( datetime.date.today() + datetime.timedelta(days=delta2)) def render_date(col, cell, model, i): date = model.get_value(i, self.DATE_COL) if date == _NO_DATE: cell.set_property('text', '') else: cell.set_property('text', date) # TODO allow strftime here if date <= today: color = HIGH_COLOR elif date <= tomorrow: color = MEDIUM_COLOR elif date <= dayafter: color = ALERT_COLOR # "<=" because tomorrow and/or dayafter can be after the weekend else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Date'), cell_renderer) # T: Column header Task List dialog column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.DATE_COL) self.append_column(column) # Finalize self.refresh()
def __init__(self, ui, plugin, filter_actionable): self.real_model = gtk.TreeStore(bool, int, str, str, str, bool, bool, int, object) # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, PAGE_COL, ACT_COL, OPEN_COL, TASKID_COL, TAGS_COL model = self.real_model.filter_new() model.set_visible_column(self.VIS_COL) model = gtk.TreeModelSort(model) model.set_sort_column_id(self.PRIO_COL, gtk.SORT_DESCENDING) BrowserTreeView.__init__(self, model) self.ui = ui self.plugin = plugin self.filter = None self.tag_filter = None self.label_filter = None self.filter_actionable = filter_actionable self._tags = {} self._labels = {} # Add some rendering for the Prio column def render_prio(col, cell, model, i): prio = model.get_value(i, self.PRIO_COL) cell.set_property('text', str(prio)) if prio >= 3: color = HIGH_COLOR elif prio == 2: color = MEDIUM_COLOR elif prio == 1: color = ALERT_COLOR else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() # ~ column = gtk.TreeViewColumn(_('Prio'), cell_renderer) # T: Column header Task List dialog column = gtk.TreeViewColumn(' ! ', cell_renderer) column.set_cell_data_func(cell_renderer, render_prio) column.set_sort_column_id(self.PRIO_COL) self.append_column(column) # Rendering for task description column cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn(_('Task'), cell_renderer, markup=self.TASK_COL) # T: Column header Task List dialog column.set_resizable(True) column.set_sort_column_id(self.TASK_COL) column.set_expand(True) if ui_environment['platform'] == 'maemo': column.set_min_width(250) # don't let this column get too small else: column.set_min_width(300) # don't let this column get too small self.append_column(column) self.set_expander_column(column) if gtk.gtk_version >= (2, 12, 0): self.set_tooltip_column(self.TASK_COL) # Rendering of the Date column use_workweek = plugin.preferences['use_workweek'] day_of_week = datetime.date.today().isoweekday() if use_workweek and day_of_week == 4: # Today is Thursday - 2nd day ahead is after the weekend delta1, delta2 = 1, 3 elif use_workweek and day_of_week == 5: # Today is Friday - next day ahead is after the weekend delta1, delta2 = 3, 4 else: delta1, delta2 = 1, 2 today = str(datetime.date.today()) tomorrow = str(datetime.date.today() + datetime.timedelta(days=delta1)) dayafter = str(datetime.date.today() + datetime.timedelta(days=delta2)) def render_date(col, cell, model, i): date = model.get_value(i, self.DATE_COL) if date == _NO_DATE: cell.set_property('text', '') else: cell.set_property('text', date) # TODO allow strftime here if date <= today: color = HIGH_COLOR elif date <= tomorrow: color = MEDIUM_COLOR elif date <= dayafter: color = ALERT_COLOR # "<=" because tomorrow and/or dayafter can be after the weekend else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Date'), cell_renderer) # T: Column header Task List dialog column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.DATE_COL) self.append_column(column) # Rendering for page name column cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.PAGE_COL) # T: Column header Task List dialog column.set_sort_column_id(self.PAGE_COL) self.append_column(column) # Finalize self.refresh() # HACK because we can not register ourselves :S self.connect('row_activated', self.__class__.do_row_activated)
def __init__(self, index_ext, opener, filter_actionable=False, tag_by_page=False, use_workweek=False): self.real_model = gtk.TreeStore(bool, int, str, str, str, bool, bool, int, object) # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, PAGE_COL, ACT_COL, OPEN_COL, TASKID_COL, TAGS_COL model = self.real_model.filter_new() model.set_visible_column(self.VIS_COL) model = gtk.TreeModelSort(model) model.set_sort_column_id(self.PRIO_COL, gtk.SORT_DESCENDING) BrowserTreeView.__init__(self, model) self.index_ext = index_ext self.opener = opener self.filter = None self.tag_filter = None self.label_filter = None self.filter_actionable = filter_actionable self.tag_by_page = tag_by_page self._tags = {} self._labels = {} # Add some rendering for the Prio column def render_prio(col, cell, model, i): prio = model.get_value(i, self.PRIO_COL) cell.set_property('text', str(prio)) if prio >= 3: color = HIGH_COLOR elif prio == 2: color = MEDIUM_COLOR elif prio == 1: color = ALERT_COLOR else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() #~ column = gtk.TreeViewColumn(_('Prio'), cell_renderer) # T: Column header Task List dialog column = gtk.TreeViewColumn(' ! ', cell_renderer) column.set_cell_data_func(cell_renderer, render_prio) column.set_sort_column_id(self.PRIO_COL) self.append_column(column) # Rendering for task description column cell_renderer = gtk.CellRendererText() cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END) column = gtk.TreeViewColumn(_('Task'), cell_renderer, markup=self.TASK_COL) # T: Column header Task List dialog column.set_resizable(True) column.set_sort_column_id(self.TASK_COL) column.set_expand(True) if ui_environment['platform'] == 'maemo': column.set_min_width(250) # don't let this column get too small else: column.set_min_width(300) # don't let this column get too small self.append_column(column) self.set_expander_column(column) if gtk.gtk_version >= (2, 12, 0): self.set_tooltip_column(self.TASK_COL) # Rendering of the Date column day_of_week = datetime.date.today().isoweekday() if use_workweek and day_of_week == 4: # Today is Thursday - 2nd day ahead is after the weekend delta1, delta2 = 1, 3 elif use_workweek and day_of_week == 5: # Today is Friday - next day ahead is after the weekend delta1, delta2 = 3, 4 else: delta1, delta2 = 1, 2 today = str(datetime.date.today()) tomorrow = str(datetime.date.today() + datetime.timedelta(days=delta1)) dayafter = str(datetime.date.today() + datetime.timedelta(days=delta2)) def render_date(col, cell, model, i): date = model.get_value(i, self.DATE_COL) if date == _NO_DATE: cell.set_property('text', '') else: cell.set_property('text', date) # TODO allow strftime here if date <= today: color = HIGH_COLOR elif date <= tomorrow: color = MEDIUM_COLOR elif date <= dayafter: color = ALERT_COLOR # "<=" because tomorrow and/or dayafter can be after the weekend else: color = None cell.set_property('cell-background', color) cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Date'), cell_renderer) # T: Column header Task List dialog column.set_cell_data_func(cell_renderer, render_date) column.set_sort_column_id(self.DATE_COL) self.append_column(column) # Rendering for page name column cell_renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Page'), cell_renderer, text=self.PAGE_COL) # T: Column header Task List dialog column.set_sort_column_id(self.PAGE_COL) self.append_column(column) # Finalize self.refresh() # HACK because we can not register ourselves :S self.connect('row_activated', self.__class__.do_row_activated)