Commit 2f0793c0 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Make the send button context dependent with SDL

Depending on the state of the SDL model, some buttons for sending
messages are now disabled, if the messages are not explicitely handled
by the model.
parent cda3d354
from PySide.QtCore import QSettings, Qt, Signal
from PySide.QtGui import QMainWindow, QDockWidget
from asn1_value_editor import PLOTTERS
from PySide.QtCore import QSettings, Qt, Signal, Slot
from PySide.QtGui import QMainWindow, QDockWidget, QPushButton
from asn1_value_editor import PLOTTERS, asn1Editor
class TasteMainWindow(QMainWindow):
......@@ -15,6 +15,23 @@ class TasteMainWindow(QMainWindow):
self.FVname = ''
self.msc = None
@Slot(list)
def allowed_editors(self, allowed_tc):
''' The SDL handler may disable some TCs depending on the internal
state of the SDL model '''
for editor in self.editors:
# Keep only editors, not viewers
dock = editor.parent()
buttons = editor.parent().findChildren(QPushButton)
try:
send_button, = [b for b in buttons
if b.objectName() == 'sendButton']
send_button.setEnabled(True if editor.objectName()
in allowed_tc else False)
except ValueError:
# No send button in case of telemetries
pass
def closeEvent(self, event):
''' Save application state before closing '''
settings = QSettings(self.FVname+".ini", QSettings.IniFormat)
......@@ -22,10 +39,11 @@ class TasteMainWindow(QMainWindow):
for dock in self.plotter.plotPool:
if dock._speedo:
minR, maxR = dock._speedo.getRange()
docks.append(dock._speedoName+':'+str(minR)+':'+str(maxR))
docks.append(dock._speedoName + ':' + str(minR) +
':' + str(maxR))
elif dock._tasteplot:
# Save plot configuration (axis, etc)
docks.append('Plot ' +
docks.append('Plot ' +
str(dock.handle) +
':' + str(dock._tasteplot.scrollingLimit) +
':' + str(dock._tasteplot.yAuto) +
......@@ -35,7 +53,7 @@ class TasteMainWindow(QMainWindow):
':' + str(dock._tasteplot.saveCsv) +
':' + str(dock._tasteplot.csvFile) +
':' + str(dock._tasteplot.savePng) +
':' + str(dock._tasteplot.pngFile))
':' + str(dock._tasteplot.pngFile))
settings.setValue('plots', docks)
settings.setValue('geometry', self.saveGeometry())
settings.setValue('windowState', self.saveState())
......
......@@ -320,6 +320,7 @@ def gui():
sdl.dll = dll
sdl.msc.connect(msc.addToMsc)
sdl.state_change.connect(msc.addCondition)
sdl.allowed_messages.connect(myWidget.allowed_editors)
except IOError:
log.info('SDL viewer not available')
sdl = None
......
......@@ -46,6 +46,7 @@ class sdlHandler(QObject):
msc = Signal(unicode, unicode)
# Signal sent when the state of the SDL model changes
state_change = Signal(unicode)
allowed_messages = Signal(list)
def __init__(self, parent):
''' Startup: check if there are some SDL files in
the directory and try to parse them and build the widget '''
......@@ -180,13 +181,27 @@ class sdlHandler(QObject):
setter = getattr(ASN1.DV, "SetDataFor_{}".format(typename))
setter(asn1_instance._ptr, swig_ptr)
gser = asn1_instance.GSER()
#print "GSER= '{}'".format(gser)
as_pyside = vn.fromValueNotationToPySide(var, gser)
#print "PYSIDE:", as_pyside
self.asn1_editor.updateVariable(as_pyside,
root=self.tree_items[var])
# Check if the SDL state has changed
self.check_state()
# Check if the SDL state has changed
self.check_state()
# Find the list of allowed TC based on the current state
inputs = self.proc.mapping[self.current_sdl_state.lower()]
allowed_tc = []
for each in inputs:
allowed_tc.extend(each.inputlist)
# Remove timers from the list
allowed_tc = set(allowed_tc) - set(self.proc.timers)
# Enable/disable the parameterless TC buttons accordingly
for tc, button in self.buttons.viewitems():
if tc in self.proc.timers:
# Ignore timers, they are handled differently
continue
button.setEnabled(True if tc in allowed_tc else False)
# Emit the list of allowed TC for the GUI to update other buttons
self.allowed_messages.emit(allowed_tc)
def start_simu(self):
'''
......
Supports Markdown
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