Scrolling Tk Checkboxes
Friends, How do I put a Scrollbar on the following? use Tk; my $mw=new MainWindow; $mw-geometry(200x400+400+10);# Width X height + from left + from top @output=(a, b, c, d, e, f, g, h, i, j, k, l, a, b, c, d, e, f, g, h, i, j, k, l); while($output[$cnt]){ $show=$mw-Checkbutton(-text, $output[$cnt])-pack(-anchor, w); $cnt++; } MainLoop; Thanks! Jerry _ Fixing up the home? Live Search can help http://imagine-windowslive.com/search/kits/default.aspx?kit=improvelocale=en-USsource=hmemailtaglinenov06FORM=WLMTAG ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Scrolling Tk Checkboxes
Jerry Kassebaum wrote: Friends, How do I put a Scrollbar on the following? use Tk; my $mw=new MainWindow; $mw-geometry(200x400+400+10); # Width X height + from left + from top my $f = $mw-Scrolled(Frame)-pack(qw/-side left -expand yes -fill both/); @output=(a, b, c, d, e, f, g, h, i, j, k, l, a, b, c, d, e, f, g, h, i, j, k, l); while($output[$cnt]) { # $show=$mw-Checkbutton(-text, $output[$cnt])-pack(-anchor, w); $show=$f-Checkbutton(-text, $output[$cnt])-pack(-anchor, w); $cnt++; } MainLoop; Thanks! Jerry 'use strict;' added at the top will highlight the need for a couple more edits ;-) HTH - Lynn. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Checkboxes
Hi all The [subscribers] section in the .cfg file of my mailing list manager gives a flag value for each subscriber ... Flags=1414 ... which is linked to a set of gui checkboxes - some, but not all, of which are mutually exclusive. Checking each option in turn and monitoring the .cfg file results in this table ... 0 no flags set 1 subscriber is suspended 2 receives list messages 4 posts lists messages 8 subscriber is list administrator 16 subscriber is moderated 32 subscriber is barred 64 receives multipart/mixed digests 128 receives binaries 256 posts binaries 512 receives multipart/digest digests 1024 receives text/plain digests 2048 public membership 4096 concealed subscription address 8192 force text/plain posts Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Checkboxes
Code: $bitstring=unpack(b16,$flags); print Bitstring is $bitstring\n; # 100011101100 for 1414 HTH :) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jim Hill Sent: Tuesday, January 27, 2004 1:42 PM To: [EMAIL PROTECTED] Subject: Checkboxes Hi all The [subscribers] section in the .cfg file of my mailing list manager gives a flag value for each subscriber ... Flags=1414 ... which is linked to a set of gui checkboxes - some, but not all, of which are mutually exclusive. Checking each option in turn and monitoring the .cfg file results in this table ... 0 no flags set 1 subscriber is suspended 2 receives list messages 4 posts lists messages 8 subscriber is list administrator 16 subscriber is moderated 32 subscriber is barred 64 receives multipart/mixed digests 128 receives binaries 256 posts binaries 512 receives multipart/digest digests 1024 receives text/plain digests 2048 public membership 4096 concealed subscription address 8192 force text/plain posts Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Checkboxes
Jim Hill wrote: Hi all The [subscribers] section in the .cfg file of my mailing list manager gives a flag value for each subscriber ... Flags=1414 ... which is linked to a set of gui checkboxes - some, but not all, of which are mutually exclusive. Checking each option in turn and monitoring the .cfg file results in this table ... 0 no flags set 1 subscriber is suspended 2 receives list messages 4 posts lists messages 8 subscriber is list administrator 16 subscriber is moderated 32 subscriber is barred 64 receives multipart/mixed digests 128 receives binaries 256 posts binaries 512 receives multipart/digest digests 1024 receives text/plain digests 2048 public membership 4096 concealed subscription address 8192 force text/plain posts Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? I would just use a hash and for loop. eg: use strict; my $flags = 2; my %hash = (1 = 'Subscriber is Suspended', 2 = 'Receives List Messages', ...); foreach (sort keys %hash) { print $hash{$_}\n if $flags $_; } __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Checkboxes
$Bill Luebkert in [EMAIL PROTECTED]: Jim Hill wrote: Flags=1414 Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? I would just use a hash and for loop. eg: I suspected that there might be solution completely outside my ken. Thanks $Bill, another brilliant response. use strict; my $flags = 2; my %hash = (1 = 'Subscriber is Suspended', 2 = 'Receives List Messages', ...); foreach (sort keys %hash) { print $hash{$_}\n if $flags $_; } I don't follow that. How are the keys in the hash processed such that they sum to the $flags value? Is it possible to get the matching hash values to print out in the same order in which the hash was initialised? -- ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Checkboxes
Jim Hill wrote: $Bill Luebkert in [EMAIL PROTECTED]: Jim Hill wrote: Flags=1414 Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? I would just use a hash and for loop. eg: I suspected that there might be solution completely outside my ken. Thanks $Bill, another brilliant response. use strict; my $flags = 2; my %hash = (1 = 'Subscriber is Suspended', 2 = 'Receives List Messages', ...); foreach (sort keys %hash) { print $hash{$_}\n if $flags $_; } I don't follow that. How are the keys in the hash processed such that they sum to the $flags value? The keys don't necessarily sum to the $flags value. Some of the keys may be present in the $flags value. The ones that are are printed out - determined by the bit-wise and. Is it possible to get the matching hash values to print out in the same order in which the hash was initialised? Only if the hash sorts to the same order. You could create an array to re-order the values for you - where $array[0] has the value to lookup up in the hash for the first value, etc. Then the stmt becomes : my @array = (2, 32, 16, 8, 1, 4); for (my $ii = 0; $ii @array; $ii++) { print array ordered: $hash{$array[$ii]}\n if $flags $array[$ii]; } -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Checkboxes
[Jim Hill wrote] [...] Flags=1414 ... which is linked to a set of gui checkboxes - some, but not all, of which are mutually exclusive. Checking each option in turn and monitoring the .cfg file results in this table ... 0 no flags set 1 subscriber is suspended 2 receives list messages 4 posts lists messages 8 subscriber is list administrator 16 subscriber is moderated 32 subscriber is barred 64 receives multipart/mixed digests 128 receives binaries 256 posts binaries 512 receives multipart/digest digests 1024 receives text/plain digests 2048 public membership 4096 concealed subscription address 8192 force text/plain posts Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? [Mark Messenger wrote] [...] $bitstring=unpack(b16,$flags); print Bitstring is $bitstring\n; # 100011101100 for 1414 Actually, given $flags == 1414, this is unpacking the _string_ 14 (0x31 0x34). unpack() expects its 2nd arg to be a string, so Perl passes the _string_ value of $flags, 1414, to unpack() (only the first 2 chars of 1414 are used because of the 'b16' template). To pass unpack() the appropriate byte stream, use pack() first. Such as: $bitstring = unpack('b16', pack('S', $flags)); # $bitstring == '01111010' LSB - MSB As I prefer the MSB (Most Significant Bit) on the left, I would probably be more likely to use: $bitstring = sprintf('%0.16b', 1414); # $bitstring == '01011110' MSB - LSB If you would prefer the decimal values of the bits set, consider: my @bits = (); for (8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1) { push(@bits, $_) if $flags $_; } # Given $flags == 1414, @bits will contain (1024, 256, 128, 4, 2) If you want the text corresponding to each checkbox, see $Bill's post. Hmm...Let me slightly tweak his suggestion and sort the keys in numeric order and include the bit value in the output - might make it easier to compare with the checkbox list. use strict; my $flags = 1414; # Just to be consistent with the other examples my %hash = (1 = 'Subscriber is Suspended', 2 = 'Receives List Messages', ...); foreach (sort {$a = $b} keys %hash) { printf %4d %s\n, $_, $hash{$_} if $flags $_; } This prints: 2 receives list messages 4 posts lists messages 128 receives binaries 256 posts binaries 1024 receives text/plain digests HTH, Jonathan D Johnston ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re[2]: Checkboxes
Hello Jim, Tuesday, January 27, 2004, 7:46:33 PM, you wrote: JH $Bill Luebkert in [EMAIL PROTECTED]: Jim Hill wrote: Flags=1414 Is there a module or a perl algorithm for determining which of the 14 checkboxes are enabled from a Flags= value? I would just use a hash and for loop. eg: JH I suspected that there might be solution completely outside my JH ken. Thanks $Bill, another brilliant response. use strict; my $flags = 2; my %hash = (1 = 'Subscriber is Suspended', 2 = 'Receives List Messages', ...); foreach (sort keys %hash) { print $hash{$_}\n if $flags $_; } JH I don't follow that. How are the keys in the hash processed such JH that they sum to the $flags value? Each value is assigned, in turn, to $_. $_ is then anded with the flags value. JH Is it possible to get the matching hash values to print out in JH the same order in which the hash was initialised? A bitwise and () will return true if the flag bit is true in a value. Eg: 1414 1024 == true # text/plain digests. This might make more sense in binary: 1011110 # 1414 100 # 1024 == 100; # true Bitwise and sets each bit in the return value to 1 if both input bits at the same position are 1. And remember, any non-zero value is a true boolean (At least in C, I can only assume the same about perl :P). I also wanted to point out that the binary value for 1414 posted by Mark Messenger is a bit wild. I would suggest against using unpack (at least in that form) to get the binary values of perl integers. Unpack seems to get some of the underlying data structure or at least the binary machine representation in the unpacking. Eg: print unpack(b16,1); 10001100 print unpack(b16,2); 01001100 print unpack(b16,1414); 100011101100 print unpack(b16,14); 100011101100 print unpack(b32,1414); 100011101100100011101100 It looks like perl's integer data-type is 1 byte per decimal place with the left four bits representing decimal values 0-9 (little endian). The right four bits seem to always be 1100. Heck, those look like the (reversed) ascii values of the characters to me. 00110 001100011 001100102 001100113 001101004 001101015 001101106 001101117 001110008 001110019 Woops, I guess so (just looked it up). Is there some way to force unpack to do this using the integer value?seems immune, fortunately. -- Best regards, Sammailto:[EMAIL PROTECTED] ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs