Made bulk-adding "Detailed info" to characters possible

-Changed the selection mode to extended selection on the lstCharacters tree-view. This will not affect anything else other than the "detailed info" rows. Every other change to a character's descriptions, motivations and such only affect the last selected one.

-Made a method to get all the IDs of the selected characters.

-Added a character-info dialog UI. Originally, adding information worked by adding a placeholder and then changing it. Users never want to just add a placeholder without initialising the values. And the bulk-adding only works this way.
This commit is contained in:
tntscreed 2023-03-05 00:58:25 +01:00
parent 2ca25a06f6
commit a046656acf
5 changed files with 316 additions and 2 deletions

View file

@ -219,6 +219,17 @@ class characterModel(QAbstractItemModel, searchableModel):
))
self.endInsertRows()
mainWindow().updatePersoInfoView()
def addCharacterInfo(self, ID, description, value):
c = self.getCharacterByID(ID)
self.beginInsertRows(c.index(), len(c.infos), len(c.infos))
c.infos.append(CharacterInfo(
c,
description=self.tr(description),
value=self.tr(value)
))
self.endInsertRows()
mainWindow().updatePersoInfoView()
def removeCharacterInfo(self, ID):

View file

@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\OpensourceWork\manuskript\manuskript\ui\characterInfoDialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_characterInfoDialog(object):
def setupUi(self, characterInfoDialog):
characterInfoDialog.setObjectName("characterInfoDialog")
characterInfoDialog.resize(481, 148)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(characterInfoDialog.sizePolicy().hasHeightForWidth())
characterInfoDialog.setSizePolicy(sizePolicy)
characterInfoDialog.setMinimumSize(QtCore.QSize(481, 148))
characterInfoDialog.setMaximumSize(QtCore.QSize(481, 148))
characterInfoDialog.setTabletTracking(False)
characterInfoDialog.setFocusPolicy(QtCore.Qt.NoFocus)
characterInfoDialog.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
self.gridLayout = QtWidgets.QGridLayout(characterInfoDialog)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(characterInfoDialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.valueLineEdit = QtWidgets.QLineEdit(characterInfoDialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.valueLineEdit.sizePolicy().hasHeightForWidth())
self.valueLineEdit.setSizePolicy(sizePolicy)
self.valueLineEdit.setFocusPolicy(QtCore.Qt.StrongFocus)
self.valueLineEdit.setLayoutDirection(QtCore.Qt.RightToLeft)
self.valueLineEdit.setObjectName("valueLineEdit")
self.horizontalLayout_2.addWidget(self.valueLineEdit)
self.gridLayout.addLayout(self.horizontalLayout_2, 3, 0, 1, 1)
self.horizontalLayout_1 = QtWidgets.QHBoxLayout()
self.horizontalLayout_1.setObjectName("horizontalLayout_1")
self.label = QtWidgets.QLabel(characterInfoDialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setObjectName("label")
self.horizontalLayout_1.addWidget(self.label)
self.descriptionLineEdit = QtWidgets.QLineEdit(characterInfoDialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.descriptionLineEdit.sizePolicy().hasHeightForWidth())
self.descriptionLineEdit.setSizePolicy(sizePolicy)
self.descriptionLineEdit.setFocusPolicy(QtCore.Qt.StrongFocus)
self.descriptionLineEdit.setLayoutDirection(QtCore.Qt.RightToLeft)
self.descriptionLineEdit.setObjectName("descriptionLineEdit")
self.horizontalLayout_1.addWidget(self.descriptionLineEdit)
self.gridLayout.addLayout(self.horizontalLayout_1, 2, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(characterInfoDialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.buttonBox.sizePolicy().hasHeightForWidth())
self.buttonBox.setSizePolicy(sizePolicy)
self.buttonBox.setFocusPolicy(QtCore.Qt.StrongFocus)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 1)
self.retranslateUi(characterInfoDialog)
self.buttonBox.accepted.connect(characterInfoDialog.accept)
self.buttonBox.rejected.connect(characterInfoDialog.reject)
QtCore.QMetaObject.connectSlotsByName(characterInfoDialog)
characterInfoDialog.setTabOrder(self.descriptionLineEdit, self.valueLineEdit)
def retranslateUi(self, characterInfoDialog):
_translate = QtCore.QCoreApplication.translate
characterInfoDialog.setWindowTitle(_translate("characterInfoDialog", "Add Character Info"))
self.label_2.setText(_translate("characterInfoDialog", "Value:"))
self.label.setText(_translate("characterInfoDialog", "Name:"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
characterInfoDialog = QtWidgets.QDialog()
ui = Ui_characterInfoDialog()
ui.setupUi(characterInfoDialog)
characterInfoDialog.show()
sys.exit(app.exec_())

View file

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>characterInfoDialog</class>
<widget class="QDialog" name="characterInfoDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<height>148</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>481</width>
<height>148</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>481</width>
<height>148</height>
</size>
</property>
<property name="tabletTracking">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle">
<string>Add Character Info</string>
</property>
<property name="locale">
<locale language="English" country="UnitedKingdom"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Value:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="valueLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="descriptionLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>descriptionLineEdit</tabstop>
<tabstop>valueLineEdit</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>characterInfoDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>259</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>147</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>characterInfoDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>327</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>147</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -313,6 +313,7 @@ class Ui_MainWindow(object):
self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.groupBox)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.lstCharacters = characterTreeView(self.groupBox)
self.lstCharacters.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.lstCharacters.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.lstCharacters.setDragEnabled(True)
self.lstCharacters.setObjectName("lstCharacters")

View file

@ -2,11 +2,12 @@
# --!-- coding: utf8 --!--
from PyQt5.QtCore import QSize, QModelIndex, Qt
from PyQt5.QtGui import QPixmap, QColor, QIcon, QBrush
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QColorDialog
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QColorDialog, QDialog
from manuskript.enums import Character
from manuskript.functions import iconColor, mainWindow
from manuskript.ui import style as S
from manuskript.ui import characterInfoDialog
class characterTreeView(QTreeWidget):
@ -170,7 +171,22 @@ class characterTreeView(QTreeWidget):
mainWindow().updateCharacterPOVState(ID)
def addCharacterInfo(self):
self._model.addCharacterInfo(self.currentCharacterID())
#Setting up dialog
charInfoDialog = QDialog()
charInfoUi = characterInfoDialog.Ui_characterInfoDialog()
charInfoUi.setupUi(charInfoDialog)
if charInfoDialog.exec_() == QDialog.Accepted:
# User clicked OK, get the input values
description = charInfoUi.descriptionLineEdit.text()
value = charInfoUi.valueLineEdit.text()
# Add the character info with the input values
IDs = self.currentCharacterIDs()
for ID in IDs:
self._model.addCharacterInfo(ID, description, value)
def removeCharacterInfo(self):
self._model.removeCharacterInfo(self.currentCharacterID())
@ -182,6 +198,14 @@ class characterTreeView(QTreeWidget):
return ID
def currentCharacterIDs(self): #Exactly like currentCharacterID(), except for multiselection
IDs = []
for item in self.selectedItems():
ID = item.data(0, Qt.UserRole)
if ID is not None:
IDs.append(ID)
return IDs
def currentCharacter(self):
"""
Returns the selected character