Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
16f6cf3f
Commit
16f6cf3f
authored
Jul 20, 2016
by
Maxime Perrotin
Browse files
GUIs: custom widget to store TC in databases
parent
7514e4b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/UserWidgets.py
View file @
16f6cf3f
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment