UserWidgets.py 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/python
# -*- coding: utf-8 -*-

''' Edit this module at will to create custom widgets that can send TC or
    receive TM - and do anything you like with the data.
    (c) 2016-2019 European Space Agency
'''

__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__url__ = "https://taste.tools"

import sys
import os
import importlib

17 18 19 20 21 22 23 24
try:
    from PySide.QtCore import (QObject, Signal, Slot, Qt, QTimer)
    from PySide.QtGui import *
except ImportError:
    # When using Python3/PySide2
    from PySide2.QtCore import *
    from PySide2.QtGui import *
    from PySide2.QtWidgets import *
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

from asn1_value_editor import UserWidgetsCommon

# ** IMPORTANT **
# you must list here the classes you want to expose to the GUI:
__all__ = ['CustomTC_Widget', 'CustomTM_Widget']


class CustomTC_Widget(UserWidgetsCommon.TC):
    ''' Fill / mimick this class to create a custom TC widget '''
    name = 'My TC Widget' # name on the GUI combo button

    def __init__(self, asn1_typename, parent):
        ''' Initialise the widget '''
        super(CustomTC_Widget, self).__init__(asn1_typename, parent)
        self._asn1_typename = asn1_typename

        # examples of widgets
43
        #self.widget = QListWidget()
44 45 46
        #self.widget.itemClicked.connect(self.select)
        #self.setWidget(self.widget)

47
        #self.widget = QPushButton(asn1_typename)
48 49 50 51 52 53 54 55 56 57 58
        #self.widget.clicked.connect(self.clicked))
        #self.setWidget(self.widget)

        # parent is the ASN.1 value editor
        self.parent = parent
        self.setWindowTitle("My Window")
        self.show()

    @staticmethod
    def applicable():
        ''' Return True to activate this widget '''
Maxime Perrotin's avatar
Maxime Perrotin committed
59 60 61 62 63 64
        return True

    @staticmethod
    def editorIsApplicable(editor):
        ''' Return true if this particular editor is compatible with this
        widget'''
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
        return False

    def select(self, item):
        ''' Called when user clicks on a line of the table '''
        #self.parent.asn1Instance.SetData(native_asn1scc._ptr)

    def clicked(self):
        ''' Called when user clicks on the button '''
        # Get the ASN.1 value from the database (in native an1scc format)
        # self.parent.getVariable(dest=self.parent.asn1Instance)

       #self.parent.tmToEditor(emit_msc=False)

    def onUpdateButtonClick(self, lineNb):
        ''' When user clicks on Update, the content of the selected TC will
        be used to feed the main GUI TC editor '''
        #self.update.emit(as_asn1)   # use signal to send data to the GUI

    def onSendButtonClick(self, lineNb):
        ''' When user clicks on Send, the selected TC will be sent to the
        running application '''
        #self.send.emit(as_asn1)   # use signal to send data to the GUI


class CustomTM_Widget(UserWidgetsCommon.TM):
    '''Save telemetries in the database'''
    name = 'My Widget'  # name for the combo button in the GUI

    def __init__(self, parent=None):
        ''' Initialise the widget '''
        super(CustomTM_Widget, self).__init__(parent)
        self.hide()

    @Slot()
    def new_tm(self):
        ''' Slot called when a TM has been received in the editor '''
        # Nothing to do, the update() function does nothing thread-related
        # that would need to be done here
        print('Recorded a new TM in the database')

    def update(self, value):
        ''' Receive ASN.1 value '''
        pass

    @staticmethod
    def applicable():
        ''' Return True to enable this widget '''
Maxime Perrotin's avatar
Maxime Perrotin committed
112 113 114 115 116 117
        return True

    @staticmethod
    def editorIsApplicable(editor):
        ''' Return true if this particular editor is compatible with this
        widget'''
118 119
        return False

Maxime Perrotin's avatar
Maxime Perrotin committed
120

121
if __name__ == '__main__':
122
    print('This module can only be imported from the main TASTE guis')
123
    sys.exit(-1)