File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/Library/demos/Spin Button Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import gi
2+
3+ gi .require_version ("Gtk" , "4.0" )
4+ from gi .repository import Gtk
5+ import workbench
6+
7+ hours : Gtk .SpinButton = workbench .builder .get_object ("hours" )
8+ minutes : Gtk .SpinButton = workbench .builder .get_object ("minutes" )
9+
10+ hours .set_text ("00" )
11+ minutes .set_text ("00" )
12+
13+
14+ def tell_time (hours , minutes ):
15+ return f"The time selected is { hours .get_text ()} :{ minutes .get_text ()} "
16+
17+
18+ def on_value_changed (spin_button ):
19+ value = spin_button .get_adjustment ().get_value ()
20+ spin_button .set_text (f"{ int (value ):02} " )
21+ return True
22+
23+
24+ hours .connect ("value-changed" , lambda * args : print (tell_time (hours , minutes )))
25+ minutes .connect ("value-changed" , lambda * args : print (tell_time (hours , minutes )))
26+
27+
28+ hours .connect ("output" , on_value_changed )
29+
30+ minutes .connect ("output" , on_value_changed )
31+
32+
33+ # This only works for one direction
34+ # Add any extra logic to account for wrapping in both directions
35+ minutes .connect ("wrapped" , lambda * args : hours .spin (Gtk .SpinType .STEP_FORWARD , 1 ))
You can’t perform that action at this time.
0 commit comments