Changes every Enum to IntEnum

This commit is contained in:
Olivier Keshavjee 2017-11-15 21:05:48 +01:00
parent 9e95196cc5
commit cf4c1c83bf
15 changed files with 107 additions and 107 deletions

View file

@ -140,7 +140,7 @@ class mindMapImporter(abstractImporter):
item.setData(Outline.type, 'md')
# Move notes to text
if item.data(Outline.notes):
item.setData(Outline.text.value, item.data(Outline.notes))
item.setData(Outline.text, item.data(Outline.notes))
item.setData(Outline.notes, "")
return items

View file

@ -473,7 +473,7 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
outline.attrib[w.name] = val
# List characters as attrib
if y == Plot.characters.value:
if y == Plot.characters:
if mdl.hasChildren(index):
characters = []
for cX in range(mdl.rowCount(index)):
@ -486,7 +486,7 @@ def addPlotItem(root, mdl, parent=QModelIndex()):
outline.attrib.pop(Plot.characters.name)
# List resolution steps as sub items
elif y == Plot.steps.value:
elif y == Plot.steps:
if mdl.hasChildren(index):
for cX in range(mdl.rowCount(index)):
step = ET.SubElement(outline, "step")
@ -762,16 +762,16 @@ def loadProject(project, zip=None):
log("* Add plot: ", row[0].text())
# Characters
if row[Plot.characters.value].text():
IDs = row[Plot.characters.value].text().split(",")
if row[Plot.characters].text():
IDs = row[Plot.characters].text().split(",")
item = QStandardItem()
for ID in IDs:
item.appendRow(QStandardItem(ID.strip()))
row[Plot.characters.value] = item
row[Plot.characters] = item
# Subplots
for step in plot:
row[Plot.steps.value].appendRow(
row[Plot.steps].appendRow(
getStandardItemRowFromXMLEnum(step, PlotStep)
)

View file

@ -326,12 +326,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.txtPlotResult.setCurrentModelIndex(index)
self.sldPlotImportance.setCurrentModelIndex(index)
self.lstPlotPerso.setRootIndex(index.sibling(index.row(),
Plot.characters.value))
Plot.characters))
# Slider importance
self.updatePlotImportance(index.row())
subplotindex = index.sibling(index.row(), Plot.steps.value)
subplotindex = index.sibling(index.row(), Plot.steps)
self.lstSubPlots.setRootIndex(subplotindex)
if self.mdlPlots.rowCount(subplotindex):
self.updateSubPlotView()
@ -351,22 +351,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# So instead we set their width to 0.
#for i in range(self.mdlPlots.columnCount()):
#self.lstSubPlots.hideColumn(i)
#self.lstSubPlots.showColumn(PlotStep.name.value)
#self.lstSubPlots.showColumn(PlotStep.meta.value)
#self.lstSubPlots.showColumn(PlotStep.name)
#self.lstSubPlots.showColumn(PlotStep.meta)
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
PlotStep.ID.value, QHeaderView.Fixed)
PlotStep.ID, QHeaderView.Fixed)
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
PlotStep.summary.value, QHeaderView.Fixed)
PlotStep.summary, QHeaderView.Fixed)
self.lstSubPlots.horizontalHeader().resizeSection(
PlotStep.ID.value, 0)
PlotStep.ID, 0)
self.lstSubPlots.horizontalHeader().resizeSection(
PlotStep.summary.value, 0)
PlotStep.summary, 0)
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
PlotStep.name.value, QHeaderView.Stretch)
PlotStep.name, QHeaderView.Stretch)
self.lstSubPlots.horizontalHeader().setSectionResizeMode(
PlotStep.meta.value, QHeaderView.ResizeToContents)
PlotStep.meta, QHeaderView.ResizeToContents)
self.lstSubPlots.verticalHeader().hide()
def updatePlotImportance(self, ID):
@ -375,7 +375,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def changeCurrentSubPlot(self, index):
# Got segfaults when using textEditView model system, so ad hoc stuff.
index = index.sibling(index.row(), PlotStep.summary.value)
index = index.sibling(index.row(), PlotStep.summary)
item = self.mdlPlots.itemFromIndex(index)
if not item:
self.txtSubPlotSummary.setEnabled(False)
@ -393,7 +393,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
index = self.lstSubPlots.currentIndex()
if not index.isValid():
return
index = index.sibling(index.row(), PlotStep.summary.value)
index = index.sibling(index.row(), PlotStep.summary)
item = self.mdlPlots.itemFromIndex(index)
self._updatingSubPlot = True
@ -814,16 +814,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
pass
for w, c in [
(self.txtPersoName, Character.name.value),
(self.sldPersoImportance, Character.importance.value),
(self.txtPersoMotivation, Character.motivation.value),
(self.txtPersoGoal, Character.goal.value),
(self.txtPersoConflict, Character.conflict.value),
(self.txtPersoEpiphany, Character.epiphany.value),
(self.txtPersoSummarySentence, Character.summarySentence.value),
(self.txtPersoSummaryPara, Character.summaryPara.value),
(self.txtPersoSummaryFull, Character.summaryFull.value),
(self.txtPersoNotes, Character.notes.value)
(self.txtPersoName, Character.name),
(self.sldPersoImportance, Character.importance),
(self.txtPersoMotivation, Character.motivation),
(self.txtPersoGoal, Character.goal),
(self.txtPersoConflict, Character.conflict),
(self.txtPersoEpiphany, Character.epiphany),
(self.txtPersoSummarySentence, Character.summarySentence),
(self.txtPersoSummaryPara, Character.summaryPara),
(self.txtPersoSummaryFull, Character.summaryFull),
(self.txtPersoNotes, Character.notes)
]:
w.setModel(self.mdlCharacter)
w.setColumn(c)
@ -845,10 +845,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.lstSubPlots.selectionModel().currentRowChanged.connect(self.changeCurrentSubPlot, AUC)
for w, c in [
(self.txtPlotName, Plot.name.value),
(self.txtPlotDescription, Plot.description.value),
(self.txtPlotResult, Plot.result.value),
(self.sldPlotImportance, Plot.importance.value),
(self.txtPlotName, Plot.name),
(self.txtPlotDescription, Plot.description),
(self.txtPlotResult, Plot.result),
(self.sldPlotImportance, Plot.importance),
]:
w.setModel(self.mdlPlots)
w.setColumn(c)
@ -861,7 +861,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.plotCharacterDelegate = outlineCharacterDelegate(self.mdlCharacter, self)
self.lstPlotPerso.setItemDelegate(self.plotCharacterDelegate)
self.plotDelegate = plotDelegate(self)
self.lstSubPlots.setItemDelegateForColumn(PlotStep.meta.value, self.plotDelegate)
self.lstSubPlots.setItemDelegateForColumn(PlotStep.meta, self.plotDelegate)
# World
self.treeWorld.setModel(self.mdlWorld)
@ -873,10 +873,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.btnAddWorld.clicked.connect(self.mdlWorld.addItem, AUC)
self.btnRmWorld.clicked.connect(self.mdlWorld.removeItem, AUC)
for w, c in [
(self.txtWorldName, World.name.value),
(self.txtWorldDescription, World.description.value),
(self.txtWorldPassion, World.passion.value),
(self.txtWorldConflict, World.conflict.value),
(self.txtWorldName, World.name),
(self.txtWorldDescription, World.description),
(self.txtWorldPassion, World.passion),
(self.txtWorldConflict, World.conflict),
]:
w.setModel(self.mdlWorld)
w.setColumn(c)
@ -918,7 +918,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.tblDebugPersos.selectionModel().currentChanged.connect(
lambda: self.tblDebugPersosInfos.setRootIndex(self.mdlCharacter.index(
self.tblDebugPersos.selectionModel().currentIndex().row(),
Character.name.value)), AUC)
Character.name)), AUC)
self.tblDebugPlots.setModel(self.mdlPlots)
self.tblDebugPlotsPersos.setModel(self.mdlPlots)
@ -926,11 +926,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.tblDebugPlots.selectionModel().currentChanged.connect(
lambda: self.tblDebugPlotsPersos.setRootIndex(self.mdlPlots.index(
self.tblDebugPlots.selectionModel().currentIndex().row(),
Plot.characters.value)), AUC)
Plot.characters)), AUC)
self.tblDebugPlots.selectionModel().currentChanged.connect(
lambda: self.tblDebugSubPlots.setRootIndex(self.mdlPlots.index(
self.tblDebugPlots.selectionModel().currentIndex().row(),
Plot.steps.value)), AUC)
Plot.steps)), AUC)
self.treeDebugWorld.setModel(self.mdlWorld)
self.treeDebugOutline.setModel(self.mdlOutline)
self.lstDebugLabels.setModel(self.mdlLabels)
@ -997,15 +997,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.disconnectAll(self.tblDebugPersos.selectionModel().currentChanged,
lambda: self.tblDebugPersosInfos.setRootIndex(self.mdlCharacter.index(
self.tblDebugPersos.selectionModel().currentIndex().row(),
Character.name.value)))
Character.name)))
self.disconnectAll(self.tblDebugPlots.selectionModel().currentChanged,
lambda: self.tblDebugPlotsPersos.setRootIndex(self.mdlPlots.index(
self.tblDebugPlots.selectionModel().currentIndex().row(),
Plot.characters.value)))
Plot.characters)))
self.disconnectAll(self.tblDebugPlots.selectionModel().currentChanged,
lambda: self.tblDebugSubPlots.setRootIndex(self.mdlPlots.index(
self.tblDebugPlots.selectionModel().currentIndex().row(),
Plot.steps.value)))
Plot.steps)))
###############################################################################
# HELP

View file

@ -132,7 +132,7 @@ class abstractItem():
# Checking if we will have to recount words
updateWordCount = False
if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal]:
if column in [Outline.wordCount, Outline.goal, Outline.setGoal]:
updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data
# Stuff to do before
@ -149,7 +149,7 @@ class abstractItem():
self.emitDataChanged(cols=[Outline.text]) # new in 0.5.0
if column == Outline.compile:
self.emitDataChanged(cols=[Outline.title.value, Outline.compile], recursive=True)
self.emitDataChanged(cols=[Outline.title, Outline.compile], recursive=True)
if column == Outline.customIcon:
# If custom icon changed, we tell views to update title (so that icons
@ -197,8 +197,8 @@ class abstractItem():
self.setData(Outline.goalPercentage, "")
if emit:
self.emitDataChanged([Outline.goal.value, Outline.setGoal,
Outline.wordCount.value, Outline.goalPercentage])
self.emitDataChanged([Outline.goal, Outline.setGoal,
Outline.wordCount, Outline.goalPercentage])
if self.parent():
self.parent().updateWordCount(emit)
@ -492,8 +492,8 @@ class abstractItem():
elif self.type() == "html":
self.setData(Outline.type, "md")
self.setData(Outline.text.value, HTML2PlainText(self.data(Outline.text)))
self.setData(Outline.notes.value, HTML2PlainText(self.data(Outline.notes)))
self.setData(Outline.text, HTML2PlainText(self.data(Outline.text)))
self.setData(Outline.notes, HTML2PlainText(self.data(Outline.notes)))
for child in root:
if child.tag == "outlineItem":

View file

@ -28,8 +28,8 @@ class plotModel(QStandardItemModel):
def getPlotsByImportance(self):
plots = [[], [], []]
for i in range(self.rowCount()):
importance = self.item(i, Plot.importance.value).text()
ID = self.item(i, Plot.ID.value).text()
importance = self.item(i, Plot.importance).text()
ID = self.item(i, Plot.ID).text()
plots[2 - toInt(importance)].append(ID)
return plots
@ -37,23 +37,23 @@ class plotModel(QStandardItemModel):
index = self.getIndexFromID(ID)
if not index.isValid():
return
index = index.sibling(index.row(), Plot.steps.value)
index = index.sibling(index.row(), Plot.steps)
item = self.itemFromIndex(index)
lst = []
for i in range(item.rowCount()):
if item.child(i, PlotStep.ID.value):
_ID = item.child(i, PlotStep.ID.value).text()
if item.child(i, PlotStep.ID):
_ID = item.child(i, PlotStep.ID).text()
# Don't know why sometimes name is None (while drag'n'droping
# several items)
if item.child(i, PlotStep.name.value):
name = item.child(i, PlotStep.name.value).text()
if item.child(i, PlotStep.name):
name = item.child(i, PlotStep.name).text()
else:
name = ""
# Don't know why sometimes summary is None
if item.child(i, PlotStep.summary.value):
summary = item.child(i, PlotStep.summary.value).text()
if item.child(i, PlotStep.summary):
summary = item.child(i, PlotStep.summary).text()
else:
summary = ""
@ -62,17 +62,17 @@ class plotModel(QStandardItemModel):
def getPlotNameByID(self, ID):
for i in range(self.rowCount()):
_ID = self.item(i, Plot.ID.value).text()
_ID = self.item(i, Plot.ID).text()
if _ID == ID or toInt(_ID) == ID:
name = self.item(i, Plot.name.value).text()
name = self.item(i, Plot.name).text()
return name
return None
def getPlotImportanceByID(self, ID):
for i in range(self.rowCount()):
_ID = self.item(i, Plot.ID.value).text()
_ID = self.item(i, Plot.ID).text()
if _ID == ID or toInt(_ID) == ID:
importance = self.item(i, Plot.importance.value).text()
importance = self.item(i, Plot.importance).text()
return importance
return "0" # Default to "Minor"
@ -81,13 +81,13 @@ class plotModel(QStandardItemModel):
is ``subplotRaw``, of plot whose ID is ``plotID``.
"""
plotIndex = self.getIndexFromID(plotID)
name = plotIndex.child(subplotRaw, PlotStep.name.value).data()
summary = plotIndex.child(subplotRaw, PlotStep.summary.value).data()
name = plotIndex.child(subplotRaw, PlotStep.name).data()
summary = plotIndex.child(subplotRaw, PlotStep.summary).data()
return name, summary
def getIndexFromID(self, ID):
for i in range(self.rowCount()):
_ID = self.item(i, Plot.ID.value).text()
_ID = self.item(i, Plot.ID).text()
if _ID == ID or toInt(_ID) == ID:
return self.index(i, 0)
return QModelIndex()
@ -115,8 +115,8 @@ class plotModel(QStandardItemModel):
parentItem = self.itemFromIndex(parent)
vals = []
for i in range(self.rowCount(parent)):
index = self.index(i, Plot.ID.value, parent)
# item = self.item(i, Plot.ID.value)
index = self.index(i, Plot.ID, parent)
# item = self.item(i, Plot.ID)
if index.isValid() and index.data():
vals.append(int(index.data()))
@ -135,9 +135,9 @@ class plotModel(QStandardItemModel):
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
if section == PlotStep.name.value:
if section == PlotStep.name:
return self.tr("Name")
elif section == PlotStep.meta.value:
elif section == PlotStep.meta:
return self.tr("Meta")
else:
return ""
@ -148,8 +148,8 @@ class plotModel(QStandardItemModel):
def data(self, index, role=Qt.DisplayRole):
if index.parent().isValid() and \
index.parent().column() == Plot.steps.value and \
index.column() == PlotStep.meta.value:
index.parent().column() == Plot.steps and \
index.column() == PlotStep.meta:
if role == Qt.TextAlignmentRole:
return Qt.AlignRight | Qt.AlignVCenter
elif role == Qt.ForegroundRole:
@ -165,8 +165,8 @@ class plotModel(QStandardItemModel):
if not index.isValid():
return
parent = index.sibling(index.row(), Plot.steps.value)
parentItem = self.item(index.row(), Plot.steps.value)
parent = index.sibling(index.row(), Plot.steps)
parentItem = self.item(index.row(), Plot.steps)
if not parentItem:
return
@ -216,10 +216,10 @@ class plotModel(QStandardItemModel):
def addPlotPerso(self, v):
index = self.mw.lstPlots.currentPlotIndex()
if index.isValid():
if not self.item(index.row(), Plot.characters.value):
self.setItem(index.row(), Plot.characters.value, QStandardItem())
if not self.item(index.row(), Plot.characters):
self.setItem(index.row(), Plot.characters, QStandardItem())
item = self.item(index.row(), Plot.characters.value)
item = self.item(index.row(), Plot.characters)
# We check that the PersoID is not in the list yet
for i in range(item.rowCount()):

View file

@ -72,7 +72,7 @@ class plotsProxyModel(QSortFilterProxyModel):
self.mapModel()
def mapModelMaybe(self, topLeft, bottomRight):
if topLeft.column() <= Plot.importance.value <= bottomRight.column():
if topLeft.column() <= Plot.importance <= bottomRight.column():
self.mapModel()
def mapModel(self):
@ -85,7 +85,7 @@ class plotsProxyModel(QSortFilterProxyModel):
self._map.append(self._cats[i])
for p in range(src.rowCount()):
item = src.item(p, Plot.importance.value)
item = src.item(p, Plot.importance)
if item:
imp = int(item.text())

View file

@ -279,15 +279,15 @@ def infos(ref):
# Description
description = m.data(index.sibling(index.row(),
Plot.description.value))
Plot.description))
# Result
result = m.data(index.sibling(index.row(),
Plot.result.value))
Plot.result))
# Characters
pM = mainWindow().mdlCharacter
item = m.item(index.row(), Plot.characters.value)
item = m.item(index.row(), Plot.characters)
characters = ""
if item:
for r in range(item.rowCount()):
@ -298,12 +298,12 @@ def infos(ref):
# Resolution steps
steps = ""
item = m.item(index.row(), Plot.steps.value)
item = m.item(index.row(), Plot.steps)
if item:
for r in range(item.rowCount()):
title = item.child(r, PlotStep.name.value).text()
summary = item.child(r, PlotStep.summary.value).text()
meta = item.child(r, PlotStep.meta.value).text()
title = item.child(r, PlotStep.name).text()
summary = item.child(r, PlotStep.summary).text()
meta = item.child(r, PlotStep.meta).text()
if meta:
meta = " <span style='color:gray;'>({})</span>".format(meta)
steps += "<li><b>{title}</b>{summary}{meta}</li>".format(

View file

@ -46,24 +46,24 @@ class worldModel(QStandardItemModel):
def ID(self, index):
"""Returns the ID of the given index."""
index = index.sibling(index.row(), World.ID.value)
index = index.sibling(index.row(), World.ID)
return self.data(index)
def name(self, index):
"""Returns the name of the given index."""
index = index.sibling(index.row(), World.name.value)
index = index.sibling(index.row(), World.name)
return self.data(index)
def description(self, index):
index = index.sibling(index.row(), World.description.value)
index = index.sibling(index.row(), World.description)
return self.data(index)
def conflict(self, index):
index = index.sibling(index.row(), World.conflict.value)
index = index.sibling(index.row(), World.conflict)
return self.data(index)
def passion(self, index):
index = index.sibling(index.row(), World.passion.value)
index = index.sibling(index.row(), World.passion)
return self.data(index)
def itemID(self, item):

View file

@ -46,9 +46,9 @@ autoSaveDelay = 5
autoSaveNoChanges = True
autoSaveNoChangesDelay = 5
saveOnQuit = True
outlineViewColumns = [Outline.title.value, Outline.POV.value, Outline.status,
Outline.compile.value, Outline.wordCount.value, Outline.goal,
Outline.goalPercentage.value, Outline.label]
outlineViewColumns = [Outline.title, Outline.POV, Outline.status,
Outline.compile, Outline.wordCount, Outline.goal,
Outline.goalPercentage, Outline.label]
corkBackground = {
"color": "#926239",
"image": "writingdesk"

View file

@ -105,9 +105,9 @@ class cheatSheet(QWidget, Ui_cheatSheet):
d = []
for r in range(self.plotModel.rowCount()):
name = self.plotModel.item(r, Plot.name.value).text()
ID = self.plotModel.item(r, Plot.ID.value).text()
imp = self.plotModel.item(r, Plot.importance.value).text()
name = self.plotModel.item(r, Plot.name).text()
ID = self.plotModel.item(r, Plot.ID).text()
imp = self.plotModel.item(r, Plot.importance).text()
imp = [self.tr("Minor"), self.tr("Secondary"), self.tr("Main")][int(imp)]
d.append((name, ID, imp))

View file

@ -45,7 +45,7 @@ class textFormat(QWidget, Ui_textFormat):
self.setVisible(False)
return
if index.column() not in [Outline.text.value, Outline.notes]:
if index.column() not in [Outline.text, Outline.notes]:
self.setVisible(False)
return

View file

@ -44,11 +44,11 @@ class characterTreeView(QTreeWidget):
if topLeft.parent() != QModelIndex():
return
if topLeft.column() <= Character.name.value <= bottomRight.column():
if topLeft.column() <= Character.name <= bottomRight.column():
# Update name
self.updateNames()
elif topLeft.column() <= Character.importance.value <= bottomRight.column():
elif topLeft.column() <= Character.importance <= bottomRight.column():
# Importance changed
self.updateItems()

View file

@ -114,7 +114,7 @@ class outlineCharacterDelegate(QStyledItemDelegate):
item = QModelIndex()
character = self.mdlCharacter.getCharacterByID(index.data())
if character:
item = character.index(Character.name.value)
item = character.index(Character.name)
opt = QStyleOptionViewItem(option)
self.initStyleOption(opt, item)
@ -172,7 +172,7 @@ class outlineCharacterDelegate(QStyledItemDelegate):
itemIndex = QModelIndex()
character = self.mdlCharacter.getCharacterByID(index.data())
if character:
itemIndex = character.index(Character.name.value)
itemIndex = character.index(Character.name)
opt = QStyleOptionViewItem(option)
self.initStyleOption(opt, itemIndex)

View file

@ -78,7 +78,7 @@ class plotTreeView(QTreeWidget):
def updateMaybe(self, topLeft, bottomRight):
if topLeft.parent() != QModelIndex() and \
topLeft.column() <= PlotStep.name.value <= bottomRight.column() and \
topLeft.column() <= PlotStep.name <= bottomRight.column() and \
self._showSubPlot:
# Name's of Step has been updated, we update Items if showing
# subplots.
@ -86,11 +86,11 @@ class plotTreeView(QTreeWidget):
elif topLeft.parent() != QModelIndex():
return
if topLeft.column() <= Plot.name.value <= bottomRight.column():
if topLeft.column() <= Plot.name <= bottomRight.column():
# Update name
self.updateNames()
elif topLeft.column() <= Plot.importance.value <= bottomRight.column():
elif topLeft.column() <= Plot.importance <= bottomRight.column():
# Importance changed
self.updateItems()

View file

@ -180,7 +180,7 @@ class textEditView(QTextEdit):
return
# what type of text are we editing?
if self._column not in [Outline.text.value, Outline.notes]:
if self._column not in [Outline.text, Outline.notes]:
self._textFormat = "text"
else:
@ -189,7 +189,7 @@ class textEditView(QTextEdit):
# Setting highlighter
if self._highlighting:
item = index.internalPointer()
if self._column in [Outline.text.value, Outline.notes]:
if self._column in [Outline.text, Outline.notes]:
self.highlighter = MMDHighlighter(self)
else:
self.highlighter = basicHighlighter(self)