From 719f6e6fe0c8c72520626f3c00485a82db2b5cd7 Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Tue, 30 Jun 2015 14:01:32 +0200 Subject: [PATCH] Better cheat sheet --- i18n/manuskript_fr.qm | Bin 28418 -> 29593 bytes i18n/manuskript_fr.ts | 123 ++++++++++++++++++++++++++----- src/models/outlineModel.py | 40 +++++++++- src/models/persosModel.py | 10 ++- src/models/references.py | 147 +++++++++++++++++++++++++++++++++---- src/ui/cheatSheet.py | 5 ++ 6 files changed, 288 insertions(+), 37 deletions(-) diff --git a/i18n/manuskript_fr.qm b/i18n/manuskript_fr.qm index 5ebb7dd218ac39b24b21c8a434c4cbf4e77c1e13..413f028b4ac60c8e61bfad5f3a4cac407f576abe 100644 GIT binary patch delta 1772 zcmZvcdrVVz6vw}9@4bBi1>~V14NQdrQb2=7C(g)IUe=c0fBZa%sFeb4!w^F8Nw z{eWcmb;-7v^dA6B1E#z~%mpmb0M`kGtBJdb(*d~%H05s3FOD`}0|xwnLjbp{4p>&b zeW$3Z`3u~|&46|5_Mr^zwKafoA-G?1fQVngjaUFp0`U|n-e-A|Vrgv_>yTumR__6- zKLsxq0ShjMSXv)qg`Ri_u*=v5i8k6*1b&wTDC`Td;Tn4&(Mnx!uq0`fs&NpN99?To zWNlJ!S*;V*FP;aY8)0e=@=l0Fdtq|-QqD|>8z^__CgNGDVG!n7-9X$7)I9hN$hnW& zeN>av#-_;vvoGAbLz-#0!d(Fx%(&`307!-<`WY_+I=$qj&sUId*^+~m2B?Vr z#9Kgoo~-}9G{7auF2=}!yeQe-l-H=J&0KL8=^P_m)m5^#U>mnszXed7<$Pa}&gJ1& z+0FnH%D7kdN6=6UxPW&MSZX5<5gBoq_%U&WI7IvtnW#(U0xhJkGZUr6SBX5ahYK9^ z0rfYy4eix5^UExYpD$f@ig|d~I_vkmtYZU^*~!O7X=zW4eA-4zYxMAGn`Q!$_d=Zh z3IB8-17!C@T++uc5b3@0G+)}*PyRAqWHiF)4|(x;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~TNrk$oQJ;U`%tHo8U_#%Nmg`6eDofPsY&!w1~KLl+2R++1hB`b`|7eXaOH-AlO zRlC zpgyQ+99^N=otl#k!@!z7ny~FMEyCyArfxENSxnD)YGF6Vy!-k(daXC+)QQzJ?0$Y# zZPmF)WB!a#=WQRv#s Filtre - + Minor Mineur - + Secondary Secondaire - + Main Principal - + Characters Personnages - + Texts Textes @@ -1346,47 +1346,47 @@ des lignes: outlineModel - + Title Titre - + POV POV - + Label Label - + Status Status - + Compile Compilation - + Word count Nombre de mots - + Goal Goal - + {} words / {} ({}) {} mots / {} ({}) - + {} words {} mots @@ -1542,24 +1542,109 @@ des lignes: references - + Unknown reference: {}. Référence inconnue: {}. - + Text: <b>{}</b> Texte: <b>{}</b> - + Character: <b>{}</b> Personnage: <b>{}</b> + + + Basic infos + Informations générales + + + + Detailed infos + Informations détaillées + + + + POV of: + POV de: + + + + Referenced in: + Référencé dans: + + + + Motivation + Motivation + + + + Goal + Goal + + + + Conflict + Conflit + + + + Epiphany + Épiphanie + + + + Short summary + Résumé court + + + + Longer summary + Résumé long + + + + Path: + Chemin: + + + + Stats: + Stats: + + + + POV: + POV: + + + + Status: + Status: + + + + Label: + Label: + + + + Short summary: + Résumé court: + + + + Long summary: + Résumé long: + - None - Aucun + Notes: + Notes: diff --git a/src/models/outlineModel.py b/src/models/outlineModel.py index 4209f136..53c889c1 100644 --- a/src/models/outlineModel.py +++ b/src/models/outlineModel.py @@ -55,6 +55,14 @@ class outlineModel(QAbstractItemModel): item = index.internalPointer() return item.ID() + def findItemsByPOV(self, POV): + "Returns a list of IDs of all items whose POV is ``POV``." + return self.rootItem.findItemsByPOV(POV) + + def findItemsContaining(self, text, column): + "Returns a list of IDs of all items containing ``text`` in column ``column``." + return self.rootItem.findItemsContaining(text, column) + def getIndexByID(self, ID): "Returns the index of item whose ID is ``ID``. If none, returns QModelIndex()." def search(item): @@ -630,6 +638,12 @@ class outlineItem(): def POV(self): return self.data(Outline.POV.value) + def status(self): + return self.data(Outline.status.value) + + def label(self): + return self.data(Outline.label.value) + def path(self): "Returns path to item as string." if self.parent().parent(): @@ -737,4 +751,28 @@ class outlineItem(): path = self.data(Outline.ID.value) if self.parent().parent(): path = "{}:{}".format(self.parent().pathToItem(), path) - return path \ No newline at end of file + return path + + def findItemsByPOV(self, POV): + "Returns a list of IDs of all subitems whose POV is ``POV``." + lst = [] + if self.POV() == POV: + lst.append(self.ID()) + + for c in self.children(): + lst.extend(c.findItemsByPOV(POV)) + + return lst + + def findItemsContaining(self, text, column): + """Returns a list if IDs of all subitems + containing ``text`` in column ``column``. + """ + lst = [] + if text in self.data(column): + lst.append(self.ID()) + + for c in self.children(): + lst.extend(c.findItemsContaining(text, column)) + + return lst \ No newline at end of file diff --git a/src/models/persosModel.py b/src/models/persosModel.py index e5e86f87..270485bf 100644 --- a/src/models/persosModel.py +++ b/src/models/persosModel.py @@ -165,5 +165,13 @@ class persosModel(QStandardItemModel): rm.reverse() for r in rm: perso.takeRow(r) - + + def listPersoInfos(self, index): + infos = [] + for i in range(self.rowCount(index)): + name = self.data(index.child(i, Perso.infoName.value)) + val = self.data(index.child(i, Perso.infoData.value)) + infos.append((name, val)) + + return infos \ No newline at end of file diff --git a/src/models/references.py b/src/models/references.py index 5e647ab3..c6b55e6d 100644 --- a/src/models/references.py +++ b/src/models/references.py @@ -22,15 +22,33 @@ def infoForRef(ref): item = idx.internalPointer() - #

Status: {status}

- #

Label: {label}

- + #Titles + pathTitle = qApp.translate("references", "Path:") + statsTitle = qApp.translate("references", "Stats:") + POVTitle = qApp.translate("references", "POV:") + statusTitle = qApp.translate("references", "Status:") + labelTitle = qApp.translate("references", "Label:") + ssTitle = qApp.translate("references", "Short summary:") + lsTitle = qApp.translate("references", "Long summary:") + notesTitle = qApp.translate("references", "Notes:") + + POV = "" if item.POV(): POV = "{text}".format( ref="::C:{}::".format(item.POV()), text=mainWindow().mdlPersos.getPersoNameByID(item.POV())) + + status = item.status() + if status: + status = mainWindow().mdlStatus.item(int(status), 0).text() else: - POV = qApp.translate("references", "None") + status = "" + + label = item.label() + if label: + label = mainWindow().mdlLabels.item(int(label), 0).text() + else: + label = "" path = item.pathID() pathStr = [] @@ -40,28 +58,125 @@ def infoForRef(ref): text=title)) path = " > ".join(pathStr) + ss = item.data(Outline.summarySentance.value) + ls = item.data(Outline.summaryFull.value) + notes = item.data(Outline.notes.value) + text = """

{title}

-

Path: {path}

-

Stats: {stats}

-

POV: {POV}

-

Short summary: {ss}

-

Long summary: {ls}

-

Notes: {notes}

+

{pathTitle} {path}

+

{statsTitle} {stats}
+ {POV} + {status} + {label}

+ {ss} + {ls} + {notes} """.format( title=item.title(), + pathTitle=pathTitle, path=path, + statsTitle=statsTitle, stats=item.stats(), - POV=POV, - ss=item.data(Outline.summarySentance.value).replace("\n", "
"), - ls=item.data(Outline.summaryFull.value).replace("\n", "
"), - notes=linkifyAllRefs(item.data(Outline.notes.value)).replace("\n", "
")) + POV="{POVTitle} {POV}
".format( + POVTitle=POVTitle, + POV=POV) if POV else "", + status="{statusTitle} {status}
".format( + statusTitle=statusTitle, + status=status) if status else "", + label="{labelTitle} {label}

".format( + labelTitle=labelTitle, + label=label) if label else "", + ss="

{ssTitle} {ss}

".format( + ssTitle=ssTitle, + ss=ss.replace("\n", "
")) if ss else "", + ls="

{lsTitle}
{ls}

".format( + lsTitle=lsTitle, + ls=ls.replace("\n", "
")) if ls else "", + notes="

{notesTitle}
{notes}

".format( + notesTitle=notesTitle, + notes=linkifyAllRefs(notes).replace("\n", "
")) if notes else "", + ) return text elif _type == "C": m = mainWindow().mdlPersos - name = m.item(int(_ref), Perso.name.value).text() - return "

{}

".format(name) + index = m.getIndexFromID(_ref) + name = m.name(index.row()) + + # Titles + basicTitle = qApp.translate("references", "Basic infos") + detailedTitle = qApp.translate("references", "Detailed infos") + POVof = qApp.translate("references", "POV of:") + referencedIn = qApp.translate("references", "Referenced in:") + + # basic infos + basic = [] + for i in [ + (Perso.motivation, qApp.translate("references", "Motivation"), False), + (Perso.goal, qApp.translate("references", "Goal"), False), + (Perso.conflict, qApp.translate("references", "Conflict"), False), + (Perso.epiphany, qApp.translate("references", "Epiphany"), False), + (Perso.summarySentance, qApp.translate("references", "Short summary"), True), + (Perso.summaryPara, qApp.translate("references", "Longer summary"), True), + ]: + val = m.data(index.sibling(index.row(), i[0].value)) + if val: + basic .append("{title}:{n}{val}".format( + title=i[1], + n = "\n" if i[2] else " ", + val=val)) + basic = "
".join(basic) + + # detailed infos + detailed = [] + for _name, _val in m.listPersoInfos(index): + detailed.append("{}: {}".format( + _name, + _val)) + detailed = "
".join(detailed) + + # list scenes of which it is POV + oM = mainWindow().mdlOutline + lst = oM.findItemsByPOV(_ref) + + listPOV = "" + for t in lst: + idx = oM.getIndexByID(t) + listPOV += "
  • {text}".format( + link="::T:{}::".format(t), + text=oM.data(idx, Outline.title.value)) + + # List scences where character is referenced + listRefs = "" + lst = oM.findItemsContaining(ref, Outline.notes.value) + for t in lst: + idx = oM.getIndexByID(t) + listRefs += "
  • {text}".format( + link="::T:{}::".format(t), + text=oM.data(idx, Outline.title.value)) + + text = """

    {name}

    + {basicInfos} + {detailedInfos} + {POV} + {references} + """.format( + name=name, + basicInfos="

    {basicTitle}

    {basic}".format( + basicTitle=basicTitle, + basic=basic) if basic else "", + detailedInfos="

    {detailedTitle}

    {detailed}".format( + detailedTitle=detailedTitle, + detailed=detailed) if detailed else "", + POV="

    {POVof}

      {listPOV}
    ".format( + POVof=POVof, + listPOV=listPOV) if listPOV else "", + references="

    {referencedIn}

      {listRefs}
    ".format( + referencedIn=referencedIn, + listRefs=listRefs) if listRefs else "", + ) + return text else: return qApp.translate("references", "Unknown reference: {}.").format(ref) diff --git a/src/ui/cheatSheet.py b/src/ui/cheatSheet.py index 119a9700..6b393a2e 100644 --- a/src/ui/cheatSheet.py +++ b/src/ui/cheatSheet.py @@ -24,6 +24,7 @@ class cheatSheet(QWidget, Ui_cheatSheet): self.list.setItemDelegate(self.listDelegate) self.list.itemActivated.connect(self.showInfos) self.view.linkActivated.connect(self.openLink) + self.view.linkHovered.connect(self.linkHovered) self.outlineModel = None self.persoModel = None @@ -104,6 +105,10 @@ class cheatSheet(QWidget, Ui_cheatSheet): def openLink(self, link): openReference(link) + def linkHovered(self, link): + if link: + QToolTip.showText(QCursor.pos(), tooltipForRef(link)) + def keyPressEvent(self, event): if event.key() in [Qt.Key_Up, Qt.Key_Down]: self.list.keyPressEvent(event)