Exemplo n.º 1
0
    def closeEvent(self, event=None):
        if event:
            event.ignore()

        self.hide()
        self.metadataDialog.hide()
        self.settingsDialog.hide()
        self.definitionDialog.hide()
        self.temp_dir.remove()

        self.settings['last_open_books'] = []
        if self.tabWidget.count() > 1:

            # All tabs must be iterated upon here
            all_metadata = []
            for i in range(1, self.tabWidget.count()):
                tab_metadata = self.tabWidget.widget(i).metadata
                all_metadata.append(tab_metadata)

                if self.settings['remember_files']:
                    self.settings['last_open_books'].append(tab_metadata['path'])

            Settings(self).save_settings()
            self.thread = BackGroundTabUpdate(
                self.database_path, all_metadata)
            self.thread.finished.connect(self.database_care)
            self.thread.start()

        else:
            Settings(self).save_settings()
            self.database_care()
Exemplo n.º 2
0
 def no_more_settings(self):
     self.main_window.libraryToolBar.settingsButton.setChecked(False)
     self.gather_annotations()
     Settings(self.main_window).save_settings()
     Settings(self.main_window).read_settings()
     self.main_window.settings['last_open_tab'] = None  # Needed to allow focus change
                                                        # to newly opened book
     self.resizeEvent()
Exemplo n.º 3
0
 def reset_profile(self):
     current_profile_index = self.bookToolBar.profileBox.currentIndex()
     current_profile_default = Settings(
         self).default_profiles[current_profile_index]
     self.bookToolBar.profileBox.setItemData(current_profile_index,
                                             current_profile_default,
                                             QtCore.Qt.UserRole)
     self.format_contentView()
Exemplo n.º 4
0
    def __init__(self):
        super(MainUI, self).__init__()
        self.setupUi(self)

        # Set window icon
        self.setWindowIcon(QtGui.QIcon(':/images/Lector.png'))

        # Central Widget - Make borders disappear
        self.centralWidget().layout().setContentsMargins(0, 0, 0, 0)
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)

        # Initialize translation function
        self._translate = QtCore.QCoreApplication.translate

        # Create library widgets
        self.listView = DragDropListView(self, self.listPage)
        self.gridLayout_4.addWidget(self.listView, 0, 0, 1, 1)

        self.tableView = DragDropTableView(self, self.tablePage)
        self.gridLayout_3.addWidget(self.tableView, 0, 0, 1, 1)

        # Empty variables that will be infested soon
        self.settings = {}
        self.thread = None  # Background Thread
        self.current_contentView = None  # For fullscreening purposes
        self.display_profiles = None
        self.current_profile_index = None
        self.comic_profile = {}
        self.database_path = None
        self.active_library_filters = []
        self.active_bookmark_docks = []

        # Initialize application
        Settings(self).read_settings(
        )  # This should populate all variables that need
        # to be remembered across sessions

        # Initialize icon factory
        self.QImageFactory = QImageFactory(self)

        # Initialize toolbars
        self.libraryToolBar = LibraryToolBar(self)
        self.bookToolBar = BookToolBar(self)

        # Widget declarations
        self.libraryFilterMenu = QtWidgets.QMenu()
        self.statusMessage = QtWidgets.QLabel()

        # Reference variables
        self.alignment_dict = {
            'left': self.bookToolBar.alignLeft,
            'right': self.bookToolBar.alignRight,
            'center': self.bookToolBar.alignCenter,
            'justify': self.bookToolBar.alignJustify
        }

        # Create the database in case it doesn't exist
        database.DatabaseInit(self.database_path)

        # Initialize settings dialog
        self.settingsDialog = SettingsUI(self)

        # Initialize metadata dialog
        self.metadataDialog = MetadataUI(self)

        # Initialize definition view dialog
        self.definitionDialog = DefinitionsUI(self)

        # Make the statusbar invisible by default
        self.statusBar.setVisible(False)

        # Statusbar widgets
        self.statusMessage.setObjectName('statusMessage')
        self.statusBar.addPermanentWidget(self.statusMessage)
        self.sorterProgress = QtWidgets.QProgressBar()
        self.sorterProgress.setMaximumWidth(300)
        self.sorterProgress.setObjectName('sorterProgress')
        sorter.progressbar = self.sorterProgress  # This is so that updates can be
        # connected to setValue
        self.statusBar.addWidget(self.sorterProgress)
        self.sorterProgress.setVisible(False)

        # Application wide temporary directory
        self.temp_dir = QtCore.QTemporaryDir()

        # Init the Library
        self.lib_ref = Library(self)

        # Initialize Cover loading functions
        # Must be after the Library init
        self.cover_functions = CoverLoadingAndCulling(self)

        # Init the culling timer
        self.culling_timer = QtCore.QTimer()
        self.culling_timer.setSingleShot(True)
        self.culling_timer.timeout.connect(self.cover_functions.cull_covers)

        # Initialize profile modification functions
        self.profile_functions = ViewProfileModification(self)

        # Toolbar display
        # Maybe make this a persistent option
        self.settings['show_bars'] = True

        # Library toolbar
        self.libraryToolBar.addButton.triggered.connect(self.add_books)
        self.libraryToolBar.deleteButton.triggered.connect(self.delete_books)
        self.libraryToolBar.coverViewButton.triggered.connect(
            self.switch_library_view)
        self.libraryToolBar.tableViewButton.triggered.connect(
            self.switch_library_view)
        self.libraryToolBar.reloadLibraryButton.triggered.connect(
            self.settingsDialog.start_library_scan)
        self.libraryToolBar.colorButton.triggered.connect(self.get_color)
        self.libraryToolBar.settingsButton.triggered.connect(
            self.show_settings)
        self.libraryToolBar.searchBar.textChanged.connect(
            self.lib_ref.update_proxymodels)
        self.libraryToolBar.sortingBox.activated.connect(
            self.lib_ref.update_proxymodels)
        self.libraryToolBar.libraryFilterButton.setPopupMode(
            QtWidgets.QToolButton.InstantPopup)
        self.libraryToolBar.searchBar.textChanged.connect(
            self.statusbar_visibility)
        self.addToolBar(self.libraryToolBar)

        if self.settings['current_view'] == 0:
            self.libraryToolBar.coverViewButton.trigger()
        else:
            self.libraryToolBar.tableViewButton.trigger()

        # Book toolbar
        self.bookToolBar.annotationButton.triggered.connect(
            self.toggle_dock_widgets)
        self.bookToolBar.addBookmarkButton.triggered.connect(self.add_bookmark)
        self.bookToolBar.bookmarkButton.triggered.connect(
            self.toggle_dock_widgets)
        self.bookToolBar.distractionFreeButton.triggered.connect(
            self.toggle_distraction_free)
        self.bookToolBar.fullscreenButton.triggered.connect(
            self.set_fullscreen)

        self.bookToolBar.singlePageButton.triggered.connect(
            self.change_page_view)
        self.bookToolBar.doublePageButton.triggered.connect(
            self.change_page_view)
        if self.settings['page_view_button'] == 'singlePageButton':
            self.bookToolBar.singlePageButton.setChecked(True)
        else:
            self.bookToolBar.doublePageButton.setChecked(True)

        for count, i in enumerate(self.display_profiles):
            self.bookToolBar.profileBox.setItemData(count, i,
                                                    QtCore.Qt.UserRole)
        self.bookToolBar.profileBox.currentIndexChanged.connect(
            self.profile_functions.format_contentView)
        self.bookToolBar.profileBox.setCurrentIndex(self.current_profile_index)
        self.bookToolBar.searchBar.textChanged.connect(self.search_book)

        self.bookToolBar.fontBox.currentFontChanged.connect(self.modify_font)
        self.bookToolBar.fontSizeBox.currentIndexChanged.connect(
            self.modify_font)
        self.bookToolBar.lineSpacingUp.triggered.connect(self.modify_font)
        self.bookToolBar.lineSpacingDown.triggered.connect(self.modify_font)
        self.bookToolBar.paddingUp.triggered.connect(self.modify_font)
        self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
        self.bookToolBar.resetProfile.triggered.connect(
            self.profile_functions.reset_profile)

        profile_index = self.bookToolBar.profileBox.currentIndex()
        current_profile = self.bookToolBar.profileBox.itemData(
            profile_index, QtCore.Qt.UserRole)
        for i in self.alignment_dict.items():
            i[1].triggered.connect(self.modify_font)
        self.alignment_dict[current_profile['text_alignment']].setChecked(True)

        self.bookToolBar.zoomIn.triggered.connect(self.modify_comic_view)
        self.bookToolBar.zoomOut.triggered.connect(self.modify_comic_view)
        self.bookToolBar.fitWidth.triggered.connect(self.modify_comic_view)
        self.bookToolBar.bestFit.triggered.connect(self.modify_comic_view)
        self.bookToolBar.originalSize.triggered.connect(self.modify_comic_view)
        self.bookToolBar.comicBGColor.clicked.connect(self.get_color)

        self.bookToolBar.colorBoxFG.clicked.connect(self.get_color)
        self.bookToolBar.colorBoxBG.clicked.connect(self.get_color)
        self.bookToolBar.tocBox.currentIndexChanged.connect(
            self.set_toc_position)
        self.addToolBar(self.bookToolBar)

        # Get the stylesheet of the default QLineEdit
        self.lineEditStyleSheet = self.bookToolBar.searchBar.styleSheet()

        # Make the correct toolbar visible
        self.current_tab = self.tabWidget.currentIndex()
        self.tab_switch()
        self.tabWidget.currentChanged.connect(self.tab_switch)

        # Tab closing
        self.tabWidget.setTabsClosable(True)

        # Get list of available parsers
        self.available_parsers = '*.' + ' *.'.join(sorter.available_parsers)
        print('Available parsers: ' + self.available_parsers)

        # The Library tab gets no button
        self.tabWidget.tabBar().setTabButton(0, QtWidgets.QTabBar.RightSide,
                                             None)
        self.tabWidget.tabCloseRequested.connect(self.tab_close)
        self.tabWidget.setTabBarAutoHide(True)

        # Init display models
        self.lib_ref.generate_model('build')
        self.lib_ref.generate_proxymodels()
        self.lib_ref.generate_library_tags()
        self.set_library_filter()
        self.start_culling_timer()

        # ListView
        self.listView.setGridSize(QtCore.QSize(175, 240))
        self.listView.setMouseTracking(True)
        self.listView.verticalScrollBar().setSingleStep(9)
        self.listView.doubleClicked.connect(self.library_doubleclick)
        self.listView.setItemDelegate(
            LibraryDelegate(self.temp_dir.path(), self))
        self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.listView.customContextMenuRequested.connect(
            self.generate_library_context_menu)
        self.listView.verticalScrollBar().valueChanged.connect(
            self.start_culling_timer)
        self.listView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.listView.setAcceptDrops(True)

        self.listView.setStyleSheet(
            "QListView {{background-color: {0}}}".format(
                self.settings['listview_background'].name()))

        # TODO
        # Maybe use this for readjusting the border of the focus rectangle
        # in the listView. Maybe this is a job for QML?

        # self.listView.setStyleSheet(
        #     "QListView::item:selected { border-color:blue; border-style:outset;"
        #     "border-width:2px; color:black; }")

        # TableView
        self.tableView.doubleClicked.connect(self.library_doubleclick)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Interactive)
        self.tableView.horizontalHeader().setSortIndicator(
            2, QtCore.Qt.AscendingOrder)
        self.tableView.setColumnHidden(0, True)
        self.tableView.horizontalHeader().setHighlightSections(False)
        if self.settings['main_window_headers']:
            for count, i in enumerate(self.settings['main_window_headers']):
                self.tableView.horizontalHeader().resizeSection(count, int(i))
        self.tableView.horizontalHeader().resizeSection(5, 30)
        self.tableView.horizontalHeader().setStretchLastSection(False)
        self.tableView.horizontalHeader().sectionClicked.connect(
            self.lib_ref.tableProxyModel.sort_table_columns)
        self.tableView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableView.customContextMenuRequested.connect(
            self.generate_library_context_menu)

        # Keyboard shortcuts
        self.ksDistractionFree = QtWidgets.QShortcut(
            QtGui.QKeySequence('Ctrl+D'), self)
        self.ksDistractionFree.setContext(QtCore.Qt.ApplicationShortcut)
        self.ksDistractionFree.activated.connect(self.toggle_distraction_free)

        self.ksOpenFile = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+O'),
                                              self)
        self.ksOpenFile.setContext(QtCore.Qt.ApplicationShortcut)
        self.ksOpenFile.activated.connect(self.add_books)

        self.ksExitAll = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'),
                                             self)
        self.ksExitAll.setContext(QtCore.Qt.ApplicationShortcut)
        self.ksExitAll.activated.connect(self.closeEvent)

        self.ksCloseTab = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+W'),
                                              self)
        self.ksCloseTab.setContext(QtCore.Qt.ApplicationShortcut)
        self.ksCloseTab.activated.connect(self.tab_close)

        self.ksDeletePressed = QtWidgets.QShortcut(
            QtGui.QKeySequence('Delete'), self)
        self.ksDeletePressed.setContext(QtCore.Qt.ApplicationShortcut)
        self.ksDeletePressed.activated.connect(self.delete_pressed)

        self.listView.setFocus()
        self.open_books_at_startup()

        # Scan the library @ startup
        if self.settings['scan_library']:
            self.settingsDialog.start_library_scan()
Exemplo n.º 5
0
 def no_more_settings(self):
     self.main_window.libraryToolBar.settingsButton.setChecked(False)
     self.gather_annotations()
     Settings(self.main_window).save_settings()
     self.resizeEvent()