def refresh(self): from zim.gui.widgets import encode_markup_text model = self.get_model() model.clear() for tool in self.manager: pixbuf = tool.get_pixbuf(gtk.ICON_SIZE_MENU) text = '<b>%s</b>\n%s' % (encode_markup_text(tool.name), encode_markup_text(tool.comment)) model.append((pixbuf, text, tool.key))
def _append(self, info): path = File(info.uri).path text = '<b>%s</b>\n<span foreground="#5a5a5a" size="small">%s</span>' % \ (encode_markup_text(info.name), encode_markup_text(path)) # T: Path label in 'open notebook' dialog if info.icon and File(info.icon).exists(): w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_BUTTON) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(File(info.icon).path, w, h) else: pixbuf = None self.append((False, info.name, text, pixbuf, info))
def on_get_value(self, iter, column): #~ print '>> on_get_value', iter, column path = iter.indexpath if column == NAME_COL: return path.basename elif column == TIP_COL: return encode_markup_text(path.basename) elif column == PATH_COL: return path elif column == EMPTY_COL: return not path.hascontent and not path.haschildren elif column == STYLE_COL: if path.hascontent or path.haschildren: return pango.STYLE_NORMAL else: return pango.STYLE_ITALIC elif column == FGCOLOR_COL: if path.hascontent or path.haschildren: return self.NORMAL_COLOR else: return self.EMPTY_COLOR elif column == WEIGHT_COL: if path == self.current_page: return pango.WEIGHT_BOLD else: return pango.WEIGHT_NORMAL elif column == N_CHILD_COL: if path.haschildren: return str(self.index.n_list_pages(path)) else: return '' # not "0", want to keep look bit clean
def on_get_value(self, iter, column): '''Returns the data for a specific column''' if isinstance(iter, PageTreeTagIter): tag = iter.indextag if column == NAME_COL: return tag.name elif column == TIP_COL: return encode_markup_text(tag.name) elif column == PATH_COL: return tag elif column == EMPTY_COL: return tag == self.untagged elif column == STYLE_COL: if tag == self.untagged: return pango.STYLE_ITALIC else: return pango.STYLE_NORMAL elif column == FGCOLOR_COL: if tag == self.untagged: return self.EMPTY_COLOR else: return self.NORMAL_COLOR elif column == WEIGHT_COL: return pango.WEIGHT_NORMAL # TODO: use this property to show tags in current page? elif column == N_CHILD_COL: return '' ## Due to multiple tag filtering this result is no good.. #~ if tag == self.untagged: #~ return str(self.index.n_list_untagged_root_pages()) #~ else: #~ return str(self.index.n_list_tagged_pages(tag)) else: return PageTreeStore.on_get_value(self, iter, column)
def _append_tasks(self, task, iter, path_cache): for row in self.index_ext.list_tasks(task): if not row['open']: continue # Only include open items for now if row['source'] not in path_cache: path = self.index_ext.get_path(row) if path is None: # Be robust for glitches - filter these out continue else: path_cache[row['source']] = path path = path_cache[row['source']] # Update labels for label in self.index_ext.task_label_re.findall( row['description']): self._labels[label] = self._labels.get(label, 0) + 1 # Update tag count tags = row['tags'].split(',') if self.tag_by_page: tags = tags + path.parts if tags: for tag in tags: self._tags[tag] = self._tags.get(tag, 0) + 1 else: self._tags[_NO_TAGS] = self._tags.get(_NO_TAGS, 0) + 1 # Format description task = _date_re.sub('', row['description'], count=1) task = re.sub('\s*!+\s*', ' ', task) # get rid of exclamation marks task = self.index_ext.next_label_re.sub( '', task) # get rid of "next" label in description task = encode_markup_text(task) if row['actionable']: task = _tag_re.sub( r'<span color="#ce5c00">@\1</span>', task) # highlight tags - same color as used in pageview task = self.index_ext.task_label_re.sub( r'<b>\1</b>', task) # highlight labels else: task = r'<span color="darkgrey">%s</span>' % task # Insert all columns modelrow = [ False, row['prio'], task, row['due'], path.name, row['actionable'], row['open'], row['id'], tags ] # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, PAGE_COL, ACT_COL, OPEN_COL, TASKID_COL, TAGS_COL modelrow[0] = self._filter_item(modelrow) myiter = self.real_model.append(iter, modelrow) if row['haschildren']: self._append_tasks(row, myiter, path_cache) # recurs
def set_active(button, active): button.handler_block_by_func(self.on_button_clicked) button.set_active(active) label = button.get_child() if active: label.set_markup("<b>" + encode_markup_text(label.get_text()) + "</b>") else: label.set_text(label.get_text()) # get_text() gives string without markup button.handler_unblock_by_func(self.on_button_clicked)
def set_active(button, active): button.handler_block_by_func(self.on_button_clicked) button.set_active(active) label = button.get_child() if active: label.set_markup('<b>'+encode_markup_text(label.get_text())+'</b>') else: label.set_text(label.get_text()) # get_text() gives string without markup button.handler_unblock_by_func(self.on_button_clicked)
def _select(self, path): for button in self.get_scrolled_children(): active = button.zim_path == path if button.get_active() != active: button.handler_block_by_func(self.on_button_clicked) button.set_active(active) label = button.get_child() if active: label.set_markup('<b>' + encode_markup_text(label.get_text()) + '</b>') else: label.set_text(label.get_text()) # get_text() gives string without markup button.handler_unblock_by_func(self.on_button_clicked)
def _append_tasks(self, task, iter, path_cache): for row in self.plugin.list_tasks(task): if not row['open']: continue # Only include open items for now if row['source'] not in path_cache: path = self.plugin.get_path(row) if path is None: # Be robust for glitches - filter these out continue else: path_cache[row['source']] = path path = path_cache[row['source']] # Update labels for label in self.plugin.task_label_re.findall(row['description']): self._labels[label] = self._labels.get(label, 0) + 1 # Update tag count tags = row['tags'].split(',') if self.plugin.preferences['tag_by_page']: tags = tags + path.parts if tags: for tag in tags: self._tags[tag] = self._tags.get(tag, 0) + 1 else: self._tags[_NO_TAGS] = self._tags.get(_NO_TAGS, 0) + 1 # Format description task = _date_re.sub('', row['description'], count=1) task = encode_markup_text(task) task = re.sub('\s*!+\s*', ' ', task) # get rid of exclamation marks task = self.plugin.next_label_re.sub('', task) # get rid of "next" label in description if row['actionable']: task = _tag_re.sub(r'<span color="#ce5c00">@\1</span>', task) # highlight tags - same color as used in pageview task = self.plugin.task_label_re.sub(r'<b>\1</b>', task) # highlight labels else: task = r'<span color="darkgrey">%s</span>' % task # Insert all columns modelrow = [False, row['prio'], task, row['due'], path.name, row['actionable'], row['open'], row['id'], tags] # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, PAGE_COL, ACT_COL, OPEN_COL, TASKID_COL, TAGS_COL modelrow[0] = self._filter_item(modelrow) myiter = self.real_model.append(iter, modelrow) if row['haschildren']: self._append_tasks(row, myiter, path_cache) # recurs
def _append_tasks(self, task, iter): for row in self.index_ext.list_tasks(): # Format summary task = _date_re.sub('', row['summary'], count=1) task = re.sub('\s*!+\s*', ' ', task) # get rid of exclamation marks task = encode_markup_text(task) task = _tag_re.sub(r'<span color="#ce5c00">@\1</span>', task) # highlight tags - same color as used in pageview due = datetime.date.fromtimestamp(row['due']) if row['due'] != 0 else _NO_DATE priority = 10 - row['priority'] if row['priority'] != 0 else 0 # Insert all columns modelrow = [False, priority, task, due, row['uid'], row['description']] # VIS_COL, PRIO_COL, TASK_COL, DATE_COL, TASKID_COL, DESCR_COL modelrow[0] = self._filter_item(modelrow) myiter = self.real_model.append(iter, modelrow)
def on_get_value(self, iter, column): '''Returns the data for a specific column''' if isinstance(iter, PageTreeTagIter): tag = iter.indextag if column == NAME_COL: return tag.name elif column == TIP_COL: return encode_markup_text(tag.name) elif column == PATH_COL: return tag elif column == EMPTY_COL: return tag == self.untagged elif column == STYLE_COL: if tag == self.untagged: return pango.STYLE_ITALIC else: return pango.STYLE_NORMAL elif column == FGCOLOR_COL: if tag == self.untagged: return self.EMPTY_COLOR else: return self.NORMAL_COLOR elif column == WEIGHT_COL: return pango.WEIGHT_NORMAL # TODO: use this property to show tags in current page? elif column == N_CHILD_COL: return '' ## Due to multiple tag filtering this result is no good.. #~ if tag == self.untagged: #~ return str(self.index.n_list_untagged_root_pages()) #~ else: #~ return str(self.index.n_list_tagged_pages(tag)) else: if column == NAME_COL and self.show_full_page_name: # Show top level pages with full contex # top level tree is tags, so top level pages len(path) is 2 if len(iter.treepath) <= 2: return iter.indexpath.name else: return iter.indexpath.basename else: return PageTreeStore.on_get_value(self, iter, column)
def on_get_value(self, iter, column): if column == NAME_COL: return iter.row['name'].split(':')[-1] elif column == TIP_COL: basename = iter.row['name'].split(':')[-1] return encode_markup_text(basename) elif column == PATH_COL: return PageIndexRecord(iter.row) elif column == EXISTS_COL: return not iter.row['is_link_placeholder'] elif column == STYLE_COL: if iter.row['is_link_placeholder']: return Pango.Style.ITALIC else: return Pango.Style.NORMAL elif column == WEIGHT_COL: if self.current_page and iter.row['name'] == self.current_page.name: return Pango.Weight.BOLD else: return Pango.Weight.NORMAL elif column == N_CHILD_COL: return str(iter.n_children) if iter.n_children > 0 else ''
def _query_tooltip_cb(self, widget, x, y, keyboard_tip, tooltip): context = widget.get_tooltip_context(x, y, keyboard_tip) if not context: return False model, path, iter = context task = model[iter][self.DESC_COL] start = model[iter][self.START_COL] due = model[iter][self.DUE_COL] page = model[iter][self.PAGE_COL] today = str( datetime.date.today() ) text = [task, '\n'] if start and start > today: text += ['<b>', _('Start'), ':</b> ', start, '\n'] # T: start date for task if due != _MAX_DUE_DATE: text += ['<b>', _('Due'), ':</b> ', due, '\n'] # T: due date for task text += ['<b>', _('Page'), ':</b> ', encode_markup_text(page)] # T: page label tooltip.set_markup(''.join(text)) return True
def on_get_value(self, iter, column): ''' Modify to return new pagenames, tooltips and icons. Columns 'NAME_COL', 'TIP_COL' and 'ICON_COL' use cache, other columns works with default methods. ''' path = iter.indexpath if (column == NAME_COL) or (column == TIP_COL): try: return self._pagenames_cache[path.name][column] except KeyError: pass elif column == ICON_COL: try: return render_icon(self._pagenames_cache[path.name][column]) except KeyError: pass else: return PageTreeStore.on_get_value(self, iter, column) # Value is not in cache. # Find tags, icons and put values to cache. tags = [a.name for a in self.index.list_tags(path)] icon = self.index_ext.get_icon(path) if icon: icon = ICONS.get(icon, ICONS[NO_IMAGE]) elif tags: # Check icons for tags. _icons = [ self.icons_for_tags[a] for a in tags if a in self.icons_for_tags ] if _icons: # Check whether all icons are the same. if len(set(_icons)) > 1: icon = ICONS[SEVERAL_ICONS] else: icon = ICONS[_icons[0]] elif path.haschildren: icon = ICONS[FOLDER_TAGS_ICON] else: icon = ICONS[FILE_TAGS_ICON] else: if path.haschildren: icon = ICONS[FOLDER_ICON] else: icon = ICONS[FILE_ICON] if tags and self.show_tags: # show tags after page name name = '{} ({})'.format(path.basename, ', '.join(tags)) else: name = path.basename self._pagenames_cache[path.name] = { NAME_COL: name, TIP_COL: encode_markup_text(name), ICON_COL: icon } # Launch function to clear cache. if not self._clear_cache_scheduled: self._clear_pagenames_cache() return self.on_get_value(iter, column)
def _append_tasks(self, task, iter, path_cache): task_label_re = _task_labels_re(self.task_labels) today = datetime.date.today() today_str = str(today) if self.flatlist: assert task is None tasks = self.tasksview.list_open_tasks_flatlist() else: tasks = self.tasksview.list_open_tasks(task) for prio_sort_int, row in enumerate(tasks): if row['source'] not in path_cache: # TODO: add pagename to list_open_tasks query - need new index path = self.tasksview.get_path(row) if path is None: # Be robust for glitches - filter these out continue else: path_cache[row['source']] = path path = path_cache[row['source']] # Update labels for label in task_label_re.findall(row['description']): self._labels[label] = self._labels.get(label, 0) + 1 # Update tag count tags = [t for t in row['tags'].split(',') if t] if self.tag_by_page: tags = tags + path.parts if tags: for tag in tags: self._tags[tag] = self._tags.get(tag, 0) + 1 else: self._tags[_NO_TAGS] = self._tags.get(_NO_TAGS, 0) + 1 lowertags = [t.lower() for t in tags] actionable = not any(t in lowertags for t in self.nonactionable_tags) # Format label for "prio" column if row['start'] > today_str: actionable = False y, m, d = row['start'].split('-') td = datetime.date(int(y), int(m), int(d)) - today prio_sort_label = '>' + days_to_str(td.days) if row['prio'] > 0: prio_sort_label += ' ' + '!' * min(row['prio'], 3) elif row['due'] < _MAX_DUE_DATE: y, m, d = row['due'].split('-') td = datetime.date(int(y), int(m), int(d)) - today prio_sort_label = \ '!' * min(row['prio'], 3) + ' ' if row['prio'] > 0 else '' if td.days < 0: prio_sort_label += '<b><u>OD</u></b>' # over due elif td.days == 0: prio_sort_label += '<u>TD</u>' # today else: prio_sort_label += days_to_str(td.days) else: prio_sort_label = '!' * min(row['prio'], 3) # Format description desc = _date_re.sub('', row['description'], count=1) desc = re.sub('\s*!+\s*', ' ', desc) # get rid of exclamation marks desc = encode_markup_text(desc) if actionable: desc = _tag_re.sub( r'<span color="#ce5c00">@\1</span>', desc) # highlight tags - same color as used in pageview desc = task_label_re.sub(r'<b>\1</b>', desc) # highlight labels else: desc = r'<span color="darkgrey">%s</span>' % desc # Insert all columns modelrow = [ False, actionable, row['prio'], row['start'], row['due'], tags, desc, path.name, row['id'], prio_sort_int, prio_sort_label ] # 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 modelrow[0] = self._filter_item(modelrow) myiter = self.real_model.append(iter, modelrow) if row['haschildren'] and not self.flatlist: self._append_tasks(row, myiter, path_cache) # recurs
def on_get_value(self, iter, column): ''' Modify to return new pagenames, tooltips and icons. Columns 'NAME_COL', 'TIP_COL' and 'ICON_COL' use cache, other columns works with default methods. ''' path = iter.indexpath if (column == NAME_COL) or (column == TIP_COL): try: return self._pagenames_cache[path.name][column] except KeyError: pass elif column == ICON_COL: try: return render_icon(self._pagenames_cache[path.name][column]) except KeyError: pass else: return PageTreeStore.on_get_value(self, iter, column) # Value is not in cache. # Find tags, icons and put values to cache. tags = [a.name for a in self.index.list_tags(path)] icon = self.index_ext.get_icon(path) if icon: icon = ICONS.get(icon, ICONS[NO_IMAGE]) elif tags: # Check icons for tags. _icons = [self.icons_for_tags[a] for a in tags if a in self.icons_for_tags] if _icons: # Check whether all icons are the same. if len( set(_icons) ) > 1: icon = ICONS[SEVERAL_ICONS] else: icon = ICONS[_icons[0]] elif path.haschildren: icon = ICONS[FOLDER_TAGS_ICON] else: icon = ICONS[FILE_TAGS_ICON] else: if path.haschildren: icon = ICONS[FOLDER_ICON] else: icon = ICONS[FILE_ICON] if tags and self.show_tags: # show tags after page name name = '{} ({})'.format(path.basename, ', '.join(tags)) else: name = path.basename self._pagenames_cache[path.name] = {NAME_COL: name, TIP_COL: encode_markup_text(name), ICON_COL: icon} # Launch function to clear cache. if not self._clear_cache_scheduled: self._clear_pagenames_cache() return self.on_get_value(iter, column)