develooper Front page | perl.wxperl.users | Postings from April 2011


Thread Next
Bruce Ravel
April 4, 2011 14:22
Message ID:


I continue to be surprised by small differences in behavior on linux
and Windows.  

This time, the thing I'd like to do is to change the background color
of a StatusBar to indicate how urgently the status message should be
considered by the user.  In the following script, I try to change the
StatusBar background using a callback attached to a RadioBox.  This
works as I expect on Linux -- the StatusBar changes to ugly green and
red colors when those buttons are clicked.  On Windows, however,
nothing happens.  The callback is called, but the StatusBar background
color is unchanged.

Am I misunderstanding something about how the StatusBar is intended to
be used?  Or about how it is implemented on Windows?

Thanks again!

package MyApp;
use base 'Wx::App';
use Wx qw(:everything);
use Wx::Event qw(EVT_RADIOBOX);

sub OnInit {
  my $frame  = Wx::Frame ->  new(undef, -1, 'demo', [-1,-1], [250,150]);
  my $sizer  = Wx::BoxSizer->new(wxVERTICAL);
  $frame->{statusbar} = $frame->CreateStatusBar;
  $frame->{radio} = Wx::RadioBox->new($frame, -1, "Colors", 
                                      wxDefaultPosition, wxDefaultSize,
                                      ['normal', 'green', 'red']);
  $sizer -> Add($frame->{radio}, 0, wxALL 5);
  $frame->{radio} -> SetSelection(0);
  EVT_RADIOBOX($frame, $frame->{radio}, \&change_color);

  $frame ->  SetSizer($sizer);
  $frame->{statusbar} -> PushStatusText("Started!");
  $frame ->  Show(1);

sub change_color {
  my ($frame, $event) = @_;
  my $choice = $frame->{radio}->GetSelection;
  my $color = ($choice == 1) ? Wx::Colour->new(0, 255, 0)
            : ($choice == 2) ? Wx::Colour->new(255, 0, 0)
            : wxNullColour;
  $frame->{statusbar} -> SetBackgroundColour($color);

package main;
use Wx qw(:everything);
my $app = MyApp->new->MainLoop;


 Bruce Ravel  ------------------------------------

 National Institute of Standards and Technology
 Synchrotron Methods Group at NSLS --- Beamlines U7A, X24A, X23A2
 Building 535A
 Upton NY, 11973

 My homepage:
 EXAFS software:

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About