Re: wxGlade Generated Code

2009-08-16 Thread Johan Vromans
"Steve Cookson"  writes:

> I have looked at them, but I didn't totally understand how they work.
> I'm using them for integer entry and time entry, but field lookup,
> I'm not clear what I should do.  Do you think I can use the validators
> for lookup?

The validator's Validate method is supposed to return true or false
depening on the data being correct. How it finds out validity is up to
you...

Note that you need Wx::PlValidator as base class.

-- Johan


RE: wxGlade Generated Code

2009-08-15 Thread Steve Cookson
Hi Johan,

I have looked at them, but I didn't totally understand how they work.
I'm using them for integer entry and time entry, but field lookup,
I'm not clear what I should do.  Do you think I can use the validators
for lookup?

Regards

Steve




-Original Message-
From: Johan Vromans [mailto:jvrom...@squirrel.nl] 
Sent: 15 August 2009 14:16
To: Steve Cookson
Subject: Re: wxGlade Generated Code

"Steve Cookson"  writes:

> So if I want to detect tabbing out of a field 
> to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on
> the control. But alt-tab (and I guess alt-esc etc) to another app 
> also trigger it.  How can I filter out alt-tab etc?

Using EVT_KILL_FOCUS for field validation is generally a bad idea, for
reasons you've already experienced.

Have you looked at the validators?

-- Johan



RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Hi Ryan,

Thanks for your kind and thought-out reply.  Well, I think you're right 
about disabling alt-tab and similar events.  I should do that.  Not
just for the reasons you list, but also because I am creating a totally
controlled environment, so we just don't want all that op sys stuff 
visible.  So that would mean I can just log it as an issue and forget 
about it for the time being.

Regarding FindFocus(): it could work, if I didn't find that for some
reason the event-handler was being called TWICE, one for the first control
and once for the second control (ie the tabbed-to control).  It may just 
be a coding fault, of course.

The other route I'm looking at is GetID() and FindWindow(), which should 
also allow me to ascertain where I am.  I'm manually setting some ids 
rather than using wxANY in order to know which button I'm being called 
from.

I'll play around with them in the background and let this forum know
how I get on.

Thanks again.

Regards

Steve




-Original Message-
From: Ryan Jendoubi [mailto:ryan.jendo...@googlemail.com] 
Sent: 14 August 2009 12:10
To: wxPerl users
Subject: Re: wxGlade Generated Code

[ Sorry again all for my double postings ]

Hi Steve,

Steve Cookson wrote:
> So that's how it works!  So if I want to detect tabbing out of a field 
> to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on
> the control. But alt-tab (and I guess alt-esc etc) to another app 
> also trigger it.  How can I filter out alt-tab etc?

I know you've been tackling that for a few days, I'm still not sure I 
can help.

I don't think filtering keys is the way to go. I'd imagine it's not the 
actual keypress that generates a KILL_FOCUS, it's the /result/ of the 
keypress, if you get me. I think the best you could do with filtering 
key presses would be to disable alt-tab / program switching altogether 
when in that text field. That'd be in an event handler of a TextCtrl you 
subclassed yourself. You'd have to read up the wxWidgets docs [0], 
particularly wxKeyEvent and wxKeyCode to see what combination of 
EVT_KEY_DOWN, EVT_KEY_UP and/or EVT_CHAR you'd need to do what you need.

Looking around in the docs, I think a better way to do what you need 
would be using Wx::Window::FindFocus() [1] (in wxWidgets there's also a 
HasFocus() event that could be even more elegant but grep'ing for that 
doesn't show it anywhere in the Wx-0.91 source; maybe someone could 
correct me on that).

Could you just have something at the start of your EVT_KILL_FOCUS 
handler like this?

if ( Wx::Window::FindFocus ne $self->{nextCtrlByTab} ) { return; }

Or conceivably just if ( FindFocus == NULL ) if it returns null when 
focus has moved out of the program.

What do you think, workable?

-- Ryan



[0] http://docs.wxwidgets.org/trunk/

[1] 
http://docs.wxwidgets.org/trunk/classwx_window.html#777258379a3eef1b0530f12d
b6b77cab



Re: wxGlade Generated Code

2009-08-14 Thread Ryan Jendoubi

[ Sorry again all for my double postings ]

Hi Steve,

Steve Cookson wrote:
So that's how it works!  So if I want to detect tabbing out of a field 
to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on
the control. But alt-tab (and I guess alt-esc etc) to another app 
also trigger it.  How can I filter out alt-tab etc?


I know you've been tackling that for a few days, I'm still not sure I 
can help.


I don't think filtering keys is the way to go. I'd imagine it's not the 
actual keypress that generates a KILL_FOCUS, it's the /result/ of the 
keypress, if you get me. I think the best you could do with filtering 
key presses would be to disable alt-tab / program switching altogether 
when in that text field. That'd be in an event handler of a TextCtrl you 
subclassed yourself. You'd have to read up the wxWidgets docs [0], 
particularly wxKeyEvent and wxKeyCode to see what combination of 
EVT_KEY_DOWN, EVT_KEY_UP and/or EVT_CHAR you'd need to do what you need.


Looking around in the docs, I think a better way to do what you need 
would be using Wx::Window::FindFocus() [1] (in wxWidgets there's also a 
HasFocus() event that could be even more elegant but grep'ing for that 
doesn't show it anywhere in the Wx-0.91 source; maybe someone could 
correct me on that).


Could you just have something at the start of your EVT_KILL_FOCUS 
handler like this?


if ( Wx::Window::FindFocus ne $self->{nextCtrlByTab} ) { return; }

Or conceivably just if ( FindFocus == NULL ) if it returns null when 
focus has moved out of the program.


What do you think, workable?

-- Ryan



[0] http://docs.wxwidgets.org/trunk/

[1] 
http://docs.wxwidgets.org/trunk/classwx_window.html#777258379a3eef1b0530f12db6b77cab


Re: wxGlade Generated Code

2009-08-14 Thread Ryan Jendoubi

Hi James,

GMAIL - James McDonald wrote:
I am not really understanding the event subsystem very well. Of course 
I have looked at the documentation but due to my lack of understanding 
I still am not grasping the concept. I have little idea of what 
$event->Skip means and where in the block it should appear, if at all. 
Can anyone enlighten me?
My understanding from the C++ is that $event->Skip indicates that the 
handling of an event should be passed on higher up the inheritance 
chain, first of the object itself, then its parent object, etc. So for 
example (from the wxWidgets book), in a myTextCtrl subclass, you could 
handle its keypress events to filter out certain keys by returning 
without calling $event->Skip or $event->Skip(0) to be explicit, then for 
all other keys do $event-Skip and the event will be handed on to be 
handled normally by the regular TextCtrl class. For events handled in a 
myFrame class, Skip'ed events would get passed on to the regular 
Wx::Frame, then Wx::TopLevelWindow, then Wx::Window.


So in your code:

sub keyPress {
   my ($self, $event) = @_;
# wxGlade: MyFrame::keyPress 

   warn "Event handler (keyPress) not implemented";
   $event->Skip;
   my $key = $event->GetEventObject()->GetLabel();
   my $keyid = $event->GetEventObject()->GetId();
# end wxGlade

   Wx::MessageBox("You pressed: $key\nKey ID: $keyid", "wxPerl Sample");

}
It just means these wxEVT_BUTTON events will be passed on to Wx::Frame 
when your sub has finished with them.
But let's say I want to know the actual control name such as return 
"button_1" from the EVT_BUTTON event how do I return that? I can use 
GetId to return the default number but how do I return it's 
programmatic name?

$self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);
I'm afraid I don't know how to do exactly what you want, without 
resorting to something silly with naming conventions and eval()s. You 
mentioned about GetId and I noticed you set random id's for everything 
in your program. Why not set specific id's with usefully-named integer 
scalars in your code, then check with something like if ( 
$event->GetEventObject->GetId == $ID_KEY9 ) or whatever? You can see 
this idea used in wxToolBar.pm in Wx::Demo.


HTH,

-- Ryan


RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Hi Ryan,

So that's how it works!  So if I want to detect tabbing out of a field 
to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on
the control. But alt-tab (and I guess alt-esc etc) to another app 
also trigger it.  How can I filter out alt-tab etc?

Regards

Steve




-Original Message-
From: Ryan Jendoubi [mailto:ryan.jendo...@googlemail.com] 
Sent: 14 August 2009 11:03
To: wxPerl users
Subject: Re: wxGlade Generated Code

[ Apologies if this was received before; I think I had a problem after 
changing my subscription address, and it wasn't showing up on 
nntp.perl.org~ ]

Hi James,

GMAIL - James McDonald wrote:
> I am not really understanding the event subsystem very well. Of course 
> I have looked at the documentation but due to my lack of understanding 
> I still am not grasping the concept. I have little idea of what 
> $event->Skip means and where in the block it should appear, if at all. 
> Can anyone enlighten me?
My understanding from the C++ is that $event->Skip indicates that the 
handling of an event should be passed on higher up the inheritance 
chain, first of the object itself, then its parent object, etc. So for 
example (from the wxWidgets book), in a myTextCtrl subclass, you could 
handle its keypress events to filter out certain keys by returning 
without calling $event->Skip or $event->Skip(0) to be explicit, then for 
all other keys do $event-Skip and the event will be handed on to be 
handled normally by the regular TextCtrl class. For events handled in a 
myFrame class, Skip'ed events would get passed on to the regular 
Wx::Frame, then Wx::TopLevelWindow, then Wx::Window.

So in your code:
> sub keyPress {
>my ($self, $event) = @_;
> # wxGlade: MyFrame::keyPress 
>
>warn "Event handler (keyPress) not implemented";
>$event->Skip;
>my $key = $event->GetEventObject()->GetLabel();
>my $keyid = $event->GetEventObject()->GetId();
> # end wxGlade
>
>Wx::MessageBox("You pressed: $key\nKey ID: $keyid", "wxPerl Sample");
>
> }
I think it just means these wxEVT_BUTTON events will be passed on to 
Wx::Frame when your MyFrame sub has finished with them.
> But let's say I want to know the actual control name such as return 
> "button_1" from the EVT_BUTTON event how do I return that? I can use 
> GetId to return the default number but how do I return it's 
> programmatic name?
> $self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);
I'm afraid I don't know how to do exactly what you want, without 
resorting to something silly with naming conventions and eval()s. As 
Steve already said though, I think id's are the way to go. It's probably 
easiest to use usefully-named integer scalars so your check will look 
something like if ( $event->GetEventObject->GetId == $ID_KEY9 ). You can 
see this idea used in wxToolBar.pm in Wx::Demo.

HTH,

-- Ryan



Re: wxGlade Generated Code

2009-08-14 Thread Ryan Jendoubi
[ Apologies if this was received before; I think I had a problem after 
changing my subscription address, and it wasn't showing up on 
nntp.perl.org~ ]


Hi James,

GMAIL - James McDonald wrote:
I am not really understanding the event subsystem very well. Of course 
I have looked at the documentation but due to my lack of understanding 
I still am not grasping the concept. I have little idea of what 
$event->Skip means and where in the block it should appear, if at all. 
Can anyone enlighten me?
My understanding from the C++ is that $event->Skip indicates that the 
handling of an event should be passed on higher up the inheritance 
chain, first of the object itself, then its parent object, etc. So for 
example (from the wxWidgets book), in a myTextCtrl subclass, you could 
handle its keypress events to filter out certain keys by returning 
without calling $event->Skip or $event->Skip(0) to be explicit, then for 
all other keys do $event-Skip and the event will be handed on to be 
handled normally by the regular TextCtrl class. For events handled in a 
myFrame class, Skip'ed events would get passed on to the regular 
Wx::Frame, then Wx::TopLevelWindow, then Wx::Window.


So in your code:

sub keyPress {
   my ($self, $event) = @_;
# wxGlade: MyFrame::keyPress 

   warn "Event handler (keyPress) not implemented";
   $event->Skip;
   my $key = $event->GetEventObject()->GetLabel();
   my $keyid = $event->GetEventObject()->GetId();
# end wxGlade

   Wx::MessageBox("You pressed: $key\nKey ID: $keyid", "wxPerl Sample");

}
I think it just means these wxEVT_BUTTON events will be passed on to 
Wx::Frame when your MyFrame sub has finished with them.
But let's say I want to know the actual control name such as return 
"button_1" from the EVT_BUTTON event how do I return that? I can use 
GetId to return the default number but how do I return it's 
programmatic name?

$self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);
I'm afraid I don't know how to do exactly what you want, without 
resorting to something silly with naming conventions and eval()s. As 
Steve already said though, I think id's are the way to go. It's probably 
easiest to use usefully-named integer scalars so your check will look 
something like if ( $event->GetEventObject->GetId == $ID_KEY9 ). You can 
see this idea used in wxToolBar.pm in Wx::Demo.


HTH,

-- Ryan


RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Whoops, I removed all references to the $i parameter before 
I sent, but I forgot to remove:

"In this routine, you should ignore the $i parameter."

Regards

Steve




-Original Message-
From: Steve Cookson [mailto:steve.cook...@sca-uk.com] 
Sent: 14 August 2009 09:54
To: 'wxperl-users@perl.org'
Subject: RE: wxGlade Generated Code

Hi Johan,

Yes it's true I don't change it when I have a simple form.

But most of my forms are more complicated so I have to create them 
programmatically.  Eg I have a form with a wxNotebook with a variable
number of tabs.  I have to create the tabs dynamically in a loop, so
it is easier to set the properties and add them to the sizer all
at the same time.  So I have a sub-routine to do it, (see below). In
This routine, you should ignore the $i parameter.
I am gradually creating little routines like this for all my control 
types.

Regards

Steve

sub __new_TextCtrl{

# sets field properties, format:
# __new_TextCtrl(\$loc_self_ptr, $loc_enabled, $loc_max_length,
$loc_minsize_x, $loc_minsize_y, $loc_validation_string, $loc_tooltip,
\$loc_sizer_ptr, \$loc_panel_ptr, $loc_control_value);

my $loc_self_ptr=shift; # pointer to control (Pass
by reference)
my $loc_enabled=shift;  #Enabled or disabled
my $loc_max_length=shift;   # Hold maximum number of
characters the control will accept before beeping.
my $loc_minsize_x=shift;# Holds minimum size of
control (x-axis)
my $loc_minsize_y=shift;# Holds minimum size of
control (y-axis)
my $loc_validation_string=shift;# Holds validation string
my $loc_tooltip=shift;  # Holds tooltip already
translated.
my $loc_sizer_ptr=shift;# pointer to sizer (Pass by
reference)
my $loc_panel_ptr=shift;# pointer to panel (Pass by
reference)
my $loc_control_value=shift;# Holds default value of
control

#   Use wxTE_READONLY instead of Enabled/Disabled
if ($loc_enabled=0){
$$loc_self_ptr = Wx::TextCtrl->
new($$loc_panel_ptr, wxID_ANY,
__trim($loc_control_value), wxDefaultPosition, wxDefaultSize,
wxTE_READONLY); 
} else {
$$loc_self_ptr = Wx::TextCtrl->
new($$loc_panel_ptr, wxID_ANY,
__trim($loc_control_value), wxDefaultPosition, wxDefaultSize, );

}

if ($loc_max_length ne "")
{$$loc_self_ptr->SetMaxLength($loc_max_length)};#Set maximum length
of text control
if ($loc_minsize_x ne "") {
# Set minimum physical size of field in pixels
$$loc_self_ptr->SetMinSize(Wx::Size->new($loc_minsize_x,
$loc_minsize_y))
};
if ($loc_tooltip ne "")
{$$loc_self_ptr->SetToolTipString($loc_tooltip)};   #Set tooltip
if ($loc_validation_string ne "") {
my $loc_numval = Wx::Perl::TextValidator->new(
$loc_validation_string );   # Set validation string
$$loc_self_ptr->SetValidator( $loc_numval );
# Set validation
}   
$$loc_sizer_ptr->Add($$loc_self_ptr, 0, 0, 0);
# Add to grid
}

-Original Message-
From: Johan Vromans [mailto:jvrom...@squirrel.nl] 
Sent: 14 August 2009 09:27
To: wxperl-users@perl.org
Subject: Re: wxGlade Generated Code

"Steve Cookson"  writes:

> However on the Glade code, while I wrote my whole prototype In
> Glade, and I wouldn't have progressed as fast as I have without it,
> I don't like its programmatic structure. [...] This makes the code
> much more maintainable.

I think there's a misunderstanding here. wxGlade is not a prototype
generator, it's an UI designer/generator. The idea is to leave the
maintainance of the wxGlade generated code to wxGlade.

Personally I find wxGlade's programmatic structure okay to work with.

-- Johan



RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Hi Johan,

Yes it's true I don't change it when I have a simple form.

But most of my forms are more complicated so I have to create them 
programmatically.  Eg I have a form with a wxNotebook with a variable
number of tabs.  I have to create the tabs dynamically in a loop, so
it is easier to set the properties and add them to the sizer all
at the same time.  So I have a sub-routine to do it, (see below). In
This routine, you should ignore the $i parameter.
I am gradually creating little routines like this for all my control 
types.

Regards

Steve

sub __new_TextCtrl{

# sets field properties, format:
# __new_TextCtrl(\$loc_self_ptr, $loc_enabled, $loc_max_length,
$loc_minsize_x, $loc_minsize_y, $loc_validation_string, $loc_tooltip,
\$loc_sizer_ptr, \$loc_panel_ptr, $loc_control_value);

my $loc_self_ptr=shift; # pointer to control (Pass
by reference)
my $loc_enabled=shift;  #Enabled or disabled
my $loc_max_length=shift;   # Hold maximum number of
characters the control will accept before beeping.
my $loc_minsize_x=shift;# Holds minimum size of
control (x-axis)
my $loc_minsize_y=shift;# Holds minimum size of
control (y-axis)
my $loc_validation_string=shift;# Holds validation string
my $loc_tooltip=shift;  # Holds tooltip already
translated.
my $loc_sizer_ptr=shift;# pointer to sizer (Pass by
reference)
my $loc_panel_ptr=shift;# pointer to panel (Pass by
reference)
my $loc_control_value=shift;# Holds default value of
control

#   Use wxTE_READONLY instead of Enabled/Disabled
if ($loc_enabled=0){
$$loc_self_ptr = Wx::TextCtrl->
new($$loc_panel_ptr, wxID_ANY,
__trim($loc_control_value), wxDefaultPosition, wxDefaultSize,
wxTE_READONLY); 
} else {
$$loc_self_ptr = Wx::TextCtrl->
new($$loc_panel_ptr, wxID_ANY,
__trim($loc_control_value), wxDefaultPosition, wxDefaultSize, );

}

if ($loc_max_length ne "")
{$$loc_self_ptr->SetMaxLength($loc_max_length)};#Set maximum length
of text control
if ($loc_minsize_x ne "") {
# Set minimum physical size of field in pixels
$$loc_self_ptr->SetMinSize(Wx::Size->new($loc_minsize_x,
$loc_minsize_y))
};
if ($loc_tooltip ne "")
{$$loc_self_ptr->SetToolTipString($loc_tooltip)};   #Set tooltip
if ($loc_validation_string ne "") {
my $loc_numval = Wx::Perl::TextValidator->new(
$loc_validation_string );   # Set validation string
$$loc_self_ptr->SetValidator( $loc_numval );
# Set validation
}   
$$loc_sizer_ptr->Add($$loc_self_ptr, 0, 0, 0);
# Add to grid
}

-Original Message-
From: Johan Vromans [mailto:jvrom...@squirrel.nl] 
Sent: 14 August 2009 09:27
To: wxperl-users@perl.org
Subject: Re: wxGlade Generated Code

"Steve Cookson"  writes:

> However on the Glade code, while I wrote my whole prototype In
> Glade, and I wouldn't have progressed as fast as I have without it,
> I don't like its programmatic structure. [...] This makes the code
> much more maintainable.

I think there's a misunderstanding here. wxGlade is not a prototype
generator, it's an UI designer/generator. The idea is to leave the
maintainance of the wxGlade generated code to wxGlade.

Personally I find wxGlade's programmatic structure okay to work with.

-- Johan



Re: wxGlade Generated Code

2009-08-14 Thread Johan Vromans
"Steve Cookson"  writes:

> However on the Glade code, while I wrote my whole prototype In
> Glade, and I wouldn't have progressed as fast as I have without it,
> I don't like its programmatic structure. [...] This makes the code
> much more maintainable.

I think there's a misunderstanding here. wxGlade is not a prototype
generator, it's an UI designer/generator. The idea is to leave the
maintainance of the wxGlade generated code to wxGlade.

Personally I find wxGlade's programmatic structure okay to work with.

-- Johan


RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Hi James,

One more thing I've discovered.  If you set the ID in the first place
then you know what it means.  So instead of passing -1 (wxANY), pass
a positive integer of your own invention.  Apparently all wxPerl ids 
are negative.

Regards

Steve



-Original Message-
From: GMAIL - James McDonald [mailto:ja...@jamesmcdonald.id.au] 
Sent: 14 August 2009 02:39
To: wxperl-users@perl.org
Subject: wxGlade Generated Code

I use wxPerl to create custom interfaces.

Alot of these interfaces have a  Number Keypad and I've only just 
figured out how to get hold of the actual object I click using a post 
from Steve Cookson (Thanks Steve). It's embarrassing to admit but I was 
creating one event handler per key ( keyPress1, keyPress2 etc...)

So using:
my $keyLabel = $event->GetEventObject()->GetLabel();
I can get the text on the button I have clicked.

But let's say I want to know the actual control name such as return 
"button_1" from the EVT_BUTTON event how do I return that? I can use 
GetId to return the default number but how do I return it's programmatic 
name?
$self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);

I am not really understanding the event subsystem very well. Of course I 
have looked at the documentation but due to my lack of understanding I 
still am not grasping the concept. I have little idea of what 
$event->Skip means and where in the block it should appear, if at all. 
Can anyone enlighten me?

What does the doco it mean when it says you can have "further event 
handlers", can you create a chain of event handlers?


# copy and paste from docs


  wxEvent::Skip

*void* *Skip*(*bool*/ skip = true/)

This method can be used inside an event handler to control whether 
further event handlers bound to this event will be called after the 
current one returns. Without Skip() (or equivalently if Skip(false) is 
used), the event will not be processed any more. If Skip(true) is 
called, the event processing system continues searching for a further 
handler function for this event, even though it has been processed 
already in the current handler.

In general, it is recommended to skip all non-command events to allow 
the default handling to take place. The command events are, however, 
normally not skipped as usually a single command such as a button click 
or menu item selection must only be processed by one handler.


# my sample application

#!/usr/bin/perl -w --
# generated by wxGlade 0.6.3 on Fri Aug 14 14:57:39 2009
# To get wxPerl visit http://wxPerl.sourceforge.net/

use Wx 0.15 qw[:allclasses];
use strict;

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;

sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef  unless defined $parent;
$id = -1 unless defined $id;
$title  = "" unless defined $title;
$pos= wxDefaultPosition  unless defined $pos;
$size   = wxDefaultSize  unless defined $size;
$name   = "" unless defined $name;

# begin wxGlade: MyFrame::new

$style = wxDEFAULT_FRAME_STYLE
unless defined $style;

$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, 
$style, $name );
$self->{button_1} = Wx::Button->new($self, -1, "1");
$self->{button_2} = Wx::Button->new($self, -1, "2");
$self->{button_3} = Wx::Button->new($self, -1, "3");
$self->{button_4} = Wx::Button->new($self, -1, "4");
$self->{button_5} = Wx::Button->new($self, -1, "5");
$self->{button_6} = Wx::Button->new($self, -1, "6");
$self->{button_7} = Wx::Button->new($self, -1, "7");
$self->{button_8} = Wx::Button->new($self, -1, "8");
$self->{button_9} = Wx::Button->new($self, -1, "9");

$self->__set_properties();
$self->__do_layout();

Wx::Event::EVT_BUTTON($self, $self->{button_1}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_2}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_3}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_4}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_5}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_6}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_7}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_8}->GetId, \&keyPress);
Wx::Event::EVT_BUTTON($self, $self->{button_9}->GetId, \&keyPress);

# end wxGlade
return $self;

}


sub __set_properties {
my $self = shift;

# begin wxGlade: MyFrame::__set_properties

$self->SetTitle("A sample keypad program");

#

RE: wxGlade Generated Code

2009-08-14 Thread Steve Cookson
Hi James,

I totally agree with you.  I'm also failing to grasp this.  If
Anyone can point me to some documentation that would be great.

However on the Glade code, while I wrote my whole prototype
In Glade, and I wouldn't have progressed as fast as I have
without it, I don't like its programmatic structure.  It
seems to scan for items and create them.  Scan for properties,
create them, scan for sizer info and create it.  The first thing 
I do is get rid of "do layout" and "do properties" and 
group like lines so that similar items are together. This
makes the code much more maintainable.  So with your sample code, I get:

# my sample application

#!/usr/bin/perl -w --
# generated by wxGlade 0.6.3 on Fri Aug 14 14:57:39 2009
# To get wxPerl visit http://wxPerl.sourceforge.net/

use Wx 0.15 qw[:allclasses];
use strict;

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;

sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef  unless defined $parent;
$id = -1 unless defined $id;
$title  = "" unless defined $title;
$pos= wxDefaultPosition  unless defined $pos;
$size   = wxDefaultSize  unless defined $size;
$name   = "" unless defined $name;

# begin wxGlade: MyFrame::new

$style = wxDEFAULT_FRAME_STYLE unless defined $style;

$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style,
$name );

$self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
$self->{grid_sizer_1} = Wx::GridSizer->new(3, 3, 0, 0);

for (my $i=1; $i<=9;$i++){
$self->{"button_".$i} = Wx::Button->new($self, -1, $i);
Wx::Event::EVT_BUTTON($self, $self->{"button_".$i}->GetId,
\&keyPress);
$self->{grid_sizer_1}->Add($self->{"button_".$i}, 0, 0, 0);

}
$self->{sizer_1}->Add($self->{grid_sizer_1}, 1, wxEXPAND, 0);
$self->SetSizer($self->{sizer_1});
$self->{sizer_1}->Fit($self);
$self->Layout();
$self->SetTitle("A sample keypad program");

return $self;

}
sub keyPress {
my ($self, $event) = @_;
# wxGlade: MyFrame::keyPress 

warn "Event handler (keyPress) not implemented";
$event->Skip;
my $key = $event->GetEventObject()->GetLabel();
my $keyid = $event->GetEventObject()->GetId();
# end wxGlade

Wx::MessageBox("You pressed: $key\nKey ID: $keyid", "wxPerl Sample");
}

# end of class MyFrame

1;

package main;

unless(caller){
local *Wx::App::OnInit = sub{1};
my $app = Wx::App->new();
Wx::InitAllImageHandlers();

my $frame_1 = MyFrame->new();

$app->SetTopWindow($frame_1);
    $frame_1->Show(1);
$app->MainLoop();
}


Regards

Steve




-Original Message-
From: GMAIL - James McDonald [mailto:ja...@jamesmcdonald.id.au] 
Sent: 14 August 2009 02:39
To: wxperl-users@perl.org
Subject: wxGlade Generated Code

I use wxPerl to create custom interfaces.

Alot of these interfaces have a  Number Keypad and I've only just 
figured out how to get hold of the actual object I click using a post 
from Steve Cookson (Thanks Steve). It's embarrassing to admit but I was 
creating one event handler per key ( keyPress1, keyPress2 etc...)

So using:
my $keyLabel = $event->GetEventObject()->GetLabel();
I can get the text on the button I have clicked.

But let's say I want to know the actual control name such as return 
"button_1" from the EVT_BUTTON event how do I return that? I can use 
GetId to return the default number but how do I return it's programmatic 
name?
$self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);

I am not really understanding the event subsystem very well. Of course I 
have looked at the documentation but due to my lack of understanding I 
still am not grasping the concept. I have little idea of what 
$event->Skip means and where in the block it should appear, if at all. 
Can anyone enlighten me?

What does the doco it mean when it says you can have "further event 
handlers", can you create a chain of event handlers?


# copy and paste from docs


  wxEvent::Skip

*void* *Skip*(*bool*/ skip = true/)

This method can be used inside an event handler to control whether 
further event handlers bound to this event will be called after the 
current one returns. Without Skip() (or equivalently if Skip(false) is 
used), the event will not be processed any more. If Skip(true) is 
called, the event processing system continues searching for a further 
handler function for this event, even though it has been processed 
already in the current handler.

In general, it is recommended to skip all non-command events to allow 
the default handling to take place. The command events

wxGlade Generated Code

2009-08-13 Thread GMAIL - James McDonald

I use wxPerl to create custom interfaces.

Alot of these interfaces have a  Number Keypad and I've only just 
figured out how to get hold of the actual object I click using a post 
from Steve Cookson (Thanks Steve). It's embarrassing to admit but I was 
creating one event handler per key ( keyPress1, keyPress2 etc...)


So using:
my $keyLabel = $event->GetEventObject()->GetLabel();
I can get the text on the button I have clicked.

But let's say I want to know the actual control name such as return 
"button_1" from the EVT_BUTTON event how do I return that? I can use 
GetId to return the default number but how do I return it's programmatic 
name?

$self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);

I am not really understanding the event subsystem very well. Of course I 
have looked at the documentation but due to my lack of understanding I 
still am not grasping the concept. I have little idea of what 
$event->Skip means and where in the block it should appear, if at all. 
Can anyone enlighten me?


What does the doco it mean when it says you can have "further event 
handlers", can you create a chain of event handlers?



# copy and paste from docs


 wxEvent::Skip

*void* *Skip*(*bool*/ skip = true/)

This method can be used inside an event handler to control whether 
further event handlers bound to this event will be called after the 
current one returns. Without Skip() (or equivalently if Skip(false) is 
used), the event will not be processed any more. If Skip(true) is 
called, the event processing system continues searching for a further 
handler function for this event, even though it has been processed 
already in the current handler.


In general, it is recommended to skip all non-command events to allow 
the default handling to take place. The command events are, however, 
normally not skipped as usually a single command such as a button click 
or menu item selection must only be processed by one handler.



# my sample application

#!/usr/bin/perl -w --
# generated by wxGlade 0.6.3 on Fri Aug 14 14:57:39 2009
# To get wxPerl visit http://wxPerl.sourceforge.net/

use Wx 0.15 qw[:allclasses];
use strict;

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;

sub new {
   my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
   $parent = undef  unless defined $parent;
   $id = -1 unless defined $id;
   $title  = "" unless defined $title;
   $pos= wxDefaultPosition  unless defined $pos;
   $size   = wxDefaultSize  unless defined $size;
   $name   = "" unless defined $name;

# begin wxGlade: MyFrame::new

   $style = wxDEFAULT_FRAME_STYLE
   unless defined $style;

   $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, 
$style, $name );

   $self->{button_1} = Wx::Button->new($self, -1, "1");
   $self->{button_2} = Wx::Button->new($self, -1, "2");
   $self->{button_3} = Wx::Button->new($self, -1, "3");
   $self->{button_4} = Wx::Button->new($self, -1, "4");
   $self->{button_5} = Wx::Button->new($self, -1, "5");
   $self->{button_6} = Wx::Button->new($self, -1, "6");
   $self->{button_7} = Wx::Button->new($self, -1, "7");
   $self->{button_8} = Wx::Button->new($self, -1, "8");
   $self->{button_9} = Wx::Button->new($self, -1, "9");

   $self->__set_properties();
   $self->__do_layout();

   Wx::Event::EVT_BUTTON($self, $self->{button_1}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_2}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_3}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_4}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_5}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_6}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_7}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_8}->GetId, \&keyPress);
   Wx::Event::EVT_BUTTON($self, $self->{button_9}->GetId, \&keyPress);

# end wxGlade
   return $self;

}


sub __set_properties {
   my $self = shift;

# begin wxGlade: MyFrame::__set_properties

   $self->SetTitle("A sample keypad program");

# end wxGlade
}

sub __do_layout {
   my $self = shift;

# begin wxGlade: MyFrame::__do_layout

   $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
   $self->{grid_sizer_1} = Wx::GridSizer->new(3, 3, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_2}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_3}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_4}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_5}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_6}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_7}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_8}, 0, 0, 0);
   $self->{grid_sizer_1}->Add($self->{button_9}, 0, 0, 0);
   $self->{sizer_1}->Add($self->{grid_sizer_1}, 1, wxEXPAND,