示例#1
0
 def date_range_function():
     oneday = datetime.timedelta(days=1)
     yield start
     next = start + oneday
     while next <= end:
         yield next
         next += oneday
示例#2
0
def daterange_from_path(path):
	'''Determine the calendar dates mapped by a specific page
	@param path: a L{Path} object
	@returns: a 3-tuple of:
	  - the page type (one of "C{day}", "C{week}", "C{month}", or "C{year}")
	  - a C{datetime.date} object for the start date
	  - a C{datetime.date} object for the end date
	or C{None} when the page does not map a date
	'''
	if date_path_re.match(path.name):
		type = 'day'
		year, month, day = map(int, path.name.rsplit(':', 3)[-3:])
		date = datetime.date(year, month, day)
		end_date = date
	elif week_path_re.match(path.name):
		type = 'week'
		year, week = path.name.rsplit(':', 2)[-2:]
		year, week = map(int, (year, week[5:])) # Assumes "Week XX" string
		date, end_date = dates_for_week(year, week)
	elif month_path_re.match(path.name):
		type = 'month'
		year, month = map(int, path.name.rsplit(':', 2)[-2:])
		date = datetime.date(year, month, 1)
		if month == 12:
			end_date = datetime.date(year, 12, 31)
		else:
			end_date = datetime.date(year, month+1, 1) + datetime.timedelta(-1)
	elif year_path_re.match(path.name):
		type = 'year'
		year = int(path.name.rsplit(':', 1)[-1])
		date = datetime.date(year, 1, 1)
		end_date = datetime.date(year, 12, 31)
	else:
		return None # Not a calendar path
	return type, date, end_date
示例#3
0
文件: calendar.py 项目: thejeshgn/Zim
	def __call__(self, dict):
		oneday = datetime.timedelta(days=1)
		yield self.start
		next = self.start + oneday
		while next <= self.end:
			yield next
			next += oneday
示例#4
0
	def date_range_function():
		oneday = datetime.timedelta(days=1)
		yield start
		next = start + oneday
		while next <= end:
			yield next
			next += oneday
示例#5
0
 def __call__(self, dict):
     oneday = datetime.timedelta(days=1)
     yield self.start
     next = self.start + oneday
     while next <= self.end:
         yield next
         next += oneday
示例#6
0
    def __init__(self, plugin, pageview):
        PageViewExtension.__init__(self, plugin, pageview)

        self.notebook = pageview.notebook
        hpm = self.plugin.preferences['hours_past_midnight']
        self.hour_delta = datetime.timedelta(hours=hpm)
        # JournalPageViewExtension: go_page_today journal.plugin.path_from_date
        self.journal = find_extension(self.pageview, JournalPageViewExtension)
    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):
            mtime = model.get_value(i, self.MODIFIED_COL)
            if mtime:
                dt = datetime.datetime.fromtimestamp(float(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,
                                    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)
示例#8
0
    def get_date(self):
        '''Get the datetime object for the selected date'''
        year, month, day = gtk.Calendar.get_date(self)
        if day == 0: day = 1

        try:
            date = datetime.date(year, month + 1, day)
        except ValueError:
            # This error may mean that day number is higher than allowed.
            # If so, set date to the last day of the month.
            if day > 27:
                date = datetime.date(year, month + 2,
                                     1) - datetime.timedelta(days=1)
            else:
                raise
        return date
示例#9
0
    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)
示例#10
0
    def get_visible_data_as_html(self):
        html = '''\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Task List - Zim</title>
		<meta name='Generator' content='Zim [%% zim.version %%]'>
		<style type='text/css'>
			table.tasklist {
				border-width: 1px;
				border-spacing: 2px;
				border-style: solid;
				border-color: gray;
				border-collapse: collapse;
			}
			table.tasklist th {
				border-width: 1px;
				padding: 1px;
				border-style: solid;
				border-color: gray;
			}
			table.tasklist td {
				border-width: 1px;
				padding: 1px;
				border-style: solid;
				border-color: gray;
			}
			.high {background-color: %s}
			.medium {background-color: %s}
			.alert {background-color: %s}
		</style>
	</head>
	<body>

<h1>Task List - Zim</h1>

<table class="tasklist">
<tr><th>Prio</th><th>Task</th><th>Date</th><th>Page</th></tr>
''' % (HIGH_COLOR, MEDIUM_COLOR, ALERT_COLOR)

        today = str(datetime.date.today())
        tomorrow = str(datetime.date.today() + datetime.timedelta(days=1))
        dayafter = str(datetime.date.today() + datetime.timedelta(days=2))
        for indent, prio, desc, date, page in self.get_visible_data():
            if prio >= 3:
                prio = '<td class="high">%s</td>' % prio
            elif prio == 2:
                prio = '<td class="medium">%s</td>' % prio
            elif prio == 1:
                prio = '<td class="alert">%s</td>' % prio
            else:
                prio = '<td>%s</td>' % prio

            if date and date <= today:
                date = '<td class="high">%s</td>' % date
            elif date == tomorrow:
                date = '<td class="medium">%s</td>' % date
            elif date == dayafter:
                date = '<td class="alert">%s</td>' % date
            else:
                date = '<td>%s</td>' % date

            desc = '<td>%s%s</td>' % ('&nbsp;' * (4 * indent), desc)
            page = '<td>%s</td>' % page

            html += '<tr>' + prio + desc + date + page + '</tr>\n'

        html += '''\
</table>

	</body>

</html>
'''
        return html
示例#11
0
    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)
示例#12
0
    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)
示例#13
0
    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)
示例#14
0
    def get_visible_data_as_html(self):
        html = '''\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Task List - Zim</title>
        <meta name='Generator' content='Zim [%% zim.version %%]'>
        <style type='text/css'>
            table.tasklist {
                border-width: 1px;
                border-spacing: 2px;
                border-style: solid;
                border-color: gray;
                border-collapse: collapse;
            }
            table.tasklist th {
                border-width: 1px;
                padding: 1px;
                border-style: solid;
                border-color: gray;
            }
            table.tasklist td {
                border-width: 1px;
                padding: 1px;
                border-style: solid;
                border-color: gray;
            }
            .high {background-color: %s}
            .medium {background-color: %s}
            .alert {background-color: %s}
        </style>
    </head>
    <body>

<h1>Task List - Zim</h1>

<table class="tasklist">
<tr><th>Prio</th><th>Task</th><th>Date</th><th>Page</th></tr>
''' % (HIGH_COLOR, MEDIUM_COLOR, ALERT_COLOR)

        today = str(datetime.date.today())
        tomorrow = str(datetime.date.today() + datetime.timedelta(days=1))
        dayafter = str(datetime.date.today() + datetime.timedelta(days=2))
        for indent, prio, desc, date, page in self.get_visible_data():
            if prio >= 3: prio = '<td class="high">%s</td>' % prio
            elif prio == 2: prio = '<td class="medium">%s</td>' % prio
            elif prio == 1: prio = '<td class="alert">%s</td>' % prio
            else: prio = '<td>%s</td>' % prio

            if date and date <= today: date = '<td class="high">%s</td>' % date
            elif date == tomorrow: date = '<td class="medium">%s</td>' % date
            elif date == dayafter: date = '<td class="alert">%s</td>' % date
            else: date = '<td>%s</td>' % date

            desc = '<td>%s%s</td>' % ('&nbsp;' * (4 * indent), desc)
            page = '<td>%s</td>' % page

            html += '<tr>' + prio + desc + date + page + '</tr>\n'

        html += '''\
</table>

    </body>

</html>
'''
        return html