Пример #1
0
class ShowQuickviewAction(InterfaceAction):

    name = 'Show Quickview'
    action_spec = (_('Show Quickview'), 'quickview.png', None, _('Q'))
    dont_add_to = frozenset(['context-menu-device'])
    action_type = 'current'

    current_instance = None

    def genesis(self):
        self.focus_action = QAction(self.gui)
        self.gui.addAction(self.focus_action)
        self.gui.keyboard.register_shortcut(
            'Focus To Quickview',
            _('Focus to Quickview'),
            description=_('Move the focus to the Quickview panel/window'),
            default_keys=('Shift+Q', ),
            action=self.focus_action,
            group=self.action_spec[0])
        self.focus_action.triggered.connect(self.focus_quickview)

        self.search_action = QAction(self.gui)
        self.gui.addAction(self.search_action)
        self.gui.keyboard.register_shortcut(
            'Search from Quickview',
            _('Search from Quickview'),
            description=_('Search for the currently selected Quickview item'),
            default_keys=('Shift+S', ),
            action=self.search_action,
            group=self.action_spec[0])
        self.search_action.triggered.connect(self.search_quickview)
        self.search_action.changed.connect(self.set_search_shortcut)
        self.menuless_qaction.changed.connect(self.set_search_shortcut)
        self.qv_button = QuickviewButton(self.gui, self)

    def _hide_quickview(self):
        '''
        This is called only from the QV button toggle
        '''
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance._reject()
            self.current_instance = None

    def _show_quickview(self, *args):
        '''
        This is called only from the QV button toggle
        '''
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance._reject()
            self.current_instance = None
        if self.gui.current_view() is not self.gui.library_view:
            error_dialog(
                self.gui, _('No quickview available'),
                _('Quickview is not available for books '
                  'on the device.')).exec_()
            return
        self.qv_button.set_state_to_hide()
        index = self.gui.library_view.currentIndex()
        self.current_instance = Quickview(self.gui, index)
        self.current_instance.reopen_after_dock_change.connect(
            self.open_quickview)
        self.set_search_shortcut()
        self.current_instance.show()
        self.current_instance.quickview_closed.connect(
            self.qv_button.set_state_to_show)

    def set_search_shortcut(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.set_shortcuts(
                self.search_action.shortcut().toString(),
                self.menuless_qaction.shortcut().toString())

    def open_quickview(self):
        '''
        QV moved from/to dock. Close and reopen the pane/window.
        Also called when QV is closed and the user asks to move the focus
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
        self.current_instance = None
        self.qaction.triggered.emit()

    def refill_quickview(self):
        '''
        Called when the data or the columns shown in the QV pane might have changed.
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.refill()

    def change_quickview_column(self, idx):
        '''
        Called from the column header context menu to change the QV query column
        '''
        self.focus_quickview()
        self.current_instance.slave(idx)

    def library_changed(self, db):
        '''
        If QV is open, close it then reopen it so the columns are correct
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
            self.qaction.triggered.emit()

    def focus_quickview(self):
        '''
        Used to move the focus to the QV books table. Open QV if needed
        '''
        if not self.current_instance or self.current_instance.is_closed:
            self.open_quickview()
        else:
            self.current_instance.set_focus()

    def search_quickview(self):
        if not self.current_instance or self.current_instance.is_closed:
            return
        self.current_instance.do_search()
Пример #2
0
class ShowQuickviewAction(InterfaceAction):

    name = 'Show Quickview'
    action_spec = (_('Show Quickview'), 'search.png', None, _('Q'))
    dont_add_to = frozenset(['context-menu-device'])
    action_type = 'current'

    current_instance = None

    def genesis(self):
        self.qaction.triggered.connect(self.show_quickview)

        self.focus_action = QAction(self.gui)
        self.gui.addAction(self.focus_action)
        self.gui.keyboard.register_shortcut(
            'Focus To Quickview',
            _('Focus To Quickview'),
            description=_('Move the focus to the Quickview pane/window'),
            default_keys=('Shift+Q', ),
            action=self.focus_action,
            group=self.action_spec[0])
        self.focus_action.triggered.connect(self.focus_quickview)

        self.search_action = QAction(self.gui)
        self.gui.addAction(self.search_action)
        self.gui.keyboard.register_shortcut(
            'Search from Quickview',
            _('Search from Quickview'),
            description=_('Search for the currently selected Quickview item'),
            default_keys=('Shift+S', ),
            action=self.search_action,
            group=self.action_spec[0])
        self.search_action.triggered.connect(self.search_quickview)
        self.search_action.changed.connect(self.set_search_shortcut)
        self.menuless_qaction.changed.connect(self.set_search_shortcut)

    def show_quickview(self, *args):
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance.reject()
                self.current_instance = None
                return
            self.current_instance = None
        if self.gui.current_view() is not self.gui.library_view:
            error_dialog(
                self.gui, _('No quickview available'),
                _('Quickview is not available for books '
                  'on the device.')).exec_()
            return
        index = self.gui.library_view.currentIndex()
        if index.isValid():
            self.current_instance = Quickview(self.gui, index)
            self.current_instance.reopen_quickview.connect(
                self.reopen_quickview)
            self.set_search_shortcut()
            self.current_instance.show()

    def set_search_shortcut(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.set_shortcuts(
                self.search_action.shortcut().toString(),
                self.menuless_qaction.shortcut().toString())

    def reopen_quickview(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
        self.current_instance = None
        self.show_quickview()

    def change_quickview_column(self, idx):
        self.show_quickview()
        if self.current_instance:
            if self.current_instance.is_closed:
                return
            self.current_instance.change_quickview_column.emit(idx)

    def library_changed(self, db):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()

    def focus_quickview(self):
        if not (self.current_instance and not self.current_instance.is_closed):
            self.show_quickview()
        self.current_instance.set_focus()

    def search_quickview(self):
        if not self.current_instance or self.current_instance.is_closed:
            return
        self.current_instance.do_search()
Пример #3
0
class ShowQuickviewAction(InterfaceAction):

    name = 'Show Quickview'
    action_spec = (_('Show Quickview'), 'search.png', None, _('Q'))
    dont_add_to = frozenset(['context-menu-device'])
    action_type = 'current'

    current_instance = None

    def genesis(self):
        self.qaction.triggered.connect(self.show_quickview)

        self.focus_action = QAction(self.gui)
        self.gui.addAction(self.focus_action)
        self.gui.keyboard.register_shortcut('Focus To Quickview', _('Focus to Quickview'),
                     description=_('Move the focus to the Quickview panel/window'),
                     default_keys=('Shift+Q',), action=self.focus_action,
                     group=self.action_spec[0])
        self.focus_action.triggered.connect(self.focus_quickview)

        self.search_action = QAction(self.gui)
        self.gui.addAction(self.search_action)
        self.gui.keyboard.register_shortcut('Search from Quickview', _('Search from Quickview'),
                     description=_('Search for the currently selected Quickview item'),
                     default_keys=('Shift+S',), action=self.search_action,
                     group=self.action_spec[0])
        self.search_action.triggered.connect(self.search_quickview)
        self.search_action.changed.connect(self.set_search_shortcut)
        self.menuless_qaction.changed.connect(self.set_search_shortcut)

    def show_quickview(self, *args):
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance.reject()
                self.current_instance = None
                return
            self.current_instance = None
        if self.gui.current_view() is not self.gui.library_view:
            error_dialog(self.gui, _('No quickview available'),
                _('Quickview is not available for books '
                  'on the device.')).exec_()
            return
        index = self.gui.library_view.currentIndex()
        if index.isValid():
            self.current_instance = Quickview(self.gui, index)
            self.current_instance.reopen_quickview.connect(self.reopen_quickview)
            self.set_search_shortcut()
            self.current_instance.show()

    def set_search_shortcut(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.set_shortcuts(self.search_action.shortcut().toString(),
                                                self.menuless_qaction.shortcut().toString())

    def reopen_quickview(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
        self.current_instance = None
        self.show_quickview()

    def change_quickview_column(self, idx):
        self.show_quickview()
        if self.current_instance:
            if self.current_instance.is_closed:
                return
            self.current_instance.change_quickview_column.emit(idx)

    def library_changed(self, db):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()

    def focus_quickview(self):
        if not (self.current_instance and not self.current_instance.is_closed):
            self.show_quickview()
        self.current_instance.set_focus()

    def search_quickview(self):
        if not self.current_instance or self.current_instance.is_closed:
            return
        self.current_instance.do_search()
Пример #4
0
class ShowQuickviewAction(InterfaceAction):

    name = 'Quickview'
    action_spec = (_('Quickview'), 'quickview.png', None, None)
    dont_add_to = frozenset(['context-menu-device'])
    action_type = 'current'

    current_instance = None

    def genesis(self):
        self.gui.keyboard.register_shortcut('Toggle Quickview', _('Toggle Quickview'),
                     description=_('Open/close the Quickview panel/window'),
                     default_keys=('Q',), action=self.qaction,
                     group=self.action_spec[0])
        self.focus_action = QAction(self.gui)
        self.gui.addAction(self.focus_action)
        self.gui.keyboard.register_shortcut('Focus To Quickview', _('Focus to Quickview'),
                     description=_('Move the focus to the Quickview panel/window'),
                     default_keys=('Shift+Q',), action=self.focus_action,
                     group=self.action_spec[0])
        self.focus_action.triggered.connect(self.focus_quickview)

        self.focus_bl_action = QAction(self.gui)
        self.gui.addAction(self.focus_bl_action)
        self.gui.keyboard.register_shortcut('Focus from Quickview',
                     _('Focus from Quickview to the book list'),
                     description=_('Move the focus from Quickview to the book list'),
                     default_keys=('Shift+Alt+Q',), action=self.focus_bl_action,
                     group=self.action_spec[0])
        self.focus_bl_action.triggered.connect(self.focus_booklist)

        self.search_action = QAction(self.gui)
        self.gui.addAction(self.search_action)
        self.gui.keyboard.register_shortcut('Search from Quickview', _('Search from Quickview'),
                     description=_('Search for the currently selected Quickview item'),
                     default_keys=('Shift+S',), action=self.search_action,
                     group=self.action_spec[0])
        self.search_action.triggered.connect(self.search_quickview)
        self.search_action.changed.connect(self.set_search_shortcut)
        self.menuless_qaction.changed.connect(self.set_search_shortcut)
        self.qv_button = QuickviewButton(self.gui, self)

    def initialization_complete(self):
        set_quickview_action_plugin(self)

    def _hide_quickview(self):
        '''
        This is called only from the QV button toggle
        '''
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance._reject()
            self.current_instance = None

    def _show_quickview(self, *args):
        '''
        This is called only from the QV button toggle
        '''
        if self.current_instance:
            if not self.current_instance.is_closed:
                self.current_instance._reject()
            self.current_instance = None
        if self.gui.current_view() is not self.gui.library_view:
            error_dialog(self.gui, _('No quickview available'),
                _('Quickview is not available for books '
                  'on the device.')).exec_()
            return
        self.qv_button.set_state_to_hide()
        index = self.gui.library_view.currentIndex()
        self.current_instance = Quickview(self.gui, index)
        self.current_instance.reopen_after_dock_change.connect(self.open_quickview)
        self.set_search_shortcut()
        self.current_instance.show()
        self.current_instance.quickview_closed.connect(self.qv_button.set_state_to_show)

    def set_search_shortcut(self):
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.addAction(self.focus_bl_action)
            self.current_instance.set_shortcuts(self.search_action.shortcut().toString(),
                                                self.menuless_qaction.shortcut().toString())

    def open_quickview(self):
        '''
        QV moved from/to dock. Close and reopen the pane/window.
        Also called when QV is closed and the user asks to move the focus
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
        self.current_instance = None
        self.qaction.triggered.emit()

    def refill_quickview(self):
        '''
        Called when the data or the columns shown in the QV pane might have changed.
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.refill()

    def change_quickview_column(self, idx):
        '''
        Called from the column header context menu to change the QV query column
        '''
        self.focus_quickview()
        self.current_instance.slave(idx)

    def library_changed(self, db):
        '''
        If QV is open, close it then reopen it so the columns are correct
        '''
        if self.current_instance and not self.current_instance.is_closed:
            self.current_instance.reject()
            self.qaction.triggered.emit()

    def focus_quickview(self):
        '''
        Used to move the focus to the QV books table. Open QV if needed
        '''
        if not self.current_instance or self.current_instance.is_closed:
            self.open_quickview()
        else:
            self.current_instance.set_focus()

    def focus_booklist(self):
        self.gui.activateWindow()
        self.gui.library_view.setFocus()

    def search_quickview(self):
        if not self.current_instance or self.current_instance.is_closed:
            return
        self.current_instance.do_search()