Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Two packing problems
Hi,

in the example below i get strange results when:

1. i drag the Adjuster, it seems the Listbox is not
resized

2. When i make the whole window larger, not only the
Tk::Text is enlarged, but also the Frame "top", that
only contains the "Exit" button.

Is this related to the used Tk::Scrolled widget?


Best regards,
Torsten.


#! /usr/bin/perl -w

use Tk;

$mw = MainWindow->new();

$top = $mw->Frame();
$txt = $mw->Frame();
$choice = $mw->Frame();

$lb = $mw->Scrolled('Listbox', '-scrollbars' => 'se');
$lb->pack('-side' => 'left', '-fill' => 'both', '-expand' => 1);

$q = $top->Button('-text' => 'Exit', '-command' => \&ex);
$q->pack('-side' => 'left');

$t = $txt->Scrolled('Text', '-scrollbars' => 'se');
$t->pack('-side' => 'top', '-fill' => 'both', '-expand' => 1);

$choice->packAdjust('-side' => 'left', '-fill' => 'both', '-expand' => 1);
$top->pack('-side' => 'top', '-fill' => 'x', '-expand' => 1);
$txt->pack('-side' => 'top', '-fill' => 'both', '-expand' => 1);


MainLoop;

sub ex {
exit;
}


Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
09-08-04 09:00 PM


Re: Two packing problems
"Torsten Mohr" <tmohr@s.netic.de> wrote in message
news:chnk1u$akg$1@schleim.qwe.de...
> Hi,
>
> in the example below i get strange results when:
>
> 1. i drag the Adjuster, it seems the Listbox is not
>    resized
>
> 2. When i make the whole window larger, not only the
>    Tk::Text is enlarged, but also the Frame "top", that
>    only contains the "Exit" button.
>
> Is this related to the used Tk::Scrolled widget?
>
>
> Best regards,
> Torsten.
>
>
> #! /usr/bin/perl -w
>
> use Tk;
>
> $mw = MainWindow->new();
>
> $top = $mw->Frame();
> $txt = $mw->Frame();
> $choice = $mw->Frame();
>
> $lb = $mw->Scrolled('Listbox', '-scrollbars' => 'se');
> $lb->pack('-side' => 'left', '-fill' => 'both', '-expand' => 1);
#######
$lb->pack(-in=>$choice, '-side' => 'left', '-fill' => 'both', '-expand' =>
1);
#######
>
> $q = $top->Button('-text' => 'Exit', '-command' => \&ex);
> $q->pack('-side' => 'left');
>
> $t = $txt->Scrolled('Text', '-scrollbars' => 'se');
> $t->pack('-side' => 'top', '-fill' => 'both', '-expand' => 1);
>
> $choice->packAdjust('-side' => 'left', '-fill' => 'both', '-expand' => 1);
> $top->pack('-side' => 'top', '-fill' => 'x', '-expand' => 1);
#######
$top->pack('-side' => 'top', '-fill' => 'x', '-expand' => 0);
#######

> $txt->pack('-side' => 'top', '-fill' => 'both', '-expand' => 1);
>
>
> MainLoop;
>
> sub ex {
>         exit;
> }
>

Jack



Report this thread to moderator Post Follow-up to this message
Old Post
Jack D
09-09-04 01:56 AM


Re: Two packing problems
On Wed, 08 Sep 2004 20:46:22 +0200, Torsten Mohr <tmohr@s.netic.de>
wrote:
>
>$lb = $mw->Scrolled('Listbox', '-scrollbars' => 'se');
>$lb->pack('-side' => 'left', '-fill' => 'both', '-expand' => 1);

Hi,  just a style comment. Before you get into a "habit" of doing it,
the left side of an options hash element, dosn't need to be quoted.
Not only will it save you some keystrokes, it helps "colorization"
in editors which highlight Perl syntax.

>
>$lb = $mw->Scrolled('Listbox',  -scrollbars => 'se');
>$lb->pack(-side => 'left',  -fill => 'both',  -expand => 1);



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
zentara
09-09-04 08:58 PM


Re: Two packing problems
Jack D wrote:

Thanks!  That solves both problems.


Best regards,
Torsten.


Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
09-09-04 08:58 PM


Re: Two packing problems
Hi,

> Hi,  just a style comment. Before you get into a "habit" of doing it,
> the left side of an options hash element, dosn't need to be quoted.
> Not only will it save you some keystrokes, it helps "colorization"
> in editors which highlight Perl syntax.

i once got the hint in this newsgroup that i should quote
the keys because at the moment it works, but this may change
in future.


Best regards,
Torsten.



Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
09-09-04 08:58 PM


Re: Two packing problems
Torsten Mohr wrote:
> Hi,
>
> 
>
>
> i once got the hint in this newsgroup that i should quote
> the keys because at the moment it works, but this may change
> in future.

Not exactly :) If I'm not mistaken, you got the hint that you should
have a leading dash in front of your option keys since old Tk versions
allowed option names with no leading dashes.

The quotes are not required in this case because of Perl's "fat comma"
operator (=> ) which is identical to a normal comma, except that it
automagically treats what is on its left as a quoted string. So, the
following are identical:

-option => 'value'

and

'-option', 'value'

--Ala

Report this thread to moderator Post Follow-up to this message
Old Post
Ala Qumsieh
09-09-04 08:58 PM


Re: Two packing problems
Ala Qumsieh wrote:
<snip>

> The quotes are not required in this case because of Perl's "fat comma"
> operator (=> ) which is identical to a normal comma, except that it
> automagically treats what is on its left as a quoted string. So, the
> following are identical:
>
>     -option => 'value'
>
> and
>
>     '-option', 'value'
>
> --Ala

Isn't the leading dash technically an exception to the rule? I thought the r
ule
was if the thing on the left of the fat comma looks like a bareword it will 
be
automagically quoted, otherwise it will be evaluated. Since lots of people u
se
the -name form for keys in an option hash a 'negated bareword' exception was
added to the rule.

I may of course be completely wrong :)
MB

Report this thread to moderator Post Follow-up to this message
Old Post
Matthew Braid
09-10-04 01:56 AM


Re: Two packing problems
Matthew Braid wrote:

> Isn't the leading dash technically an exception to the rule?

Yes. Perl recognizes that this is a bareword and not a "negative
string". It does not attempt to subtract it from nothing. Otherwise, you
would get warnings like:

Argument "option" isn't numeric in subtraction at ...

(assuming you have warnings enabled of course).

But this has nothing to do with the fact that earlier Tk versions
allowed options without dashes. Tk804 requires the dashes.

>                                                              I thought
> the rule was if the thing on the left of the fat comma looks like a
> bareword it will be automagically quoted, otherwise it will be
> evaluated. Since lots of people use the -name form for keys in an option
> hash a 'negated bareword' exception was added to the rule.

I never saw => evaluate its left hand side, and couldn't come up with a
case were it will. According to perlop, the left hand side of => will
always be treated as a quoted string:

The => operator is a synonym for the comma, but forces any word to its
left to be interpreted as a string (as of 5.001). It is helpful in
documenting the correspondence between keys and values in hashes, and
other paired elements in lists.

--Ala


Report this thread to moderator Post Follow-up to this message
Old Post
Ala Qumsieh
09-10-04 08:58 AM


Re: Two packing problems
Ala Qumsieh wrote:

<snip> 
>
>
> I never saw => evaluate its left hand side, and couldn't come up with a
> case were it will. According to perlop, the left hand side of => will
> always be treated as a quoted string:
>
>   The => operator is a synonym for the comma, but forces any word to its
>   left to be interpreted as a string (as of 5.001). It is helpful in
>   documenting the correspondence between keys and values in hashes, and
>   other paired elements in lists.
>
> --Ala

Sorry, by 'evaluated' I meant it is considered to be a normal expression, eg
:

$two = 2;
%hash = (1 => "one",
$two => "two",
1 + $two => "three",
FOUR => 4);
print join(", ", sort keys %hash), "\n";

results in:
1, 2, 3, FOUR

not
$two, 1, 1 + $two, FOUR

or some other weird output.

MB

Report this thread to moderator Post Follow-up to this message
Old Post
Matthew Braid
09-10-04 08:58 AM


Re: Two packing problems
Matthew Braid wrote:

> Sorry, by 'evaluated' I meant it is considered to be a normal
> expression, eg:
>
> $two = 2;
> %hash = (1 => "one",
>          $two => "two",
>          1 + $two => "three",
>          FOUR => 4);
> print join(", ", sort keys %hash), "\n";
>
> results in:
>  1, 2, 3, FOUR
>
> not
>  $two, 1, 1 + $two, FOUR
>
> or some other weird output.

That's due to precedence. Again, perlop to the rescue:

left        terms and list operators (leftward)
left        ->
nonassoc    ++ --
right       **
right       ! ~ \ and unary + and -
left        =~ !~
left        * / % x
left        + - .
left        << >>
nonassoc    named unary operators
nonassoc    < > <= >= lt gt le ge
nonassoc    == != <=> eq ne cmp
left        &
left        | ^
left        &&
left        ||
nonassoc    ..  ...
right       ?:
right       = += -= *= etc.
left        , =>
nonassoc    list operators (rightward)
right       not
left        and
left        or xor

Terms have highest precedence, so they get evaluated first. Addition has
a higher precedence than =>, so it gets executed next:

1 + $two => "two"
becomes
1 + 2    => "two"
becomes
3        => "two"

--Ala


Report this thread to moderator Post Follow-up to this message
Old Post
Ala Qumsieh
09-10-04 08:58 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:02 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.