Пример #1
0
 def open_tab(self, path=None):
     """ Opens a new tab and focuses it. """
     file_buffer = self._get_or_create_file_buffer(path)
     new_tab = TabState(self._app_state, file_buffer)
     self.tabs.append(new_tab)
     events.notify(events.TabOpen(new_tab))
     self.tab_index = len(self.tabs) - 1
Пример #2
0
 def open_tab(self, path=None):
     ''' Opens a new tab and focuses it. '''
     file_buffer = self._get_or_create_file_buffer(path)
     new_tab = TabState(self._app_state, file_buffer)
     self.tabs.append(new_tab)
     events.notify(events.TabOpen(new_tab))
     self.tab_index = len(self.tabs) - 1
Пример #3
0
 def set_tab_index(self, new_tab_index):
     if new_tab_index != self._tab_index:
         self._tab_index = new_tab_index
         self._tab_index %= len(self.tabs)
     if self._old_tab_id != id(self.current_tab):
         events.notify(events.TabChange(self.current_tab))
         self._old_tab_id = id(self.current_tab)
Пример #4
0
 def set_tab_index(self, new_tab_index):
     if new_tab_index != self._tab_index:
         self._tab_index = new_tab_index
         self._tab_index %= len(self.tabs)
     if self._old_tab_id != id(self.current_tab):
         events.notify(events.TabChange(self.current_tab))
         self._old_tab_id = id(self.current_tab)
Пример #5
0
 def wrapper(*args, **kwargs):
     try:
         func(*args, **kwargs)
     except urwid.ExitMainLoop:
         raise
     except Exception as ex:
         events.notify(events.PrintMessage(str(ex), style='msg-error'))
Пример #6
0
    def run(self, args):
        key = args[0]
        value = args[1] if len(args) > 1 else None

        if not hasattr(self._app_state.settings, key):
            raise RuntimeError('Option does not exist: ' + key)
        if not value:
            value = getattr(self._app_state.settings, key)
            events.notify(events.PrintMessage(
                '%s=%s' % (key, value), style='msg-info'))
        else:
            value_type = type(getattr(self._app_state.settings, key))
            setattr(self._app_state.settings, key, value_type(value))
Пример #7
0
def main():
    anything_printed = False

    def print_message_handler(evt):
        nonlocal anything_printed
        anything_printed = True
        print(evt.message)

    events.register_handler(events.PrintMessage, print_message_handler)

    # basic initialization
    args = parse_args()
    settings = Settings()
    app_state = AppState(settings, args)
    tab_manager = TabManager(app_state)
    cmd_processor = CommandProcessor(app_state, tab_manager)

    user_interface = Ui(tab_manager, cmd_processor, app_state)

    # initial configuration
    cmd_processor.exec('source',
                       os.path.join(app_state.resources_dir, 'hexvirc'))
    for path in ['~/.hexvirc', '~/.config/hexvirc']:
        if os.path.exists(os.path.expanduser(path)):
            cmd_processor.exec('source', path)

    paths = util.filter_unique_paths(args.paths)
    for path in paths:
        try:
            tab_manager.open_tab(path)
        except Exception as ex:
            events.notify(events.PrintMessage(str(ex), style='msg-error'))
    if not tab_manager.tabs:
        tab_manager.open_tab()
    tab_manager.tab_index = 0

    # print collected messages, if any
    events.unregister_handler(events.PrintMessage, print_message_handler)
    if anything_printed:
        input('Press Enter to continue...')

    user_interface.run()
Пример #8
0
def main():
    anything_printed = False
    def print_message_handler(evt):
        nonlocal anything_printed
        anything_printed = True
        print(evt.message)
    events.register_handler(events.PrintMessage, print_message_handler)

    # basic initialization
    args = parse_args()
    settings = Settings()
    app_state = AppState(settings, args)
    tab_manager = TabManager(app_state)
    cmd_processor = CommandProcessor(app_state, tab_manager)

    user_interface = Ui(tab_manager, cmd_processor, app_state)

    # initial configuration
    cmd_processor.exec(
        'source', os.path.join(app_state.resources_dir, 'hexvirc'))
    for path in ['~/.hexvirc', '~/.config/hexvirc']:
        if os.path.exists(os.path.expanduser(path)):
            cmd_processor.exec('source', path)

    paths = util.filter_unique_paths(args.paths)
    for path in paths:
        try:
            tab_manager.open_tab(path)
        except Exception as ex:
            events.notify(events.PrintMessage(str(ex), style='msg-error'))
    if not tab_manager.tabs:
        tab_manager.open_tab()
    tab_manager.tab_index = 0

    # print collected messages, if any
    events.unregister_handler(events.PrintMessage, print_message_handler)
    if anything_printed:
        input('Press Enter to continue...')

    user_interface.run()
Пример #9
0
 def _do_close_current_tab(self):
     events.notify(events.TabClose(self.current_tab))
     self.tabs = self.tabs[: self._tab_index] + self.tabs[self._tab_index + 1 :]
     if not self.tabs:
         events.notify(events.ProgramExit())
     elif self.tab_index >= len(self.tabs):
         self.tab_index = len(self.tabs) - 1
     else:
         events.notify(events.TabChange(self.current_tab))
Пример #10
0
 def _do_close_current_tab(self):
     events.notify(events.TabClose(self.current_tab))
     self.tabs = self.tabs[:self._tab_index] + self.tabs[self._tab_index +
                                                         1:]
     if not self.tabs:
         events.notify(events.ProgramExit())
     elif self.tab_index >= len(self.tabs):
         self.tab_index = len(self.tabs) - 1
     else:
         events.notify(events.TabChange(self.current_tab))
Пример #11
0
 def run(self, _args):
     events.notify(events.ProgramExit())
Пример #12
0
 def run(self, args):
     message = ' '.join(args)
     events.notify(events.PrintMessage(message, style='msg-info'))
Пример #13
0
 def set_mode(self, value):
     ''' Sets the current mode. '''
     if value != self._mode:
         self._mode = value
         events.notify(events.ModeChange(value))
Пример #14
0
 def set_window_size(self, value):
     ''' Sets the window size. '''
     if value != self._window_size:
         self._window_size = value
         events.notify(events.WindowSizeChange(value))
Пример #15
0
 def open_in_current_tab(self, path):
     """ Opens a file in an existing focused tab. """
     file_buffer = self._get_or_create_file_buffer(path)
     new_tab = TabState(self._app_state, file_buffer)
     self.tabs[self.tab_index] = new_tab
     events.notify(events.TabChange(self.current_tab))
Пример #16
0
 def open_in_current_tab(self, path):
     ''' Opens a file in an existing focused tab. '''
     file_buffer = self._get_or_create_file_buffer(path)
     new_tab = TabState(self._app_state, file_buffer)
     self.tabs[self.tab_index] = new_tab
     events.notify(events.TabChange(self.current_tab))
Пример #17
0
    def run(self, args):
        target, bg_style, fg_style, bg_style_high, fg_style_high, *_ = \
            args + (None, None, None, None, None)

        events.notify(events.ColorChange(
            target, bg_style, fg_style, bg_style_high, fg_style_high))
Пример #18
0
 def set_mode(self, value):
     ''' Sets the current mode. '''
     if value != self._mode:
         self._mode = value
         events.notify(events.ModeChange(value))
Пример #19
0
 def set_window_size(self, value):
     ''' Sets the window size. '''
     if value != self._window_size:
         self._window_size = value
         events.notify(events.WindowSizeChange(value))
Пример #20
0
 def set_current_offset(self, value):
     self._cur_offset = max(0, min(self.size, value))
     self._validate_top_offset()
     events.notify(events.OffsetChange(self))
Пример #21
0
 def set_top_offset(self, value):
     self._top_offset = max(0, min(self.size, value))
     events.notify(events.OffsetChange(self))
Пример #22
0
 def set_pane(self, value):
     self._pane = value
     events.notify(events.PaneChange(self))