kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

2022-01-29-python-gtk-scale-value-changed-event-handler.md (1131B)


      1 title: Handling Python/GTK's GtkScale value-changed event.
      2 date: 2022-01-29
      3 
      4 It took me way too long, but now I know how to handle the value-changed event of GtkScale.
      5 
      6 In Glade:
      7 
      8 1. Create a GtkScale widget. We will ID it `foo_scale`.
      9 2. In the `Signals -> GtkRange -> value-changed` line change the `Handler`
     10     field to something sensible like `on_foo_scale_value_changed`. That will
     11     be the name of the handler.
     12 3. Make a new Adjustment in:
     13 
     14     ```
     15     General ->
     16     Adjustment ->
     17     (little pen button in the field) ->
     18     Choose a [sic] Adjustment in this project ->
     19     New
     20     ```
     21 
     22 4. Rename the adjustment to something sensible like `foo_adjustment` and set
     23     the `Value`, `Minimum Value`, `Maximum Value`, etc. Those are kind of self
     24     explanatory…
     25 5. In Python, your handler will be called with a single argument - the signal
     26     emitting object, which is the GtkScale object itself. It has a method,
     27     `get_value()`, used to get its current value:
     28 
     29     ```python
     30     def on_foo_scale_value_changed(emitter):
     31         scale_value = emitter.get_value()
     32 	do_stuff_with_scale_value(scale_value)
     33     ```
     34 
     35 Fin.