Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: perl tk frame packing question

by stefbv (Chaplain)
on Aug 20, 2013 at 05:58 UTC ( #1050128=note: print w/ replies, xml ) Need Help??


in reply to Re^2: perl tk frame packing question
in thread perl tk frame packing question

One problem that I am getting is , the font is always set to Helvetica and size as 9.

That happens when you close and restart the application, right? The "old font" is the default font, in this case probably Helvetica,9. If you restart the application the default font will be used. Use a configuration file to save the desired font and apply it at the application start.

The same for the HList, if you destroy and recreate it you have to reapply the desired font.


Comment on Re^3: perl tk frame packing question
Re^4: perl tk frame packing question
by Anonymous Monk on Aug 20, 2013 at 07:59 UTC
    Tk::Style might help with that (I havent tried it)
Re^4: perl tk frame packing question
by ghosh123 (Monk) on Aug 20, 2013 at 08:38 UTC

    Yes,this is certainly happening when I restart the application. Even when my gui is getting refreshed by $mw->after() every 10 secs , the selected font is also getting lost from the itemstyles.
    Please let me know how can I apply the desired font on HList effectively, I am applying it in the callback on the entire mainwindow widget as $mw->RefontTree(-font => $font) , is not that enough ?

      It's not enough because you don't call RefontTree again after destroing the HList. ItemStyle has a font option, make $font global and use it to set the font when the HList is recreated (-font => $font).

Re^4: perl tk frame packing question
by ghosh123 (Monk) on Aug 21, 2013 at 11:17 UTC

    In reply to your comment
    "It's not enough because you don't call RefontTree again after destroing the HList. ItemStyle has a font option, make $font global and use it to set the font when the HList is recreated (-font => $font). "
    While seleceting the fonts from the FontDialog, I was also printing the $font and its descripttive name. For example for 'courier 10 pinch' and font size 5 , the $font which we pass to -font is coming as font30.
    I created a global variable at the top of my program as $font and assigned font30 to it. Then using that $font to RefontTree for $mw and $hlistframe. Even after destroying the hlistframes i am calling the RefontTree on $hlistframe and passing $font to -font. But it does not seem to be taking that font while the gui is launched.
    Can you please show me a working example.

      It seems that despite what the docs say, you have to use the descriptive name to set the font.

      Anyhow a better way than destroying and recreating the HList widget, is to clear the contents and than add new contents like in the following example:

      use strict; use warnings; use Tk; use Tk::HList; use Tk::ItemStyle; use Tk::FontDialog; my $mw = MainWindow->new; $mw->title("View"); $mw->minsize(560, 180); my $font = '{Architects Daughter} -12 bold'; # have to use descriptive + name my $top = $mw->Frame()->pack( -side => 'top', -fill => 'both', -expand => +0 ); my $hlistframe = $mw->Frame()->pack( -side => 'top', -fill => 'both', -expand => +1 ); my $bottomframe = $mw->Frame()->pack( -fill => 'x', -expand => 0 ); my $menubutton = $top->Menubutton( -text => "Font", )->pack( -side => 'left' ); $menubutton->command( -label => "Change", -command => sub { $font = $mw->FontDialog->Show; $mw->RefontTree( -font => $font ) if defined $font; print "Font changed: $font\n"; } ); my $hl = $hlistframe->Scrolled( 'HList', -scrollbars => 'ose', -columns => 2, -header => 1, -height => -1, )->pack( -fill => 'both', -expand => 1 ); my $label1 = $hl->Label( -text => "Tool", -anchor => 'w' ); $hl->headerCreate( 0, -itemtype => 'window', -widget => $label1 ); my $label2 = $hl->Label( -text => "Vendor", -anchor => 'w' ); $hl->headerCreate( 1, -itemtype => 'window', -widget => $label2 ); #... $bottomframe->Button( -text => "Add item", -command => \&add_item ) ->pack( -side => 'right', -anchor => 'ne', -fill => 'x' ); $bottomframe->Button( -text => "Clear", -command => \&clear ) ->pack( -side => 'right', -anchor => 'ne', -fill => 'x' ); $mw->RefontTree( -font => $font ) if defined $font; # set default font my $style = $hl->ItemStyle( 'text', -background => 'light green', -font => $font, ); add_item(); sub add_item { my $e = $hl->addchild(''); if (defined $font) { my $font_descriptive = $mw->GetDescriptiveFontName($font); $style->configure( -font => $font ); print $font_descriptive, "\n"; } $hl->itemCreate( $e, 0, -text => 'Col0', -style => $style ); $hl->itemCreate( $e, 1, -text => 'Col1' ); } sub clear { $hl->delete('all'); } MainLoop;

      This way changing the font of the widget is not needed anymore.

Re^4: perl tk frame packing question
by ghosh123 (Monk) on Aug 22, 2013 at 04:37 UTC

    Thanks for your reply.
    The fonts are working.
    But the frame packing problem has surfaced again. I made the following 3 changes you mentioned
    1.Minsize for main window
    2.top and bottom frame expand=>0 and fill=>x
    3.height=>-1 to HList
    Doing the above things, frames are getting packed as I want and the 'Display' button on bottomframe is visible at the minimum size of the window. But this works only if I have 2-3 rows of data under the columns.

    If I have some 6+ rows , then the gui window is launched with a bigger size and as I contract it to a smaller size the Display button on the bottomframe starts disappearing. Hence the problem still persists. Also the vertical scrollbar on the right hand side has no use if the gui always has to be kept so long to view some 6+ rows. It should stay as small as (380x160) irrespective of the row numbers and one can make use of the scrollbar and yet see all the frames.

    One more thing : Clicking on the 'Display file' button opens a scrolled ROText widget. Hence the default font or the selected font if I choose any from the FontDialog later, is getting applied on the ROText widget as well. I think since I am applying RefontTree on the mainwindow ($mw->RefontTree) so it is happening. But can I prevent that anyway ? By that I mean, on the ROText I want the normal Tk font that happens if I do not hard-code any default font or so by RefontTree .
    To consolidate, the default font or the selected font from FontDialog will still be applied on $mw but not on the ROText window.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1050128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-09-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls