mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 02:12:29 +12:00
Adds subplot types
This commit is contained in:
parent
029165fc6b
commit
e9b4f9435e
|
@ -34,6 +34,12 @@ class Plot(Enum):
|
|||
subplots = 6
|
||||
summary = 7
|
||||
|
||||
class Subplot(Enum):
|
||||
name = 0
|
||||
ID = 1
|
||||
meta = 2
|
||||
summary = 3
|
||||
|
||||
class Outline(Enum):
|
||||
title = 0
|
||||
ID = 1
|
||||
|
|
|
@ -105,14 +105,21 @@ def loadStandardItemModelXML(mdl, xml, fromString=False):
|
|||
|
||||
#print(root.find("header").find("vertical").text)
|
||||
|
||||
mdl.setVerticalHeaderLabels(vLabels)
|
||||
mdl.setHorizontalHeaderLabels(hLabels)
|
||||
#mdl.setVerticalHeaderLabels(vLabels)
|
||||
#mdl.setHorizontalHeaderLabels(hLabels)
|
||||
|
||||
# Populates with empty items
|
||||
for i in range(len(vLabels)):
|
||||
row = []
|
||||
for r in range(len(hLabels)):
|
||||
row.append(QStandardItem())
|
||||
mdl.appendRow(row)
|
||||
|
||||
#Data
|
||||
data = root.find("data")
|
||||
loadItem(data, mdl)
|
||||
|
||||
#print("OK")
|
||||
return True
|
||||
|
||||
def loadItem(root, mdl, parent=QModelIndex()):
|
||||
for row in root:
|
||||
|
|
|
@ -12,6 +12,7 @@ from models.outlineModel import *
|
|||
from models.persosModel import *
|
||||
from models.plotModel import *
|
||||
from ui.views.outlineDelegates import outlinePersoDelegate
|
||||
from ui.views.plotDelegate import plotDelegate
|
||||
#from models.persosProxyModel import *
|
||||
from functions import *
|
||||
from settingsWindow import *
|
||||
|
@ -298,9 +299,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.sldPlotImportance.setCurrentModelIndex(index)
|
||||
self.lstPlotPerso.setRootIndex(index.sibling(index.row(),
|
||||
Plot.persos.value))
|
||||
subplotindex = index.sibling(index.row(), Plot.subplots.value)
|
||||
self.lstSubPlots.setRootIndex(subplotindex)
|
||||
if self.mdlPlots.rowCount(subplotindex):
|
||||
self.updateSubPlotView()
|
||||
|
||||
self.lstSubPlots.setRootIndex(index.sibling(index.row(),
|
||||
Plot.subplots.value))
|
||||
#self.txtSubPlotSummary.setCurrentModelIndex(QModelIndex())
|
||||
self.txtSubPlotSummary.setEnabled(False)
|
||||
self._updatingSubPlot = True
|
||||
|
@ -308,9 +311,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self._updatingSubPlot = False
|
||||
self.lstPlotPerso.selectionModel().clear()
|
||||
|
||||
def updateSubPlotView(self):
|
||||
# Hide columns
|
||||
for i in range(self.mdlPlots.columnCount()):
|
||||
self.lstSubPlots.hideColumn(i)
|
||||
self.lstSubPlots.showColumn(Subplot.name.value)
|
||||
self.lstSubPlots.showColumn(Subplot.meta.value)
|
||||
|
||||
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
|
||||
Subplot.name.value, QHeaderView.Stretch)
|
||||
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
|
||||
Subplot.meta.value, QHeaderView.ResizeToContents)
|
||||
self.lstSubPlots.verticalHeader().hide()
|
||||
|
||||
def changeCurrentSubPlot(self, index):
|
||||
# Got segfaults when using textEditView model system, so ad hoc stuff.
|
||||
index = index.sibling(index.row(), 3)
|
||||
index = index.sibling(index.row(), Subplot.summary.value)
|
||||
item = self.mdlPlots.itemFromIndex(index)
|
||||
if not item:
|
||||
self.txtSubPlotSummary.setEnabled(False)
|
||||
|
@ -328,7 +344,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
index = self.lstSubPlots.currentIndex()
|
||||
if not index.isValid():
|
||||
return
|
||||
index = index.sibling(index.row(), 3)
|
||||
index = index.sibling(index.row(), Subplot.summary.value)
|
||||
item = self.mdlPlots.itemFromIndex(index)
|
||||
|
||||
self._updatingSubPlot = True
|
||||
|
@ -356,8 +372,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
5000)
|
||||
return
|
||||
|
||||
self.currentProject = project
|
||||
QSettings().setValue("lastProject", project)
|
||||
|
||||
if loadFromFile:
|
||||
# Load empty settings
|
||||
|
@ -365,7 +379,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
|
||||
# Load data
|
||||
self.loadEmptyDatas()
|
||||
self.loadDatas()
|
||||
self.loadDatas(project)
|
||||
|
||||
self.makeConnections()
|
||||
|
||||
|
@ -419,6 +433,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
# Stuff
|
||||
#self.checkPersosID() # Should'n be necessary any longer
|
||||
|
||||
self.currentProject = project
|
||||
QSettings().setValue("lastProject", project)
|
||||
|
||||
# Show main Window
|
||||
self.stack.setCurrentIndex(1)
|
||||
|
||||
|
@ -551,9 +568,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.mdlPlots = plotModel(self)
|
||||
self.mdlOutline = outlineModel(self)
|
||||
|
||||
def loadDatas(self):
|
||||
def loadDatas(self, project):
|
||||
# Loading
|
||||
files = loadFilesFromZip(self.currentProject)
|
||||
files = loadFilesFromZip(project)
|
||||
|
||||
errors = []
|
||||
|
||||
|
@ -607,15 +624,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
|
||||
# Giving some feedback
|
||||
if not errors:
|
||||
print(self.tr("Project {} loaded.").format(self.currentProject))
|
||||
print(self.tr("Project {} loaded.").format(project))
|
||||
self.statusBar().showMessage(
|
||||
self.tr("Project {} loaded.").format(self.currentProject), 5000)
|
||||
self.tr("Project {} loaded.").format(project), 5000)
|
||||
else:
|
||||
print(self.tr("Project {} loaded with some errors:").format(self.currentProject))
|
||||
print(self.tr("Project {} loaded with some errors:").format(project))
|
||||
for e in errors:
|
||||
print(self.tr(" * {} wasn't found in project file.").format(e))
|
||||
self.statusBar().showMessage(
|
||||
self.tr("Project {} loaded with some errors.").format(self.currentProject), 5000)
|
||||
self.tr("Project {} loaded with some errors.").format(project), 5000)
|
||||
|
||||
###############################################################################
|
||||
# MAIN CONNECTIONS
|
||||
|
@ -769,6 +786,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.lstOutlinePlots.setShowSubPlot(True)
|
||||
self.plotPersoDelegate = outlinePersoDelegate(self.mdlPersos, self)
|
||||
self.lstPlotPerso.setItemDelegate(self.plotPersoDelegate)
|
||||
self.plotDelegate = plotDelegate(self)
|
||||
self.lstSubPlots.setItemDelegateForColumn(Subplot.meta.value, self.plotDelegate)
|
||||
|
||||
# Outline
|
||||
self.treeRedacOutline.setModel(self.mdlOutline)
|
||||
|
|
|
@ -143,7 +143,7 @@ class persosModel(QStandardItemModel):
|
|||
else:
|
||||
return Perso(section).name
|
||||
else:
|
||||
return QStandardItemModel.headerData(self, section, orientation, role=Qt.DisplayRole)
|
||||
return QStandardItemModel.headerData(self, section, orientation, role)
|
||||
|
||||
def addPersoInfo(self):
|
||||
perso = self.itemFromIndex(self.currentPersoIndex())
|
||||
|
|
|
@ -102,7 +102,35 @@ class plotModel(QStandardItemModel):
|
|||
###############################################################################
|
||||
# SUBPLOTS
|
||||
###############################################################################
|
||||
|
||||
|
||||
def headerData(self, section, orientation, role=Qt.DisplayRole):
|
||||
if role == Qt.DisplayRole:
|
||||
if orientation == Qt.Horizontal:
|
||||
if section == Subplot.name.value:
|
||||
return self.tr("Name")
|
||||
elif section == Subplot.meta.value:
|
||||
return self.tr("Meta")
|
||||
else:
|
||||
return ""
|
||||
else:
|
||||
return ""
|
||||
else:
|
||||
return QStandardItemModel.headerData(self, section, orientation, role)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
if index.parent().isValid() and \
|
||||
index.parent().column() == Plot.subplots.value and \
|
||||
index.column() == Subplot.meta.value:
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignRight | Qt.AlignVCenter
|
||||
elif role == Qt.ForegroundRole:
|
||||
return QBrush(Qt.gray)
|
||||
else:
|
||||
return QStandardItemModel.data(self, index, role)
|
||||
|
||||
else:
|
||||
return QStandardItemModel.data(self, index, role)
|
||||
|
||||
def addSubPlot(self):
|
||||
index = self.mw.lstPlots.currentPlotIndex()
|
||||
if not index.isValid():
|
||||
|
|
|
@ -266,11 +266,15 @@ def infos(ref):
|
|||
item = m.item(index.row(), Plot.subplots.value)
|
||||
if item:
|
||||
for r in range(item.rowCount()):
|
||||
title = item.child(r, 0).text()
|
||||
summary = item.child(r, 3).text()
|
||||
steps += "<li><b>{title}:</b> {summary}</li>".format(
|
||||
title = item.child(r, Subplot.name.value).text()
|
||||
summary = item.child(r, Subplot.summary.value).text()
|
||||
meta = item.child(r, Subplot.meta.value).text()
|
||||
if meta:
|
||||
meta = " <span style='color:gray;'>({})</span>".format(meta)
|
||||
steps += "<li><b>{title}</b>{summary}{meta}</li>".format(
|
||||
title=title,
|
||||
summary=summary)
|
||||
summary=": {}".format(summary) if summary else "",
|
||||
meta = meta if meta else "")
|
||||
|
||||
text = """<h1>{name}</h1>
|
||||
{goto}
|
||||
|
|
|
@ -624,9 +624,10 @@ class Ui_MainWindow(object):
|
|||
self.tab_15.setObjectName("tab_15")
|
||||
self.verticalLayout_28 = QtWidgets.QVBoxLayout(self.tab_15)
|
||||
self.verticalLayout_28.setObjectName("verticalLayout_28")
|
||||
self.lstSubPlots = QtWidgets.QListView(self.tab_15)
|
||||
self.lstSubPlots = QtWidgets.QTableView(self.tab_15)
|
||||
self.lstSubPlots.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
|
||||
self.lstSubPlots.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||
self.lstSubPlots.setShowGrid(False)
|
||||
self.lstSubPlots.setObjectName("lstSubPlots")
|
||||
self.verticalLayout_28.addWidget(self.lstSubPlots)
|
||||
self.grpSubPlotSummary = QtWidgets.QGroupBox(self.tab_15)
|
||||
|
@ -1050,8 +1051,8 @@ class Ui_MainWindow(object):
|
|||
self.stack.setCurrentIndex(1)
|
||||
self.tabMain.setCurrentIndex(3)
|
||||
self.tabSummary.setCurrentIndex(0)
|
||||
self.tabPersos.setCurrentIndex(0)
|
||||
self.tabPlot.setCurrentIndex(0)
|
||||
self.tabPersos.setCurrentIndex(3)
|
||||
self.tabPlot.setCurrentIndex(1)
|
||||
self.comboBox_2.setCurrentIndex(0)
|
||||
self.stkPlotSummary.setCurrentIndex(0)
|
||||
self.tabRedacInfos.setCurrentIndex(0)
|
||||
|
@ -1176,17 +1177,17 @@ class Ui_MainWindow(object):
|
|||
self.actCompile.setText(_translate("MainWindow", "Compile"))
|
||||
self.actCompile.setShortcut(_translate("MainWindow", "F6"))
|
||||
|
||||
from ui.cheatSheet import cheatSheet
|
||||
from ui.views.textEditView import textEditView
|
||||
from ui.views.metadataView import metadataView
|
||||
from ui.search import search
|
||||
from ui.views.outlineView import outlineView
|
||||
from ui.sldImportance import sldImportance
|
||||
from ui.editors.mainEditor import mainEditor
|
||||
from ui.collapsibleGroupBox2 import collapsibleGroupBox2
|
||||
from ui.views.plotTreeView import plotTreeView
|
||||
from ui.views.basicItemView import basicItemView
|
||||
from ui.cheatSheet import cheatSheet
|
||||
from ui.views.lineEditView import lineEditView
|
||||
from ui.views.treeView import treeView
|
||||
from ui.views.metadataView import metadataView
|
||||
from ui.views.basicItemView import basicItemView
|
||||
from ui.welcome import welcome
|
||||
from ui.views.outlineView import outlineView
|
||||
from ui.views.textEditView import textEditView
|
||||
from ui.collapsibleGroupBox2 import collapsibleGroupBox2
|
||||
from ui.search import search
|
||||
from ui.views.plotTreeView import plotTreeView
|
||||
from ui.views.persoTreeView import persoTreeView
|
||||
from ui.views.treeView import treeView
|
||||
|
|
|
@ -717,7 +717,7 @@
|
|||
</widget>
|
||||
<widget class="QTabWidget" name="tabPersos">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="infos">
|
||||
<attribute name="title">
|
||||
|
@ -1083,7 +1083,7 @@
|
|||
</widget>
|
||||
<widget class="QTabWidget" name="tabPlot">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
|
@ -1220,13 +1220,16 @@
|
|||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_28">
|
||||
<item>
|
||||
<widget class="QListView" name="lstSubPlots">
|
||||
<widget class="QTableView" name="lstSubPlots">
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
105
src/ui/views/plotDelegate.py
Normal file
105
src/ui/views/plotDelegate.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env python
|
||||
#--!-- coding: utf8 --!--
|
||||
|
||||
from qt import *
|
||||
from enums import *
|
||||
from functions import *
|
||||
import settings
|
||||
import collections
|
||||
|
||||
class plotDelegate(QStyledItemDelegate):
|
||||
def __init__(self, parent=None):
|
||||
QStyledItemDelegate.__init__(self, parent)
|
||||
|
||||
def sizeHint(self, option, index):
|
||||
s = QStyledItemDelegate.sizeHint(self, option, index)
|
||||
if s.width() < 200:
|
||||
s.setWidth(200)
|
||||
return s
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
editor = QLineEdit(parent)
|
||||
editor.setFrame(False)
|
||||
editor.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||||
return editor
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
editor.setText(index.model().data(index))
|
||||
|
||||
self.txt = editor
|
||||
self.menu = QMenu(editor)
|
||||
|
||||
plotsTypes = collections.OrderedDict({
|
||||
self.tr("General"): [
|
||||
self.tr("Promise"),
|
||||
self.tr("Problem"),
|
||||
self.tr("Progress"),
|
||||
self.tr("Resolution")
|
||||
],
|
||||
self.tr("Try / Fail"): [
|
||||
self.tr("No but"),
|
||||
self.tr("Yes and"),
|
||||
],
|
||||
self.tr("Freytag's pyramid"): [
|
||||
self.tr("Exposition"),
|
||||
self.tr("Rising action"),
|
||||
self.tr("Climax"),
|
||||
self.tr("Falling action"),
|
||||
self.tr("Resolution"),
|
||||
],
|
||||
self.tr("Three acts"): [
|
||||
self.tr("1. Setup"),
|
||||
self.tr("1. Inciting event"),
|
||||
self.tr("1. Turning point"),
|
||||
"---",
|
||||
self.tr("2. Choice"),
|
||||
self.tr("2. Reversal"),
|
||||
self.tr("2. Disaster"),
|
||||
"---",
|
||||
self.tr("3. Stand up"),
|
||||
self.tr("3. Climax"),
|
||||
self.tr("3. Ending"),
|
||||
],
|
||||
|
||||
self.tr("Hero's journey"): [
|
||||
self.tr("Ordinary world"),
|
||||
self.tr("Call to adventure"),
|
||||
self.tr("Refusal of the call"),
|
||||
self.tr("Meeting with mentor"),
|
||||
self.tr("Corssing the Threshold"),
|
||||
self.tr("Tests"),
|
||||
self.tr("Approach"),
|
||||
self.tr("Abyss"),
|
||||
self.tr("Reward / Revelation"),
|
||||
self.tr("Transformation"),
|
||||
self.tr("Atonement"),
|
||||
self.tr("Return"),
|
||||
],
|
||||
})
|
||||
|
||||
for name in plotsTypes:
|
||||
m = QMenu(name, self.menu)
|
||||
|
||||
for sub in plotsTypes[name]:
|
||||
if sub == "---":
|
||||
m.addSeparator()
|
||||
else:
|
||||
a = QAction(sub, m)
|
||||
a.triggered.connect(self.submit)
|
||||
m.addAction(a)
|
||||
|
||||
self.menu.addMenu(m)
|
||||
|
||||
editor.addAction(QIcon.fromTheme("list-add"), QLineEdit.LeadingPosition).triggered.connect(self.popupMenu)
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
val = editor.text()
|
||||
model.setData(index, val)
|
||||
|
||||
def popupMenu(self):
|
||||
act = self.sender()
|
||||
self.menu.popup(self.txt.parent().mapToGlobal(self.txt.geometry().bottomLeft()))
|
||||
|
||||
def submit(self):
|
||||
act = self.sender()
|
||||
self.txt.setText(act.text())
|
Loading…
Reference in a new issue