11from typing import Optional
2- from typing import Union
32from typing import List
43
54
@@ -61,6 +60,13 @@ def toggle_visibility(checkbox, widget):
6160 widget .setVisible (checkbox .isChecked ())
6261
6362
63+ def add_label (widget , label , label_before = True , horizontal = True ):
64+ if label_before :
65+ return combine_blocks (widget , label , horizontal = horizontal )
66+ else :
67+ return combine_blocks (label , widget , horizontal = horizontal )
68+
69+
6470class Button (QPushButton ):
6571 """Class for a button with a title and connected to a function when clicked. Inherits from QPushButton.
6672
@@ -492,20 +498,33 @@ def __init__(
492498 step = 1 ,
493499 parent : Optional [QWidget ] = None ,
494500 fixed : Optional [bool ] = True ,
501+ label : Optional [str ] = None ,
495502 ):
496503 """Args:
497504 min (Optional[int]): minimum value, defaults to 0
498505 max (Optional[int]): maximum value, defaults to 10
499506 default (Optional[int]): default value, defaults to 0
500507 step (Optional[int]): step value, defaults to 1
501508 parent: parent widget, defaults to None
502- fixed (bool): if True, sets the QSizePolicy of the spinbox to Fixed"""
509+ fixed (bool): if True, sets the QSizePolicy of the spinbox to Fixed
510+ label (Optional[str]): if provided, creates a label with the chosen title to use with the counter"""
503511
504512 super ().__init__ (parent )
505513 set_spinbox (self , min , max , default , step , fixed )
506514
515+ if label is not None :
516+ self .label = make_label (name = label )
517+
518+ # def setToolTip(self, a0: str) -> None:
519+ # self.setToolTip(a0)
520+ # if self.label is not None:
521+ # self.label.setToolTip(a0)
522+
523+ def get_with_label (self , horizontal = True ):
524+ return add_label (self , self .label , horizontal = horizontal )
525+
507526 def set_precision (self , decimals ):
508- """Sets the precision of the box to the speicifed number of decimals"""
527+ """Sets the precision of the box to the specified number of decimals"""
509528 self .setDecimals (decimals )
510529
511530 @classmethod
@@ -533,6 +552,7 @@ def __init__(
533552 step = 1 ,
534553 parent : Optional [QWidget ] = None ,
535554 fixed : Optional [bool ] = True ,
555+ label : Optional [str ] = None ,
536556 ):
537557 """Args:
538558 min (Optional[int]): minimum value, defaults to 0
@@ -544,6 +564,9 @@ def __init__(
544564
545565 super ().__init__ (parent )
546566 set_spinbox (self , min , max , default , step , fixed )
567+ self .label = None
568+ if label is not None :
569+ self .label = make_label (label , self )
547570
548571 @classmethod
549572 def make_n (
0 commit comments