@@ -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