kaka.farm

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

commit 4a0791da47fc65cbd73d3f3fe1b58d74add5a527
parent 56146db34daa0f718194ece5201a6870d1001563
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 29 Jan 2022 02:55:15 +0200

Add Python/GTK GtkScale value-changed event handler stuff.

Diffstat:
Acontent/2022-01-29-python-gtk-scale-value-changed-event-handler.md | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/content/2022-01-29-python-gtk-scale-value-changed-event-handler.md b/content/2022-01-29-python-gtk-scale-value-changed-event-handler.md @@ -0,0 +1,35 @@ +title: Handling Python/GTK's GtkScale value-changed event. +date: 2022-01-29 + +It took me way too long, but now I know how to handle the value-changed event of GtkScale. + +In Glade: + +1. Create a GtkScale widget. We will ID it `foo_scale`. +2. In the `Signals -> GtkRange -> value-changed` line change the `Handler` + field to something sensible like `on_foo_scale_value_changed`. That will + be the name of the handler. +2. Make a new Adjustment in: + + ``` + General -> + Adjustment -> + (little pen button in the field) -> + Choose a [sic] Adjustment in this project -> + New + ``` + +3. Rename the adjustment to something sensible like `foo_adjustment` and set + the `Value`, `Minimum Value`, `Maximum Value`, etc. Those are kind of self + explanatory… +4. In Python, your handler will be called with a single argument - the signal + emitting object, which is the GtkScale object itself. It has a method, + `get_value()`, used to get its current value: + + ```python + def on_foo_scale_value_changed(emitter): + scale_value = emitter.get_value() + do_stuff_with_scale_value(scale_value) + ``` + +Fin.