From: Scott Worley Date: Sat, 13 Sep 2025 17:46:07 +0000 (-0700) Subject: Factor out make_button() X-Git-Tag: v1.0.0~5 X-Git-Url: http://git.scottworley.com/nix-env-apps/commitdiff_plain/d8a00b09faaa7038eb00be860f5eacad32161f04?ds=sidebyside Factor out make_button() --- diff --git a/apps.py b/apps.py index 959c148..59aa4a9 100644 --- a/apps.py +++ b/apps.py @@ -1,6 +1,6 @@ import os import subprocess -from typing import Any +from typing import Any, Callable import gi gi.require_version("Gtk", "4.0") @@ -80,14 +80,18 @@ def on_apply(_: Any) -> None: os.execvp(command[0], command) +def make_button(label: str, action: Callable[[Any], None]) -> Gtk.Button: + button = Gtk.Button(label=label) + button.connect('clicked', action) + return button + + def on_activate(app: Gtk.Application) -> None: win = Gtk.ApplicationWindow(application=app) box = Gtk.Box() box.set_orientation(Gtk.Orientation.VERTICAL) - edit = Gtk.Button(label="Edit Configuration") - apply = Gtk.Button(label="Apply Configuration") - edit.connect('clicked', on_edit) - apply.connect('clicked', on_apply) + edit = make_button("Edit Configuration", on_edit) + apply = make_button("Apply Configuration", on_apply) box.append(edit) box.append(apply) win.set_child(box)