26
26
import sys
27
27
from pathlib import Path
28
28
29
- from PyQt5 .QtWidgets import QApplication , QDialog
29
+ from PyQt5 .QtWidgets import (QApplication , QDialog , QHeaderView , QPushButton ,
30
+ QTableWidgetItem )
30
31
31
32
from Ui_CommandSystemDialog import Ui_CommandSystemDialog
32
33
@@ -43,23 +44,13 @@ def __init__(self):
43
44
self .setupUi (self )
44
45
self .move (800 , 100 )
45
46
46
- for n in range (21 ):
47
- btn = getattr (self , f"pushButton_{ n } " )
48
- btn .clicked .connect (lambda _ , x = n : self .ProcessButtonGeneric (x ))
49
-
50
- for l in range (22 ):
51
- btn = getattr (self , f"quickButton_{ l + 1 } " )
52
- btn .clicked .connect (lambda _ , x = l : self .ProcessQuickButton (x ))
53
-
54
47
#
55
48
# Processes 'Display Page' button
56
49
#
57
50
def ProcessButtonGeneric (self , idx ):
58
51
if cmdPageIsValid [idx ]:
59
- lePID = getattr (self , f'lineEditPktId_{ idx } ' )
60
- leAddr = getattr (self , f'lineEdit_{ idx } ' )
61
- pktId = lePID .text ()
62
- address = leAddr .text ()
52
+ pktId = self .tblCmdSys .item (idx , 1 ).text ()
53
+ address = self .tblCmdSys .item (idx , 2 ).text ()
63
54
launch_string = (
64
55
f'python3 { ROOTDIR } /{ cmdClass [0 ]} '
65
56
f'--title=\" { cmdPageDesc [idx ]} \" --pktid={ pktId } '
@@ -87,10 +78,8 @@ def checkParams(idx):
87
78
def ProcessQuickButton (self , idx ):
88
79
if cmdPageIsValid [idx ] and quickIndices [idx ] >= 0 :
89
80
qIdx = quickIndices [idx ]
90
- lePID = getattr (self , f'lineEditPktId_{ idx } ' )
91
- leAddr = getattr (self , f'lineEdit_{ idx } ' )
92
- pktId = lePID .text ()
93
- address = leAddr .text ()
81
+ pktId = self .tblCmdSys .item (idx , 1 ).text ()
82
+ address = self .tblCmdSys .item (idx , 2 ).text ()
94
83
95
84
# if requires parameters
96
85
if self .checkParams (qIdx ):
@@ -128,6 +117,7 @@ def ProcessQuickButton(self, idx):
128
117
#
129
118
app = QApplication (sys .argv )
130
119
Command = CommandSystem ()
120
+ tbl = Command .tblCmdSys
131
121
132
122
#
133
123
# Read in the contents of the telemetry packet definition
@@ -141,7 +131,7 @@ def ProcessQuickButton(self, idx):
141
131
reader = csv .reader (cmdfile , skipinitialspace = True )
142
132
for cmdRow in reader :
143
133
try :
144
- if cmdRow [0 ][ 0 ] != '#' :
134
+ if not cmdRow [0 ]. startswith ( '#' ) :
145
135
cmdPageIsValid .append (True )
146
136
cmdPageDesc .append (cmdRow [0 ])
147
137
cmdPageDefFile .append (cmdRow [1 ])
@@ -190,24 +180,30 @@ def ProcessQuickButton(self, idx):
190
180
#
191
181
# fill the data fields on the page
192
182
#
193
- for k in range (22 ):
194
- subsysBrowser = getattr (Command , f'SubsysBrowser_{ k } ' )
183
+ for k , desc in enumerate (cmdPageDesc ):
195
184
if cmdPageIsValid [k ]:
196
- lineEditPktId = getattr (Command , f'lineEditPktId_{ k } ' )
197
- lineEditAddress = getattr (Command , f'lineEdit_{ k } ' )
198
- quickButton = getattr (Command , f'quickButton_{ k + 1 } ' )
199
- subsysBrowser .setText (cmdPageDesc [k ])
200
- lineEditPktId .setText (hex (cmdPageAppid [k ]))
201
- lineEditAddress .setText (cmdPageAddress [k ])
185
+ tbl .insertRow (k )
186
+ for col , text in enumerate (
187
+ (desc , hex (cmdPageAppid [k ]), cmdPageAddress [k ])):
188
+ tblItem = QTableWidgetItem (text )
189
+ tbl .setItem (k , col , tblItem )
190
+ tblBtn = QPushButton ("Display Page" )
191
+ tblBtn .clicked .connect (
192
+ lambda _ , x = k : Command .ProcessButtonGeneric (x ))
193
+ tbl .setCellWidget (k , 3 , tblBtn )
202
194
quickIdx = - 1
203
195
try :
204
- quickIdx = subsys .index (cmdPageDesc [k ])
205
- quickButton .setText (quickCmd [quickIdx ])
196
+ quickIdx = subsys .index (desc )
206
197
except ValueError :
207
- pass # Ignore quick button
198
+ pass # Ignore quick button
199
+ else :
200
+ quickBtn = QPushButton (quickCmd [quickIdx ])
201
+ quickBtn .clicked .connect (
202
+ lambda _ , x = k : Command .ProcessQuickButton (x ))
203
+ tbl .setCellWidget (k , 4 , quickBtn )
208
204
quickIndices .append (quickIdx )
209
- else :
210
- subsysBrowser . setText ( "(unused)" )
205
+ tbl . horizontalHeader (). setSectionResizeMode ( QHeaderView . ResizeToContents )
206
+ tbl . horizontalHeader (). setStretchLastSection ( True )
211
207
212
208
#
213
209
# Display the page
0 commit comments