Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions

by HelenCr (Monk)
on Mar 25, 2013 at 14:43 UTC ( [id://1025321]=perlquestion: print w/replies, xml ) Need Help??

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

Dear esteemed PerlMonks

Continuing my odyssey, I need to develop an application for traversing/roaming in databases, letting the user inspect/view tables and joins in an efficient and friendly way. (On Windowz only).

Quite a while ago I decided to do it in Perl (over friendly attempts of colleagues and friends to have me use ASP .Net and C#).
I had to choose a GUI development environment. Initially I've chosen Win32::GUI. It was pretty neat, but eventually I had to drop it, since:
a. it doesn't support Unicode/UTF-8,
and b. it doesn't seem to be supported any longer.
So after considering various pieces of advice, I decided to use wxPerl.

But, I am getting more and more frustrated. Here is a concrete question, and then some more general ones:
1. It seems to me that the widget I should be using for the main purpose I listed above (namely, a user-friendly way of browsing database tables and joins) is wxListCtrl (and mainly the virtual list control). (Gurus: I'd love to get you opinion on this).
For a neat look, I need to be able:
a. to set size and font of the list control column headings;
b. to set size and font of the item lines.

The wxPerl documentation is scant. I couldn't find an example for doing that. I did find a wxPython example: at: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-SetItemTextColor-SetItemFont-td2348263.html (attached to Robert Tomlin's post, Oct 15, 2006 4:55 (8th from top)):

# taken from: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-Set +ItemTextColor-SetItemFont-td2348263.html (main.py) import wx class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), siz +e=(350, 400)) # Now create the Panel to put the other controls on. panel = wx.Panel(self) btnBold = wx.Button(panel, -1, "Bold") btnRed = wx.Button(panel, -1, "Red") self.Bind(wx.EVT_BUTTON, self.OnBold, btnBold) self.Bind(wx.EVT_BUTTON, self.OnRed, btnRed) # create a list control self.listControl = wx.ListCtrl(panel, style=wx.LC_REPORT, size +=(200,100)) self.listControl.InsertColumn(0, "Col1") self.listControl.InsertColumn(1, "Col2") self.listControl.InsertStringItem(0, "Data 1") self.listControl.SetStringItem(0,1, "Data 2") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.listControl, 0, wx.ALL, 10) sizer.Add(btnBold, 0, wx.ALL, 10) sizer.Add(btnRed, 0, wx.ALL, 10) panel.SetSizer(sizer) panel.Layout() def OnBold(self, evt): f = self.listControl.GetItemFont(0) f.SetWeight(wx.BOLD) self.listControl.SetItemFont(0, f) def OnRed(self, evt): self.listControl.SetItemTextColour(0, wx.RED) class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, "Demonstrate listctrl") self.SetTopWindow(frame) frame.Show(True) return True app = MyApp(redirect=True) app.MainLoop()

Porting this example into wxPerl:

# taken from: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-Set +ItemTextColor-SetItemFont-td2348263.html (main.py) # ported 23 3 2013 v 0-1 use strict; use warnings; use Wx; use 5.014; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; use Win32::Console; package MyFrame; use Wx ':everything'; use Wx ':listctrl'; use Wx::Event 'EVT_BUTTON'; use parent -norequire, 'Wx::Frame'; sub new { #1 MyFrame:: my ($class, $parent, $title) = @_; my $self = $class->SUPER::new( $parent, -1, # parent window; ID -1 means any $title, # title [150, 150 ], # position [ 350, 400 ], # size ); # wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size +=(350, 400)) (Python) my $panel = Wx::Panel->new($self); my $btnBold = Wx::Button->new($panel, -1, 'Bold', wxDefaultPos +ition, wxDefaultSize); my $btnRed = Wx::Button->new($panel, -1, 'Red', wxDefaultPosit +ion, wxDefaultSize); EVT_BUTTON ($self, $btnBold, sub { $self->{listControl}->MyFr +ame::OnBold }); # self.Bind(wx.EVT_BUTTON, self.OnBold, btnBold) (Python) EVT_BUTTON ($self, $btnRed, sub { $self->{listControl}->MyFram +e::OnRed }); # self.Bind(wx.EVT_BUTTON, self.OnRed, btnRed) (Python) # create a list control $self->{listControl} = Wx::ListCtrl->new($panel, -1, wxDefault +Position, [300,100], wxLC_REPORT); $self->{listControl}->InsertColumn(0, 'Col1', wxLIST_FORMAT_LE +FT, 150); $self->{listControl}->InsertColumn(1, 'Col2', wxLIST_FORMAT_LE +FT, 150); $self->{listControl}->InsertStringItem( 0, 'dummy' ); $self->{listControl}->SetItemText( 0, 'Data 1'); $self->{listControl}->SetItem( 0, 1, 'Data 3'); $self->{listControl}->InsertStringItem( 1, 'dummy' ); $self->{listControl}->SetItemText(1, 'Data 2'); $self->{listControl}->SetItem( 0, 1, 'Data 3'); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add($self->{listControl}, 0, wxALL, 10); $sizer->Add($btnBold, 0, wxALL, 10); $sizer->Add($btnRed, 0, wxALL, 10); $panel->SetSizer($sizer); $panel->Layout(); return $self; } #1 end sub new MyFrame:: sub OnBold { # def OnBold(self, evt) +: (Python) my $this = shift; my $f = $this->GetItemFont(0); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'arial' +); $f->SetWeight(wxBOLD); $this->Wx::ListCtrl->SetItemFont(0, $f); } #1 end sub OnBold sub OnRed { # def OnRed(self, evt): + (Python) my $this = shift; $this->SetItemTextColour(0, wxRED); } #1 end sub OnRed # end class MyFrame:: # class MyApp(Wx::App): (Python) # def OnInit(self): (Python) my $frame = MyFrame->new(undef, 'Demonstrate listctrl'); # Wx::SetTopWindow($frame); $frame->Show(1); # return True (Python) my $app = Wx::SimpleApp->new; $app->MainLoop; 1;

you note that the "Red" button works ok (makes the items red), but the "Bold" button fails, with the error message: (the program is called: "Set item font post.pl"):

Error while autoloading 'Wx::ListCtrl' at F:/Win7programs/Dwimperl/per +l/site/lib/Wx.pm line 48 Wx::AUTOLOAD('Wx::ListCtrl=HASH(0x26f6454)') called at Set ite +m font post.pl line 60 MyFrame::OnBold('Wx::ListCtrl=HASH(0x26f6454)') called at Set +item font post.pl line 31 MyFrame::__ANON__('MyFrame=HASH(0x2712734)', 'Wx::CommandEvent +=SCALAR(0x2b9f3bc)') called at Set item font post.pl line 76 eval {...} called at F:/Win7programs/Dwimperl/perl/site/lib/Wx +.pm line 48

So here are my case-specific questions, and some more general questions:

1. Is GetItemFont/SetItemFont implemented for Wx::ListCtrl in wxPerl? If not, how come it's not implemented; if yes, what am I doing wrong?
2. Are all methods (see here: http://docs.wxwidgets.org/2.8/wx_wxlistctrl.html#wxlistctrlgetitemfont) of the wxListCtrl widget implemented in wxPerl? wxPerl documentation led me to think so?
3. Should I stick with wxPerl and Wx::ListCtrl for this project, or should I choose some other tools?
4. This "ObjectListView" wxPython widget looks neat: http://objectlistview.sourceforge.net/python/features.html. Is there something like it in Perl?
Should I try to port it into wxPerl?
5. I had chosen using Perl (and investing time and energy in it) since I was impressed with the power and expressiveness of the language, and its internal logic; you can feel it was designed by a linguist. But, considering the dearth of support and examples (for displaying database tables in a neat GUI), should I abandon Perl and do the project in Python?

Esteemed gurus - your help and advice will be appreciated

Many TIA - Helen

Replies are listed 'Best First'.
Re: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by ww (Archbishop) on Mar 25, 2013 at 16:39 UTC
    IMO, there's a lot of merit to using the clients' browsers (assuming a homogeneous set such as might be found in a corporate setting) and some well chosen CSS to provide all the display elements you need.

    Then, you can rely on CGI or friends to render the data... which you can obtain as required using DBD, DBI or other db modules. The catch is, you still have to get the user input. So -- along side your Perl-controlled browser -- why not use a wxPerl window whose capabilities handle the minimal requirements for input only, thus simplifying the UI at the requestor end?


    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by hdb (Monsignor) on Mar 25, 2013 at 16:16 UTC

    Try to replace

    $this->Wx::ListCtrl->SetItemFont(0, $f);

    in sub OnBold, line 60 with

    $this->{listControl}->SetItemFont(0, $f);

    or

    $this->SetItemFont(0, $f);

    Untested, as I do not have wx but these two look more logical than yours.

      hdb: I tried, (in fact, that's what I started off with), here is the modified sub:

      sub OnBold { # def OnBold(self, evt): (Py +thon) my $this = shift; my $f = $this->GetItemFont(0); # my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'aria +l'); $f->SetWeight(wxBOLD); $this->SetItemFont(0, $f); } #1 end sub OnBold

      you get a slightly different error:

      Can't locate object method "GetItemFont" via package "Wx::ListCtrl" at + Set item font post.pl line 57 MyFrame::OnBold('Wx::ListCtrl=HASH(0x23d6454)') called at Set +item font post.pl line 31 MyFrame::__ANON__('MyFrame=HASH(0x23f2734)', 'Wx::CommandEvent +=SCALAR(0 x287f36c)') called at Set item font post.pl line 76 eval {...} called at Set item font post.pl line 76

      So it seems that the Perl interpreter has correctly identified that the object belongs to the Wx::ListCtrl class; but it can't find the GetItemFont method. Why?

        Probably because is not implemented. Using a trick I learned here recently (Re: How to use wxHtmlEasyPrinting), does not show any font related methods:

        perl -MWx=:allclasses -le " print for grep/set/i, keys %Wx::ListCtrl:: + "

        Stefan.

        Update: It is now fixed with the new release of Wx, see Wx 0.9918 Released, thanks to Mark Dootson.

        Yes, hdb has a point about the OnRed method using:

        $this->{listCtrl}->SetItemTextColour( 0, wxRED );

        But also the event handler method is has to be written like this:

        EVT_BUTTON( $self, $btnBold, sub { $self->OnBold } );

        The OnBold method is in the current package.

        Another remark is that you can skip all the use.+ stuff until the first package declaration in your code examples, they are not needed and is recommended to keep the posts as short as possible. It is also better for debugging, to not load unused modules.

        Regards, Stefan.

Re: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by Anonymous Monk on Mar 26, 2013 at 01:40 UTC

    wxListCtrl (and mainly the virtual list control). (Gurus: I'd love to get you opinion on this).

    Try http://cpansearch.perl.org/src/MBARBON/Wx-Perl-ListView-0.01/example/listview.pl

    2. Are all methods ...

    No, but enough are, see Re^4: wxPerl: is wxListCtrl Get/SetItemFont implemented? ( Wx::ListCtrl::GetItemFont, Wx::ListCtrl::SetItemFont ), see Wx::DemoModules::wxListCtrl, Wx::DemoModules::wxListCtrl::Report

    although adding the missing ones is practically trivial, just look inside Wx-0.9917/XS/ListCtrl.xs

    so you might write

    I know what you're thinking, holy batguano batman, that just stinks ... :)

    I don't know, someone smarter than me (a hermit) might just send in a bug report and/or a patch -- Wx-0.9917 released 11 Feb 2013

    3. Should I stick with wxPerl and Wx::ListCtrl for this project, or should I choose some other tools?

    You know, given that you've got practically no experience with any existing toolkits, picking a different toolkit, a third or fourth one, isn't going to help you finish your project any quicker -- there will always be bumps you'll run into, whatever you pick, but they're surmountable

    5. But, considering the dearth of support and examples (for displaying database tables in a neat GUI), should I abandon Perl and do the project in Python?

    Yes, sure, go ahead, if perl isn't working for you, if perl isn't making your life easier, stop using perl,

    On the plus side, you've got all these wxPython examples you've been trying to translate, if you do your project in python, you don't have to translate any examples

Re: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by jmlynesjr (Deacon) on Mar 26, 2013 at 02:01 UTC

    I have found that it is very easy to get confused about what an object pointer is pointing to at any given moment. We tend to use and reuse $self/$this to represent different objects at different points in our code. I have found that I have to use Data::Dumper and print Dumper($self) or ($this) or ($f) to make sure the object that I think I am acting on is in fact the one that I want.

    Try adding a few print Dumpers to verify your object pointers.

    James

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-19 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found