Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Wise Monks, I am trying to use Wx::FontDialog on Windows XP to let the user select a font. However, I don't seem to be able to retrieve the font information from the dialog box. I have created a short demo (adapted from this one) of the problem below. The way I understand it (may or may not be correct) is as follows: The GetFontData method returns a reference to a Wx::FontData object. From this object, I should be able to get the Wx::Font that the user chose. However, I always get output as seen here:
OK button pressed, getting font info... Font Data: Wx::FontData=SCALAR(0x1c051ec) Font: 1
Shouldn't $font be a reference to Wx::Font instead of a "1"? My setup is as follows:

Windows XP
ActiveState Perl 5.6.1 build 635
Wx version 0.21 installed from here.

Any advice is most appreciated.

use Wx; package MyApp; use strict; use vars qw(@ISA); @ISA=qw(Wx::App); $| = 1; sub OnInit { my($this) = @_; my($frame) = MyFrame->new("Font Selector Demo", Wx::Point->new(50, + 50), Wx::Size->new(450, 350)); $this->SetTopWindow($frame); $frame->Show(1); 1; } package MyFrame; use strict; use vars qw(@ISA); @ISA=qw(Wx::Frame); use Wx::Event qw(EVT_MENU); use Wx qw(wxBITMAP_TYPE_ICO wxMENU_TEAROFF); sub new { my($class) = shift; my($this) = $class->SUPER::new(undef, -1, $_[0], $_[1], $_[2]); my($mfile) = Wx::Menu->new(undef, wxMENU_TEAROFF); my($ID_TEST, $ID_EXIT) = (1, 2); $mfile->Append($ID_TEST, "&Test Font Dialog\tCtrl-T", "Display a f +ont dialog"); $mfile->Append($ID_EXIT, "E&xit\tAlt-X", "Quit this program"); my($mbar) = Wx::MenuBar->new(); $mbar->Append($mfile, "&Test"); $this->SetMenuBar($mbar); EVT_MENU($this, $ID_TEST, \&OnTest); EVT_MENU($this, $ID_EXIT, \&OnQuit); $this; } sub OnQuit { my($this, $event) = @_; $this->Close(1); } use Wx qw(wxID_OK wxOK wxICON_INFORMATION wxVERSION_STRING); sub OnTest { my($this, $event) = @_; my $fontdata; my $font; my $facename; my $dialog = Wx::FontDialog->new($this); $dialog->Create($this); if ($dialog->ShowModal() == wxID_OK) { print "OK button pressed, getting font info...\n"; $fontdata = $dialog->GetFontData; print " Font Data: $fontdata\n"; $font = $fontdata->GetChosenFont(); print " Font: $font\n"; } } package main; my($app) = MyApp->new(); $app->MainLoop();

2005-03-30 Janitored by Arunbear - added readmore tags, as per Monastery guidelines


In reply to Wx::FontDialog Problem by T.G. Cornholio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-24 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found