Example #1
0
    def _create_color_palette(self):
        project_color = to_urwid_color(config().project_color())
        context_color = to_urwid_color(config().context_color())
        metadata_color = to_urwid_color(config().metadata_color())
        link_color = to_urwid_color(config().link_color())

        palette = [
            (PaletteItem.PROJECT, '', '', '', project_color, ''),
            (PaletteItem.PROJECT_FOCUS, '', 'light gray', '', project_color, None),
            (PaletteItem.CONTEXT, '', '', '', context_color, ''),
            (PaletteItem.CONTEXT_FOCUS, '', 'light gray', '', context_color, None),
            (PaletteItem.METADATA, '', '', '', metadata_color, ''),
            (PaletteItem.METADATA_FOCUS, '', 'light gray', '', metadata_color, None),
            (PaletteItem.LINK, '', '', '', link_color, ''),
            (PaletteItem.LINK_FOCUS, '', 'light gray', '', link_color, None),
            (PaletteItem.DEFAULT_FOCUS, 'black', 'light gray'),
            (PaletteItem.MARKED, '', 'light blue'),
        ]

        for C in ascii_uppercase:
            pri_color_cfg = config().priority_color(C)

            pri_color = to_urwid_color(pri_color_cfg)
            pri_color_focus = pri_color if not pri_color_cfg.is_neutral() else 'black'

            palette.append((
                'pri_' + C, '', '', '', pri_color, ''
            ))
            palette.append((
                'pri_' + C + '_focus', '', 'light gray', '', pri_color_focus, None
            ))

        return palette
Example #2
0
    def __init__(self, p_todo):
        # clients use this to associate this widget with the given todo item
        self.todo = p_todo

        todo_text = TEXT_FORMATTER.parse(p_todo)
        priority_text = PRIO_FORMATTER.parse(p_todo)

        # split todo_text at each occurrence of tag/project/context/url
        txt_pattern = r'|'.join([PRJ_CON_PATTERN, TAG_PATTERN, URL_PATTERN])
        txt_pattern = r'(' + txt_pattern + r')'
        txt_splitted = re.split(txt_pattern, todo_text)
        txt_markup = []

        # Examine each substring and apply relevant palette entry if needed
        for substring in txt_splitted:
            # re.split can generate empty strings when capturing group is used
            if not substring:
                continue
            if re.match(TAG_PATTERN, substring):
                txt_markup.append((PaletteItem.METADATA, substring))
            elif re.match(URL_PATTERN, substring):
                txt_markup.append((PaletteItem.LINK, substring))
            elif re.match(PRJ_CON_PATTERN, substring):
                if substring.startswith('+'):
                    txt_markup.append((PaletteItem.PROJECT, substring))
                else:
                    txt_markup.append((PaletteItem.CONTEXT, substring))
            else:
                txt_markup.append(substring)

        self.id_widget = urwid.Text('', align='right')
        priority_widget = urwid.Text(priority_text)
        self.text_widget = urwid.Text(txt_markup)

        progress = to_urwid_color(progress_color(p_todo)) if config().colors() else PaletteItem.DEFAULT
        self.progress_bar = urwid.AttrMap(
                urwid.SolidFill(' '),
                {},
        )
        self.update_progress()

        self.columns = urwid.Columns(
            [
                (1, self.progress_bar),
                (4, self.id_widget),
                (3, priority_widget),
                ('weight', 1, self.text_widget),
            ],
            dividechars=1,
            box_columns=[0] # the progress bar adapts its height to the rest
        )

        self.widget = urwid.AttrMap(
            self.columns,
            _markup(p_todo, p_focus=False),
            _markup(p_todo, p_focus=True)
        )

        super().__init__(self.widget)
Example #3
0
        def create_color_palette():
            project_color = to_urwid_color(config().project_color())
            context_color = to_urwid_color(config().context_color())
            metadata_color = to_urwid_color(config().metadata_color())
            link_color = to_urwid_color(config().link_color())
            focus_background_color = to_urwid_color(
                config().focus_background_color())
            marked_background_color = to_urwid_color(
                config().marked_background_color())

            palette = [
                (PaletteItem.PROJECT, '', '', '', project_color, ''),
                (PaletteItem.PROJECT_FOCUS, '', 'light gray', '',
                 project_color, focus_background_color),
                (PaletteItem.CONTEXT, '', '', '', context_color, ''),
                (PaletteItem.CONTEXT_FOCUS, '', 'light gray', '',
                 context_color, focus_background_color),
                (PaletteItem.METADATA, '', '', '', metadata_color, ''),
                (PaletteItem.METADATA_FOCUS, '', 'light gray', '',
                 metadata_color, focus_background_color),
                (PaletteItem.LINK, '', '', '', link_color, ''),
                (PaletteItem.LINK_FOCUS, '', 'light gray', '', link_color,
                 focus_background_color),
                (PaletteItem.DEFAULT_FOCUS, '', 'light gray', '', '',
                 focus_background_color),
                (PaletteItem.MARKED, '', 'light blue', '', '',
                 marked_background_color),
            ]

            for C in ascii_uppercase:
                pri_color_cfg = config().priority_color(C)

                pri_color = to_urwid_color(pri_color_cfg)
                pri_color_focus = pri_color if not pri_color_cfg.is_neutral(
                ) else 'black'

                palette.append(('pri_' + C, '', '', '', pri_color, ''))
                palette.append(('pri_' + C + '_focus', '', 'light gray', '',
                                pri_color_focus, focus_background_color))

            return palette
Example #4
0
    def update_progress(self):
        color = to_urwid_color(progress_color(self.todo)) if config().colors() else PaletteItem.DEFAULT

        self.progress_bar.set_attr_map(
            {None: urwid.AttrSpec(PaletteItem.DEFAULT, color, 256)}
        )
Example #5
0
    def __init__(self, p_todo, p_id_width=4):
        # clients use this to associate this widget with the given todo item
        self.todo = p_todo

        todo_text = TEXT_FORMATTER.parse(p_todo)

        if p_todo.is_completed():
            priority_text = ' x '
        else:
            priority_text = PRIO_FORMATTER.parse(p_todo)

        # split todo_text at each occurrence of tag/project/context/url
        txt_pattern = r'|'.join([PRJ_CON_PATTERN, TAG_PATTERN, URL_PATTERN])
        txt_pattern = r'(' + txt_pattern + r')'
        txt_splitted = re.split(txt_pattern, todo_text)
        txt_markup = []

        # Examine each substring and apply relevant palette entry if needed
        for substring in txt_splitted:
            # re.split can generate empty strings when capturing group is used
            if not substring:
                continue
            if re.match(TAG_PATTERN, substring):
                txt_markup.append((PaletteItem.METADATA, substring))
            elif re.match(URL_PATTERN, substring):
                txt_markup.append((PaletteItem.LINK, substring))
            elif re.match(PRJ_CON_PATTERN, substring):
                if substring.startswith('+'):
                    txt_markup.append((PaletteItem.PROJECT, substring))
                else:
                    txt_markup.append((PaletteItem.CONTEXT, substring))
            else:
                txt_markup.append(substring)

        self.id_widget = urwid.Text('', align='right')
        priority_widget = urwid.Text(priority_text)
        self.text_widget = urwid.Text(txt_markup)

        progress = to_urwid_color(progress_color(
            p_todo)) if config().colors() else PaletteItem.DEFAULT
        self.progress_bar = urwid.AttrMap(
            urwid.SolidFill(' '),
            {},
        )
        self.update_progress()

        self.columns = urwid.Columns(
            [
                (1, self.progress_bar),
                (p_id_width, self.id_widget),
                (3, priority_widget),
                ('weight', 1, self.text_widget),
            ],
            dividechars=1,
            box_columns=[0]  # the progress bar adapts its height to the rest
        )

        self.widget = urwid.AttrMap(self.columns, _markup(p_todo,
                                                          p_focus=False),
                                    _markup(p_todo, p_focus=True))

        super().__init__(self.widget)
Example #6
0
    def update_progress(self):
        color = to_urwid_color(progress_color(
            self.todo)) if config().colors() else PaletteItem.DEFAULT

        self.progress_bar.set_attr_map(
            {None: urwid.AttrSpec(PaletteItem.DEFAULT, color, 256)})