UI improvements

This commit is contained in:
BasioMeusPuga
2017-11-12 21:54:14 +05:30
parent 405ea3547c
commit e2ec7e680e
3 changed files with 180 additions and 44 deletions

View File

@@ -85,16 +85,28 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.viewModel = None self.viewModel = None
self.lib_ref = Library(self) self.lib_ref = Library(self)
# Create toolbars # Library toolbar
self.libraryToolBar = LibraryToolBar(self) self.libraryToolBar = LibraryToolBar(self)
self.libraryToolBar.addButton.triggered.connect(self.add_books) self.libraryToolBar.addButton.triggered.connect(self.add_books)
self.libraryToolBar.deleteButton.triggered.connect(self.delete_books) self.libraryToolBar.deleteButton.triggered.connect(self.delete_books)
self.libraryToolBar.filterEdit.textChanged.connect(self.only_update_listview) self.libraryToolBar.searchBar.textChanged.connect(self.only_update_listview)
self.libraryToolBar.sortingBox.activated.connect(self.only_update_listview) self.libraryToolBar.sortingBox.activated.connect(self.only_update_listview)
self.addToolBar(self.libraryToolBar) self.addToolBar(self.libraryToolBar)
# Book toolbar
self.bookToolBar = BookToolBar(self) self.bookToolBar = BookToolBar(self)
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen) self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
self.bookToolBar.fontBox.activated.connect(self.modify_font)
self.bookToolBar.fontSizeUp.triggered.connect(self.modify_font)
self.bookToolBar.fontSizeDown.triggered.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.colorBoxFG.clicked.connect(self.get_color)
self.bookToolBar.colorBoxBG.clicked.connect(self.get_color)
self.bookToolBar.tocBox.activated.connect(self.set_toc_position) self.bookToolBar.tocBox.activated.connect(self.set_toc_position)
self.addToolBar(self.bookToolBar) self.addToolBar(self.bookToolBar)
@@ -125,6 +137,17 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self) self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
self.exit_all.activated.connect(self.closeEvent) self.exit_all.activated.connect(self.closeEvent)
# Display profiles
# TODO
# Get display profiles from settings
# Current using a default
self.current_profile = {
'foreground': 'grey',
'background': 'black',
'padding': 100,
'font_size': 22,
'line_spacing': 1.5}
def resizeEvent(self, event=None): def resizeEvent(self, event=None):
if event: if event:
# This implies a vertical resize event only # This implies a vertical resize event only
@@ -163,6 +186,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# TODO # TODO
# Maybe expand this to traverse directories recursively # Maybe expand this to traverse directories recursively
self.statusMessage.setText('Adding books...') self.statusMessage.setText('Adding books...')
# TODO
# Generate list of available parsers
my_file = QtWidgets.QFileDialog.getOpenFileNames( my_file = QtWidgets.QFileDialog.getOpenFileNames(
self, 'Open file', self.last_open_path, self, 'Open file', self.last_open_path,
"eBooks (*.epub *.mobi *.aws *.txt *.pdf *.fb2 *.djvu *.cbz)") "eBooks (*.epub *.mobi *.aws *.txt *.pdf *.fb2 *.djvu *.cbz)")
@@ -258,8 +284,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
current_tab.contentView.setHtml(required_content) current_tab.contentView.setHtml(required_content)
def set_fullscreen(self): def set_fullscreen(self):
self.current_tab = self.tabWidget.currentIndex() current_tab = self.tabWidget.currentIndex()
self.current_contentView = self.tabWidget.widget(self.current_tab) current_tab_widget = self.tabWidget.widget(current_tab)
self.current_contentView = current_tab_widget.findChildren(QtWidgets.QTextBrowser)[0]
self.exit_shortcut = QtWidgets.QShortcut( self.exit_shortcut = QtWidgets.QShortcut(
QtGui.QKeySequence('Escape'), self.current_contentView) QtGui.QKeySequence('Escape'), self.current_contentView)
@@ -293,7 +320,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
tab_ref = Tab(contents, self.tabWidget) tab_ref = Tab(contents, self.tabWidget)
self.tabWidget.setCurrentWidget(tab_ref) self.tabWidget.setCurrentWidget(tab_ref)
# print(tab_ref.book_metadata) # Metadata upon tab creation self.format_contentView()
def close_tab(self, tab_index): def close_tab(self, tab_index):
temp_dir = self.tabWidget.widget(tab_index).metadata['temp_dir'] temp_dir = self.tabWidget.widget(tab_index).metadata['temp_dir']
@@ -301,6 +328,68 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
shutil.rmtree(temp_dir) shutil.rmtree(temp_dir)
self.tabWidget.removeTab(tab_index) self.tabWidget.removeTab(tab_index)
def get_color(self):
signal_sender = self.sender().objectName()
colorDialog = QtWidgets.QColorDialog()
new_color = colorDialog.getColor()
if not new_color:
return
color_name = new_color.name()
if signal_sender == 'fgColor':
self.bookToolBar.colorBoxFG.setStyleSheet(
'background-color: %s' % color_name)
self.current_profile['foreground'] = color_name
elif signal_sender == 'bgColor':
self.bookToolBar.colorBoxBG.setStyleSheet(
'background-color: %s' % color_name)
self.current_profile['background'] = color_name
self.format_contentView()
def modify_font(self):
signal_sender = self.sender().objectName()
if signal_sender == 'fontBox':
pass
if signal_sender == 'fontSizeUp':
self.current_profile['font_size'] += 1
if signal_sender == 'fontSizeDown':
if self.current_profile['font_size'] > 5:
self.current_profile['font_size'] -= 1
if signal_sender == 'lineSpacingUp':
self.current_profile['line_spacing'] += .5
if signal_sender == 'lineSpacingDown':
self.current_profile['line_spacing'] -= .5
if signal_sender == 'paddingUp':
self.current_profile['padding'] += 5
if signal_sender == 'paddingDown':
self.current_profile['padding'] -= 5
self.format_contentView()
def format_contentView(self):
# TODO
# Implement line spacing
# Implement font changing
foreground = self.current_profile['foreground']
background = self.current_profile['background']
padding = self.current_profile['padding']
font_size = self.current_profile['font_size']
current_tab = self.tabWidget.currentIndex()
current_tab_widget = self.tabWidget.widget(current_tab)
current_contentView = current_tab_widget.findChildren(QtWidgets.QTextBrowser)[0]
current_contentView.setStyleSheet(
"QTextEdit {{font-size: {0}px; padding-left: {1}; padding-right: {1}; color: {2}; background-color: {3}}}".format(
font_size, padding, foreground, background))
def closeEvent(self, event=None): def closeEvent(self, event=None):
# All tabs must be iterated upon here # All tabs must be iterated upon here
for i in range(1, self.tabWidget.count()): for i in range(1, self.tabWidget.count()):

View File

@@ -110,7 +110,7 @@ class Library:
self.proxy_model.setFilterRole(QtCore.Qt.UserRole + 4) self.proxy_model.setFilterRole(QtCore.Qt.UserRole + 4)
self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.proxy_model.setFilterWildcard( self.proxy_model.setFilterWildcard(
self.parent_window.libraryToolBar.filterEdit.text()) self.parent_window.libraryToolBar.searchBar.text())
self.parent_window.statusMessage.setText( self.parent_window.statusMessage.setText(
str(self.proxy_model.rowCount()) + ' books') str(self.proxy_model.rowCount()) + ' books')

View File

@@ -11,11 +11,8 @@ class BookToolBar(QtWidgets.QToolBar):
spacer.setSizePolicy( spacer.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
# Size policy
# TODO
# Prevent resizing
sizePolicy = QtWidgets.QSizePolicy( sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.setMovable(False) self.setMovable(False)
self.setIconSize(QtCore.QSize(22, 22)) self.setIconSize(QtCore.QSize(22, 22))
@@ -43,40 +40,61 @@ class BookToolBar(QtWidgets.QToolBar):
self.fontSizeUp = QtWidgets.QAction( self.fontSizeUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-font-size-more'), QtGui.QIcon.fromTheme('format-font-size-more'),
'Increase font size', self) 'Increase font size', self)
self.fontSizeUp.setObjectName('fontSizeUp')
self.fontSizeDown = QtWidgets.QAction( self.fontSizeDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-font-size-less'), QtGui.QIcon.fromTheme('format-font-size-less'),
'Decrease font size', self) 'Decrease font size', self)
self.fontSizeDown.setObjectName('fontSizeDown')
self.marginsUp = QtWidgets.QAction( self.paddingUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-justify-fill'), QtGui.QIcon.fromTheme('format-justify-fill'),
'Increase margins', self) 'Increase padding', self)
self.marginsDown = QtWidgets.QAction( self.paddingUp.setObjectName('paddingUp')
self.paddingDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-indent-less'), QtGui.QIcon.fromTheme('format-indent-less'),
'Decrease margins', self) 'Decrease padding', self)
self.paddingDown.setObjectName('paddingDown')
self.lineSpacingUp = QtWidgets.QAction( self.lineSpacingUp = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-line-spacing-triple'), QtGui.QIcon.fromTheme('format-line-spacing-triple'),
'Increase line spacing', self) 'Increase line spacing', self)
self.lineSpacingUp.setObjectName('lineSpacingUp')
self.lineSpacingDown = QtWidgets.QAction( self.lineSpacingDown = QtWidgets.QAction(
QtGui.QIcon.fromTheme('format-line-spacing-double'), QtGui.QIcon.fromTheme('format-line-spacing-double'),
'Decrease line spacing', self) 'Decrease line spacing', self)
self.lineSpacingDown.setObjectName('lineSpacingDown')
self.fontBox = QtWidgets.QFontComboBox() self.fontBox = QtWidgets.QFontComboBox()
self.colorBoxFG = QtWidgets.QPushButton() self.fontBox.setObjectName('fontBox')
self.colorBoxBG = QtWidgets.QPushButton()
self.colorBoxFG = FixedPushButton(self)
self.colorBoxFG.setObjectName('fgColor')
self.colorBoxFG.setToolTip('Set foreground color')
self.colorBoxBG = FixedPushButton(self)
self.colorBoxBG.setToolTip('Set background color')
self.colorBoxBG.setObjectName('bgColor')
# TODO
# Get color profiles from settings
# Generate default profiles
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
self.profileBox = QtWidgets.QComboBox(self)
self.profileBox.addItems(profiles)
self.profileAction = self.addWidget(self.profileBox)
self.fontSeparator1 = self.addSeparator()
self.fontBoxAction = self.addWidget(self.fontBox) self.fontBoxAction = self.addWidget(self.fontBox)
self.addAction(self.fontSizeUp) self.addAction(self.fontSizeUp)
self.addAction(self.fontSizeDown) self.addAction(self.fontSizeDown)
self.fontSeparator1 = self.addSeparator() self.fontSeparator2 = self.addSeparator()
self.fgColorAction = self.addWidget(self.colorBoxFG) self.fgColorAction = self.addWidget(self.colorBoxFG)
self.bgColorAction = self.addWidget(self.colorBoxBG) self.bgColorAction = self.addWidget(self.colorBoxBG)
self.fontSeparator2 = self.addSeparator() self.fontSeparator3 = self.addSeparator()
self.addAction(self.lineSpacingUp) self.addAction(self.lineSpacingUp)
self.addAction(self.lineSpacingDown) self.addAction(self.lineSpacingDown)
self.fontSeparator3 = self.addSeparator() self.fontSeparator4 = self.addSeparator()
self.addAction(self.marginsUp) self.addAction(self.paddingUp)
self.addAction(self.marginsDown) self.addAction(self.paddingDown)
self.fontBoxAction.setVisible(False) self.fontBoxAction.setVisible(False)
self.fontSizeUp.setVisible(False) self.fontSizeUp.setVisible(False)
@@ -85,24 +103,24 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(False) self.bgColorAction.setVisible(False)
self.lineSpacingUp.setVisible(False) self.lineSpacingUp.setVisible(False)
self.lineSpacingDown.setVisible(False) self.lineSpacingDown.setVisible(False)
self.marginsUp.setVisible(False) self.paddingUp.setVisible(False)
self.marginsDown.setVisible(False) self.paddingDown.setVisible(False)
self.profileAction.setVisible(False)
self.fontSeparator1.setVisible(False) self.fontSeparator1.setVisible(False)
self.fontSeparator2.setVisible(False) self.fontSeparator2.setVisible(False)
self.fontSeparator3.setVisible(False) self.fontSeparator3.setVisible(False)
self.fontSeparator4.setVisible(False)
self.searchBar = QtWidgets.QLineEdit() self.searchBar = FixedLineEdit(self)
self.searchBar.setPlaceholderText('Search...') self.searchBar.setPlaceholderText(
'Search...')
self.searchBar.setSizePolicy(sizePolicy) self.searchBar.setSizePolicy(sizePolicy)
self.searchBar.setContentsMargins(10, 0, 0, 0) self.searchBar.setContentsMargins(10, 0, 0, 0)
self.searchBar.setMinimumWidth(150)
self.searchBar.setObjectName('searchBar') self.searchBar.setObjectName('searchBar')
# Sorter # Sorter
self.tocBox = QtWidgets.QComboBox() self.tocBox = FixedComboBox(self)
self.tocBox.setObjectName('sortingBox') self.tocBox.setObjectName('sortingBox')
self.tocBox.setSizePolicy(sizePolicy)
self.tocBox.setMinimumContentsLength(10)
self.tocBox.setToolTip('Table of Contents') self.tocBox.setToolTip('Table of Contents')
# All of these will be put after the spacer # All of these will be put after the spacer
@@ -130,11 +148,14 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(True) self.bgColorAction.setVisible(True)
self.lineSpacingUp.setVisible(True) self.lineSpacingUp.setVisible(True)
self.lineSpacingDown.setVisible(True) self.lineSpacingDown.setVisible(True)
self.marginsUp.setVisible(True) self.paddingUp.setVisible(True)
self.marginsDown.setVisible(True) self.paddingDown.setVisible(True)
self.profileAction.setVisible(True)
self.fontSeparator1.setVisible(True) self.fontSeparator1.setVisible(True)
self.fontSeparator2.setVisible(True) self.fontSeparator2.setVisible(True)
self.fontSeparator3.setVisible(True) self.fontSeparator3.setVisible(True)
self.fontSeparator3.setVisible(True)
self.fontSeparator4.setVisible(False)
self.tocBoxAction.setVisible(False) self.tocBoxAction.setVisible(False)
self.searchBarAction.setVisible(False) self.searchBarAction.setVisible(False)
@@ -150,11 +171,13 @@ class BookToolBar(QtWidgets.QToolBar):
self.bgColorAction.setVisible(False) self.bgColorAction.setVisible(False)
self.lineSpacingUp.setVisible(False) self.lineSpacingUp.setVisible(False)
self.lineSpacingDown.setVisible(False) self.lineSpacingDown.setVisible(False)
self.marginsUp.setVisible(False) self.paddingUp.setVisible(False)
self.marginsDown.setVisible(False) self.paddingDown.setVisible(False)
self.profileAction.setVisible(False)
self.fontSeparator1.setVisible(False) self.fontSeparator1.setVisible(False)
self.fontSeparator2.setVisible(False) self.fontSeparator2.setVisible(False)
self.fontSeparator3.setVisible(False) self.fontSeparator3.setVisible(False)
self.fontSeparator4.setVisible(False)
self.tocBoxAction.setVisible(True) self.tocBoxAction.setVisible(True)
self.searchBarAction.setVisible(True) self.searchBarAction.setVisible(True)
@@ -189,30 +212,54 @@ class LibraryToolBar(QtWidgets.QToolBar):
# Filter # Filter
sizePolicy = QtWidgets.QSizePolicy( sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.filterEdit = QtWidgets.QLineEdit() # self.searchBar = QtWidgets.QLineEdit()
self.filterEdit.setPlaceholderText( self.searchBar = FixedLineEdit(self)
self.searchBar.setPlaceholderText(
'Search for Title, Author, Tags...') 'Search for Title, Author, Tags...')
self.filterEdit.setSizePolicy(sizePolicy) self.searchBar.setSizePolicy(sizePolicy)
self.filterEdit.setContentsMargins(10, 0, 0, 0) self.searchBar.setContentsMargins(10, 0, 0, 0)
self.filterEdit.setMinimumWidth(150) self.searchBar.setObjectName('searchBar')
self.filterEdit.setObjectName('filterEdit')
# Sorter # Sorter
sorting_choices = ['Title', 'Author', 'Year'] sorting_choices = ['Title', 'Author', 'Year']
self.sortingBox = QtWidgets.QComboBox() self.sortingBox = FixedComboBox(self)
self.sortingBox.addItems(sorting_choices) self.sortingBox.addItems(sorting_choices)
self.sortingBox.setObjectName('sortingBox') self.sortingBox.setObjectName('sortingBox')
self.sortingBox.setSizePolicy(sizePolicy) self.sortingBox.setSizePolicy(sizePolicy)
# self.sortingBox.setContentsMargins(30, 0, 0, 0)
self.sortingBox.setMinimumContentsLength(10) self.sortingBox.setMinimumContentsLength(10)
self.sortingBox.setToolTip('Sort by') self.sortingBox.setToolTip('Sort by')
# Add widgets # Add widgets
self.addWidget(spacer) self.addWidget(spacer)
self.addWidget(self.sortingBox) self.addWidget(self.sortingBox)
self.addWidget(self.filterEdit) self.addWidget(self.searchBar)
# Sublassing these widgets out prevents them from resizing
class FixedComboBox(QtWidgets.QComboBox):
def __init__(self, parent=None):
super(FixedComboBox, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(400, 22)
class FixedLineEdit(QtWidgets.QLineEdit):
def __init__(self, parent=None):
super(FixedLineEdit, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(400, 22)
class FixedPushButton(QtWidgets.QPushButton):
def __init__(self, parent=None):
super(FixedPushButton, self).__init__(parent)
def sizeHint(self):
return QtCore.QSize(36, 30)
class Tab(QtWidgets.QWidget): class Tab(QtWidgets.QWidget):
@@ -227,7 +274,7 @@ class Tab(QtWidgets.QWidget):
super(Tab, self).__init__(parent) super(Tab, self).__init__(parent)
self.parent = parent self.parent = parent
self.metadata = metadata # Save progress data into this dictionary self.metadata = metadata # Save progress data into this dictionary
self.setStyleSheet("background-color: black") # self.setStyleSheet("background-color: black")
title = self.metadata['title'] title = self.metadata['title']
path = self.metadata['path'] path = self.metadata['path']