From 66df68af692ecc31098bb855806fb38722664d13 Mon Sep 17 00:00:00 2001 From: tntscreed Date: Tue, 7 Mar 2023 18:13:36 +0100 Subject: [PATCH] Made the code a little nicer, added addition and deletion The bulk manager has been made partially functional. --- manuskript/mainWindow.py | 55 ++++++++++++++++++++++------ manuskript/ui/bulkInfoManager.py | 10 ++++- manuskript/ui/bulkInfoManager.ui | 22 ++++++++++- manuskript/ui/characterInfoDialog.ui | 3 ++ 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/manuskript/mainWindow.py b/manuskript/mainWindow.py index 7ac89f8..a4f7f8c 100644 --- a/manuskript/mainWindow.py +++ b/manuskript/mainWindow.py @@ -9,7 +9,7 @@ from PyQt5.QtCore import (pyqtSignal, QSignalMapper, QTimer, QSettings, Qt, QPoi QRegExp, QUrl, QSize, QModelIndex) from PyQt5.QtGui import QStandardItemModel, QIcon, QColor, QStandardItem from PyQt5.QtWidgets import QMainWindow, QHeaderView, qApp, QMenu, QActionGroup, QAction, QStyle, QListWidgetItem, \ - QLabel, QDockWidget, QWidget, QMessageBox, QLineEdit, QTextEdit, QTreeView, QDialog + QLabel, QDockWidget, QWidget, QMessageBox, QLineEdit, QTextEdit, QTreeView, QDialog, QTableView from manuskript import settings from manuskript.enums import Character, PlotStep, Plot, World, Outline @@ -182,8 +182,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): # self.loadProject(os.path.join(appPath(), "test_project.zip")) # Bulk Character Info Management - self.tabsData = self.saveCharacterTabs() # Used for restoring tabsData with loadCharacterTabs() methods. - self.isPersoBulkModeEnabled = False # Used in setPersoBulkMode() + self.tabsData = self.saveCharacterTabs() # Used for restoring tabsData with loadCharacterTabs() methods. + self.BulkManageUi = None self.bulkAffectedCharacters = [] def updateDockVisibility(self, restore=False): @@ -305,35 +305,60 @@ class MainWindow(QMainWindow, Ui_MainWindow): ############################################################################### def setPersoBulkMode(self, enabled: bool): - if enabled and not self.isPersoBulkModeEnabled: # Delete all tabs and create the manager one + if enabled and self.BulkManageUi is None: # Delete all tabs and create the manager one + # Create the widget bulkPersoInfoManager = QWidget() bulkPersoInfoManagerUi = Ui_BulkInfoManager() bulkPersoInfoManagerUi.setupUi(bulkPersoInfoManager) - bulkPersoInfoManagerUi.tableView.setModel(QStandardItemModel()) + + self.BulkManageUi = bulkPersoInfoManagerUi # for global use + + model = QStandardItemModel() + + # Set the column headers + model.setColumnCount(2) + model.setHorizontalHeaderLabels(["Name", "Value"]) + + # Set the width + bulkPersoInfoManagerUi.tableView.horizontalHeader().setStretchLastSection(True) + bulkPersoInfoManagerUi.tableView.horizontalHeader().setMinimumSectionSize(20) + bulkPersoInfoManagerUi.tableView.horizontalHeader().setMaximumSectionSize(500) + + bulkPersoInfoManagerUi.tableView.setModel(model) # Set the model of tableView + self.tabPersos.clear() self.tabPersos.addTab(bulkPersoInfoManager, "Bulk Info Manager") self.isPersoBulkModeEnabled = True - self.refreshAffectedCharacters() + self.refreshBulkAffectedCharacters() # Showing the character names on the label labelText = "" for characterName in self.bulkAffectedCharacters: - labelText += characterName + ", " + labelText += characterName + " ; " bulkPersoInfoManagerUi.lblCharactersDynamic.setText(labelText) # Making the connections self.setBulkInfoConnections(bulkPersoInfoManagerUi) - else: # Delete manager tab and restore the others - if not enabled and self.isPersoBulkModeEnabled: + elif enabled and self.BulkManageUi is not None: # If yet another character is selected, refresh the label + labelText = "" + self.refreshBulkAffectedCharacters() + for characterName in self.bulkAffectedCharacters: + labelText += characterName + " ; " + self.BulkManageUi.lblCharactersDynamic.setText(labelText) + + else: # Delete manager tab and restore the others + if self.BulkManageUi is not None: self.tabPersos.clear() self.loadCharacterTabs() - self.isPersoBulkModeEnabled = False + self.BulkManageUi = None self.bulkAffectedCharacters.clear() def setBulkInfoConnections(self, bulkUi): + # A lambda has to be used to pass in the argument bulkUi.btnPersoBulkAddInfo.clicked.connect(lambda: self.addBulkInfo(bulkUi)) + bulkUi.btnPersoBulkRmInfo.clicked.connect(lambda: self.removeBulkInfo(bulkUi)) def addBulkInfo(self, bulkUi): # Adds an item to the list charInfoDialog = QDialog() @@ -351,6 +376,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): bulkUi.tableView.model().appendRow(row) bulkUi.tableView.update() + def removeBulkInfo(self, bulkUi): + # Get the selected rows + selection = bulkUi.tableView.selectionModel().selectedRows() + + # Iterate over the rows and remove them + for index in reversed(selection): + bulkUi.tableView.model().removeRow(index.row()) def saveCharacterTabs(self): tabsData = [] @@ -384,7 +416,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.tabPersos.setEnabled(True) - def refreshAffectedCharacters(self): #Characters affected by a potential bulk-info modification + def refreshBulkAffectedCharacters(self): #Characters affected by a potential bulk-info modification + self.bulkAffectedCharacters = [] for character in self.lstCharacters.currentCharacters(): self.bulkAffectedCharacters.append(character.name()) diff --git a/manuskript/ui/bulkInfoManager.py b/manuskript/ui/bulkInfoManager.py index 0052b85..8e26349 100644 --- a/manuskript/ui/bulkInfoManager.py +++ b/manuskript/ui/bulkInfoManager.py @@ -14,7 +14,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_BulkInfoManager(object): def setupUi(self, BulkInfoManager): BulkInfoManager.setObjectName("BulkInfoManager") - BulkInfoManager.resize(533, 556) + BulkInfoManager.setWindowModality(QtCore.Qt.WindowModal) + BulkInfoManager.resize(548, 556) self.verticalLayout = QtWidgets.QVBoxLayout(BulkInfoManager) self.verticalLayout.setObjectName("verticalLayout") self.lblStaticMessage = QtWidgets.QLabel(BulkInfoManager) @@ -24,11 +25,15 @@ class Ui_BulkInfoManager(object): self.lblCharactersDynamic.setObjectName("lblCharactersDynamic") self.verticalLayout.addWidget(self.lblCharactersDynamic) self.tableView = QtWidgets.QTableView(BulkInfoManager) + self.tableView.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom)) + self.tableView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.tableView.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents) self.tableView.setAlternatingRowColors(True) self.tableView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.tableView.setTextElideMode(QtCore.Qt.ElideNone) - self.tableView.setCornerButtonEnabled(True) + self.tableView.setCornerButtonEnabled(False) self.tableView.setObjectName("tableView") + self.tableView.verticalHeader().setVisible(False) self.verticalLayout.addWidget(self.tableView) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") @@ -39,6 +44,7 @@ class Ui_BulkInfoManager(object): self.btnPersoBulkRmInfo.setObjectName("btnPersoBulkRmInfo") self.horizontalLayout.addWidget(self.btnPersoBulkRmInfo) self.btnPersoBulkApply = QtWidgets.QPushButton(BulkInfoManager) + self.btnPersoBulkApply.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom)) self.btnPersoBulkApply.setObjectName("btnPersoBulkApply") self.horizontalLayout.addWidget(self.btnPersoBulkApply) self.verticalLayout.addLayout(self.horizontalLayout) diff --git a/manuskript/ui/bulkInfoManager.ui b/manuskript/ui/bulkInfoManager.ui index 0dd07dd..35bf8ac 100644 --- a/manuskript/ui/bulkInfoManager.ui +++ b/manuskript/ui/bulkInfoManager.ui @@ -2,11 +2,14 @@ BulkInfoManager + + Qt::WindowModal + 0 0 - 533 + 548 556 @@ -30,6 +33,15 @@ + + + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + true @@ -40,8 +52,11 @@ Qt::ElideNone - true + false + + false + @@ -62,6 +77,9 @@ + + + Apply Changes diff --git a/manuskript/ui/characterInfoDialog.ui b/manuskript/ui/characterInfoDialog.ui index 8949f50..e1a5e94 100644 --- a/manuskript/ui/characterInfoDialog.ui +++ b/manuskript/ui/characterInfoDialog.ui @@ -2,6 +2,9 @@ characterInfoDialog + + Qt::WindowModal + 0