manuskript/manuskript/ui/sldImportance.py

86 lines
2.4 KiB
Python
Raw Normal View History

2015-05-28 13:32:09 +12:00
#!/usr/bin/env python
#--!-- coding: utf8 --!--
2015-06-04 04:40:19 +12:00
from qt import *
2015-06-22 04:35:42 +12:00
from functions import *
2015-05-28 13:32:09 +12:00
from ui.sldImportance_ui import *
class sldImportance(QWidget, Ui_sldImportance):
2015-05-31 16:03:07 +12:00
importanceChanged = pyqtSignal(str)
2015-05-28 13:32:09 +12:00
def __init__(self, parent=None):
2015-06-24 04:22:39 +12:00
QWidget.__init__(self, parent)
2015-05-28 13:32:09 +12:00
self.setupUi(self)
2015-06-22 04:35:42 +12:00
self._column = 0
self._updating = False
self._index = None
2015-05-28 13:32:09 +12:00
2015-05-31 16:03:07 +12:00
self.lastValue = -1
2015-05-28 13:32:09 +12:00
self.sld.valueChanged.connect(self.changed)
self.setValue(0)
2015-05-31 16:03:07 +12:00
def getImportance(self):
return str(self.sld.value())
2015-05-28 13:32:09 +12:00
def changed(self, v):
val = [
2015-06-08 22:01:45 +12:00
self.tr("Minor"),
self.tr("Secondary"),
self.tr("Main"),
2015-05-28 13:32:09 +12:00
]
self.lbl.setText(val[v])
2015-05-31 16:03:07 +12:00
self.importanceChanged.emit(str(v))
2015-06-22 04:35:42 +12:00
if self._index and not self._updating:
if str(v) != self._model.data(self._index):
self._updating = True
self._model.setData(self._index, str(v))
self._updating = False
2015-05-28 13:32:09 +12:00
def setValue(self, v):
2015-06-08 08:06:57 +12:00
if v != self.lastValue:
2015-06-01 08:41:32 +12:00
self.sld.setValue(int(v) if v else 0)
self.changed(int(v) if v else 0)
2015-05-31 16:03:07 +12:00
self.lastValue = v
def setProperty():
pass
2015-06-22 04:35:42 +12:00
# MODEL / VIEW
def setColumn(self, column):
self._column = column
def setModel(self, model):
self._model = model
self._model.dataChanged.connect(self.update)
def update(self, topLeft, bottomRight):
if self._updating:
return
if self._index:
if topLeft.row() <= self._index.row() <= bottomRight.row():
self.updateValue()
def setCurrentModelIndex(self, index):
if index.isValid():
if index.column() != self._column:
index = index.sibling(index.row(), self._column)
self._index = index
self.updateValue()
def updateValue(self):
if self._index:
val = toInt(self._model.data(self._index))
if self.sld.value() != val:
self._updating = True
self.setValue(val)
self._updating = False
2015-05-31 16:03:07 +12:00
importance = pyqtProperty(str, fget=getImportance, fset=setValue, notify=importanceChanged)