@@ -6,11 +6,11 @@ class AnimatedButton(QPushButton):
66 def __init__ (self , text = "" , parent = None , is_secondary = False , is_destructive = False ):
77 super ().__init__ (text , parent )
88 self .setCursor (Qt .CursorShape .PointingHandCursor )
9-
9+
1010 self .default_color = QColor ("#4a9eff" )
1111 self .hover_color = QColor ("#5badff" )
1212 self .pressed_color = QColor ("#3a8eef" )
13-
13+
1414 if is_secondary :
1515 self .default_color = QColor ("#3c3c3c" )
1616 self .hover_color = QColor ("#4a4a4a" )
@@ -19,17 +19,17 @@ def __init__(self, text="", parent=None, is_secondary=False, is_destructive=Fals
1919 self .default_color = QColor (200 , 50 , 50 )
2020 self .hover_color = QColor (220 , 70 , 70 )
2121 self .pressed_color = QColor (180 , 40 , 40 )
22-
22+
2323 self ._bg_color = self .default_color
24-
25- # Stylesheet base - we handle background color via animation,
24+
25+ # Stylesheet base - we handle background color via animation,
2626 # so remove background-color from stylesheet if we want pure py animation,
2727 # OR we just animate a property that updates stylesheet.
2828 # But QPropertyAnimation on "styleSheet" is inefficient.
2929 # Better: use QObject property and paint event override OR simple qss transition?
3030 # PyQt doesn't support CSS transitions.
3131 # We will use a custom property for background color.
32-
32+
3333 self .setStyleSheet (f"""
3434 QPushButton {{
3535 color: white;
@@ -40,7 +40,7 @@ def __init__(self, text="", parent=None, is_secondary=False, is_destructive=Fals
4040 border: none;
4141 }}
4242 """ )
43-
43+
4444 def _get_bg_color (self ):
4545 return self ._bg_color
4646
@@ -97,29 +97,29 @@ def __init__(self, parent=None):
9797 self .default_border = QColor ("#3a3a3a" )
9898 self .focus_border = QColor ("#4a9eff" )
9999 self .error_border = QColor ("#f44336" )
100-
100+
101101 # Initial style updates happen via qss usually, but we want to animate border.
102102 # Animatng border in QSS is hard via property.
103- # We'll just stick to QSS with simple state changes for now,
103+ # We'll just stick to QSS with simple state changes for now,
104104 # OR animate a "borderColor" property.
105-
105+
106106 def shake (self ):
107107 # Simple shake animation
108108 key_pos = self .pos ()
109109 x = key_pos .x ()
110110 y = key_pos .y ()
111-
111+
112112 self .anim = QPropertyAnimation (self , b"pos" )
113113 self .anim .setDuration (50 )
114114 self .anim .setLoopCount (5 )
115-
115+
116116 # Shake sequence: left, right, left, right...
117117 # Note: 'pos' animation on a widget in a layout might be fought by layout.
118118 # Better to simple set style to error and flash it.
119119 self .setProperty ("error" , True )
120120 self .style ().unpolish (self )
121121 self .style ().polish (self )
122-
122+
123123 QTimer .singleShot (500 , self .clear_error )
124124
125125 def clear_error (self ):
0 commit comments