def __init__(self): super().__init__() args = self._process_flags() try: opts, args = getopt.getopt(args[1:], 'l:') except getopt.GetoptError as e: error(str(e)) sys.exit(1) self.alt_layout_path = None for opt, value in opts: if opt == "-l": self.alt_layout_path = value def callback(): self.todolist.erase() self.todolist.add_list(self.todofile.read()) self._update_all_columns() self._redraw() self.column_width = config().column_width() self.todofile = TodoFileWatched(config().todotxt(), callback) self.todolist = TodoList.TodoList(self.todofile.read()) self.marked_todos = set() self.columns = urwid.Columns([], dividechars=0, min_width=config().column_width()) self.columns.contents.set_focus_changed_callback(self._move_highlight) completer = ColumnCompleter(self.todolist) self.commandline = CommandLineWidget(completer, 'topydo> ') self.keystate_widget = KeystateWidget() self.status_line = urwid.Columns([ ('weight', 1, urwid.Filler(self.commandline)), ]) self.cli_wrapper = CliWrapper([(1, self.status_line)]) self.keymap = config().column_keymap() self._alarm = None self._last_cmd = None # console widget self.console = ConsoleWidget() get_terminal_size(self._console_width) urwid.connect_signal(self.commandline, 'blur', self._blur_commandline) urwid.connect_signal(self.commandline, 'execute_command', self._execute_handler) urwid.connect_signal(self.commandline, 'show_completions', self._show_completion_box) urwid.connect_signal(self.commandline, 'hide_completions', self._hide_completion_box) def hide_console(p_focus_commandline=False): if p_focus_commandline: self._focus_commandline() else: self._console_visible = False urwid.connect_signal(self.console, 'close', hide_console) # view widget self.viewwidget = ViewWidget(self.todolist) urwid.connect_signal(self.viewwidget, 'save', lambda: self._update_view(self.viewwidget.data)) def hide_viewwidget(): # prevent the view widget to be hidden when the last column was # deleted if self.columns.contents: self._viewwidget_visible = False self._blur_commandline() urwid.connect_signal(self.viewwidget, 'close', hide_viewwidget) self.mainwindow = MainPile([ ('weight', 1, self.columns), ('pack', self.cli_wrapper), ]) urwid.connect_signal(self.mainwindow, 'blur_console', hide_console) # the columns should have keyboard focus self._blur_commandline() self._screen = urwid.raw_display.Screen() 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 def create_mono_palette(): palette = [ (PaletteItem.DEFAULT_FOCUS, 'black', 'light gray'), (PaletteItem.PROJECT_FOCUS, PaletteItem.DEFAULT_FOCUS), (PaletteItem.CONTEXT_FOCUS, PaletteItem.DEFAULT_FOCUS), (PaletteItem.METADATA_FOCUS, PaletteItem.DEFAULT_FOCUS), (PaletteItem.LINK_FOCUS, PaletteItem.DEFAULT_FOCUS), (PaletteItem.MARKED, 'default,underline,bold', 'default'), ] for C in ascii_uppercase: palette.append( ('pri_' + C + '_focus', PaletteItem.DEFAULT_FOCUS)) return palette if config().colors(): self._screen.register_palette(create_color_palette()) else: self._screen.register_palette(create_mono_palette()) self._screen.set_terminal_properties(256) self.mainloop = urwid.MainLoop(self.mainwindow, screen=self._screen, unhandled_input=self._handle_input, pop_ups=True) self.column_mode = _APPEND_COLUMN self._set_alarm_for_next_midnight_update()
def __init__(self): super().__init__() args = self._process_flags() try: opts, args = getopt.getopt(args[1:], 'l:') except getopt.GetoptError as e: error(str(e)) sys.exit(1) self.alt_layout_path = None for opt, value in opts: if opt == "-l": self.alt_layout_path = value def callback(): self.todolist.erase() self.todolist.add_list(self.todofile.read()) self._update_all_columns() self._redraw() self.column_width = config().column_width() self.todofile = TodoFileWatched(config().todotxt(), callback) self.todolist = TodoList.TodoList(self.todofile.read()) self.marked_todos = set() self.columns = urwid.Columns([], dividechars=0, min_width=config().column_width()) completer = ColumnCompleter(self.todolist) self.commandline = CommandLineWidget(completer, 'topydo> ') self.keystate_widget = KeystateWidget() self.status_line = urwid.Columns([ ('weight', 1, urwid.Filler(self.commandline)), ]) self.cli_wrapper = CliWrapper([(1, self.status_line)]) self.keymap = config().column_keymap() self._alarm = None self._last_cmd = None # console widget self.console = ConsoleWidget() get_terminal_size(self._console_width) urwid.connect_signal(self.commandline, 'blur', self._blur_commandline) urwid.connect_signal(self.commandline, 'execute_command', self._execute_handler) urwid.connect_signal(self.commandline, 'show_completions', self._show_completion_box) urwid.connect_signal(self.commandline, 'hide_completions', self._hide_completion_box) def hide_console(p_focus_commandline=False): if p_focus_commandline: self._focus_commandline() else: self._console_visible = False urwid.connect_signal(self.console, 'close', hide_console) # view widget self.viewwidget = ViewWidget(self.todolist) urwid.connect_signal(self.viewwidget, 'save', lambda: self._update_view(self.viewwidget.data)) def hide_viewwidget(): # prevent the view widget to be hidden when the last column was # deleted if self.columns.contents: self._viewwidget_visible = False self._blur_commandline() urwid.connect_signal(self.viewwidget, 'close', hide_viewwidget) self.mainwindow = MainPile([ ('weight', 1, self.columns), ('pack', self.cli_wrapper), ]) urwid.connect_signal(self.mainwindow, 'blur_console', hide_console) # the columns should have keyboard focus self._blur_commandline() self._screen = urwid.raw_display.Screen() if config().colors(): self._screen.register_palette(self._create_color_palette()) else: self._screen.register_palette(self._create_mono_palette()) self._screen.set_terminal_properties(256) self.mainloop = urwid.MainLoop(self.mainwindow, screen=self._screen, unhandled_input=self._handle_input, pop_ups=True) self.column_mode = _APPEND_COLUMN self._set_alarm_for_next_midnight_update()