Commit 430050bb authored by Maxime Perrotin's avatar Maxime Perrotin

Trigger gui update when choice index changes

parent f9cdffcb
......@@ -5,7 +5,7 @@
Main GUI widget
Copyright (c) 2012-2016 European Space Agency
Copyright (c) 2012-2018 European Space Agency
Designed and implemented by Maxime Perrotin
......@@ -16,11 +16,12 @@
__author__ = "Maxime Perrotin"
__license__ = "LGPLv3"
__version__ = "1.6.7"
__url__ = "http://taste.tuxfamily.org"
__version__ = "1.6.8"
__url__ = "https://taste.tools"
import sys
import logging
from functools import partial
try:
from PySide import *
......@@ -32,12 +33,12 @@ except ImportError as err:
import vn
MIN_RANGE = Qt.UserRole + 1
MAX_RANGE = Qt.UserRole + 2
MIN_RANGE = Qt.UserRole + 1
MAX_RANGE = Qt.UserRole + 2
CHOICE_LIST = Qt.UserRole + 1 # list of strings (enumerants)
INTMAP = Qt.UserRole + 5 # for enum/choice: map string-numerical value
PLOTTERS = Qt.UserRole + 4
ASN1TYPE = Qt.UserRole
PLOTTERS = Qt.UserRole + 4
ASN1TYPE = Qt.UserRole
class myTextEdit(QTextEdit):
......@@ -74,9 +75,9 @@ combo box, while INTEGERS values can be set using a spin box.
Three functions have been redefined:
(1) createEditor, which sets an editor to a cell, using the cell attributes
to learn about the ASN.1 basic type (stored in Qt.UserRole)
(2) SetEditorData, which is used at runtime to put the value in the given
(2) setEditorData, which is used at runtime to put the value in the given
editor when the user clicks on the cell
(3) SetModelData, which is called when the user is done with the editing: it
(3) setModelData, which is called when the user is done with the editing: it
reads the value from the editor and place it back in the model '''
seqof = Signal(QModelIndex, int, int)
choice = Signal(QModelIndex, int, int)
......@@ -86,8 +87,15 @@ reads the value from the editor and place it back in the model '''
def createEditor(self, parent, option, index):
''' Define the delegate (editor) to use for a given cell.
index.data() returns the actual value, and index.data(role) points to
some user data when role >= 32. 32 is Qt.UserRole. '''
index.data() returns the actual value, and index.data(role) points
to some user data when role >= 32. 32 is Qt.UserRole. '''
def update_model(editor, index, event):
''' Trigger an immediate update of the model and therefore of the
visible elements of the gui, when user changes a value in the
editor. For example when the CHOICE index changes, this makes sure
that the relevant choice data is updated without gaving to wait
for the user to click outside from the widget '''
self.setModelData(editor, index.model(), index)
# Check the (user-defined) type associated with the cell
asnType = index.data(ASN1TYPE)
if asnType == 'INTEGER':
......@@ -106,8 +114,10 @@ some user data when role >= 32. 32 is Qt.UserRole. '''
minVal = index.data(MIN_RANGE)
maxVal = index.data(MAX_RANGE)
editor.setRange(minVal, maxVal)
editor.valueChanged.connect(partial(update_model, editor, index))
elif asnType in ('ENUMERATED', 'CHOICE'):
editor = QComboBox(parent)
editor.activated.connect(partial(update_model, editor, index))
enumVal = index.data(CHOICE_LIST)
for val in enumVal:
editor.addItem(val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment