Commit ff4ea20b authored by Maxime Perrotin's avatar Maxime Perrotin

Refactor the user widgets customisation capability

parent fd3eb6ea
......@@ -3,17 +3,13 @@ This directory contains the code for the ASN.1 Value editor:
- the standalone ASN.1 value editor, which can be used from the command line (or from another python module)
- code for communication using UDP packets instead of the TASTE message queues
** WARNING **
This version is different than the one present in the old Subversion repos
It contains a setup.py and is meant to be installed using the Python way:
Install with pip:
$ pip2 install --user --upgrade .
$ sudo make install
If needed, after modifications, use "make" to update the Qt resource file
This command will update the Qt resource file and call: python setup.py install --record
The auto-generated GUIs make use of the speedometer and of the MSC Editor/Viewer.
* You must install them first *
The auto-generated GUIs make use of the speedometer and of the MSC Editor/Viewer
* You must install them first
Usage for the standalone editor:
......@@ -27,13 +23,14 @@ Or with a default value (make sure you use quote):
$ standalone_editor.py -a test/TPos.asn -t T-POS -d 'myIntSetOf: { 1, 2, 3, 4, 1 }'
(c) European Space Agency
(c) 2012-2019 European Space Agency
Author: Maxime Perrotin
LICENSE: LGPL - see LICENSE file
CHANGELOG:
1.8.0 - Refactor the UserWidgets, allowing easier customisation of TM/TC handling
1.7.8 - Minor fix in Scenario.py
1.7.7 - Workaround pyside bug raising Overflow error for 64 bits numbers
1.7.5 - Better compatibility with old versions of DMT not supporting Optional fields
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
''' User can customise the TASTE auto-generated GUIs using by modifying this
module.
There are two base class: TC and TM
TC correspond to ASN.1 messages sent from the GUI to the application
and TM is the opposite.
Creat subclasses, they will be dynamically loaded and the widget will
be placed in a docking window.
''' This module illustrates how to create custom GUI widgets
to process custom TM and TC handlers.
It makes a connection to an SQL database generated for a TASTE project
using the command "taste-create-database", and offers the following
options:
- received TM can be stored in the database
- TC can be saved and picked from the database
(c) 2016-2019 European Space Agency
'''
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__version__ = "1.0"
__url__ = "http://taste.tuxfamily.org"
__url__ = "https://taste.tools"
import sys
import os
......@@ -26,58 +23,12 @@ import importlib
from PySide.QtCore import (QObject, Signal, Slot, Qt, QTimer)
import PySide.QtGui as QtGui
from UserWidgetsCommon import TM, TC
# User must list explicitly the classes he wants to expose to the GUI:
__all__ = ['SQLTelecommands', 'SQLTelemetries', 'SQLStoreTelecommand']
class TM(QtGui.QDockWidget, QObject):
''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
value is updated (through a Qt slot)
'''
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
self.setObjectName(self.name)
self.setWindowTitle("Select TC")
self.show()
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
pass
class TC(QtGui.QDockWidget, QObject):
''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
and to automatically send it to the application.
Example of uses: Buttons, SQL interface...
Define your widget and send signals at will.
'''
send = Signal()
update = Signal()
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
self.setObjectName(self.name)
self.show()
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
def connect_to_db():
'''
This will fetch all _model classes in global scope,
......@@ -274,12 +225,3 @@ class SQLStoreTelecommand(TC):
if __name__ == '__main__':
print 'This module can only be imported from the main TASTE guis'
sys.exit(-1)
#
# obsolete tests
#
#a = SQLTelecommands('MyInteger')
#assert a.sql2asn1(1).Get() == 22L
#b = db_module.MyInteger()
#b.Set(15)
#c = SQLTelemetries()
#c.update(b)
#!/usr/bin/python
# -*- coding: utf-8 -*-
''' User can customise the TASTE auto-generated GUIs using this module
There are two base class: TC and TM
TC correspond to ASN.1 messages sent from the GUI to the application
and TM is the opposite.
Create subclasses in an optional UserWidgets.py module placed in the
directory from which you run the GUI.
The subclases will be dynamically loaded and the widget will
be placed in a docking window provided you have specified them in the
__all__ array at the begining of the module.
(c) 2016-2019 European Space Agency / Maxime Perrotin
'''
import sys
import os
import importlib
from PySide.QtCore import (QObject, Signal, Slot, Qt, QTimer)
import PySide.QtGui as QtGui
class TM(QtGui.QDockWidget, QObject):
''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
value is updated (through a Qt slot)
'''
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
self.setObjectName(self.name)
self.setWindowTitle("Select TC")
self.show()
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
pass
class TC(QtGui.QDockWidget, QObject):
''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
and to automatically send it to the application.
Example of uses: Buttons, SQL interface...
Define your widget and send signals at will.
'''
send = Signal()
update = Signal()
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
self.setObjectName(self.name)
self.show()
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
......@@ -16,7 +16,7 @@
__author__ = "Maxime Perrotin"
__license__ = "LGPLv3"
__version__ = "1.7.8"
__version__ = "1.8.0"
__url__ = "https://taste.tools"
import sys
......
......@@ -14,9 +14,6 @@
License is LGPLv3 - Check the LICENSE file
"""
__url__ = "http://taste.tuxfamily.org"
import os
import traceback
import signal
......@@ -41,7 +38,17 @@ from asn1_value_editor import asn1Editor, asn1Viewer, __version__
from plotmanager import PlotManager
import vn
import UserWidgets
import UserWidgetsCommon
import SQLConnection_UserWidgets
try:
# user can create a file named UserWidgets.py in the folder containing the
# auto-generated GUI data. This file may contain custom TM and TC widgets
# for a specific project. Check SQLConnection_UserWidgets.py for guidance
import UserWidgets
except ImportError:
print ("No custom user wigets found")
# no user-defined widgets
UserWidgets = type ("no_user_widgets", (), {"__all__" : []})
try:
import speedometer
......@@ -418,12 +425,15 @@ def gui():
# retrieve user widgets for TM and TC
customTC, customTM = [], []
for each in UserWidgets.__all__:
widget = getattr(UserWidgets, each)
if widget.__base__ == UserWidgets.TC and widget.applicable():
customTC.append(widget)
elif widget.__base__ == UserWidgets.TM and widget.applicable():
customTM.append(widget)
for extraModule in (SQLConnection_UserWidgets, UserWidgets):
for each in extraModule.__all__:
widget = getattr(extraModule, each)
if(widget.__base__ == UserWidgetsCommon.TC
and widget.applicable()):
customTC.append(widget)
elif(widget.__base__ == UserWidgetsCommon.TM
and widget.applicable()):
customTM.append(widget)
if isinstance(editor, asn1Viewer): # TM Viewer
hasTM = True
......
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