Made the code a little nicer, added addition and deletion

The bulk manager has been made partially functional.
This commit is contained in:
tntscreed 2023-03-07 18:13:36 +01:00
parent b5dfee59d7
commit 66df68af69
4 changed files with 75 additions and 15 deletions

View file

@ -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())

View file

@ -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)

View file

@ -2,11 +2,14 @@
<ui version="4.0">
<class>BulkInfoManager</class>
<widget class="QWidget" name="BulkInfoManager">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<width>548</width>
<height>556</height>
</rect>
</property>
@ -30,6 +33,15 @@
</item>
<item>
<widget class="QTableView" name="tableView">
<property name="locale">
<locale language="English" country="UnitedKingdom"/>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@ -40,8 +52,11 @@
<enum>Qt::ElideNone</enum>
</property>
<property name="cornerButtonEnabled">
<bool>true</bool>
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
@ -62,6 +77,9 @@
</item>
<item>
<widget class="QPushButton" name="btnPersoBulkApply">
<property name="locale">
<locale language="English" country="UnitedKingdom"/>
</property>
<property name="text">
<string>Apply Changes</string>
</property>

View file

@ -2,6 +2,9 @@
<ui version="4.0">
<class>characterInfoDialog</class>
<widget class="QDialog" name="characterInfoDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>