Beispiel #1
0
    def write_config_files(self):

        self.filehandler.write_fileinfo_file()
        preferences.write_preferences_file()
        bookmark_backend.BookmarksStore.write_bookmarks_file()

        # Write keyboard accelerator map
        keybindings.keybinding_manager(self).save()
Beispiel #2
0
    def write_config_files(self):

        self.filehandler.write_fileinfo_file()
        preferences.write_preferences_file()
        self.uimanager.bookmarks.write_bookmarks_file()

        # Write keyboard accelerator map
        gtk.accel_map_save(constants.KEYBINDINGS_PATH)
        keybindings.keybinding_manager().save()
Beispiel #3
0
 def _init_shortcuts_tab(self):
     # ----------------------------------------------------------------
     # The "Shortcuts" tab.
     # ----------------------------------------------------------------
     km = keybindings.keybinding_manager(self._window)
     page = keybindings_editor.KeybindingEditorWindow(km)
     return page
Beispiel #4
0
    def key_press_event(self, widget, event, *args):
        """Handle key press events on the main window."""

        # Dispatch keyboard input handling
        manager = keybindings.keybinding_manager()
        manager.execute((event.keyval, event.state))

        # ---------------------------------------------------------------
        # Register CTRL for scrolling only one page instead of two
        # pages in double page mode
        # ---------------------------------------------------------------
        if event.keyval in (gtk.keysyms.Control_L, gtk.keysyms.Control_R):
            self._window.imagehandler.force_single_step = True

        # ----------------------------------------------------------------
        # We kill the signals here for the Up, Down, Space and Enter keys,
        # or they will start fiddling with the thumbnail selector (bad).
        # ----------------------------------------------------------------
        if event.keyval in (
            gtk.keysyms.Up,
            gtk.keysyms.Down,
            gtk.keysyms.space,
            gtk.keysyms.KP_Enter,
            gtk.keysyms.KP_Up,
            gtk.keysyms.KP_Down,
            gtk.keysyms.KP_Home,
            gtk.keysyms.KP_End,
            gtk.keysyms.KP_Page_Up,
            gtk.keysyms.KP_Page_Down,
        ) or (event.keyval == gtk.keysyms.Return and not "GDK_MOD1_MASK" in event.state.value_names):

            self._window.emit_stop_by_name("key_press_event")
            return True
Beispiel #5
0
    def key_press_event(self, widget, event, *args):
        '''Handle key press events on the main window.'''

        # This is set on demand by callback functions
        self._scroll_protection = False

        # Dispatch keyboard input handling
        manager = keybindings.keybinding_manager(self._window)
        # Some keys can only be pressed with certain modifiers that
        # are irrelevant to the actual hotkey. Find out and ignore them.
        ALL_ACCELS_MASK = (Gdk.ModifierType.CONTROL_MASK
                           | Gdk.ModifierType.SHIFT_MASK
                           | Gdk.ModifierType.MOD1_MASK)

        keymap = Gdk.Keymap.get_default()
        code = keymap.translate_keyboard_state(event.hardware_keycode,
                                               event.get_state(), event.group)

        if code[0]:
            keyval = code[1]
            consumed = code[4]

            # If the resulting key is upper case (i.e. SHIFT + key),
            # convert it to lower case and remove SHIFT from the consumed flags
            # to match how keys are registered (<Shift> + lowercase)
            if (event.get_state() & Gdk.ModifierType.SHIFT_MASK
                    and keyval != Gdk.keyval_to_lower(keyval)):
                keyval = Gdk.keyval_to_lower(keyval)
                consumed &= ~Gdk.ModifierType.SHIFT_MASK

            # 'consumed' is the modifier that was necessary to type the key
            manager.execute(
                (keyval, event.get_state() & ~consumed & ALL_ACCELS_MASK))

        # ---------------------------------------------------------------
        # Register CTRL for scrolling only one page instead of two
        # pages in double page mode. This is mainly for mouse scrolling.
        # ---------------------------------------------------------------
        if event.keyval in (Gdk.KEY_Control_L, Gdk.KEY_Control_R):
            self._window.imagehandler.force_single_step = True

        # ----------------------------------------------------------------
        # We kill the signals here for the Up, Down, Space and Enter keys,
        # or they will start fiddling with the thumbnail selector (bad).
        # ----------------------------------------------------------------
        if (event.keyval
                in (Gdk.KEY_Up, Gdk.KEY_Down, Gdk.KEY_space, Gdk.KEY_KP_Enter,
                    Gdk.KEY_KP_Up, Gdk.KEY_KP_Down, Gdk.KEY_KP_Home,
                    Gdk.KEY_KP_End, Gdk.KEY_KP_Page_Up, Gdk.KEY_KP_Page_Down)
                or (event.keyval == Gdk.KEY_Return
                    and not 'GDK_MOD1_MASK' in event.get_state().value_names)):

            self._window.stop_emission_by_name('key_press_event')
            return True
Beispiel #6
0
    def key_press_event(self, widget, event, *args):
        """Handle key press events on the main window."""

        # This is set on demand by callback functions
        self._scroll_protection = False

        # Dispatch keyboard input handling
        manager = keybindings.keybinding_manager(self._window)
        # Some keys can only be pressed with certain modifiers that
        # are irrelevant to the actual hotkey. Find out and ignore them.
        ALL_ACCELS_MASK = (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
                           | gtk.gdk.MOD1_MASK)

        keymap = gtk.gdk.keymap_get_default()
        code = keymap.translate_keyboard_state(event.hardware_keycode,
                                               event.state, event.group)

        if code is not None:
            keyval, egroup, level, consumed = code

            # If the resulting key is upper case (i.e. SHIFT + key),
            # convert it to lower case and remove SHIFT from the consumed flags
            # to match how keys are registered (<Shift> + lowercase)
            if (gtk.gdk.keyval_is_upper(keyval)
                    and not gtk.gdk.keyval_is_lower(keyval)
                    and event.state & gtk.gdk.SHIFT_MASK):
                keyval = gtk.gdk.keyval_to_lower(keyval)
                consumed &= ~gtk.gdk.SHIFT_MASK

            # 'consumed' is the modifier that was necessary to type the key
            manager.execute(
                (keyval, event.state & ~consumed & ALL_ACCELS_MASK))

        # ---------------------------------------------------------------
        # Register CTRL for scrolling only one page instead of two
        # pages in double page mode
        # ---------------------------------------------------------------
        if event.keyval in (gtk.keysyms.Control_L, gtk.keysyms.Control_R):
            self._window.imagehandler.force_single_step = True

        # ----------------------------------------------------------------
        # We kill the signals here for the Up, Down, Space and Enter keys,
        # or they will start fiddling with the thumbnail selector (bad).
        # ----------------------------------------------------------------
        if (event.keyval in (gtk.keysyms.Up, gtk.keysyms.Down,
                             gtk.keysyms.space, gtk.keysyms.KP_Enter,
                             gtk.keysyms.KP_Up, gtk.keysyms.KP_Down,
                             gtk.keysyms.KP_Home, gtk.keysyms.KP_End,
                             gtk.keysyms.KP_Page_Up, gtk.keysyms.KP_Page_Down)
                or (event.keyval == gtk.keysyms.Return
                    and not 'GDK_MOD1_MASK' in event.state.value_names)):

            self._window.emit_stop_by_name('key_press_event')
            return True
Beispiel #7
0
    def key_press_event(self, widget, event, *args):
        """Handle key press events on the main window."""

        # This is set on demand by callback functions
        self._scroll_protection = False

        # Dispatch keyboard input handling
        manager = keybindings.keybinding_manager(self._window)
        # Some keys can only be pressed with certain modifiers that
        # are irrelevant to the actual hotkey. Find out and ignore them.
        ALL_ACCELS_MASK = (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK |
                           gtk.gdk.MOD1_MASK)

        keymap = gtk.gdk.keymap_get_default()
        code = keymap.translate_keyboard_state(
                event.hardware_keycode, event.state, event.group)

        if code is not None:
            keyval, egroup, level, consumed = code

            # If the resulting key is upper case (i.e. SHIFT + key),
            # convert it to lower case and remove SHIFT from the consumed flags
            # to match how keys are registered (<Shift> + lowercase)
            if (gtk.gdk.keyval_is_upper(keyval) and
                not gtk.gdk.keyval_is_lower(keyval) and
                event.state & gtk.gdk.SHIFT_MASK):
                keyval = gtk.gdk.keyval_to_lower(keyval)
                consumed &= ~gtk.gdk.SHIFT_MASK

            # 'consumed' is the modifier that was necessary to type the key
            manager.execute((keyval, event.state & ~consumed & ALL_ACCELS_MASK))

        # ---------------------------------------------------------------
        # Register CTRL for scrolling only one page instead of two
        # pages in double page mode. This is mainly for mouse scrolling.
        # ---------------------------------------------------------------
        if event.keyval in (gtk.keysyms.Control_L, gtk.keysyms.Control_R):
            self._window.imagehandler.force_single_step = True

        # ----------------------------------------------------------------
        # We kill the signals here for the Up, Down, Space and Enter keys,
        # or they will start fiddling with the thumbnail selector (bad).
        # ----------------------------------------------------------------
        if (event.keyval in (gtk.keysyms.Up, gtk.keysyms.Down,
          gtk.keysyms.space, gtk.keysyms.KP_Enter, gtk.keysyms.KP_Up,
          gtk.keysyms.KP_Down, gtk.keysyms.KP_Home, gtk.keysyms.KP_End,
          gtk.keysyms.KP_Page_Up, gtk.keysyms.KP_Page_Down) or
          (event.keyval == gtk.keysyms.Return and not
          'GDK_MOD1_MASK' in event.state.value_names)):

            self._window.emit_stop_by_name('key_press_event')
            return True
Beispiel #8
0
    def _response(self, dialog, response):
        if response == gtk.RESPONSE_CLOSE:
            _close_dialog()

        elif response == constants.RESPONSE_REVERT_TO_DEFAULT:
            if self.notebook.get_nth_page(self.notebook.get_current_page()) == self.shortcuts:
                # "Shortcuts" page is active, reset all keys to their default value
                km = keybindings.keybinding_manager(self._window)
                km.clear_all()
                self._window._event_handler.register_key_events()
                km.save()
                self.shortcuts.refresh_model()
            else:
                # Reset stored choices
                prefs["stored dialog choices"] = {}
                self.reset_button.set_sensitive(False)

        else:
            # Other responses close the dialog, e.g. clicking the X icon on the dialog.
            _close_dialog()
    def _response(self, dialog, response):
        if response == Gtk.ResponseType.CLOSE:
            _close_dialog()

        elif response == constants.RESPONSE_REVERT_TO_DEFAULT:
            if self.notebook.get_nth_page(self.notebook.get_current_page()) == self.shortcuts:
                # "Shortcuts" page is active, reset all keys to their default value
                km = keybindings.keybinding_manager(self._window)
                km.reset_keybindings()
                self._window._event_handler.register_key_events()
                km.save()
                self.shortcuts.refresh_model()
            else:
                # Reset stored choices
                prefs['stored dialog choices'] = {}
                self.reset_button.set_sensitive(False)

        else:
            # Other responses close the dialog, e.g. clicking the X icon on the dialog.
            _close_dialog()
Beispiel #10
0
    def register_key_events(self):
        """ Registers keyboard events and their default binings, and hooks
        them up with their respective callback functions. """

        manager = keybindings.keybinding_manager(self._window)

        # Navigation keys
        manager.register('previous_page',
            ['Page_Up', 'KP_Page_Up', 'BackSpace'],
            self._flip_page, kwargs={'number_of_pages': -1})
        manager.register('next_page',
            ['Page_Down', 'KP_Page_Down'],
            self._flip_page, kwargs={'number_of_pages': 1})
        manager.register('previous_page_singlestep',
            ['<Ctrl>Page_Up', '<Ctrl>KP_Page_Up', '<Ctrl>BackSpace'],
            self._flip_page, kwargs={'number_of_pages': -1, 'single_step': True})
        manager.register('next_page_singlestep',
            ['<Ctrl>Page_Down', '<Ctrl>KP_Page_Down'],
            self._flip_page, kwargs={'number_of_pages': 1, 'single_step': True})
        manager.register('previous_page_dynamic',
            ['<Mod1>Left'],
            self._left_right_page_progress, kwargs={'number_of_pages': -1})
        manager.register('next_page_dynamic',
            ['<Mod1>Right'],
            self._left_right_page_progress, kwargs={'number_of_pages': 1})

        manager.register('previous_page_ff',
            ['<Shift>Page_Up', '<Shift>KP_Page_Up', '<Shift>BackSpace', '<Shift><Mod1>Left'],
            self._flip_page, kwargs={'number_of_pages': -10})
        manager.register('next_page_ff',
            ['<Shift>Page_Down', '<Shift>KP_Page_Down', '<Shift><Mod1>Right'],
            self._flip_page, kwargs={'number_of_pages': 10})


        manager.register('first_page',
            ['Home', 'KP_Home'],
            self._window.first_page)
        manager.register('last_page',
            ['End', 'KP_End'],
            self._window.last_page)
        manager.register('go_to',
            ['G'],
            self._window.page_select)

        # Numpad (without numlock) aligns the image depending on the key.
        manager.register('scroll_left_bottom',
            ['KP_1'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (-1, 1), 'index': constants.UNION_INDEX})
        manager.register('scroll_middle_bottom',
            ['KP_2'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (constants.SCROLL_TO_CENTER, 1),
                'index': constants.UNION_INDEX})
        manager.register('scroll_right_bottom',
            ['KP_3'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (1, 1), 'index': constants.UNION_INDEX})

        manager.register('scroll_left_middle',
            ['KP_4'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (-1, constants.SCROLL_TO_CENTER),
                'index': constants.UNION_INDEX})
        manager.register('scroll_middle',
            ['KP_5'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (constants.SCROLL_TO_CENTER,
                constants.SCROLL_TO_CENTER), 'index': constants.UNION_INDEX})
        manager.register('scroll_right_middle',
            ['KP_6'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (1, constants.SCROLL_TO_CENTER),
                'index': constants.UNION_INDEX})

        manager.register('scroll_left_top',
            ['KP_7'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (-1, -1), 'index': constants.UNION_INDEX})
        manager.register('scroll_middle_top',
            ['KP_8'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (constants.SCROLL_TO_CENTER, -1),
                'index': constants.UNION_INDEX})
        manager.register('scroll_right_top',
            ['KP_9'],
            self._window.scroll_to_predefined,
            kwargs={'destination': (1, -1), 'index': constants.UNION_INDEX})

        # Enter/exit fullscreen.
        manager.register('exit_fullscreen',
            ['Escape'],
            self.escape_event)

        # View modes
        manager.register('double_page',
            ['d'],
            self._window.actiongroup.get_action('double_page').activate)


        manager.register('best_fit_mode',
            ['b'],
            self._window.actiongroup.get_action('best_fit_mode').activate)

        manager.register('fit_width_mode',
            ['w'],
            self._window.actiongroup.get_action('fit_width_mode').activate)

        manager.register('fit_height_mode',
            ['h'],
            self._window.actiongroup.get_action('fit_height_mode').activate)

        manager.register('fit_size_mode',
            ['s'],
            self._window.actiongroup.get_action('fit_size_mode').activate)

        manager.register('fit_manual_mode',
            ['a'],
            self._window.actiongroup.get_action('fit_manual_mode').activate)


        manager.register('manga_mode',
            ['m'],
            self._window.actiongroup.get_action('manga_mode').activate)

        manager.register('invert_scroll',
            ['x'],
            self._window.actiongroup.get_action('invert_scroll').activate)

        manager.register('keep_transformation',
            ['k'],
            self._window.actiongroup.get_action('keep_transformation').activate)

        manager.register('lens',
            ['l'],
            self._window.actiongroup.get_action('lens').activate)

        manager.register('stretch',
            ['y'],
            self._window.actiongroup.get_action('stretch').activate)

        # Zooming commands for manual zoom mode
        manager.register('zoom_in',
            ['plus', 'KP_Add', 'equal'],
            self._window.actiongroup.get_action('zoom_in').activate)
        manager.register('zoom_out',
            ['minus', 'KP_Subtract'],
            self._window.actiongroup.get_action('zoom_out').activate)
        # Zoom out is already defined as GTK menu hotkey
        manager.register('zoom_original',
            ['<Control>0', 'KP_0'],
            self._window.actiongroup.get_action('zoom_original').activate)

        manager.register('rotate_90',
            ['r'],
            self._window.rotate_90)

        manager.register('rotate_270',
            ['<Shift>r'],
            self._window.rotate_270)

        manager.register('rotate_180',
            [],
            self._window.rotate_180)

        manager.register('flip_horiz',
            [],
            self._window.flip_horizontally)

        manager.register('flip_vert',
            [],
            self._window.flip_vertically)

        manager.register('no_autorotation',
            [],
            self._window.actiongroup.get_action('no_autorotation').activate)

        manager.register('rotate_90_width',
            [],
            self._window.actiongroup.get_action('rotate_90_width').activate)
        manager.register('rotate_270_width',
            [],
            self._window.actiongroup.get_action('rotate_270_width').activate)

        manager.register('rotate_90_height',
            [],
            self._window.actiongroup.get_action('rotate_90_height').activate)

        manager.register('rotate_270_height',
            [],
            self._window.actiongroup.get_action('rotate_270_height').activate)

        # Arrow keys scroll the image
        manager.register('scroll_down',
            ['Down', 'KP_Down'],
            self._scroll_down)
        manager.register('scroll_up',
            ['Up', 'KP_Up'],
            self._scroll_up)
        manager.register('scroll_right',
            ['Right', 'KP_Right'],
            self._scroll_right)
        manager.register('scroll_left',
            ['Left', 'KP_Left'],
            self._scroll_left)

        # File operations
        manager.register('close',
            ['<Control>W'],
            self._window.filehandler.close_file)

        manager.register('quit',
            ['<Control>Q'],
            self._window.close_program)

        manager.register('save_and_quit',
            ['<Control><shift>q'],
            self._window.save_and_terminate_program)

        manager.register('delete',
            ['Delete'],
            self._window.delete)

        manager.register('extract_page',
            ['<Control><Shift>s'],
            self._window.extract_page)

        manager.register('refresh_archive',
            ['<control><shift>R'],
            self._window.filehandler.refresh_file)

        manager.register('next_archive',
            ['<control><shift>N'],
            self._window.filehandler._open_next_archive)

        manager.register('previous_archive',
            ['<control><shift>P'],
            self._window.filehandler._open_previous_archive)

        manager.register('next_directory',
            ['<control>N'],
            self._window.filehandler.open_next_directory)

        manager.register('previous_directory',
            ['<control>P'],
            self._window.filehandler.open_previous_directory)

        manager.register('comments',
            ['c'],
            self._window.actiongroup.get_action('comments').activate)

        manager.register('properties',
            ['<Alt>Return'],
            self._window.actiongroup.get_action('properties').activate)

        manager.register('preferences',
            ['F12'],
            self._window.actiongroup.get_action('preferences').activate)

        manager.register('edit_archive',
            [],
            self._window.actiongroup.get_action('edit_archive').activate)

        manager.register('open',
            ['<Control>O'],
            self._window.actiongroup.get_action('open').activate)

        manager.register('enhance_image',
            ['e'],
            self._window.actiongroup.get_action('enhance_image').activate)

        manager.register('library',
            ['<Control>L'],
            self._window.actiongroup.get_action('library').activate)

        # Space key scrolls down a percentage of the window height or the
        # image height at a time. When at the bottom it flips to the next
        # page.
        #
        # It also has a "smart scrolling mode" in which we try to follow
        # the flow of the comic.
        #
        # If Shift is pressed we should backtrack instead.
        manager.register('smart_scroll_down',
            ['space'],
            self._smart_scroll_down)
        manager.register('smart_scroll_up',
            ['<Shift>space'],
            self._smart_scroll_up)

        # User interface
        manager.register('osd_panel',
            ['Tab'],
            self._window.show_info_panel)

        manager.register('minimize',
            ['n'],
            self._window.minimize)

        manager.register('fullscreen',
            ['f', 'F11'],
            self._window.actiongroup.get_action('fullscreen').activate)

        manager.register('toolbar',
            [],
            self._window.actiongroup.get_action('toolbar').activate)

        manager.register('menubar',
            ['<Control>M'],
            self._window.actiongroup.get_action('menubar').activate)

        manager.register('statusbar',
            [],
            self._window.actiongroup.get_action('statusbar').activate)

        manager.register('scrollbar',
            [],
            self._window.actiongroup.get_action('scrollbar').activate)

        manager.register('thumbnails',
            ['F9'],
            self._window.actiongroup.get_action('thumbnails').activate)


        manager.register('hide_all',
            ['i'],
            self._window.actiongroup.get_action('hide_all').activate)

        manager.register('slideshow',
            ['<Control>S'],
            self._window.actiongroup.get_action('slideshow').activate)

        # Execute external command. Bind keys from 1 to 9 to commands 1 to 9.
        for i in range(1, 10):
            manager.register('execute_command_%d' % i, ['%d' % i],
                             self._execute_command, args=[i - 1])
Beispiel #11
0
    def register_key_events(self):
        """ Registers keyboard events and their default binings, and hooks
        them up with their respective callback functions. """

        manager = keybindings.keybinding_manager(self._window)

        # Navigation keys
        manager.register('previous_page',
                         ['Page_Up', 'KP_Page_Up', 'BackSpace'],
                         self._flip_page, kwargs={'number_of_pages': -1})
        manager.register('next_page',
                         ['Page_Down', 'KP_Page_Down'],
                         self._flip_page, kwargs={'number_of_pages': 1})

        manager.register('delete_page',
                         ['d'],
                         self._delete_page)

        manager.register('previous_page_singlestep',
                         ['<Ctrl>Page_Up', '<Ctrl>KP_Page_Up', '<Ctrl>BackSpace'],
                         self._flip_page, kwargs={'number_of_pages': -1, 'single_step': True})
        manager.register('next_page_singlestep',
                         ['<Ctrl>Page_Down', '<Ctrl>KP_Page_Down'],
                         self._flip_page, kwargs={'number_of_pages': 1, 'single_step': True})
        manager.register('previous_page_dynamic',
                         ['<Mod1>Left'],
                         self._left_right_page_progress, kwargs={'number_of_pages': -1})
        manager.register('next_page_dynamic',
                         ['<Mod1>Right'],
                         self._left_right_page_progress, kwargs={'number_of_pages': 1})

        manager.register('previous_page_ff',
                         ['<Shift>Page_Up', '<Shift>KP_Page_Up',
                             '<Shift>BackSpace', '<Shift><Mod1>Left'],
                         self._flip_page, kwargs={'number_of_pages': -10})
        manager.register('next_page_ff',
                         ['<Shift>Page_Down', '<Shift>KP_Page_Down',
                             '<Shift><Mod1>Right'],
                         self._flip_page, kwargs={'number_of_pages': 10})

        manager.register('first_page',
                         ['Home', 'KP_Home'],
                         self._window.first_page)
        manager.register('last_page',
                         ['End', 'KP_End'],
                         self._window.last_page)
        manager.register('go_to',
                         ['G'],
                         self._window.page_select)

        # Numpad (without numlock) aligns the image depending on the key.
        manager.register('scroll_left_bottom',
                         ['KP_1'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (-1, 1), 'index': constants.UNION_INDEX})
        manager.register('scroll_middle_bottom',
                         ['KP_2'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (constants.SCROLL_TO_CENTER, 1),
                                 'index': constants.UNION_INDEX})
        manager.register('scroll_right_bottom',
                         ['KP_3'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (1, 1), 'index': constants.UNION_INDEX})

        manager.register('scroll_left_middle',
                         ['KP_4'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (-1, constants.SCROLL_TO_CENTER),
                                 'index': constants.UNION_INDEX})
        manager.register('scroll_middle',
                         ['KP_5'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (constants.SCROLL_TO_CENTER,
                                                 constants.SCROLL_TO_CENTER), 'index': constants.UNION_INDEX})
        manager.register('scroll_right_middle',
                         ['KP_6'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (1, constants.SCROLL_TO_CENTER),
                                 'index': constants.UNION_INDEX})

        manager.register('scroll_left_top',
                         ['KP_7'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (-1, -1), 'index': constants.UNION_INDEX})
        manager.register('scroll_middle_top',
                         ['KP_8'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (constants.SCROLL_TO_CENTER, -1),
                                 'index': constants.UNION_INDEX})
        manager.register('scroll_right_top',
                         ['KP_9'],
                         self._window.scroll_to_predefined,
                         kwargs={'destination': (1, -1), 'index': constants.UNION_INDEX})

        # Enter/exit fullscreen.
        manager.register('exit_fullscreen',
                         ['Escape'],
                         self.escape_event)

        # View modes
        manager.register('double_page',
                         ['<Shift>d'],
                         self._window.actiongroup.get_action('double_page').activate)

        manager.register('best_fit_mode',
                         ['b'],
                         self._window.actiongroup.get_action('best_fit_mode').activate)

        manager.register('fit_width_mode',
                         ['w'],
                         self._window.actiongroup.get_action('fit_width_mode').activate)

        manager.register('fit_height_mode',
                         ['h'],
                         self._window.actiongroup.get_action('fit_height_mode').activate)

        manager.register('fit_size_mode',
                         ['s'],
                         self._window.actiongroup.get_action('fit_size_mode').activate)

        manager.register('fit_manual_mode',
                         ['a'],
                         self._window.actiongroup.get_action('fit_manual_mode').activate)

        manager.register('manga_mode',
                         ['m'],
                         self._window.actiongroup.get_action('manga_mode').activate)

        manager.register('invert_scroll',
                         ['x'],
                         self._window.actiongroup.get_action('invert_scroll').activate)

        manager.register('keep_transformation',
                         ['k'],
                         self._window.actiongroup.get_action('keep_transformation').activate)

        manager.register('lens',
                         ['l'],
                         self._window.actiongroup.get_action('lens').activate)

        manager.register('stretch',
                         ['y'],
                         self._window.actiongroup.get_action('stretch').activate)

        # Zooming commands for manual zoom mode
        manager.register('zoom_in',
                         ['plus', 'KP_Add', 'equal'],
                         self._window.actiongroup.get_action('zoom_in').activate)
        manager.register('zoom_out',
                         ['minus', 'KP_Subtract'],
                         self._window.actiongroup.get_action('zoom_out').activate)
        # Zoom out is already defined as GTK menu hotkey
        manager.register('zoom_original',
                         ['<Control>0', 'KP_0'],
                         self._window.actiongroup.get_action('zoom_original').activate)

        manager.register('rotate_90',
                         ['r'],
                         self._window.rotate_90)

        manager.register('rotate_270',
                         ['<Shift>r'],
                         self._window.rotate_270)

        manager.register('rotate_180',
                         [],
                         self._window.rotate_180)

        manager.register('flip_horiz',
                         [],
                         self._window.flip_horizontally)

        manager.register('flip_vert',
                         [],
                         self._window.flip_vertically)

        manager.register('no_autorotation',
                         [],
                         self._window.actiongroup.get_action('no_autorotation').activate)

        manager.register('rotate_90_width',
                         [],
                         self._window.actiongroup.get_action('rotate_90_width').activate)
        manager.register('rotate_270_width',
                         [],
                         self._window.actiongroup.get_action('rotate_270_width').activate)

        manager.register('rotate_90_height',
                         [],
                         self._window.actiongroup.get_action('rotate_90_height').activate)

        manager.register('rotate_270_height',
                         [],
                         self._window.actiongroup.get_action('rotate_270_height').activate)

        # Arrow keys scroll the image
        manager.register('scroll_down',
                         ['Down', 'KP_Down'],
                         self._scroll_down)
        manager.register('scroll_up',
                         ['Up', 'KP_Up'],
                         self._scroll_up)
        manager.register('scroll_right',
                         ['Right', 'KP_Right'],
                         self._scroll_right)
        manager.register('scroll_left',
                         ['Left', 'KP_Left'],
                         self._scroll_left)

        # File operations
        manager.register('close',
                         ['<Control>W'],
                         self._window.filehandler.close_file)

        manager.register('quit',
                         ['<Control>Q'],
                         self._window.close_program)

        manager.register('save_and_quit',
                         ['<Control><shift>q'],
                         self._window.save_and_terminate_program)

        manager.register('delete',
                         ['Delete'],
                         self._window.delete)

        manager.register('extract_page',
                         ['<Control><Shift>s'],
                         self._window.extract_page)

        manager.register('refresh_archive',
                         ['<control><shift>R'],
                         self._window.filehandler.refresh_file)

        manager.register('next_archive',
                         ['<control><shift>N'],
                         self._window.filehandler._open_next_archive)

        manager.register('previous_archive',
                         ['<control><shift>P'],
                         self._window.filehandler._open_previous_archive)

        manager.register('next_directory',
                         ['<control>N'],
                         self._window.filehandler.open_next_directory)

        manager.register('previous_directory',
                         ['<control>P'],
                         self._window.filehandler.open_previous_directory)

        manager.register('comments',
                         ['c'],
                         self._window.actiongroup.get_action('comments').activate)

        manager.register('properties',
                         ['<Alt>Return'],
                         self._window.actiongroup.get_action('properties').activate)

        manager.register('preferences',
                         ['F12'],
                         self._window.actiongroup.get_action('preferences').activate)

        manager.register('edit_archive',
                         [],
                         self._window.actiongroup.get_action('edit_archive').activate)

        manager.register('open',
                         ['<Control>O'],
                         self._window.actiongroup.get_action('open').activate)

        manager.register('enhance_image',
                         ['e'],
                         self._window.actiongroup.get_action('enhance_image').activate)

        manager.register('library',
                         ['<Control>L'],
                         self._window.actiongroup.get_action('library').activate)

        # Space key scrolls down a percentage of the window height or the
        # image height at a time. When at the bottom it flips to the next
        # page.
        #
        # It also has a "smart scrolling mode" in which we try to follow
        # the flow of the comic.
        #
        # If Shift is pressed we should backtrack instead.
        manager.register('smart_scroll_down',
                         ['space'],
                         self._smart_scroll_down)
        manager.register('smart_scroll_up',
                         ['<Shift>space'],
                         self._smart_scroll_up)

        # User interface
        manager.register('osd_panel',
                         ['Tab'],
                         self._window.show_info_panel)

        manager.register('minimize',
                         ['n'],
                         self._window.minimize)

        manager.register('fullscreen',
                         ['f', 'F11'],
                         self._window.actiongroup.get_action('fullscreen').activate)

        manager.register('toolbar',
                         [],
                         self._window.actiongroup.get_action('toolbar').activate)

        manager.register('menubar',
                         ['<Control>M'],
                         self._window.actiongroup.get_action('menubar').activate)

        manager.register('statusbar',
                         [],
                         self._window.actiongroup.get_action('statusbar').activate)

        manager.register('scrollbar',
                         [],
                         self._window.actiongroup.get_action('scrollbar').activate)

        manager.register('thumbnails',
                         ['F9'],
                         self._window.actiongroup.get_action('thumbnails').activate)

        manager.register('hide_all',
                         ['i'],
                         self._window.actiongroup.get_action('hide_all').activate)

        manager.register('slideshow',
                         ['<Control>S'],
                         self._window.actiongroup.get_action('slideshow').activate)

        # Execute external command. Bind keys from 1 to 9 to commands 1 to 9.
        for i in range(1, 10):
            manager.register('execute_command_%d' % i, ['%d' % i],
                             self._execute_command, args=[i - 1])
Beispiel #12
0
    def register_key_events(self):
        ''' Registers keyboard events and their default binings, and hooks
        them up with their respective callback functions. '''

        manager = keybindings.keybinding_manager(self._window)

        # Navigation keys
        manager.register('previous_page',
                         self._flip_page,
                         kwargs={'number_of_pages': -1})
        manager.register('next_page',
                         self._flip_page,
                         kwargs={'number_of_pages': 1})
        manager.register('previous_page_singlestep',
                         self._flip_page,
                         kwargs={
                             'number_of_pages': -1,
                             'single_step': True
                         })
        manager.register('next_page_singlestep',
                         self._flip_page,
                         kwargs={
                             'number_of_pages': 1,
                             'single_step': True
                         })
        manager.register('previous_page_dynamic',
                         self._left_right_page_progress,
                         kwargs={'number_of_pages': -1})
        manager.register('next_page_dynamic',
                         self._left_right_page_progress,
                         kwargs={'number_of_pages': 1})

        manager.register('previous_page_ff',
                         self._flip_page,
                         kwargs={'number_of_pages': -10})
        manager.register('next_page_ff',
                         self._flip_page,
                         kwargs={'number_of_pages': 10})

        manager.register('first_page', self._window.first_page)
        manager.register('last_page', self._window.last_page)
        manager.register('go_to', self._window.page_select)

        manager.register('scroll_left_bottom',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (-1, 1),
                             'index': constants.UNION_INDEX
                         })
        manager.register('scroll_middle_bottom',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (constants.SCROLL_TO_CENTER, 1),
                             'index': constants.UNION_INDEX
                         })
        manager.register('scroll_right_bottom',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (1, 1),
                             'index': constants.UNION_INDEX
                         })

        manager.register('scroll_left_middle',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (-1, constants.SCROLL_TO_CENTER),
                             'index': constants.UNION_INDEX
                         })
        manager.register('scroll_middle',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (constants.SCROLL_TO_CENTER,
                                             constants.SCROLL_TO_CENTER),
                             'index':
                             constants.UNION_INDEX
                         })
        manager.register('scroll_right_middle',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (1, constants.SCROLL_TO_CENTER),
                             'index': constants.UNION_INDEX
                         })

        manager.register('scroll_left_top',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (-1, -1),
                             'index': constants.UNION_INDEX
                         })
        manager.register('scroll_middle_top',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (constants.SCROLL_TO_CENTER, -1),
                             'index': constants.UNION_INDEX
                         })
        manager.register('scroll_right_top',
                         self._window.scroll_to_predefined,
                         kwargs={
                             'destination': (1, -1),
                             'index': constants.UNION_INDEX
                         })

        # Enter/exit fullscreen.
        manager.register('exit_fullscreen', self.escape_event)

        # View modes
        manager.register(
            'double_page',
            self._window.actiongroup.get_action('double_page').activate)

        manager.register(
            'best_fit_mode',
            self._window.actiongroup.get_action('best_fit_mode').activate)
        manager.register(
            'fit_width_mode',
            self._window.actiongroup.get_action('fit_width_mode').activate)
        manager.register(
            'fit_height_mode',
            self._window.actiongroup.get_action('fit_height_mode').activate)
        manager.register(
            'fit_size_mode',
            self._window.actiongroup.get_action('fit_size_mode').activate)
        manager.register(
            'fit_manual_mode',
            self._window.actiongroup.get_action('fit_manual_mode').activate)

        manager.register(
            'manga_mode',
            self._window.actiongroup.get_action('manga_mode').activate)
        manager.register(
            'invert_scroll',
            self._window.actiongroup.get_action('invert_scroll').activate)
        manager.register(
            'keep_transformation',
            self._window.actiongroup.get_action(
                'keep_transformation').activate)
        manager.register('lens',
                         self._window.actiongroup.get_action('lens').activate)
        manager.register(
            'stretch',
            self._window.actiongroup.get_action('stretch').activate)

        # Zooming commands for manual zoom mode
        manager.register(
            'zoom_in',
            self._window.actiongroup.get_action('zoom_in').activate)
        manager.register(
            'zoom_out',
            self._window.actiongroup.get_action('zoom_out').activate)
        manager.register(
            'zoom_original',
            self._window.actiongroup.get_action('zoom_original').activate)

        manager.register('rotate_90', self._window.rotate_90)
        manager.register('rotate_270', self._window.rotate_270)
        manager.register('rotate_180', self._window.rotate_180)
        manager.register('flip_horiz', self._window.flip_horizontally)
        manager.register('flip_vert', self._window.flip_vertically)
        manager.register(
            'no_autorotation',
            self._window.actiongroup.get_action('no_autorotation').activate)
        manager.register(
            'rotate_90_width',
            self._window.actiongroup.get_action('rotate_90_width').activate)
        manager.register(
            'rotate_270_width',
            self._window.actiongroup.get_action('rotate_270_width').activate)
        manager.register(
            'rotate_90_height',
            self._window.actiongroup.get_action('rotate_90_height').activate)
        manager.register(
            'rotate_270_height',
            self._window.actiongroup.get_action('rotate_270_height').activate)

        manager.register('scroll_down', self._scroll_down)
        manager.register('scroll_up', self._scroll_up)
        manager.register('scroll_right', self._scroll_right)
        manager.register('scroll_left', self._scroll_left)

        # File operations
        manager.register('close', self._window.filehandler.close_file)
        manager.register('quit', self._window.close_program)
        manager.register('save_and_quit',
                         self._window.save_and_terminate_program)
        manager.register('extract_page', self._window.extract_page)
        manager.register('refresh_archive',
                         self._window.filehandler.refresh_file)
        manager.register('next_archive',
                         self._window.filehandler._open_next_archive)
        manager.register('previous_archive',
                         self._window.filehandler._open_previous_archive)
        manager.register('next_directory',
                         self._window.filehandler.open_next_directory)
        manager.register('previous_directory',
                         self._window.filehandler.open_previous_directory)
        manager.register(
            'comments',
            self._window.actiongroup.get_action('comments').activate)
        manager.register(
            'properties',
            self._window.actiongroup.get_action('properties').activate)
        manager.register(
            'preferences',
            self._window.actiongroup.get_action('preferences').activate)
        manager.register(
            'edit_archive',
            self._window.actiongroup.get_action('edit_archive').activate)
        manager.register('open',
                         self._window.actiongroup.get_action('open').activate)
        manager.register(
            'enhance_image',
            self._window.actiongroup.get_action('enhance_image').activate)
        manager.register(
            'library',
            self._window.actiongroup.get_action('library').activate)

        manager.register('smart_scroll_down', self._smart_scroll_down)
        manager.register('smart_scroll_up', self._smart_scroll_up)

        # User interface
        manager.register('osd_panel', self._window.show_info_panel)
        manager.register('minimize', self._window.minimize)
        manager.register(
            'fullscreen', lambda: self._window.actiongroup.get_action(
                'fullscreen').set_active(True))
        manager.register(
            'toggle_fullscreen',
            self._window.actiongroup.get_action('fullscreen').activate)
        manager.register(
            'toolbar',
            self._window.actiongroup.get_action('toolbar').activate)
        manager.register(
            'menubar',
            self._window.actiongroup.get_action('menubar').activate)
        manager.register(
            'statusbar',
            self._window.actiongroup.get_action('statusbar').activate)
        manager.register(
            'scrollbar',
            self._window.actiongroup.get_action('scrollbar').activate)
        manager.register(
            'thumbnails',
            self._window.actiongroup.get_action('thumbnails').activate)
        manager.register(
            'hide_all',
            self._window.actiongroup.get_action('hide_all').activate)
        manager.register(
            'slideshow',
            self._window.actiongroup.get_action('slideshow').activate)

        manager.register(
            'keyhandler_open',
            self._window.actiongroup.get_action('keyhandler_open').activate)

        # Execute external command. Bind keys from 1 to 9 to commands 1 to 9.
        for i in range(1, 10):
            manager.register('execute_command_%d' % i,
                             self._execute_command,
                             args=[i - 1])
Beispiel #13
0
    def register_key_events(self):
        """ Registers keyboard events and their default binings, and hooks
        them up with their respective callback functions. """

        manager = keybindings.keybinding_manager()

        # Navigation keys that work in addition to the accelerators in ui.py
        manager.register("previous page", ["KP_Page_Up", "BackSpace", "<Mod1>Left"], self._window.previous_page)
        manager.register("next page", ["KP_Page_Down", "<Mod1>Right"], self._window.next_page)

        # Numpad (without numlock) aligns the image depending on the key.
        manager.register(
            "scroll left bottom", ["KP_1"], self._window.scroll_to_fixed, kwargs={"horiz": "left", "vert": "bottom"}
        )
        manager.register(
            "scroll middle bottom", ["KP_2"], self._window.scroll_to_fixed, kwargs={"horiz": "middle", "vert": "bottom"}
        )
        manager.register(
            "scroll right bottom", ["KP_3"], self._window.scroll_to_fixed, kwargs={"horiz": "right", "vert": "bottom"}
        )

        manager.register(
            "scroll left middle", ["KP_4"], self._window.scroll_to_fixed, kwargs={"horiz": "left", "vert": "middle"}
        )
        manager.register(
            "scroll middle", ["KP_5"], self._window.scroll_to_fixed, kwargs={"horiz": "middle", "vert": "middle"}
        )
        manager.register(
            "scroll right middle", ["KP_6"], self._window.scroll_to_fixed, kwargs={"horiz": "right", "vert": "middle"}
        )

        manager.register(
            "scroll left top", ["KP_7"], self._window.scroll_to_fixed, kwargs={"horiz": "left", "vert": "top"}
        )
        manager.register(
            "scroll middle top", ["KP_8"], self._window.scroll_to_fixed, kwargs={"horiz": "middle", "vert": "top"}
        )
        manager.register(
            "scroll right top", ["KP_9"], self._window.scroll_to_fixed, kwargs={"horiz": "right", "vert": "top"}
        )

        # Enter/exit fullscreen.
        manager.register(
            "exit fullscreen", ["Escape"], self._window.actiongroup.get_action("fullscreen").set_active, args=(False,)
        )
        manager.register("toggle fullscreen", ["F11"], self._window.actiongroup.get_action("fullscreen").activate)

        # Zooming commands for manual zoom mode
        manager.register("zoom in", ["plus", "equal"], self._window.actiongroup.get_action("zoom_in").activate)
        manager.register("zoom out", ["minus"], self._window.actiongroup.get_action("zoom_out").activate)
        manager.register(
            "zoom original",
            ["<Control>0", "<Control>KP_0"],
            self._window.actiongroup.get_action("zoom_original").activate,
        )

        # Arrow keys scroll the image
        manager.register("scroll down", ["Down", "KP_Down"], self._scroll_down)
        manager.register("scroll up", ["Up", "KP_Up"], self._scroll_up)
        manager.register("scroll right", ["Right", "KP_Right"], self._scroll_right)
        manager.register("scroll left", ["Left", "KP_Left"], self._scroll_left)

        # Space key scrolls down a percentage of the window height or the
        # image height at a time. When at the bottom it flips to the next
        # page.
        #
        # It also has a "smart scrolling mode" in which we try to follow
        # the flow of the comic.
        #
        # If Shift is pressed we should backtrack instead.
        manager.register("smart scroll down", ["space"], self._smart_scroll_down)
        manager.register("smart scroll up", ["<Shift>space"], self._smart_scroll_up)

        # OSD Display
        manager.register("osd panel", ["Tab"], self._window.show_info_panel)
Beispiel #14
0
    def register_key_events(self):
        """ Registers keyboard events and their default binings, and hooks
        them up with their respective callback functions. """

        manager = keybindings.keybinding_manager()

        # Navigation keys that work in addition to the accelerators in ui.py
        manager.register('previous page',
            ['KP_Page_Up', 'BackSpace', '<Mod1>Left'],
            self._window.previous_page)
        manager.register('next page',
            ['KP_Page_Down', '<Mod1>Right'],
            self._window.next_page)

        # Numpad (without numlock) aligns the image depending on the key.
        manager.register('scroll left bottom',
            ['KP_1'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'left', 'vert':'bottom'})
        manager.register('scroll middle bottom',
            ['KP_2'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'middle', 'vert':'bottom'})
        manager.register('scroll right bottom',
            ['KP_3'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'right', 'vert':'bottom'})

        manager.register('scroll left middle',
            ['KP_4'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'left', 'vert':'middle'})
        manager.register('scroll middle',
            ['KP_5'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'middle', 'vert':'middle'})
        manager.register('scroll right middle',
            ['KP_6'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'right', 'vert':'middle'})

        manager.register('scroll left top',
            ['KP_7'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'left', 'vert':'top'})
        manager.register('scroll middle top',
            ['KP_8'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'middle', 'vert':'top'})
        manager.register('scroll right top',
            ['KP_9'],
            self._window.scroll_to_fixed,
            kwargs={'horiz':'right', 'vert':'top'})

        # Enter/exit fullscreen.
        manager.register('exit fullscreen',
            ['Escape'],
            self._window.actiongroup.get_action('fullscreen').set_active,
            args=(False,))
        manager.register('toggle fullscreen',
            ['F11'],
            self._window.actiongroup.get_action('fullscreen').activate)

        # Zooming commands for manual zoom mode
        manager.register('zoom in',
            ['plus', 'equal'],
            self._window.actiongroup.get_action('zoom_in').activate)
        manager.register('zoom out',
            ['minus'],
            self._window.actiongroup.get_action('zoom_out').activate)
        manager.register('zoom original',
            ['<Control>0', '<Control>KP_0'],
            self._window.actiongroup.get_action('zoom_original').activate)

        # Arrow keys scroll the image
        manager.register('scroll down',
            ['Down', 'KP_Down', 'j'],
            self._scroll_down)
        manager.register('scroll up',
            ['Up', 'KP_Up', 'k'],
            self._scroll_up)
        manager.register('scroll right',
            ['Right', 'KP_Right', 'l'],
            self._scroll_right)
        manager.register('scroll left',
            ['Left', 'KP_Left', 'h'],
            self._scroll_left)

        # Space key scrolls down a percentage of the window height or the
        # image height at a time. When at the bottom it flips to the next
        # page.
        #
        # It also has a "smart scrolling mode" in which we try to follow
        # the flow of the comic.
        #
        # If Shift is pressed we should backtrack instead.
        manager.register('smart scroll down',
            ['space'],
            self._smart_scroll_down)
        manager.register('smart scroll up',
            ['<Shift>space'],
            self._smart_scroll_up)

        # OSD Display
        manager.register('osd panel',
            ['Tab'],
            self._window.show_info_panel)