def run(self): """ Main entry function. """ history = InMemoryHistory() self._load_file() session = PromptSession(history=history) while True: # (re)load the todo.txt file (only if it has been modified) try: user_input = session.prompt(u'topydo> ', completer=self.completer, complete_while_typing=False) user_input = shlex.split(user_input) except EOFError: sys.exit(0) except KeyboardInterrupt: continue except ValueError as verr: error('Error: ' + str(verr)) continue try: (subcommand, args) = get_subcommand(user_input) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') continue try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: print(GENERIC_HELP)
def run(self): """ Main entry function. """ history = InMemoryHistory() self._load_file() while True: # (re)load the todo.txt file (only if it has been modified) try: user_input = prompt(u'topydo> ', history=history, completer=self.completer, complete_while_typing=False) user_input = shlex.split(user_input) except EOFError: sys.exit(0) except KeyboardInterrupt: continue except ValueError as verr: error('Error: ' + str(verr)) continue try: (subcommand, args) = get_subcommand(user_input) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') continue try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: print(GENERIC_HELP)
def main(): """ Main entry point of the CLI. """ try: args = sys.argv[1:] try: _, args = getopt.getopt(args, MAIN_OPTS, MAIN_LONG_OPTS) except getopt.GetoptError as e: error(str(e)) sys.exit(1) if args[0] == 'prompt': try: from topydo.ui.prompt.Prompt import PromptApplication PromptApplication().run() except ImportError: error("Some additional dependencies for prompt mode were not installed, please install with 'pip3 install topydo[prompt]'") elif args[0] == 'columns': try: from topydo.ui.columns.Main import UIApplication UIApplication().run() except ImportError: error("Some additional dependencies for column mode were not installed, please install with 'pip3 install topydo[columns]'") except NameError as err: if _WINDOWS: error("Column mode is not supported on Windows.") else: error("Could not load column mode: {}".format(err)) else: CLIApplication().run() except IndexError: CLIApplication().run()
def run(self): """ Main entry function. """ args = self._process_flags() self.todofile = TodoFile.TodoFile(config().todotxt()) self.todolist = TodoList.TodoList(self.todofile.read()) try: (subcommand, args) = get_subcommand(args) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') sys.exit(1) if subcommand is None: self._usage() if self._execute(subcommand, args) == False: sys.exit(1) else: self._post_execute()
def run(self): """ Main entry function. """ args = self._process_flags() self.todofile = TodoFile.TodoFile(config().todotxt()) self.todolist = TodoList.TodoList(self.todofile.read()) try: (subcommand, args) = get_subcommand(args) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') sys.exit(1) if subcommand is None: CLIApplicationBase._usage() if self._execute(subcommand, args) == False: sys.exit(1) else: self._post_execute()
def main(): """ Main entry point of the CLI. """ try: args = sys.argv[1:] try: _, args = getopt.getopt(args, MAIN_OPTS, MAIN_LONG_OPTS) except getopt.GetoptError as e: error(str(e)) sys.exit(1) if args[0] == 'prompt': try: from topydo.ui.prompt.Prompt import PromptApplication PromptApplication().run() except ImportError: error("You have to install prompt-toolkit to run prompt mode.") elif args[0] == 'columns': try: from topydo.ui.columns.Main import UIApplication UIApplication().run() except ImportError: error("You have to install urwid to run column mode.") else: CLIApplication().run() except IndexError: CLIApplication().run()
def main(): """ Main entry point of the CLI. """ try: args = sys.argv[1:] try: _, args = getopt.getopt(args, MAIN_OPTS, MAIN_LONG_OPTS) except getopt.GetoptError as e: error(str(e)) sys.exit(1) if args[0] == 'prompt': try: from topydo.ui.prompt.Prompt import PromptApplication PromptApplication().run() except ImportError: error("Some additional dependencies for prompt mode were not installed, please install with 'pip install topydo[prompt]'") elif args[0] == 'columns': try: from topydo.ui.columns.Main import UIApplication UIApplication().run() except ImportError: error("Some additional dependencies for column mode were not installed, please install with 'pip install topydo[columns]'") else: CLIApplication().run() except IndexError: CLIApplication().run()
def run(self): """ Main entry function. """ history = InMemoryHistory() while True: # (re)load the todo.txt file (only if it has been modified) self._load_file() try: user_input = prompt(u'topydo> ', history=history, completer=self.completer, complete_while_typing=False) user_input = shlex.split(user_input) except EOFError: sys.exit(0) except KeyboardInterrupt: continue except ValueError as verr: error('Error: ' + str(verr)) continue mtime_after = _todotxt_mtime() try: (subcommand, args) = get_subcommand(user_input) except ConfigError as ce: error('Error: ' + str(ce) + '. Check your aliases configuration') continue # refuse to perform operations such as 'del' and 'do' if the # todo.txt file has been changed in the background. if subcommand and not self.is_read_only(subcommand) and self.mtime != mtime_after: error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.") continue try: if self._execute(subcommand, args) != False: self._post_execute() except TypeError: usage()
from prompt_toolkit.shortcuts import prompt from topydo.Commands import get_subcommand from topydo.lib.Config import ConfigError, config from topydo.lib.TodoFileWatched import TodoFileWatched from topydo.ui.CLIApplicationBase import (GENERIC_HELP, CLIApplicationBase, error) from topydo.ui.prompt.PromptCompleter import PromptCompleter # First thing is to poke the configuration and check whether it's sane # The modules below may already read in configuration upon import, so # make sure to bail out if the configuration is invalid. try: config() except ConfigError as config_error: error(str(config_error)) sys.exit(1) class PromptApplication(CLIApplicationBase): """ This class implements a variant of topydo's CLI showing a shell and offering auto-completion thanks to the prompt toolkit. """ def __init__(self): super().__init__() self._process_flags() self.completer = None
from prompt_toolkit import prompt, PromptSession from topydo.Commands import get_subcommand from topydo.lib.Config import ConfigError, config from topydo.lib.TodoFileWatched import TodoFileWatched from topydo.ui.CLIApplicationBase import (GENERIC_HELP, CLIApplicationBase, error) from topydo.ui.prompt.PromptCompleter import PromptCompleter # First thing is to poke the configuration and check whether it's sane # The modules below may already read in configuration upon import, so # make sure to bail out if the configuration is invalid. try: config() except ConfigError as config_error: error(str(config_error)) sys.exit(1) class PromptApplication(CLIApplicationBase): """ This class implements a variant of topydo's CLI showing a shell and offering auto-completion thanks to the prompt toolkit. """ def __init__(self): super().__init__() self._process_flags() self.completer = None self.todofile = TodoFileWatched(config().todotxt(), self._load_file)
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()
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() 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()