http://www.perlmonks.org?node_id=1030169

HelenCr has asked for the wisdom of the Perl Monks concerning the following question:

Dear esteemed PerlMonks

In an application I'm working on, I am trying to incorporate a Wx::DatePickerCtrl, and a Wx::TimePickerCtrl.

Now the DatePicker control seems to be working fine; the TimePicker control is failing in a strange way.
Your help will be appreciated.

Here are the examples. They are practically identical:
DatePickerCtrl:

# File Name: datepicker example.pl use strict; use warnings; use Wx; use 5.014; use autodie; use Win32::Console; package MyForm; # ------------------------------------------------- +----------------- package MyForm:: use strict; use warnings; use Wx qw[:everything]; # easy when testing use Wx::DateTime; use Wx::Calendar; use Wx qw(:sizer :datepicker :misc); use Wx::Event qw( EVT_DATE_CHANGED EVT_TIME_CHANGED EVT_LIST_CACHE_HIN +T EVT_CLOSE ); use parent -norequire, 'Wx::Frame'; use Wx qw(:id :toolbar :statictext wxNullBitmap wxDefaultPosition wxDe +faultSize wxTB_VERTICAL wxSIZE wxDP_ALLOWNONE wxTP_DEFAULT ); sub new { #1 --------------------------- new My +Form:: my $class = shift; my $self = $class->SUPER::new( undef, -1, # parent window; ID -1 means any 'DatePicker example', # title [80,120], [300,100], ); my ( $date_ctrl, $time_ctrl); my $panel = Wx::Panel->new( # Adding a panel $self, -1, # parent window, ID wxDefaultPosition, [300,100]); $panel->SetBackgroundColour(Wx::Colour->new('light blue')); my $date_from = Wx::DateTime->new; $date_ctrl = Wx::DatePickerCtrl->new( $panel, -1, $date_from, wxDe +faultPosition, wxDefaultSize, wxDP_ALLOWNONE ); my $sizer_main = Wx::BoxSizer->new(wxVERTICAL); $sizer_main -> Add ( $date_ctrl, 0, wxALL | wxEXPAND, 10); $panel->SetSizer($sizer_main); $sizer_main->Fit($panel); $sizer_main->SetSizeHints($panel); $panel->Fit; return $self; } #1 end sub new MyForm:: 1; # end package MyForm package main; # ------------------------------------------- +---------------- package main:: use strict; use warnings; use 5.014; use autodie; use Win32::Console; use English '-no_match_vars'; my $app = Wx::SimpleApp->new; my $frame = MyForm->new; $frame->Show(1); $app->MainLoop; 1;
That example runs fine.
and here is the TimePickerCtrl example:
# File Name: timepicker example.pl use strict; use warnings; use Wx; use 5.014; use autodie; use Win32::Console; package MyForm; # ------------------------------------------------- +----------------- package MyForm:: use strict; use warnings; use Wx qw[:everything]; # easy when testing use Wx::DateTime; use Wx::Calendar; use Wx qw(:sizer :timepicker :misc); use Wx::Event qw( EVT_DATE_CHANGED EVT_TIME_CHANGED EVT_LIST_CACHE_HIN +T EVT_CLOSE ); use parent -norequire, 'Wx::Frame'; use Wx qw(:id :toolbar :statictext wxNullBitmap wxDefaultPosition wxDe +faultSize wxTB_VERTICAL wxSIZE wxDP_ALLOWNONE wxTP_DEFAULT ); sub new { #1 --------------------------- new My +Form:: my $class = shift; my $self = $class->SUPER::new( undef, -1, # parent window; ID -1 means any 'TimePicker example', # title [80,120], [300,100], ); my ( $date_ctrl, $time_ctrl); my $panel = Wx::Panel->new( # Adding a panel $self, -1, # parent window, ID wxDefaultPosition, [300,100]); $panel->SetBackgroundColour(Wx::Colour->new('light blue')); my $time_from = Wx::DateTime->new; $time_ctrl = Wx::TimePickerCtrl->new( $panel, -1, $time_from, wxDe +faultPosition, wxDefaultSize, ); my $sizer_main = Wx::BoxSizer->new(wxVERTICAL); $sizer_main -> Add ( $time_ctrl, 0, wxALL | wxEXPAND, 10); $panel->SetSizer($sizer_main); $sizer_main->Fit($panel); $sizer_main->SetSizeHints($panel); $panel->Fit; return $self; } #1 end sub new MyForm:: 1; # end package MyForm package main; # ------------------------------------------- +---------------- package main:: use strict; use warnings; use 5.014; use autodie; use Win32::Console; use English '-no_match_vars'; my $app = Wx::SimpleApp->new; my $frame = MyForm->new; $frame->Show(1); $app->MainLoop; 1;
This TimePickerCtrl example fails with the message:
variable is not of type Wx::Point at timepicker example.pl line 34.
If I add wxTP_DEFAULT when calling the TimePickerCtrl constructor, namely:
$time_ctrl = Wx::TimePickerCtrl->new( $panel, -1, $time_from, wxDefaultPosition,
									wxDefaultSize,  wxTP_DEFAULT);
the script fails now with:
Error while autoloading 'Wx::wxTP_DEFAULT' at timepicker example.pl line 34.
What to do?

Many thanks in advance - Helen

NB I am running StrawberryPerl 5.014 on WinXP, $Wx::VERSION = 0.9917

Replies are listed 'Best First'.
Re: wxPerl: Wx::DatePickerCtrl working, Wx::TimePickerCtrl failing?
by stefbv (Curate) on Apr 23, 2013 at 15:52 UTC

    Upgrade wxWidgets to a version >= 2.9.3.

    Regards, Stefan.

      Update: Looking at: http://wxperl.sourceforge.net/news.html, it seems that wxPerl 0.9915 already had support for wxwidgets 2.9.4?
      Is it true? Or do I have to install (or upgrade) wxWidgets separately from wxPerl?
      ------------------ end of update ------------------------------

      Thank you, Stefan.

      In this regard, I have two questions:
      a. When you interrogate $Wx::VERSION, you get the wxPerl Wx:: version (in my case: 0.9917). I know that the latest version on CPAN is 0.9921. How do you know which wxWidgets version this corresponds to?

      b. Upgrade wxWidgets to a version >= 2.9.3.

      How do I upgrade? By simply installing the current Wx:: version from CPAN?

      Many TIA - Helen

        For future reference, I looked at http://www.wxwidgets.org Quick Links in the "Stable Manual" and "Latest Manual" areas for the Wx::TimePickerControl documentation. As Stefan pointed out it's not mentioned in the Stable(2.8.x) documentation, but is listed in the Latest(2.9.x) documentation with the comment as being included since 2.9.3.

        wxPerl(now .9921) can be built with either version of wxWidgets. I use Citrus Perl http://citrusperl.com which comes pre-built for 2.8.x or 2.9.x on Windows, Linux, or OS/X. It also has a utility for switching between versions if necessary. I found it easy to install on Linux. Check it out. At least look at the http://www.citrusperl.com/helpweb/contents.htm Manage Installation and Citrus Packages information.

        See also: http://grokbase.com/t/perl/wxperl-users/12cy35ag00/wxwidgets-2-9-4 and related posts for building things yourself. There are also posts relating to the minimum Strawberry/gcc version required.

        Update1: See also: http://www.wxperl.it/p/download.html.

        James

        There's never enough time to do it right, but always enough time to do it over...

Re: wxPerl: Wx::DatePickerCtrl working, Wx::TimePickerCtrl failing? (bug)
by Anonymous Monk on Apr 24, 2013 at 07:49 UTC

    congratulations, you've found a bug

    According to http://docs.wxwidgets.org/trunk/classwx_time_picker_ctrl.html that module is only available since 2.9.3

    However this works (the bug part) on earlier versions

    $ perl -MWx=:allclasses -le " print Wx::TimePickerCtrl->new " Wx::TimePickerCtrl=HASH(0x3fa184) $ perl -MWx -le " print join q/ /, $Wx::VERSION, Wx::wxVERSION_STRING +" 0.9918 wxWidgets 2.8.12

    But if you provoke usage you'll see the bug part

    $ perl -MWx=:allclasses -le " print Wx::TimePickerCtrl->new( (undef) x + 33 ) " Usage: Wx::Window::newFull(CLASS, parent, id = wxID_ANY, pos = wxDefau +ltPosition, size = wxDefaultSize, style = 0, name = wxPanelNameStr) a +t -e line 1.

    The cause of the bug is inheritance

    perl\vendor\lib\Wx\Calendar.pm 33:package Wx::TimePickerCtrl; @ISA = qw(Wx::Control);

    That part should be conditional, like this package Wx::TimePickerCtrl;  Wx::wxVERSION() >= 2.009003 and  @ISA = qw(Wx::Control);

    Naturally, wxperl_usage / wxperl-usage / wxPerl::Usage / Class Method Browser , available methods, method invocation syntax, link to docs doesn't list it as available :)

      The wxperl_usage app has the potential to become a valuable tool in our tool box. I realize that is only a quick hack in the current state (or not?), but why not put it somewhere in a public repo from where we can easily install and make contributions to?

      Regards, Stefan.

        realize that is only a quick hack in the current state (or not?)

        quick hack based on what?