Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How do you draw a line in wxPerl?

by Anonymous Monk
on Feb 22, 2005 at 01:30 UTC ( #433222=perlquestion: print w/replies, xml ) Need Help??

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

I'm looking for a very simple program which draws a line using wxPerl. Currently I'm stuck on trying to get a DC. I have no idea which widgets have a getDC() method, and I can't find the information in the documentation. Here's a program I've got currently which doesn't work.
#!/usr/bin/perl -w use strict; use Wx; package MyFrame; use Wx; use Wx::Event qw(EVT_BUTTON); use base 'Wx::Frame'; sub new { my $ref = shift; my $self = $ref->SUPER::new( undef, # parent window -1, # ID -1 means any 'wxPerl rules', # title [-1, -1], # default position [640, 480], # size ); # controls should not be placed directly inside # a frame, use a Wx::Panel instead my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); # create a button my $button = Wx::Button->new( $panel, # parent window -1, # ID 'quit', # label [30, 20], # position [-1, -1], # default size ); EVT_BUTTON( $self, $button, \&quit ); # this doesn't work, Wx::Frame doesn't have a getDC call my $dc = $self->getDC; $dc->DrawEllipse( 20, 20, 50, 50 ); return $self; } sub quit { my $self = shift; #exit(0); $self->Close(1); } package MyApp; use base 'Wx::App'; sub OnInit { my $frame = MyFrame->new; $frame->Show(1); } package main; my $app = MyApp->new; $app->MainLoop; __END__

Replies are listed 'Best First'.
Re: How do you draw a line in wxPerl?
by spurperl (Priest) on Feb 22, 2005 at 06:09 UTC
    Did you try DrawLine and DrawLines ?

    In general, when working with wxPerl it's useful to have the C++ docs of WxWidgets at hand, like this one:

    wxDC

    They usually fit for wxPerl as well, and sometimes have comments that explain the difference between the C++ and Perl versions. But mostly, the methods are translated 1-to-1.

    You can find some samples of wxPerl code here. A sample with DrawLine employed is here.

Re: How do you draw a line in wxPerl?
by simonflk (Pilgrim) on Feb 22, 2005 at 12:57 UTC

    I have no idea which widgets have a getDC() method

    Afaik, none of them do. A quick grep of the docs suggest that the following have a GetDC(): Wx::EraseEvent, Wx::HtmlWinParser, Wx::Printout. I think there are two ways of achieving what your're after (maybe more) - either use a Wx::ClientDC:

    my $dc = new Wx::ClientDC($frame); $dc->DrawLine(...);

    or set up a Wx::PaintEvent for your frame:

    use Wx::Event 'EVT_PAINT'; EVT_PAINT($frame, \&OnPaint); sub OnPaint { my ($frame, $event) = @_; my $dc = new Wx::PaintDC($frame); $dc->DrawLine(...); }

    See Wx::Perl::Throbber for an example of the latter.

    The wxPython wiki has lots of useful examples. They're in Python obviously, but it's trivial to do the translation in your head.

    -- simonflk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://433222]
Approved by Zaxo
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-05-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?