manuskript/src/models/references.py

78 lines
2.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
#--!-- coding: utf8 --!--
from qt import *
from enums import *
from functions import *
import re
def infoForRef(ref):
match = re.fullmatch("::(\w):(\d+?)::", ref)
if match:
_type = match.group(1)
_ref = match.group(2)
if _type == "T":
m = mainWindow().mdlOutline
idx = m.getIndexByID(_ref)
if not idx.isValid():
return qApp.translate("references", "Unknown reference: {}.").format(ref)
item = idx.internalPointer()
text = "<h1>{}</h1>".format(item.title())
text += "<b>Path:</b> {}<br>".format(item.path())
ss = item.data(Outline.summarySentance.value)
if ss:
text += "\n<b>Short summary:</b> {}<br>".format(ss)
ls = item.data(Outline.summaryFull.value)
if ls:
text += "\n<b>Long summary:</b> {}<br>".format(ls)
return text
elif _type == "C":
m = mainWindow().mdlPersos
name = m.item(int(_ref), Perso.name.value).text()
return "<h1>{}</h1>".format(name)
else:
2015-06-27 22:20:05 +12:00
return qApp.translate("references", "Unknown reference: {}.").format(ref)
def openReference(ref):
match = re.fullmatch("::(\w):(\d+?)::", ref)
if match:
_type = match.group(1)
_ref = match.group(2)
if _type == "C":
mw = mainWindow()
for i in range(mw.mdlPersos.rowCount()):
if mw.mdlPersos.item(i, Perso.ID.value).text() == _ref:
mw.tabMain.setCurrentIndex(2)
# FIXME: update after creating a custom persomodel
#mw.lstPersos.setCurrentRow(i)
return True
print("Ref not found")
return False
elif _type == "T":
mw = mainWindow()
index = mw.mdlOutline.getIndexByID(_ref)
if index.isValid():
mw.treeRedacOutline.setCurrentIndex(index)
return True
else:
print("Ref not found")
return False
print("Ref not implemented")
return False