2015-07-07 01:00:22 +12:00
|
|
|
#!/usr/bin/env python
|
2016-02-07 00:34:22 +13:00
|
|
|
# --!-- coding: utf8 --!--
|
2015-07-07 01:00:22 +12:00
|
|
|
|
|
|
|
import collections
|
|
|
|
|
2016-02-07 00:34:22 +13:00
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from PyQt5.QtGui import QIcon
|
|
|
|
from PyQt5.QtWidgets import QStyledItemDelegate, QLineEdit, QMenu, QAction
|
|
|
|
|
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
class plotDelegate(QStyledItemDelegate):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QStyledItemDelegate.__init__(self, parent)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def sizeHint(self, option, index):
|
|
|
|
s = QStyledItemDelegate.sizeHint(self, option, index)
|
|
|
|
if s.width() < 200:
|
|
|
|
s.setWidth(200)
|
|
|
|
return s
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def createEditor(self, parent, option, index):
|
|
|
|
editor = QLineEdit(parent)
|
|
|
|
editor.setFrame(False)
|
|
|
|
editor.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
|
|
return editor
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def setEditorData(self, editor, index):
|
|
|
|
editor.setText(index.model().data(index))
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
self.txt = editor
|
|
|
|
self.menu = QMenu(editor)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
plotsTypes = collections.OrderedDict({
|
|
|
|
self.tr("General"): [
|
|
|
|
self.tr("Promise"),
|
|
|
|
self.tr("Problem"),
|
|
|
|
self.tr("Progress"),
|
|
|
|
self.tr("Resolution")
|
2016-02-07 00:34:22 +13:00
|
|
|
],
|
2015-07-07 01:00:22 +12:00
|
|
|
self.tr("Try / Fail"): [
|
2015-07-10 22:38:57 +12:00
|
|
|
self.tr("No and"),
|
|
|
|
self.tr("Yes but"),
|
2016-02-07 00:34:22 +13:00
|
|
|
],
|
2015-07-07 01:00:22 +12:00
|
|
|
self.tr("Freytag's pyramid"): [
|
|
|
|
self.tr("Exposition"),
|
|
|
|
self.tr("Rising action"),
|
|
|
|
self.tr("Climax"),
|
|
|
|
self.tr("Falling action"),
|
|
|
|
self.tr("Resolution"),
|
2016-02-07 00:34:22 +13:00
|
|
|
],
|
2015-07-07 01:00:22 +12:00
|
|
|
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"),
|
2016-02-07 00:34:22 +13:00
|
|
|
],
|
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
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"),
|
2016-02-07 00:34:22 +13:00
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
for name in plotsTypes:
|
|
|
|
m = QMenu(name, self.menu)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
for sub in plotsTypes[name]:
|
|
|
|
if sub == "---":
|
|
|
|
m.addSeparator()
|
|
|
|
else:
|
|
|
|
a = QAction(sub, m)
|
|
|
|
a.triggered.connect(self.submit)
|
|
|
|
m.addAction(a)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
self.menu.addMenu(m)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
editor.addAction(QIcon.fromTheme("list-add"), QLineEdit.LeadingPosition).triggered.connect(self.popupMenu)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def setModelData(self, editor, model, index):
|
|
|
|
val = editor.text()
|
|
|
|
model.setData(index, val)
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def popupMenu(self):
|
|
|
|
act = self.sender()
|
|
|
|
self.menu.popup(self.txt.parent().mapToGlobal(self.txt.geometry().bottomLeft()))
|
2016-02-07 00:34:22 +13:00
|
|
|
|
2015-07-07 01:00:22 +12:00
|
|
|
def submit(self):
|
|
|
|
act = self.sender()
|
2016-02-07 00:34:22 +13:00
|
|
|
self.txt.setText(act.text())
|