Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Perl: the Markov chain saw
 
PerlMonks  

Re: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?

by jmlynesjr (Pilgrim)
on Mar 28, 2013 at 16:29 UTC ( #1025995=note: print w/ replies, xml ) Need Help??


in reply to Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?

Looks like Wx::Grid has more display formatting flexibility, however, it seems that getting the data into the grid may take more effort - no built in Virtual mode. Play with the expanded grid example below and see if you can get the look you need. Your color choices may(should) vary. :)

Update 2: Skip down to the 2nd example.

#! /home/xxxx/CitrusPerl/perl/bin/perl # CppTrial-pg347.pl modified to Grid.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 347 - Simple Grid Example # Ported to wxPerl by James M. Lynes Jr. - Last Modified March 28,2013 # Expanded to test column and row label formatting use strict; use warnings; use Wx qw(:everything); use Wx::Grid; # Package not loaded by "use Wx qw(:e +verything)" # create the WxApplication my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef, -1, 'Grid.pl', wxDefaultPosition, wx +DefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); myStdDialogs($frame); $frame->Show; $app->MainLoop; sub myStdDialogs { my ( $self ) = @_; my $grid = Wx::Grid->new($self, wxID_ANY, wxDefaultPosition, Wx::Size->new(950,400)); $grid->CreateGrid(8, 7); # 8 rows by 7 columns $grid->EnableGridLines(1); # Grid lines 1-on, 0-off $grid->SetGridLineColour(wxBLACK); $grid->SetDefaultColSize(120,1); # Default Cell width ( +Fit overrides) $grid->SetDefaultRowSize(40,1); # Default Cell Heig +ht (Fit overrides) # Your color choices may vary. Not artistic at all! :) # Label colors and fonts - note affects both column and row labels - d +idn't see separate row/col methods $grid->SetLabelBackgroundColour(wxBLUE); $grid->SetLabelTextColour(Wx::Colour->new("yellow")); $grid->SetLabelFont(Wx::Font->new(14, wxFONTFAMILY_ROMAN, wxNORMAL +, wxBOLD)); # Selection mode - (optionss-cells,rows,cols) $grid->SetSelectionMode(wxGridSelectRows); # Always select +complete rows # Color changes for when cells are selected/highlighted $grid->SetSelectionForeground(wxRED); $grid->SetSelectionBackground(wxGREEN); # Click wit +hin grid, background goes green # Click on row label, background stays + black # until clicking within grid, then gre +en(???) # Column label height and Row label width $grid->SetColLabelSize(60); $grid->SetRowLabelSize(70); # 0 hides the row label +s # Custom column labels # Very creative! $grid->SetColLabelValue(0,"Column 1"); $grid->SetColLabelValue(1,"Column 2"); $grid->SetColLabelValue(2,"Column 3"); $grid->SetColLabelValue(3,"Column 4"); $grid->SetColLabelValue(4,"Column 5"); $grid->SetColLabelValue(5,"Column 6"); $grid->SetColLabelValue(6,"Column 7"); # Custom row labels # More creative $grid->SetRowLabelValue(0,"Row 1"); $grid->SetRowLabelValue(1,"Row 2"); $grid->SetRowLabelValue(2,"Row 3"); $grid->SetRowLabelValue(3,"Row 4"); $grid->SetRowLabelValue(4,"Row 5"); $grid->SetRowLabelValue(5,"Row 6"); $grid->SetRowLabelValue(6,"Row 7"); $grid->SetRowLabelValue(7,"Row 8"); # Misc dummy grid data $grid->SetCellValue(0, 0, "wxGrid is Good"); # A1 $grid->SetCellValue(0, 3, "This is Read-only"); # D1 $grid->SetReadOnly(0, 3); $grid->SetCellValue(3, 3, "Green on Grey"); # D4 $grid->SetCellFont(3, 3, Wx::Font->new(10, wxFONTFAMILY_ROMAN, wxN +ORMAL, wxBOLD)); $grid->SetCellTextColour(3, 3, wxGREEN); $grid->SetCellBackgroundColour(3, 3, wxLIGHT_GREY); $grid->SetColFormatFloat(5, 6, 4); $grid->SetCellValue(0, 5, "3.1415"); # F1 $grid->Fit(); # Shrink row/col sizes to fit +(comment out?) # overrides defaults above $self->SetClientSize($grid->GetSize); }

Update1:

This version appends 1000 rows of dummy data. Tried with 10000 rows and it did work but took awhile for the screen to open.

#! /home/xxxx/CitrusPerl/perl/bin/perl # CppTrial-pg347.pl modified to Grid.pl # Cross-Platform GUI Programming with wxWidgets - Smart, Hock, & Csomo +r # C++ Example from pg 347 - Simple Grid Example # Ported to wxPerl by James M. Lynes Jr. - Last Modified March 28,2013 # Expanded to test column and row label formatting # Appends 1000 rows of dummy data use strict; use warnings; use Wx qw(:everything); use Wx::Grid; # Package not loaded by "use Wx qw(:e +verything)" use Data::Dumper; # create the WxApplication my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef, -1, 'Grid.pl', wxDefaultPosition, wx +DefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); myStdDialogs($frame); $frame->Show; $app->MainLoop; sub myStdDialogs { my ( $self ) = @_; my $grid = Wx::Grid->new($self, wxID_ANY, wxDefaultPosition, Wx::Size->new(950,400)); $grid->CreateGrid(8, 7); # 8 rows by 7 columns $grid->EnableGridLines(1); # Grid lines 1-on, 0-off $grid->SetGridLineColour(wxBLACK); $grid->SetDefaultColSize(120,1); # Default Cell width ( +Fit overrides) $grid->SetDefaultRowSize(40,1); # Default Cell Heig +ht (Fit overrides) # Your color choices may vary. Not artistic at all! :) # Label colors and fonts - note affects both column and row labels - d +idn't see separate row/col methods $grid->SetLabelBackgroundColour(wxBLUE); $grid->SetLabelTextColour(Wx::Colour->new("yellow")); $grid->SetLabelFont(Wx::Font->new(14, wxFONTFAMILY_ROMAN, wxNORMAL +, wxBOLD)); # Selection mode - (optionss-cells,rows,cols) $grid->SetSelectionMode(wxGridSelectRows); # Always select +complete rows # Color changes for when cells are selected/highlighted $grid->SetSelectionForeground(wxRED); $grid->SetSelectionBackground(wxGREEN); # Click wit +hin grid, background goes green # Click on row label, background stays + black # until clicking within grid, then gre +en(???) # Column label height and Row label width $grid->SetColLabelSize(60); $grid->SetRowLabelSize(90); # 0 hides the row label +s # Custom column labels # Very creative! $grid->SetColLabelValue(0,"Column 1"); $grid->SetColLabelValue(1,"Column 2"); $grid->SetColLabelValue(2,"Column 3"); $grid->SetColLabelValue(3,"Column 4"); $grid->SetColLabelValue(4,"Column 5"); $grid->SetColLabelValue(5,"Column 6"); $grid->SetColLabelValue(6,"Column 7"); # Custom row labels # More creative $grid->SetRowLabelValue(0,"Row 1"); $grid->SetRowLabelValue(1,"Row 2"); $grid->SetRowLabelValue(2,"Row 3"); $grid->SetRowLabelValue(3,"Row 4"); $grid->SetRowLabelValue(4,"Row 5"); $grid->SetRowLabelValue(5,"Row 6"); $grid->SetRowLabelValue(6,"Row 7"); $grid->SetRowLabelValue(7,"Row 8"); # Misc dummy grid data $grid->SetCellValue(0, 0, "wxGrid is Good"); # A1 $grid->SetCellValue(0, 3, "This is Read-only"); # D1 $grid->SetReadOnly(0, 3); $grid->SetCellValue(3, 3, "Green on Grey"); # D4 $grid->SetCellFont(3, 3, Wx::Font->new(10, wxFONTFAMILY_ROMAN, wxN +ORMAL, wxBOLD)); $grid->SetCellTextColour(3, 3, wxGREEN); $grid->SetCellBackgroundColour(3, 3, wxLIGHT_GREY); $grid->SetColFormatFloat(5, 6, 4); # Seems to right jus +tify this column $grid->SetCellValue(0, 5, "3.1415"); # F1 for (0..1000) { # Additional rows causes th +e scroll bar to appear appendrow($grid); } $grid->Fit(); # Shrink row/col sizes to fit +(comment out?) # overrides defaults above $self->SetClientSize($grid->GetSize); } sub appendrow { # Append a row of dummy dat +a my ($grid) = @_; $grid->AppendRows(1, 1); my $rows = $grid->GetNumberRows(); $grid->SetRowLabelValue($rows-1,"Row $rows"); for my $c(0..6) { my $ctr = $c + 1; $grid->SetCellValue($rows-1, $c, "New Row: Col $ctr"); # Get r +eal data from SQL table } }

James

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


Comment on Re: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings?
Select or Download Code
Re^2: Wx::Perl: How to change/set font and size of Wx::ListCtrl column headings? (wxGrid::SetTable virtual wxGridTableBase)
by Anonymous Monk on Mar 29, 2013 at 04:31 UTC

      AM, thank you for the correction. Always more to learn.

      Response to my inquiry on the wxPerl mailing list:

      Hi,

      It isn't implemented in wxWidgets - probably because the library attempts to either use the native platform controls or mimic them as closely as possible. If you cannot do it with a native control, you most likely can't do it in wxWidgets. I doubt this is seen as a missing feature so you're unlikely to see it implemented in the future.

      Wx::Grid is the way to go to do what you want.

      By the way, I noticed on Perl Monks some information regarding how Wx::ListCtrl handles a large number of items.

      For that you need to use the wxLC_VIRTUAL|wxREPORT style. See the Wx::Demo where the virtual list control reports 100,000 items.

      For a Wx::Grid control with a large number of items, you should use a custom Wx::GridTable. The example in Wx::Demo reports 100,000 columns by 100,000 rows.

      Hope it helps. Sorry no positive answer on the column formatting.

      Regards

      Mark(Dootson)

      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
Node Status?
node history
Node Type: note [id://1025995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2014-04-21 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (498 votes), past polls