Commit 16f6cf3f authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

GUIs: custom widget to store TC in databases

parent 7514e4b3
......@@ -27,7 +27,7 @@ from PySide.QtCore import (QObject, Signal, Slot, Qt)
import PySide.QtGui as QtGui
# User must list explicitly the classes he wants to expose to the GUI:
__all__ = ['SQLTelecommands', 'SQLTelemetries']
__all__ = ['SQLTelecommands', 'SQLTelemetries', 'SQLStoreTelecommand']
class TM(QtGui.QDockWidget, QObject):
......@@ -110,7 +110,6 @@ class SQLTelecommands(TC):
def __init__(self, asn1_typename, parent):
''' Initialise the widget '''
super(SQLTelecommands, self).__init__(asn1_typename, parent)
print 'Creating instance of SQLTelecommands'
if SQLTelecommands.session is None:
SQLTelecommands.session, SQLTelecommands.dbname = \
connect_to_db()
......@@ -189,7 +188,6 @@ class SQLTelemetries(TM):
def __init__(self, parent=None):
''' Initialise the widget '''
super(SQLTelemetries, self).__init__(parent)
print 'Creating instance of SQLTelemetries'
# to do here = display a window with two buttons:
# "start storing in DB", "stop storing in DB"
self.mode = 'recording'
......@@ -225,6 +223,47 @@ class SQLTelemetries(TM):
'''' check if there is a sql_db directory, return False otherwise '''
return os.path.isdir("sql_db")
class SQLStoreTelecommand(TC):
''' Store a telecommand in the database'''
name = 'Store TC in database'
session = None
dbname = None
def __init__(self, asn1_typename, parent):
''' Initialise the widget '''
super(SQLStoreTelecommand, self).__init__(asn1_typename, parent)
if SQLTelemetries.session is None:
SQLTelemetries.session, SQLTelemetries.dbname = \
connect_to_db()
self._asn1_typename = asn1_typename
self.widget = QtGui.QPushButton('Store {} in DB'.format(asn1_typename))
self.widget.clicked.connect(self.store_in_db)
self.setWidget(self.widget)
# parent is the ASN.1 value editor
self.parent = parent
self.setWindowTitle("Store TC in database")
@staticmethod
def applicable():
'''' check if there is a sql_db directory, return False otherwise '''
return os.path.isdir("sql_db")
def store_in_db(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)
klass = self._asn1_typename + "_SQL"
asn1_klass = getattr(db_module, klass, None)
if asn1_klass is None:
raise Exception(
"No class " + klass + " found in " + SQLTelemetries.dbname)
db_row = asn1_klass(self.parent.asn1Instance)
iid = db_row.save(SQLTelemetries.session)
SQLTelemetries.session.commit()
return iid
if __name__ == '__main__':
print 'This module can only be imported from the main TASTE guis'
sys.exit(-1)
......
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