Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event controllers demo promotes bad practice for key modifiers #183

Open
gjask opened this issue Jul 5, 2024 · 1 comment
Open

Event controllers demo promotes bad practice for key modifiers #183

gjask opened this issue Jul 5, 2024 · 1 comment

Comments

@gjask
Copy link

gjask commented Jul 5, 2024

Event controller demo showcases button click with Ctrl key modifier by creating Gtk.EventControllerKey and tracking key state in global variable. This approach is at least bit quirky (eg. fails to track key state changes made off-focus) and seems like a bad practice (global variable, really?). I know it was meant to find show case for Gtk.EventControllerKey but I believe not teaching beginners (such as myself) bad practices is important. So maybe finding different show case is in order.

Proper technique for handling clicks and other events with key modifier is to use controller.get_current_event_state() in callback. For example like this.

def on_button_release(controller, clicks, x, y):
    if (controller.get_current_event_state() & Gdk.ModifierType.CONTROL_MASK):
        print("Ctrl was pressed")
    else:
        print("Ctrl was not pressed")

click = Gtk.GestureClick()
click.connect("released", on_button_release)
widget.add_controller(click)
@gjask
Copy link
Author

gjask commented Jul 5, 2024

I have created this issue, because originally I have only sent PR which didn't get much attention. I don't know if it is normal time span for reaction or because issue was missing. Also if somebody wanted to propose better solution it is good to have issue to track all progress on this.

My proposed solution is: #181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant