kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/kaka.farm
Log | Files | Refs | README

commit 2581978251642a7d138e5876894817b0ad667ff6
parent 339cb0c1b27f192835e65645ba5109a8e60b5029
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Fri, 19 Jan 2024 08:53:49 +0200

Remove old blog from the index.html list.  Also add two posts made on commonly-forgotten.

Diffstat:
Dcommonly-forgotten/content/2022-01-27-opencv-and-gtk.md | 45---------------------------------------------
Dcommonly-forgotten/content/2022-01-29-python-gtk-scale-value-changed-event-handler.md | 35-----------------------------------
Mkakafarm/index.scm | 4+---
Aposts/2022-01-27-opencv-and-gtk.md | 46++++++++++++++++++++++++++++++++++++++++++++++
Aposts/2022-01-29-python-gtk-scale-value-changed-event-handler.md | 36++++++++++++++++++++++++++++++++++++
5 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/commonly-forgotten/content/2022-01-27-opencv-and-gtk.md b/commonly-forgotten/content/2022-01-27-opencv-and-gtk.md @@ -1,45 +0,0 @@ -title: Finding mouse location in Python + GTK + OpenCV. -date: 2022-01-27 - -Expanding on the tutorial: - -<https://nofurtherquestions.wordpress.com/2017/03/03/python-3-5-gtk-3-glade-and-opencv/> - -it originally had shown the following structure: - -``` -- window1 (GtkWindow) - - box1 (GtkBox) - - grayscaleButton (GtkToggleButton) - - image (GtkImage) -``` - -According to <https://stackoverflow.com/a/24388310/189995> `GtkImage` does not -generate events, so if you want to find the mouse location, put your -`GtkImage` inside a `GtkEventBox`: - -``` -- window1 (GtkWindow) - - box1 (GtkBox) - - grayscaleButton (GtkToggleButton) - - eventbox (GtkEventBox) - - image (GtkImage) -``` - -and in `eventbox` set the `Common -> Events -> Pointer Motion` so you can add -a handler to the `motion-notify-event` event. - -Now you can write your handler: - -```python -class Handler: - … - … - … - def onMotionNotifyEvent(*args): - global current_mouse_location - - event = args[1] - - current_mouse_location = event.x, event.y -``` diff --git a/commonly-forgotten/content/2022-01-29-python-gtk-scale-value-changed-event-handler.md b/commonly-forgotten/content/2022-01-29-python-gtk-scale-value-changed-event-handler.md @@ -1,35 +0,0 @@ -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. -3. Make a new Adjustment in: - - ``` - General -> - Adjustment -> - (little pen button in the field) -> - Choose a [sic] Adjustment in this project -> - New - ``` - -4. Rename the adjustment to something sensible like `foo_adjustment` and set - the `Value`, `Minimum Value`, `Maximum Value`, etc. Those are kind of self - explanatory… -5. 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. diff --git a/kakafarm/index.scm b/kakafarm/index.scm @@ -11,9 +11,7 @@ (li (a (@ (href "/software/")) "Various software!")) (li (a (@ (href "//kaka.farm/haunt/")) - "A Haunt blog!")) - (li (a (@ (href "//kaka.farm/blog/")) - "blog-ish. Will be consolidated into the Haunt blog eventually.")) + "A blog!")) (li (a (@ (href "//kaka.farm/~commonly-forgotten/")) "Commonly Forgotten") " has some terribly written notes (which I should consolidate into diff --git a/posts/2022-01-27-opencv-and-gtk.md b/posts/2022-01-27-opencv-and-gtk.md @@ -0,0 +1,46 @@ +title: Finding mouse location in Python + GTK + OpenCV. +date: 2022-01-27 00:00 +--- + +Expanding on the tutorial: + +<https://nofurtherquestions.wordpress.com/2017/03/03/python-3-5-gtk-3-glade-and-opencv/> + +it originally had shown the following structure: + +``` +- window1 (GtkWindow) + - box1 (GtkBox) + - grayscaleButton (GtkToggleButton) + - image (GtkImage) +``` + +According to <https://stackoverflow.com/a/24388310/189995> `GtkImage` does not +generate events, so if you want to find the mouse location, put your +`GtkImage` inside a `GtkEventBox`: + +``` +- window1 (GtkWindow) + - box1 (GtkBox) + - grayscaleButton (GtkToggleButton) + - eventbox (GtkEventBox) + - image (GtkImage) +``` + +and in `eventbox` set the `Common -> Events -> Pointer Motion` so you can add +a handler to the `motion-notify-event` event. + +Now you can write your handler: + +```python +class Handler: + … + … + … + def onMotionNotifyEvent(*args): + global current_mouse_location + + event = args[1] + + current_mouse_location = event.x, event.y +``` diff --git a/posts/2022-01-29-python-gtk-scale-value-changed-event-handler.md b/posts/2022-01-29-python-gtk-scale-value-changed-event-handler.md @@ -0,0 +1,36 @@ +title: Handling Python/GTK's GtkScale value-changed event. +date: 2022-01-29 00:00 +--- + +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. +3. Make a new Adjustment in: + + ``` + General -> + Adjustment -> + (little pen button in the field) -> + Choose a [sic] Adjustment in this project -> + New + ``` + +4. Rename the adjustment to something sensible like `foo_adjustment` and set + the `Value`, `Minimum Value`, `Maximum Value`, etc. Those are kind of self + explanatory… +5. 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.