mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-15 09:24:33 +12:00
Saves plots, correctly.
This commit is contained in:
parent
8949d7b8e3
commit
c31681a724
|
@ -13,7 +13,7 @@ from PyQt5.QtCore import Qt, QModelIndex
|
||||||
from PyQt5.QtGui import QColor
|
from PyQt5.QtGui import QColor
|
||||||
|
|
||||||
from manuskript import settings
|
from manuskript import settings
|
||||||
from manuskript.enums import Character, World, Plot
|
from manuskript.enums import Character, World, Plot, PlotStep
|
||||||
from manuskript.functions import mainWindow, iconColor
|
from manuskript.functions import mainWindow, iconColor
|
||||||
from lxml import etree as ET
|
from lxml import etree as ET
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ try:
|
||||||
except:
|
except:
|
||||||
compression = zipfile.ZIP_STORED
|
compression = zipfile.ZIP_STORED
|
||||||
|
|
||||||
|
|
||||||
cache = {}
|
cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +65,7 @@ def slugify(name):
|
||||||
newName += "-"
|
newName += "-"
|
||||||
return newName
|
return newName
|
||||||
|
|
||||||
|
|
||||||
def saveProject(zip=None):
|
def saveProject(zip=None):
|
||||||
"""
|
"""
|
||||||
Saves the project. If zip is False, the project is saved as a multitude of plain-text files for the most parts
|
Saves the project. If zip is False, the project is saved as a multitude of plain-text files for the most parts
|
||||||
|
@ -87,6 +87,10 @@ def saveProject(zip=None):
|
||||||
|
|
||||||
mw = mainWindow()
|
mw = mainWindow()
|
||||||
|
|
||||||
|
if zip:
|
||||||
|
# File format version
|
||||||
|
files.append(("VERSION", "1"))
|
||||||
|
|
||||||
# General infos (book and author)
|
# General infos (book and author)
|
||||||
# Saved in plain text, in infos.txt
|
# Saved in plain text, in infos.txt
|
||||||
|
|
||||||
|
@ -187,6 +191,8 @@ def saveProject(zip=None):
|
||||||
ID=c.ID(),
|
ID=c.ID(),
|
||||||
slugName=slugify(c.name())
|
slugName=slugify(c.name())
|
||||||
))
|
))
|
||||||
|
# Has the character been renamed?
|
||||||
|
# If so, we remove the old file (if not zipped)
|
||||||
if c.lastPath and cpath != c.lastPath:
|
if c.lastPath and cpath != c.lastPath:
|
||||||
removes.append(c.lastPath)
|
removes.append(c.lastPath)
|
||||||
c.lastPath = cpath
|
c.lastPath = cpath
|
||||||
|
@ -217,13 +223,11 @@ def saveProject(zip=None):
|
||||||
# Either in XML or lots of plain texts?
|
# Either in XML or lots of plain texts?
|
||||||
# More probably XML since there is not really a lot if writing to do (third-party)
|
# More probably XML since there is not really a lot if writing to do (third-party)
|
||||||
|
|
||||||
path = "plots.opml"
|
path = "plots.xml"
|
||||||
mdl = mw.mdlPlots
|
mdl = mw.mdlPlots
|
||||||
|
|
||||||
root = ET.Element("opml")
|
root = ET.Element("root")
|
||||||
root.attrib["version"] = "1.0"
|
addPlotItem(root, mdl)
|
||||||
body = ET.SubElement(root, "body")
|
|
||||||
addPlotItem(body, mdl)
|
|
||||||
content = ET.tostring(root, encoding="UTF-8", xml_declaration=True, pretty_print=True)
|
content = ET.tostring(root, encoding="UTF-8", xml_declaration=True, pretty_print=True)
|
||||||
files.append((path, content))
|
files.append((path, content))
|
||||||
|
|
||||||
|
@ -280,6 +284,7 @@ def saveProject(zip=None):
|
||||||
else:
|
else:
|
||||||
print(" In cache, and identical. Do nothing.")
|
print(" In cache, and identical. Do nothing.")
|
||||||
|
|
||||||
|
|
||||||
def addWorldItem(root, mdl, parent=QModelIndex()):
|
def addWorldItem(root, mdl, parent=QModelIndex()):
|
||||||
"""
|
"""
|
||||||
Lists elements in a world model and create an OPML xml file.
|
Lists elements in a world model and create an OPML xml file.
|
||||||
|
@ -312,7 +317,7 @@ def addWorldItem(root, mdl, parent=QModelIndex()):
|
||||||
|
|
||||||
def addPlotItem(root, mdl, parent=QModelIndex()):
|
def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
"""
|
"""
|
||||||
Lists elements in a plot model and create an OPML xml file.
|
Lists elements in a plot model and create an xml file.
|
||||||
@param root: an Etree element
|
@param root: an Etree element
|
||||||
@param mdl: a plotModel
|
@param mdl: a plotModel
|
||||||
@param parent: the parent index in the plot model
|
@param parent: the parent index in the plot model
|
||||||
|
@ -323,7 +328,7 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
for x in range(mdl.rowCount(parent)):
|
for x in range(mdl.rowCount(parent)):
|
||||||
|
|
||||||
# For each row, create an outline item.
|
# For each row, create an outline item.
|
||||||
outline = ET.SubElement(root, "outline")
|
outline = ET.SubElement(root, "plot")
|
||||||
for y in range(mdl.columnCount(parent)):
|
for y in range(mdl.columnCount(parent)):
|
||||||
|
|
||||||
index = mdl.index(x, y, parent)
|
index = mdl.index(x, y, parent)
|
||||||
|
@ -336,6 +341,7 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
if y == w.value:
|
if y == w.value:
|
||||||
outline.attrib[w.name] = val
|
outline.attrib[w.name] = val
|
||||||
|
|
||||||
|
# List characters as attrib
|
||||||
if y == Plot.characters.value:
|
if y == Plot.characters.value:
|
||||||
if mdl.hasChildren(index):
|
if mdl.hasChildren(index):
|
||||||
characters = []
|
characters = []
|
||||||
|
@ -347,14 +353,24 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
|
||||||
else:
|
else:
|
||||||
outline.attrib.pop(Plot.characters.name)
|
outline.attrib.pop(Plot.characters.name)
|
||||||
|
|
||||||
elif y == Plot.steps.value and mdl.hasChildren(index):
|
# List resolution steps as sub items
|
||||||
|
elif y == Plot.steps.value:
|
||||||
|
if mdl.hasChildren(index):
|
||||||
|
for cX in range(mdl.rowCount(index)):
|
||||||
|
step = ET.SubElement(outline, "step")
|
||||||
|
for cY in range(mdl.columnCount(index)):
|
||||||
|
cIndex = mdl.index(cX, cY, index)
|
||||||
|
val = mdl.data(cIndex)
|
||||||
|
|
||||||
|
for w in PlotStep:
|
||||||
|
if cY == w.value:
|
||||||
|
step.attrib[w.name] = val
|
||||||
|
|
||||||
outline.attrib.pop(Plot.steps.name)
|
outline.attrib.pop(Plot.steps.name)
|
||||||
|
|
||||||
|
|
||||||
# addWorldItem(outline, mdl, index)
|
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
def loadProject(project):
|
def loadProject(project):
|
||||||
"""
|
"""
|
||||||
Loads a project.
|
Loads a project.
|
||||||
|
|
Loading…
Reference in a new issue