Commit 6f8d3c24 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add window to display global variables

Reuse the ASN.1 Editor tree view to display the shared library internal
variables.
parent f4c9cfdf
......@@ -31,7 +31,7 @@ ASN1TYPE = Qt.UserRole
class myTextEdit(QTextEdit):
''' Customized text editor that contains a context menu for loading data from a file '''
def __init__(self, parent=None):
QTextEdit.__init__(self, parent)
super(myTextEdit, self).__init__(parent)
def contextMenuEvent(self, event):
''' When the context menu is open, add the Load from file action and open the menu '''
......@@ -65,7 +65,7 @@ reads the value from the editor and place it back in the model '''
choice = Signal(QModelIndex, int, int)
def __init__(self, oParent=None):
QStyledItemDelegate.__init__(self, oParent)
super(TreeDelegate, self).__init__(oParent)
def createEditor(self, parent, option, index):
''' Define the delegate (editor) to use for a given cell.
......@@ -192,7 +192,7 @@ class asn1Editor(QTreeView):
msc = Signal(unicode, unicode)
def __init__(self, parent=None):
QTreeView.__init__(self, parent)
super(asn1Editor, self).__init__(parent)
self.model = QStandardItemModel(1, 4)
self.model.setHorizontalHeaderLabels(['Field', 'Type', 'Constraints', 'Value'])
self.delegate = TreeDelegate()
......@@ -229,38 +229,39 @@ class asn1Editor(QTreeView):
self.setColumnHidden(1, False)
self.setColumnHidden(2, False)
def setAsn1Model(self, dataview):
def setAsn1Model(self, dataview, row=0):
self.item = dataview
self.rootItem = self.addItem(self.item)
self.treeItem = self.rootItem["item"]
rootItem = self.addItem(self.item)
self.treeItem = rootItem["item"]
self.model.setItem(0, 1, QStandardItem(self.rootItem["type"]))
self.model.setItem(0, 2, QStandardItem(self.rootItem["constraint"]))
self.model.setItem(0, 3, QStandardItem(self.rootItem["value"]))
self.model.setItem(row, 1, QStandardItem(rootItem["type"]))
self.model.setItem(row, 2, QStandardItem(rootItem["constraint"]))
self.model.setItem(row, 3, QStandardItem(rootItem["value"]))
# Add the item to the actual tree. 0,0 = 1st row, 1st column
self.model.setItem(0, 0, self.treeItem)
self.model.setItem(row, 0, self.treeItem)
self.setWindowTitle('ASN.1 Variable editor')
self.hideUnusedFields(self.treeItem, True)
self.hideUnusedFields(self.treeItem, start=True, row=row)
self.setColumnWidth(0, 200)
self.setColumnWidth(1, 150)
self.expandAll()
return rootItem["item"]
def hideUnusedFields(self, root, start=False):
def hideUnusedFields(self, root, start=False, row=0):
''' Hide CHOICE unselected fields and SEQUENCE OF out-of-range fields '''
rootType = self.model.item(0, 1).text()
rootType = self.model.item(row, 1).text()
if rootType == 'CHOICE' and start:
choices = self.model.item(0, 3).data(CHOICE_LIST)
currValue = self.model.item(0, 3).text()
choices = self.model.item(row, 3).data(CHOICE_LIST)
currValue = self.model.item(row, 3).text()
for j in range(len(choices)):
if currValue == choices[j]:
break
rowIndex = self.model.item(0).index()
rowIndex = self.model.item(row).index()
self.choiceDisplay(rowIndex, len(choices), j)
elif rootType == 'SEQOF' and start:
maxValue = self.model.item(0, 3).data(MAX_RANGE)
currValue = self.model.item(0, 3).text()
rowIndex = self.model.item(0).index()
maxValue = self.model.item(row, 3).data(MAX_RANGE)
currValue = self.model.item(row, 3).text()
rowIndex = self.model.item(row).index()
self.seqofDisplay(rowIndex, currValue, maxValue)
if root.hasChildren():
......@@ -354,17 +355,17 @@ class asn1Editor(QTreeView):
pass
return value
def getVariable(self):
def getVariable(self, row=0):
''' Read the ASN.1 variable from the tree editor '''
root = self.treeItem
name = root.text()
asnType = self.model.item(0, 1).text()
asnType = self.model.item(row, 1).text()
if asnType == 'SEQOF':
nbRows = int(self.model.item(0, 3).text())
nbRows = int(self.model.item(row, 3).text())
value = self.parseModel(root, nbRows)
return {name: value}
elif asnType == 'CHOICE':
value = self.model.item(0, 3).text()
value = self.model.item(row, 3).text()
choiceValue = self.parseModel(root)
return {name: {"Choice": value, value: choiceValue[value]}}
else:
......@@ -410,40 +411,34 @@ class asn1Editor(QTreeView):
child.setText(str(len(value)))
self.updateModel(root.child(i), value, len(value))
def updateVariable(self, var):
def updateVariable(self, var, row=0, root=None):
''' Update the variable value - used when loading a TC or receiving a TM '''
self.log.debug("Entering updateVariable")
root = self.treeItem
root = root or self.treeItem
name = root.text()
value = var[name]
asnType = self.model.item(0, 1).text()
asnType = self.model.item(row, 1).text()
if asnType == 'SEQOF':
self.model.item(0, 3).setText(str(len(value)))
self.model.item(row, 3).setText(str(len(value)))
self.updateModel(root, var[name], len(value))
elif asnType == 'CHOICE':
self.model.item(0, 3).setText(str(value['Choice']))
self.model.item(row, 3).setText(str(value['Choice']))
self.updateModel(root, value)
elif asnType in ('INTEGER', 'REAL', 'STRING', 'BOOLEAN'):
self.model.item(0, 3).setText(str(value))
self.model.item(row, 3).setText(str(value))
elif asnType == 'ENUMERATED':
self.model.item(0, 3).setText(value['Enum'])
self.model.item(row, 3).setText(value['Enum'])
else: # SEQUENCE or SET
self.log.debug("E1")
self.updateModel(root, value)
self.log.debug("L1")
if asnType in ('INTEGER', 'REAL', 'SEQOF'):
plotters = self.model.item(0, 3).data(PLOTTERS)
plotters = self.model.item(row, 3).data(PLOTTERS)
if plotters != None:
for plotter in plotters:
self.plotterBackend.updatePlot(plotter, value)
self.hideUnusedFields(root, True)
if self.plotterBackend is not None:
self.log.debug("Calling plotterBackend.refresh()")
self.plotterBackend.refresh()
self.log.debug("Done calling plotterBackend.refresh()")
# Inform the thread to update the tree (expand all branches)
self.expandTree.emit()
self.log.debug("Leaving updateVariable")
def tmToEditor(self, pythonVar):
''' Check validity of a TM and update the viewer with the value '''
......@@ -814,5 +809,5 @@ class asn1Editor(QTreeView):
class asn1Viewer(asn1Editor):
''' TM Viewing class. Fields are not editable '''
def __init__(self, parent=None):
asn1Editor.__init__(self, parent)
super(asn1Viewer, self).__init__(parent)
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
......@@ -278,18 +278,6 @@ def gui():
mscButton.triggered.connect(msc.startStop)
myWidget.mscTrigger.connect(msc.startStop)
# Create a dock to handle the display of SDL diagrams
try:
sdl = sdlHandler(myWidget)
sdl.dll = dll
except IOError:
log.info('SDL viewer not available')
sdl = None
else:
sdlButton = toolbar.addAction('SDL')
sdlButton.triggered.connect(sdl.startStop)
# find dockable widgets (containing TM and TC editors)
docks = myWidget.findChildren(QDockWidget)
firstTC = None
......@@ -317,6 +305,18 @@ def gui():
#newDock.setFloating(True)
#myWidget.addDockWidget(Qt.RightDockWidgetArea, newDock)
# Create a dock to handle the display of SDL diagrams
try:
sdl = sdlHandler(myWidget)
sdl.dll = dll
except IOError:
log.info('SDL viewer not available')
sdl = None
else:
sdlButton = toolbar.addAction('SDL')
sdlButton.triggered.connect(sdl.startStop)
# Set the ASN.1 data type of each TC editor
for editor in myEdits:
# Enable mouse tracking - to display tips in the status bar
......
......@@ -2,8 +2,8 @@
# Resource object code
#
# Created: Sat Dec 20 14:16:24 2014
# by: The Resource Compiler for PySide (Qt v4.8.6)
# Created: Wed Dec 24 16:44:55 2014
# by: The Resource Compiler for PySide (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
......
......@@ -20,6 +20,9 @@ import ctypes
from PySide.QtGui import QDockWidget
from PySide.QtCore import Slot, Qt
import asn1_value_editor
from standalone_editor import asn1sccToasn1ValueEditorTypes
try:
import opengeode
except ImportError:
......@@ -38,6 +41,7 @@ class sdlHandler(object):
def __init__(self, parent):
''' Startup: check if there are some SDL files in
the directory and try to parse them and build the widget '''
self.parent = parent
all_files = os.listdir('.')
pr_files = []
for each in all_files:
......@@ -57,18 +61,47 @@ class sdlHandler(object):
self.sdl_view = opengeode.SDL_View(self.sdl_scene)
opengeode.Statechart.render_statechart(self.sdl_scene, graph)
self.sdl_view.refresh()
self.dock = QDockWidget('SDL/Statechart Viewer', parent)
# Pointer to the shared library, set by gui.py
self._dll = None
self.dock = None
self.dock_state = None
self.asn1_editor = None
self.tree_items = {}
@property
def dll(self):
return self._dll
@dll.setter
def dll(self, value):
''' Set the DLL - initialize the docks '''
self._dll = value
self.dock = QDockWidget('SDL/Statechart Viewer', self.parent)
self.dock.setFloating(True)
self.dock.resize(400, 400)
self.dock.setObjectName('SDLViewer')
parent.addDockWidget(Qt.RightDockWidgetArea, self.dock)
self.parent.addDockWidget(Qt.RightDockWidgetArea, self.dock)
self.dock.setAllowedAreas(Qt.NoDockWidgetArea)
self.sdl_view.show()
self.dock.setWidget(self.sdl_view)
self.running = False
self.dock.hide()
# Pointer to the shared library, set by gui.py
self.dll = None
# Dock widget to display the internal state
self.asn1_editor = asn1_value_editor.asn1Editor(self.parent)
self.dock_state = QDockWidget('Internal state', self.parent)
self.dock_state.setFloating(True)
self.dock_state.resize(400, 400)
self.dock_state.setObjectName('InternalStateViewer')
self.parent.addDockWidget(Qt.RightDockWidgetArea, self.dock_state)
self.dock_state.setAllowedAreas(Qt.NoDockWidgetArea)
self.dock_state.setWidget(self.asn1_editor)
# Add the SDL variables to the ASN.1 editor
row = 0
for var, (sort, _) in self.proc.variables.viewitems():
dataview = self.proc.dataview
item = asn1sccToasn1ValueEditorTypes(dataview, var, sort)
self.tree_items[var] = self.asn1_editor.setAsn1Model(item, row)
row += 1
@Slot()
def startStop(self):
......@@ -76,8 +109,10 @@ class sdlHandler(object):
self.running = not self.running
if self.running:
self.dock.show()
self.dock_state.show()
else:
self.dock.hide()
self.dock_state.hide()
@Slot(unicode)
def change_state(self, new_state):
......@@ -93,7 +128,6 @@ class sdlHandler(object):
if not ASN1:
# The dataview must have been loaded to create ASN.1 native types
return
print 'Event!'
for var, (sort, _) in self.proc.variables.viewitems():
# get internal variables, translate them to swig, and print them
typename = sort.ReferencedTypeName.replace('-', '_')
......
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