Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Gtk2-Perl: How to catch shift-clicking of a button?

by Anonymous Monk
on Nov 13, 2012 at 09:45 UTC ( #1003577=note: print w/ replies, xml ) Need Help??


in reply to Re: Gtk2-Perl: How to catch shift-clicking of a button?
in thread Gtk2-Perl: How to catch shift-clicking of a button?

Nope, the OP's approach is correct, just needs to fix the typos :) 90% of the way there.

Has to find what exports GDK_SHIFT_MASK.

Has to use  Gtk2->get_current_event because the callback doesn't get an event object

update: after some basic debugging

Gtk2::Gdk::Event::Button isa Gtk2::Gdk::Event hasa $modifiertype = $event->get_state which are flags Gtk2::Gdk::ModifierType

#!/usr/bin/perl -w use strict; use diagnostics; use Gtk2 -init; my $mw = Gtk2::Window->new(); $mw->signal_connect( 'delete_event' => sub { Gtk2->main_quit; } ); my $button=Gtk2::Button->new_from_stock( 'gtk-add' ); $button->add_events( 'key-press-mask' ); $button->signal_connect( 'clicked' => sub { use Data::Dump; my $state = Gtk2->get_current_event->get_state ; dd[ @_, $state ]; dd[ $state->as_arrayref ]; } ); $mw->add( $button ); $mw->show_all; Gtk2->main; __END__ [bless(do{\(my $o = 257)}, "Gtk2::Gdk::ModifierType")] $ perl -MData::Dump -MGtk2 -e " dd [ \%Gtk2::Gdk::ModifierType:: ] do { my $a = [{ ISA => *Gtk2::Gdk::ModifierType::ISA }]; $a->[0]{ISA} = ["Glib::Flags"]; $a; } $ perl -MData::Dump -MGtk2 -e " dd [ \%Glib::Flags:: ] do { my $a = [ { "(!=" => *Glib::Flags::(!=, "(\"\"" => *Glib::Flags::("", "(&" => *Glib::Flags::(&, "()" => *Glib::Flags::(), "(*" => *Glib::Flags::(*, "(+" => *Glib::Flags::(+, "(-" => *Glib::Flags::(-, "(/" => *Glib::Flags::(/, "(==" => *Glib::Flags::(==, "(>=" => *Glib::Flags::(>=, "(\@{}" => *Glib::Flags::(@{}, "(^" => *Glib::Flags::(^, "(bool" => *Glib::Flags::(bool, "(eq" => *Glib::Flags::(eq, "(ne" => *Glib::Flags::(ne, "(|" => *Glib::Flags::(|, "__ANON__" => *Glib::Flags::__ANON__, "all" => *Glib::Flags::all, "as_arrayref" => *Glib::Flags::as_arrayref, "BEGIN" => *Glib::Flags::BEGIN, "bool" => *Glib::Flags::bool, "eq" => *Glib::Flags::eq, "ge" => *Glib::Flags::ge, "intersect" => *Glib::Flags::intersect, "ne" => *Glib::Flags::ne, "new" => *Glib::Flags::new, "OVERLOAD" => *Glib::Flags::OVERLOAD, "sub" => *Glib::Flags::sub, "union" => *Glib::Flags::union, "xor" => *Glib::Flags::xor, }, ]; $a->[0]{"()"} = \1; $a->[0]{"OVERLOAD"} = { dummy => 1 }; $a; } [ bless({}, "Gtk2::Button"), bless(do{\(my $o = 257)}, "Gtk2::Gdk::ModifierType"), ] [["shift-mask", "button1-mask"]]
I figured it out, examples in Glib, Glib::Flags
my $state = Gtk2->get_current_event->get_state ; exit warn "How dare you shift" if $state * "shift-mask";


Comment on Re^2: Gtk2-Perl: How to catch shift-clicking of a button?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003577]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2015-07-29 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls