Mega Widget Geometry setting 
Author Message
 Mega Widget Geometry setting

Hi again,

I have another mega widget question.

How do I determine the size of a mega widget?

The following code builds a derived widget, but a call to that widget to
determine its geometry yields 1x1+0+0.

    use Tk;
    package Tk::DemoButton;
    use Tk::widgets qw/Button/;
    use base qw(Tk::Derived Tk::Button);
    use strict;
    Construct Tk::Widget 'DemoButton';
    sub ClassInit {

         $class->SUPER::ClassInit($mw);
    }
    sub Populate {

         $self->SUPER::Populate($args);
    }
    package main;
    my $mw=MainWindow->new(-title=>'DEMOBUTTON');
    my $db=$mw->DemoButton(-text=>'Demo Button')->pack();
    print "dbgeom:",$db->geometry(),"\n";
    MainLoop;



Fri, 25 Mar 2005 08:35:38 GMT  
 Mega Widget Geometry setting

Quote:

> Hi again,
> I have another mega widget question.
> How do I determine the size of a mega widget?
> The following code builds a derived widget, but a call to that widget to
> determine its geometry yields 1x1+0+0.
>     use Tk;
>     package Tk::DemoButton;
>     use Tk::widgets qw/Button/;
>     use base qw(Tk::Derived Tk::Button);
>     use strict;
>     Construct Tk::Widget 'DemoButton';
>     sub ClassInit {

>          $class->SUPER::ClassInit($mw);
>     }
>     sub Populate {

>          $self->SUPER::Populate($args);
>     }
>     package main;
>     my $mw=MainWindow->new(-title=>'DEMOBUTTON');
>     my $db=$mw->DemoButton(-text=>'Demo Button')->pack();

At this point in time there is no guarantee that anything has been
mapped on the display.  Try inserting any of these 3 statements here:

    $db->waitVisibility;
    $db->idletasks;
    $db->update;

waitVisibility() is probably what you want.  Screen updates are deferred
as low priority events, which is what idletasks() will flush.  update()
empties the entire event queue, but may have adverse side-effects, so
use with caution.              

Quote:
>     print "dbgeom:",$db->geometry(),"\n";
>     MainLoop;

Steve

'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_[1],-he,25)->grid;$c->$
En'.
'ter>',sub{$y=int(rand($m->screenheight));$m->geometry("+$y+$y")});MainLoop;


Fri, 25 Mar 2005 08:47:45 GMT  
 Mega Widget Geometry setting

Quote:

> Hi again,

> I have another mega widget question.

> How do I determine the size of a mega widget?

> The following code builds a derived widget, but a call to that widget to
> determine its geometry yields 1x1+0+0.

Ok, I've found I need to update the widget, but that isn't the end of
the story. When I pack the mega widget on a toplevel I get a different
answer for its width than when I configure it into a TableMatrix.

e.g.,
   #!/usr/local/bin/perl
   use Tk;
   use Tk::TableMatrix;
   package Tk::DemoComposite;
   $Tk::DemoComposite::VERSION='1.0';
   use Tk::widgets qw/Label Entry/;
   use base qw(Tk::Frame);
   use strict;

   Construct Tk::Widget 'DemoComposite';

   sub ClassInit {

       print "CLASSINIT\n";
       $class->SUPER::ClassInit($mw);
   }
   sub Populate {

       print "POPULATE\n";
       $self->SUPER::Populate($args);

       $self->ConfigSpecs(
            -bg=>'-background',
            -fg=>'-foreground',
       );
       my $e=$self->Component(Entry=>'Entry',-width=>7);
       my $l=$self->Component(Label=>'Label',-text=>'yyy');
       $e->pack(-side=>'left');
       $l->pack(-side=>'left');
       $self;
   }
   package main;
   my $mw=MainWindow->new(-title=>'DEMOBUTTON');
   my $tm=$mw->TableMatrix(-rows=>4,-cols=>5,
             -colwidth=>-50)->pack(-expand=>1,-fill=>'both');
   my $db=$tm->DemoComposite();
   $tm->windowConfigure("1,1",-window=>$db);
   $mw->update;
   my $db2=$mw->DemoComposite()->pack;
   my $db3=$mw->DemoComposite();
   $db->update;
   $db2->update;
   $db3->update;
   print "dbgeom:",$db->geometry(),"  width=",$db->width,"\n";
   print "entrywidth:",$db->Subwidget('Entry')->width,"\n";
   print "labelwidth:",$db->Subwidget('Label')->width,"\n";
   $tm->colWidth(1,-$db->width);
   $mw->update;
   $mw->Button(-text=>"PRESS FOR WIDTHS",-command=>sub {
             &show();
             })->pack;
   print "Widths before MainLoop\n";
   &show;

   MainLoop;
   sub show {
       print "Width of Composite Widget configured TableMatrix:",
                  $db->width, "\n";
       print "Width of Composite Widget packed in MainWindow:",
                                        $db2->width,"\n" ;
       print "Width of Composite Widget unpacked MainWindow:",
                 $db3->width,"\n";
   }



Fri, 25 Mar 2005 16:24:56 GMT  
 Mega Widget Geometry setting

Quote:
> > I have another mega widget question.

> > How do I determine the size of a mega widget?

> [...]
> At this point in time there is no guarantee that anything has been
> mapped on the display.  Try inserting any of these 3 statements here:

>     $db->waitVisibility;
>     $db->idletasks;
>     $db->update;

> waitVisibility() is probably what you want.  Screen updates are deferred
> [...]

Thanks for that, I think I now understand my REAL problem. I'm overlaying
a TableMatrix cell with a mega widget. The TableMatrix is squashing
the widget so I'm trying to find the widget size so I can tell the
TableMatrix to enlarge its cell. But if I ask for the widget size after
doing the windowConfigure to put the widget in the TableMatrix, then I
get the wrong size.

What I've finally worked out (after much RTFM and your book) is that I
need to find the $widget->req(width|height) and adjust the TableMatrix
before putting the widget in the cell. It all makes sense now.

Thanks to you and Slaven for your assistance in various parts of this
problem. I'll post the EntryTableMatrix when its a little more complete.

Cheers,
Geoff



Sat, 26 Mar 2005 07:32:08 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How do I set widget/window size (-geometry does not work)

2. Any experience with tclMotif mega-widgets using ITCL?

3. mega-widgets

4. Initial Placement Of Toplevel Mega-Widgets

5. Perl/TK Mega Widgets

6. Taking a configuration option in a mega widget

7. Getting screensize and set geometry?

8. Bug in setting geometry

9. Setting absolute coordinates for widgets in Tk

10. Setting a grab on more than one widget?

11. How to set max characters for Entry widget

12. Setting text in Tk entry widget

 

 
Powered by phpBB® Forum Software