mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-02 20:12:24 +12:00
Created a (not yet functional) bulk manager widget.
-Some variables had to be declared in the mainWindow.py __init__ function. -Added functions for creating the bulkPersoInfoManager widget as a tab when multiple characters are selected. All other tabs get stored and deleted, and restored after only one character is selected. -Started work on functions that create the intended behaviours of the widget.
This commit is contained in:
parent
25b64ad971
commit
b5dfee59d7
|
@ -7,9 +7,9 @@ import re
|
|||
from PyQt5.Qt import qVersion, PYQT_VERSION_STR
|
||||
from PyQt5.QtCore import (pyqtSignal, QSignalMapper, QTimer, QSettings, Qt, QPoint,
|
||||
QRegExp, QUrl, QSize, QModelIndex)
|
||||
from PyQt5.QtGui import QStandardItemModel, QIcon, QColor
|
||||
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
|
||||
QLabel, QDockWidget, QWidget, QMessageBox, QLineEdit, QTextEdit, QTreeView, QDialog
|
||||
|
||||
from manuskript import settings
|
||||
from manuskript.enums import Character, PlotStep, Plot, World, Outline
|
||||
|
@ -23,6 +23,7 @@ from manuskript.models.plotModel import plotModel
|
|||
from manuskript.models.worldModel import worldModel
|
||||
from manuskript.settingsWindow import settingsWindow
|
||||
from manuskript.ui import style
|
||||
from manuskript.ui import characterInfoDialog
|
||||
from manuskript.ui.about import aboutDialog
|
||||
from manuskript.ui.collapsibleDockWidgets import collapsibleDockWidgets
|
||||
from manuskript.ui.importers.importer import importerDialog
|
||||
|
@ -35,6 +36,7 @@ from manuskript.ui.views.outlineDelegates import outlineCharacterDelegate
|
|||
from manuskript.ui.views.plotDelegate import plotDelegate
|
||||
from manuskript.ui.views.MDEditView import MDEditView
|
||||
from manuskript.ui.statusLabel import statusLabel
|
||||
from manuskript.ui.bulkInfoManager import Ui_BulkInfoManager
|
||||
|
||||
# Spellcheck support
|
||||
from manuskript.ui.views.textEditView import textEditView
|
||||
|
@ -179,6 +181,11 @@ 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.bulkAffectedCharacters = []
|
||||
|
||||
def updateDockVisibility(self, restore=False):
|
||||
"""
|
||||
Saves the state of the docks visibility. Or if `restore` is True,
|
||||
|
@ -297,23 +304,91 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
# CHARACTERS
|
||||
###############################################################################
|
||||
|
||||
def setPersoBulkMode(self, enabled: bool):
|
||||
if enabled and not self.isPersoBulkModeEnabled: # Delete all tabs and create the manager one
|
||||
bulkPersoInfoManager = QWidget()
|
||||
bulkPersoInfoManagerUi = Ui_BulkInfoManager()
|
||||
bulkPersoInfoManagerUi.setupUi(bulkPersoInfoManager)
|
||||
bulkPersoInfoManagerUi.tableView.setModel(QStandardItemModel())
|
||||
|
||||
self.tabPersos.clear()
|
||||
self.tabPersos.addTab(bulkPersoInfoManager, "Bulk Info Manager")
|
||||
self.isPersoBulkModeEnabled = True
|
||||
self.refreshAffectedCharacters()
|
||||
|
||||
# Showing the character names on the label
|
||||
labelText = ""
|
||||
for characterName in self.bulkAffectedCharacters:
|
||||
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:
|
||||
self.tabPersos.clear()
|
||||
self.loadCharacterTabs()
|
||||
self.isPersoBulkModeEnabled = False
|
||||
self.bulkAffectedCharacters.clear()
|
||||
|
||||
def setBulkInfoConnections(self, bulkUi):
|
||||
bulkUi.btnPersoBulkAddInfo.clicked.connect(lambda: self.addBulkInfo(bulkUi))
|
||||
|
||||
def addBulkInfo(self, bulkUi): # Adds an item to the list
|
||||
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 a new row to the model with the description and value
|
||||
row = [QStandardItem(description), QStandardItem(value)]
|
||||
|
||||
bulkUi.tableView.model().appendRow(row)
|
||||
|
||||
bulkUi.tableView.update()
|
||||
|
||||
def saveCharacterTabs(self):
|
||||
tabsData = []
|
||||
for i in range(self.tabPersos.count()):
|
||||
tabData = {}
|
||||
widget = self.tabPersos.widget(i)
|
||||
tabData['widget'] = widget
|
||||
tabData['title'] = self.tabPersos.tabText(i)
|
||||
tabsData.append(tabData)
|
||||
return tabsData
|
||||
|
||||
def loadCharacterTabs(self):
|
||||
for tabData in self.tabsData:
|
||||
widget = tabData['widget']
|
||||
title = tabData['title']
|
||||
self.tabPersos.addTab(widget, title)
|
||||
def handleCharacterSelectionChanged(self):
|
||||
selectedCharacters = self.lstCharacters.currentCharacters()
|
||||
characterSelectionIsEmpty = not any(selectedCharacters)
|
||||
if characterSelectionIsEmpty:
|
||||
self.tabPersos.setEnabled(False)
|
||||
return
|
||||
cList = list(filter(None, self.lstCharacters.currentCharacters()))
|
||||
cList = list(filter(None, self.lstCharacters.currentCharacters())) #cList contains all valid characters
|
||||
character = cList[0]
|
||||
self.changeCurrentCharacter(character)
|
||||
|
||||
# TODO: Transform this check to still enable tabPersos,
|
||||
# but only the parts that should be editable with multi-selection
|
||||
if len(selectedCharacters) > 1:
|
||||
self.tabPersos.setEnabled(False)
|
||||
return
|
||||
self.setPersoBulkMode(True)
|
||||
else:
|
||||
self.setPersoBulkMode(False)
|
||||
|
||||
self.tabPersos.setEnabled(True)
|
||||
|
||||
def refreshAffectedCharacters(self): #Characters affected by a potential bulk-info modification
|
||||
for character in self.lstCharacters.currentCharacters():
|
||||
self.bulkAffectedCharacters.append(character.name())
|
||||
|
||||
|
||||
def changeCurrentCharacter(self, character, trash=None):
|
||||
|
||||
if character is None:
|
||||
|
|
66
manuskript/ui/bulkInfoManager.py
Normal file
66
manuskript/ui/bulkInfoManager.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'D:\OpensourceWork\manuskript\manuskript\ui\bulkInfoManager.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_BulkInfoManager(object):
|
||||
def setupUi(self, BulkInfoManager):
|
||||
BulkInfoManager.setObjectName("BulkInfoManager")
|
||||
BulkInfoManager.resize(533, 556)
|
||||
self.verticalLayout = QtWidgets.QVBoxLayout(BulkInfoManager)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.lblStaticMessage = QtWidgets.QLabel(BulkInfoManager)
|
||||
self.lblStaticMessage.setObjectName("lblStaticMessage")
|
||||
self.verticalLayout.addWidget(self.lblStaticMessage)
|
||||
self.lblCharactersDynamic = QtWidgets.QLabel(BulkInfoManager)
|
||||
self.lblCharactersDynamic.setObjectName("lblCharactersDynamic")
|
||||
self.verticalLayout.addWidget(self.lblCharactersDynamic)
|
||||
self.tableView = QtWidgets.QTableView(BulkInfoManager)
|
||||
self.tableView.setAlternatingRowColors(True)
|
||||
self.tableView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||
self.tableView.setTextElideMode(QtCore.Qt.ElideNone)
|
||||
self.tableView.setCornerButtonEnabled(True)
|
||||
self.tableView.setObjectName("tableView")
|
||||
self.verticalLayout.addWidget(self.tableView)
|
||||
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||
self.btnPersoBulkAddInfo = QtWidgets.QPushButton(BulkInfoManager)
|
||||
self.btnPersoBulkAddInfo.setObjectName("btnPersoBulkAddInfo")
|
||||
self.horizontalLayout.addWidget(self.btnPersoBulkAddInfo)
|
||||
self.btnPersoBulkRmInfo = QtWidgets.QPushButton(BulkInfoManager)
|
||||
self.btnPersoBulkRmInfo.setObjectName("btnPersoBulkRmInfo")
|
||||
self.horizontalLayout.addWidget(self.btnPersoBulkRmInfo)
|
||||
self.btnPersoBulkApply = QtWidgets.QPushButton(BulkInfoManager)
|
||||
self.btnPersoBulkApply.setObjectName("btnPersoBulkApply")
|
||||
self.horizontalLayout.addWidget(self.btnPersoBulkApply)
|
||||
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||
|
||||
self.retranslateUi(BulkInfoManager)
|
||||
QtCore.QMetaObject.connectSlotsByName(BulkInfoManager)
|
||||
|
||||
def retranslateUi(self, BulkInfoManager):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
BulkInfoManager.setWindowTitle(_translate("BulkInfoManager", "Form"))
|
||||
self.lblStaticMessage.setText(_translate("BulkInfoManager", "Affected Characters:"))
|
||||
self.lblCharactersDynamic.setText(_translate("BulkInfoManager", "NONE"))
|
||||
self.btnPersoBulkAddInfo.setText(_translate("BulkInfoManager", "Add Entry"))
|
||||
self.btnPersoBulkRmInfo.setText(_translate("BulkInfoManager", "Remove Entry"))
|
||||
self.btnPersoBulkApply.setText(_translate("BulkInfoManager", "Apply Changes"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
BulkInfoManager = QtWidgets.QWidget()
|
||||
ui = Ui_BulkInfoManager()
|
||||
ui.setupUi(BulkInfoManager)
|
||||
BulkInfoManager.show()
|
||||
sys.exit(app.exec_())
|
76
manuskript/ui/bulkInfoManager.ui
Normal file
76
manuskript/ui/bulkInfoManager.ui
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BulkInfoManager</class>
|
||||
<widget class="QWidget" name="BulkInfoManager">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>533</width>
|
||||
<height>556</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblStaticMessage">
|
||||
<property name="text">
|
||||
<string>Affected Characters:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblCharactersDynamic">
|
||||
<property name="text">
|
||||
<string>NONE</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::ElideNone</enum>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnPersoBulkAddInfo">
|
||||
<property name="text">
|
||||
<string>Add Entry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnPersoBulkRmInfo">
|
||||
<property name="text">
|
||||
<string>Remove Entry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnPersoBulkApply">
|
||||
<property name="text">
|
||||
<string>Apply Changes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in a new issue