Skip to content

Commit e5777bf

Browse files
committed
qtvcp -indicatedmixin Button: add double led option
A different style to show state - one of two LEDs
1 parent c6d1280 commit e5777bf

3 files changed

Lines changed: 94 additions & 16 deletions

File tree

8.68 KB
Loading

docs/src/gui/qtvcp-widgets.adoc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,12 +3038,13 @@ This class *modifies `QPushButton` behaviour*.
30383038

30393039
*`indicator_option`* _puts a 'LED' on the top of the button_.
30403040

3041-
.QtVCP `PushButton`: Indicated Action Button, LED Indicator Option
3042-
image::images/qtvcp_actionButton.png["QtVCP PushButton: Indicated Action Button, LED Indicator Option",scale="25%",align="center"]
3041+
.QtVCP `PushButton`: IndicatedPushButton Button, LED Indicator Option
3042+
image::images/qtvcp_indicatorButton.png["QtVCP IndicatedPushButton: Indicated Action Button, LED Indicator Option",scale="25%",align="center"]
30433043

30443044
//FIXME Better document IndicatedPushButton
30453045
// https://github.com/LinuxCNC/linuxcnc/blob/master/lib/python/qtvcp/widgets/simple_widgets.py#L317
30463046
It can be a _triangle_, _circle_, _top bar_, or _side bar_. +
3047+
The _triangle_ and _circle_ LEDs can display double vertical LEDs optionally each with it's own HAL pin. +
30473048
The _size_ and _position_ can be adjusted.
30483049

30493050
It will indicate:
@@ -3055,17 +3056,18 @@ It will indicate:
30553056
.Properties
30563057
These properties are available to customize the indicator (not all are applicable to every LED shape):
30573058

3059+
*`doubleIndicator`*:: with riangle or round LEDs add a second vertical LED.
30583060
*`on_color`*::
30593061
*`off_color`*::
3060-
*`flashIndicator`*::
3061-
*`flashRate`*::
3062-
*`indicator_size`*::
3063-
*`circle_diameter`*::
3064-
*`shape_option`*::
3065-
*`right_edge_offset`*::
3066-
*`top_edge_offset`*::
3067-
*`height_fraction`*::
3068-
*`width_fraction`*::
3062+
*`flashIndicator`*:: When the indicator is true, flash the LED on and off.
3063+
*`flashRate`*:: Rate of the flashing
3064+
*`indicator_size`*:: Size of triangle LED
3065+
*`circle_diameter`*:: Diameter of round LED
3066+
*`shape_option`*:: 0-4 LED shape type
3067+
*`right_edge_offset`*:: Space from right edge
3068+
*`top_edge_offset`*:: Space from top edge
3069+
*`height_fraction`*:: Used for bar Leds
3070+
*`width_fraction`*:: Used for bar Leds
30693071
*`corner_radius`*:: Indicator corner radius.
30703072

30713073
The LED indicator color can be defined in a _stylesheet_ with the following code added to the `.qss` file:

lib/python/qtvcp/widgets/indicatorMixIn.py

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class IndicatedMixIn( _HalWidgetBase):
2020
def __init__(self):
2121
super(IndicatedMixIn, self).__init__()
2222
self._indicator_state = False # Current State
23+
self._indicator2_state = False # Current State
2324
# if user want to block their signals
2425
self._external_block_signal = False
2526

@@ -35,6 +36,7 @@ def __init__(self):
3536

3637
# indicator LED data
3738
self.draw_indicator = False # Show LED
39+
self._doubleIndicator = False # show second ZED
3840
self._HAL_pin = False # control by HAL
3941
self._shape = 0 # 0 triangle, 1 circle
4042
self._size = .3 # triangle
@@ -50,6 +52,7 @@ def __init__(self):
5052
self._flashState = False
5153
# is flashing on?
5254
self._flashing = True
55+
self._flashing2 = True
5356
# should flash?
5457
self._flashOption = False
5558
self._flashRate = 200
@@ -111,6 +114,10 @@ def _hal_init(self):
111114
pname = self._pin_name_
112115
self.hal_pin_led = self.HAL_GCOMP_.newpin(pname + '-led', hal.HAL_BIT, hal.HAL_IN)
113116
self.hal_pin_led.value_changed.connect(lambda data: self.indicator_update(data))
117+
if self._doubleIndicator:
118+
self.hal_pin_led2 = self.HAL_GCOMP_.newpin(pname + '-led2', hal.HAL_BIT, hal.HAL_IN)
119+
self.hal_pin_led2.value_changed.connect(lambda data: self.indicator2_update(data))
120+
114121
elif self._ind_status:
115122
self._init_state_change()
116123
self._globalParameter = {'__builtins__' : None, 'MAIN_INSTANCE':self.QTVCP_INSTANCE_,
@@ -208,6 +215,7 @@ def _update(state):
208215
# update indicator to button state if halpin or status won't
209216
if self._HAL_pin is False and self._ind_status is False:
210217
self.indicator_update(state)
218+
self.indicator2_update(not state)
211219
# if using state labels option update the labels
212220
if self._state_text:
213221
self.setText(None)
@@ -386,6 +394,10 @@ def indicator_update(self, data):
386394
self._flashing = self._indicator_state = data
387395
self.update()
388396

397+
def indicator2_update(self, data):
398+
self._flashing2 = self._indicator2_state = data
399+
self.update()
400+
389401
# override paint function to first paint the stock button
390402
# then our indicator paint routine
391403
def paintEvent(self, event):
@@ -397,16 +409,29 @@ def paintEvent(self, event):
397409
def paintIndicator(self):
398410
p = QtGui.QPainter(self)
399411

400-
401412
if self._flashOption and self._flashing:
402413
if self._flashState:
403414
color = self._on_color
404415
else:
405416
color = self._off_color
406-
elif self._indicator_state:
407-
color = self._on_color
408417
else:
409-
color = self._off_color
418+
if self._indicator_state:
419+
color = self._on_color
420+
else:
421+
color = self._off_color
422+
423+
# second LED
424+
if self._flashOption and self._flashing2:
425+
if self._flashState:
426+
color2 = self._on_color
427+
else:
428+
color2 = self._off_color
429+
else:
430+
431+
if self._indicator2_state:
432+
color2 = self._on_color
433+
else:
434+
color2 = self._off_color
410435

411436
# right triangle
412437
if self._shape == 0:
@@ -428,6 +453,21 @@ def paintIndicator(self):
428453
p.drawLine(triangle.point(1), triangle.point(2))
429454
p.drawPolygon(triangle)
430455

456+
# second LED
457+
if self._doubleIndicator:
458+
bot_right = rect.bottomRight() - QtCore.QPoint(self._right_edge_offset,self._top_edge_offset)
459+
460+
gradient = QtGui.QLinearGradient(bot_right- QtCore.QPoint(size, 0), bot_right)
461+
gradient.setColorAt(0, QtCore.Qt.white)
462+
gradient.setColorAt(1, color2)
463+
p.setBrush(QtGui.QBrush(gradient))
464+
p.setPen(color2)
465+
466+
triangle = QtGui.QPolygon([bot_right, bot_right - QtCore.QPoint(size, 0),
467+
bot_right - QtCore.QPoint(0, size)])
468+
p.drawLine(triangle.point(1), triangle.point(2))
469+
p.drawPolygon(triangle)
470+
431471
# circle
432472
elif self._shape == 1:
433473
x = int(self.width() - self._diameter - self._right_edge_offset)
@@ -441,6 +481,18 @@ def paintIndicator(self):
441481
p.setRenderHint(QtGui.QPainter.Antialiasing, True)
442482
p.drawEllipse(x, y, self._diameter - 1, self._diameter - 1)
443483

484+
# second LED
485+
if self._doubleIndicator:
486+
y = self.height() - self._diameter - self._top_edge_offset
487+
gradient = QtGui.QRadialGradient(x + self._diameter / 2, y + self._diameter / 2,
488+
self._diameter * 0.4, self._diameter * 0.4, self._diameter * 0.4)
489+
gradient.setColorAt(0, QtCore.Qt.white)
490+
gradient.setColorAt(1, color2)
491+
p.setBrush(QtGui.QBrush(gradient))
492+
p.setPen(color2)
493+
p.setRenderHint(QtGui.QPainter.Antialiasing, True)
494+
p.drawEllipse(x, y, self._diameter - 1, self._diameter - 1)
495+
444496
# top bar
445497
elif self._shape == 2:
446498
rect = p.window()
@@ -491,7 +543,7 @@ def paintIndicator(self):
491543
else:
492544
size = int(self.height() * self._size)
493545

494-
gradient = QtGui.QLinearGradient(top_left- QtCore.QPoint(size, 0), top_left)
546+
gradient = QtGui.QLinearGradient(top_left + QtCore.QPoint(size, 0), top_left)
495547
gradient.setColorAt(0, QtCore.Qt.white)
496548
gradient.setColorAt(1, color)
497549
p.setBrush(QtGui.QBrush(gradient))
@@ -502,6 +554,20 @@ def paintIndicator(self):
502554
p.drawLine(triangle.point(1), triangle.point(2))
503555
p.drawPolygon(triangle)
504556

557+
# second LED
558+
if self._doubleIndicator:
559+
top_bot = rect.bottomLeft() - QtCore.QPoint(self._right_edge_offset, self._top_edge_offset)
560+
gradient = QtGui.QLinearGradient(top_bot + QtCore.QPoint(size, 0), top_bot)
561+
gradient.setColorAt(0, QtCore.Qt.white)
562+
gradient.setColorAt(1, color2)
563+
p.setBrush(QtGui.QBrush(gradient))
564+
p.setPen(color2)
565+
566+
triangle = QtGui.QPolygon([top_bot, top_bot + QtCore.QPoint(size, 0),
567+
top_bot - QtCore.QPoint(0, size)])
568+
p.drawLine(triangle.point(1), triangle.point(2))
569+
p.drawPolygon(triangle)
570+
505571
def set_indicator(self, data):
506572
self.draw_indicator = data
507573
self.update()
@@ -589,6 +655,15 @@ def reset_indicator_size(self):
589655
self._size = 0.3
590656
self.update()
591657

658+
def set_doubleIndicator(self, data):
659+
self._doubleIndicator = data
660+
self.update()
661+
def get_doubleIndicator(self):
662+
return self._doubleIndicator
663+
def reset_doubleIndicator(self):
664+
self._doubleIndicator = True
665+
self.update()
666+
592667
def set_circle_diameter(self, data):
593668
self._diameter = data
594669
self.update()
@@ -686,6 +761,7 @@ def reset_pin_name(self):
686761

687762
pin_name = QtCore.pyqtProperty(str, get_pin_name, set_pin_name, reset_pin_name)
688763
indicator_option = QtCore.pyqtProperty(bool, get_indicator, set_indicator, reset_indicator)
764+
doubleIndicator = QtCore.pyqtProperty(bool, get_doubleIndicator, set_doubleIndicator, reset_doubleIndicator)
689765
indicator_HAL_pin_option = QtCore.pyqtProperty(bool, get_HAL_pin, set_HAL_pin, reset_HAL_pin)
690766
indicator_status_option = QtCore.pyqtProperty(bool, get_ind_status, set_ind_status, reset_ind_status)
691767
checked_state_text_option = QtCore.pyqtProperty(bool, get_state_text, set_state_text, reset_state_text)

0 commit comments

Comments
 (0)