Skip to content

Commit ff34393

Browse files
committed
qtvcp -test_led/test_button - add/update test panels
test_button: An indicated HAL button for testing with many options test_led: add ability to load a test button
1 parent 42c2918 commit ff34393

5 files changed

Lines changed: 391 additions & 0 deletions

File tree

lib/python/qtvcp/lib/aux_program_loader.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ def load_halscope(self, *args):
6464
def load_tooledit(self, filepath):
6565
p = os.popen("tooledit %s" % (filepath))
6666

67+
def load_test_button(self, *args):
68+
if args:
69+
self.load_haltool_args('halscope', args)
70+
p = os.popen("qtvcp {} test_button".format(args), "w")
71+
else:
72+
p = os.popen("qtvcp test_button", "w")
73+
74+
def load_test_led(self, *args):
75+
if args:
76+
p = os.popen("qtvcp {} test_led".format(args), "w")
77+
else:
78+
p = os.popen("qtvcp test_led", "w")
79+
6780
def keyboard_onboard(self, args="", width="", height=""):
6881
try:
6982
self.ob = subprocess.Popen(["onboard", args, width, height],
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>223</width>
10+
<height>49</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="minimumSize">
20+
<size>
21+
<width>223</width>
22+
<height>26</height>
23+
</size>
24+
</property>
25+
<property name="maximumSize">
26+
<size>
27+
<width>223</width>
28+
<height>16777215</height>
29+
</size>
30+
</property>
31+
<property name="windowTitle">
32+
<string>MainWindow</string>
33+
</property>
34+
<widget class="QWidget" name="centralwidget">
35+
<property name="sizePolicy">
36+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
37+
<horstretch>0</horstretch>
38+
<verstretch>0</verstretch>
39+
</sizepolicy>
40+
</property>
41+
<layout class="QHBoxLayout" name="horizontalLayout">
42+
<property name="spacing">
43+
<number>4</number>
44+
</property>
45+
<property name="leftMargin">
46+
<number>0</number>
47+
</property>
48+
<property name="topMargin">
49+
<number>0</number>
50+
</property>
51+
<property name="rightMargin">
52+
<number>0</number>
53+
</property>
54+
<property name="bottomMargin">
55+
<number>0</number>
56+
</property>
57+
<item>
58+
<widget class="ScreenOptions" name="screen_options">
59+
<property name="minimumSize">
60+
<size>
61+
<width>0</width>
62+
<height>0</height>
63+
</size>
64+
</property>
65+
<property name="maximumSize">
66+
<size>
67+
<width>16777215</width>
68+
<height>16777215</height>
69+
</size>
70+
</property>
71+
<property name="notify_option" stdset="0">
72+
<bool>false</bool>
73+
</property>
74+
<property name="catch_close_option" stdset="0">
75+
<bool>true</bool>
76+
</property>
77+
<property name="catch_errors_option" stdset="0">
78+
<bool>false</bool>
79+
</property>
80+
<property name="use_pref_file_option" stdset="0">
81+
<bool>false</bool>
82+
</property>
83+
<property name="embedded_program_option" stdset="0">
84+
<bool>false</bool>
85+
</property>
86+
<property name="messageDialog_option" stdset="0">
87+
<bool>false</bool>
88+
</property>
89+
<property name="closeDialog_option" stdset="0">
90+
<bool>false</bool>
91+
</property>
92+
<property name="entryDialogSoftkey_option" stdset="0">
93+
<bool>false</bool>
94+
</property>
95+
</widget>
96+
</item>
97+
</layout>
98+
</widget>
99+
<action name="actionColor">
100+
<property name="text">
101+
<string>Color</string>
102+
</property>
103+
</action>
104+
<action name="actionSound">
105+
<property name="checkable">
106+
<bool>true</bool>
107+
</property>
108+
<property name="checked">
109+
<bool>false</bool>
110+
</property>
111+
<property name="text">
112+
<string>Sound</string>
113+
</property>
114+
</action>
115+
<action name="actionAddLED">
116+
<property name="text">
117+
<string>AddLED</string>
118+
</property>
119+
</action>
120+
</widget>
121+
<customwidgets>
122+
<customwidget>
123+
<class>ScreenOptions</class>
124+
<extends>QWidget</extends>
125+
<header>qtvcp.widgets.screen_options</header>
126+
<container>1</container>
127+
</customwidget>
128+
</customwidgets>
129+
<resources/>
130+
<connections/>
131+
</ui>
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
############################
2+
# **** IMPORT SECTION **** #
3+
############################
4+
import sys
5+
from PyQt5.QtCore import *
6+
from PyQt5.QtGui import *
7+
from PyQt5.QtWidgets import *
8+
from qtvcp.core import Status
9+
from qtvcp.widgets.hal_selectionbox import HALSelectionBox
10+
from qtvcp.widgets.simple_widgets import PushButton
11+
from qtvcp.lib.aux_program_loader import Aux_program_loader
12+
13+
###########################################
14+
# **** instantiate libraries section **** #
15+
###########################################
16+
STATUS = Status()
17+
EXTPROG = Aux_program_loader()
18+
###################################
19+
# **** HANDLER CLASS SECTION **** #
20+
###################################
21+
22+
class HandlerClass:
23+
24+
########################
25+
# **** INITIALIZE **** #
26+
########################
27+
# widgets allows access to widgets from the qtvcp files
28+
# at this point the widgets and hal pins are not instantiated
29+
def __init__(self, halcomp,widgets,paths):
30+
self.w = widgets
31+
self.h = halcomp
32+
self.buttonDict = dict()
33+
34+
##########################################
35+
# Special Functions called from QTVCP
36+
##########################################
37+
38+
# at this point:
39+
# the widgets are instantiated.
40+
# the HAL pins are built but HAL is not set ready
41+
def initialized__(self):
42+
geom = self.w.frameGeometry()
43+
geom.moveCenter(QDesktopWidget().availableGeometry().center())
44+
self.w.setGeometry(geom)
45+
46+
if self.w.USEROPTIONS_ is not None:
47+
try:
48+
num = int(self.w.USEROPTIONS_[0])
49+
except:
50+
print('Error with test_button number selection - not a number - using 1')
51+
num = 1
52+
53+
if num >1:
54+
for i in range(num-1):
55+
self.addButton()
56+
# make window taller now
57+
x = self.w.geometry().x()
58+
y = self.w.geometry().y()
59+
w = self.w.geometry().width()
60+
h = self.w.geometry().height() + 37
61+
self.w.setGeometry(x,y,w,h)
62+
self.w.setMinimumHeight(h)
63+
64+
self.addButton()
65+
self.w.setWindowFlags(Qt.WindowStaysOnTopHint)
66+
self.w.setWindowTitle('{}'.format(self.h.comp.getprefix()))
67+
68+
# build a button/controls line
69+
def addButton(self):
70+
71+
# new toolbar added to window
72+
toolbar = QToolBar(self.w)
73+
self.w.addToolBar(Qt.LeftToolBarArea, toolbar)
74+
75+
# containers
76+
w = QWidget()
77+
w.setContentsMargins(0,0,0,0)
78+
hbox = QHBoxLayout(w)
79+
hbox.setContentsMargins(0,0,0,0)
80+
81+
# for button name
82+
le = QLineEdit()
83+
le.setText(self.h.comp.getprefix())
84+
85+
# HAL button to display state
86+
button = PushButton()
87+
button.setProperty('indicator_option',True)
88+
button._halpin_option = False
89+
button.hal_init('button')
90+
button.setMaximumWidth(30)
91+
92+
hbox.addWidget(button)
93+
hbox.addWidget(le)
94+
95+
# menu for controls
96+
menu = QMenu()
97+
menu.setMinimumWidth(259)
98+
99+
# Check option checkbutton
100+
actionCheck = QAction('Set Checkable',menu)
101+
actionCheck.setCheckable(True)
102+
actionCheck.triggered.connect(lambda w, b=(actionCheck,button): self.actionTriggered('Checkable',b))
103+
menu.addAction(actionCheck)
104+
105+
# color option launch button
106+
actionColor = QAction('Set Indicator Color',menu)
107+
actionColor.triggered.connect(lambda w, b=(actionColor,button): self.actionTriggered('Color',b))
108+
menu.addAction(actionColor)
109+
110+
# remember signal watched, line edit widget, button widget and last state
111+
self.buttonDict[button] = [None,le,None,button,False]
112+
113+
# button to pop menu
114+
btn = QPushButton('Opt')
115+
btn.setMaximumWidth(50)
116+
btn.setMenu(menu)
117+
118+
hbox.addWidget(btn)
119+
120+
# combo box for HAL pin selection
121+
cb = HALSelectionBox()
122+
cb.setShowTypes([cb.PINS,cb.SIGNALS])
123+
cb.setPinTypes([cb.HAL_BIT])
124+
cb.setSignalTypes([cb.HAL_BIT], driven = [False,True])
125+
cb.hal_init()
126+
cb.selectionUpdated.connect(lambda w: self.signalSelected(w,button))
127+
128+
# wrap combobox so as to add it to menu
129+
action = QWidgetAction(menu)
130+
action.setDefaultWidget(cb)
131+
#menu.addAction(action)
132+
133+
# HalMeter option launch button
134+
actionHalMeter = QAction('Load HalMeter',menu)
135+
actionHalMeter.triggered.connect(lambda w, b=(actionHalMeter,button): self.actionTriggered('HalMeter',b))
136+
menu.addAction(actionHalMeter)
137+
138+
# Led option launch button
139+
actionLed = QAction('Load Test Led',menu)
140+
actionLed.triggered.connect(lambda w, b=(actionLed,button): self.actionTriggered('Led',b))
141+
menu.addAction(actionLed)
142+
143+
# button to add another button toolbar
144+
actionAdd = QAction('Add Button',menu)
145+
actionAdd.triggered.connect(lambda b: self.actionTriggered('Add', None))
146+
menu.addAction(actionAdd)
147+
148+
toolbar.addWidget(w)
149+
150+
########################
151+
# callbacks from STATUS #
152+
########################
153+
154+
#######################
155+
# callbacks from form #
156+
#######################
157+
158+
def actionTriggered(self, widget,b=None):
159+
# b[0] is action button
160+
# b[1] is main button
161+
if widget == 'Add':
162+
# add a toolbar with button and controls
163+
self.addButton()
164+
# make window taller now
165+
x = self.w.geometry().x()
166+
y = self.w.geometry().y()
167+
w = self.w.geometry().width()
168+
h = self.w.geometry().height() + 37
169+
self.w.setGeometry(x,y,w,h)
170+
self.w.setMinimumHeight(h)
171+
elif widget == 'Checkable':
172+
b[1].setCheckable(b[0].isChecked())
173+
# kill existing signals - we need to change signal type
174+
b[1].disconnectSignals()
175+
# add new signals back
176+
b[1].connectSignals()
177+
elif widget == 'Color':
178+
# Get a color from the text dialog
179+
color = QColorDialog.getColor()
180+
b[1].setProperty('on_color',color)
181+
elif widget == 'HalMeter':
182+
EXTPROG.load_halmeter()
183+
elif widget == 'Led':
184+
EXTPROG.load_test_led()
185+
186+
#####################
187+
# general functions #
188+
#####################
189+
190+
def updateLabel(self,v):
191+
self.w.hallabel.setDisplay(v)
192+
193+
def signalSelected(self, sig,button):
194+
print('Watching:',sig)
195+
if sig != '':
196+
self.buttonDict[button][0] = sig
197+
return
198+
199+
#####################
200+
# KEY BINDING CALLS #
201+
#####################
202+
203+
###########################
204+
# **** closing event **** #
205+
###########################
206+
207+
##############################
208+
# required class boiler code #
209+
##############################
210+
211+
def __getitem__(self, item):
212+
return getattr(self, item)
213+
def __setitem__(self, item, value):
214+
return setattr(self, item, value)
215+
216+
217+
################################
218+
# required handler boiler code #
219+
################################
220+
221+
def get_handlers(halcomp,widgets,paths):
222+
return [HandlerClass(halcomp,widgets,paths)]

share/qtvcp/panels/test_led/test_led.ui

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@
3939
</sizepolicy>
4040
</property>
4141
<layout class="QHBoxLayout" name="horizontalLayout">
42+
<property name="spacing">
43+
<number>4</number>
44+
</property>
45+
<property name="leftMargin">
46+
<number>0</number>
47+
</property>
48+
<property name="topMargin">
49+
<number>0</number>
50+
</property>
51+
<property name="rightMargin">
52+
<number>0</number>
53+
</property>
54+
<property name="bottomMargin">
55+
<number>0</number>
56+
</property>
4257
<item>
4358
<widget class="ScreenOptions" name="screen_options">
4459
<property name="minimumSize">

0 commit comments

Comments
 (0)