[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Perl/Tk, CheckButtons, and modifying variables

David Douthitt

7/14/2005 7:05:00 PM

I'm trying to use a series of CheckButtons, and all is going pretty
well.

However, I want to change the associated variable and have it reflected
in the CheckButton. I'm not sure of how to do this.

I searched through Google Groups and Google Web and found nothing.

Because of the number of CheckButtons in my case (300) they are split
up into 10 columns on screen in 10 different frames (which shouldn't
matter). The Checkbuttons are actually stored in a Ruby hash (based on
a text string - server name, in this case).

I created a series of associated TkVariables in a related hash, but how
do I set these variables? I've been just assigning a 1 (integer) but I
wonder.... does that change the hash value from a TkVariable to an
Integer?

I'm missing something - everything works except there is no reflection
in the display of the current status of the variables...

8 Answers

Joe Van Dyk

7/14/2005 7:58:00 PM

0

On 7/14/05, David Douthitt <ssrat@mailbag.com> wrote:
> I'm trying to use a series of CheckButtons, and all is going pretty
> well.
>
> However, I want to change the associated variable and have it reflected
> in the CheckButton. I'm not sure of how to do this.
>
> I searched through Google Groups and Google Web and found nothing.
>
> Because of the number of CheckButtons in my case (300) they are split
> up into 10 columns on screen in 10 different frames (which shouldn't
> matter). The Checkbuttons are actually stored in a Ruby hash (based on
> a text string - server name, in this case).
>
> I created a series of associated TkVariables in a related hash, but how
> do I set these variables? I've been just assigning a 1 (integer) but I
> wonder.... does that change the hash value from a TkVariable to an
> Integer?
>
> I'm missing something - everything works except there is no reflection
> in the display of the current status of the variables...

Something like
my_tk_checkbox_var = TkVariable.new
# create a checkbox assining its tkvariable to my_tk_checkbox_var
my_tk_checkbox_var.value = 1 # or maybe "1", i forget

That should check the checkbox.


David Douthitt

7/14/2005 9:35:00 PM

0

That is basically what I'm doing but it's not working. I'd put the
code up but it's longish for posting to Usenet. The basics boil down
to something like this:

$serverVariable["server"] = TkVariable.new
.....

TkButton.new(x) {
....
command { $serverVariable["server"] = 1 }
}

It doesn't work right somehow...

I looked at "pack" and "configure" (after variable assignment) and
neither seems to do what I want.

David Douthitt

7/14/2005 9:56:00 PM

0

I think I'm getting closer (at least) to understanding this. Instead
of:

$serverVariable["server"] = 1

....what I want is, in reality:

lvalue_of_what_is_pointed_to_by($serverVariable["server"]) = 1

....that is, this $serverVariable["server"] contains a TkVariable, and
after the assignment it contains a 1 instead. I want to set not the
array value, but the contents of the array value. A reference, if you
will.

But how? I'm still trying...

Joe Van Dyk

7/14/2005 10:44:00 PM

0

On 7/14/05, David Douthitt <ssrat@mailbag.com> wrote:
> I think I'm getting closer (at least) to understanding this. Instead
> of:
>
> $serverVariable["server"] = 1
>
> ....what I want is, in reality:
>
> lvalue_of_what_is_pointed_to_by($serverVariable["server"]) = 1

You mean,
$serverVariable["server"].value = 1
?

>
> ....that is, this $serverVariable["server"] contains a TkVariable, and
> after the assignment it contains a 1 instead. I want to set not the
> array value, but the contents of the array value. A reference, if you
> will.
>
> But how? I'm still trying...

Maybe this will help?

require 'tk'

$root = TkRoot.new
$var = TkVariable.new
$button = TkCheckButton.new $root, :variable => $var, :text => "Hello World"
$button.pack
# alternates the value of $var from one to zero every second.
TkTimer.start 1000, -1, proc { $var.value = $var.value == "0" ? 1 : 0 }
Tk.mainloop


David Douthitt

7/14/2005 11:14:00 PM

0

That was it exactly. Thanks!

Now..... where was that documented again? ;-)

I didn't see anything in "The Ruby Way" and I didn't have my PickAxe
book with me. The PerlTk documents don't have a "Variable" or a
"TkVariable" listed anywhere.

Joe Van Dyk

7/15/2005 2:03:00 AM

0

On 7/14/05, David Douthitt <ssrat@mailbag.com> wrote:
> That was it exactly. Thanks!
>
> Now..... where was that documented again? ;-)
>
> I didn't see anything in "The Ruby Way" and I didn't have my PickAxe
> book with me. The PerlTk documents don't have a "Variable" or a
> "TkVariable" listed anywhere.

They don't?

http://perlhelp.web.cern.ch/PerlHelp/site/lib/Tk/Checkb...

WIDGET-SPECIFIC OPTIONS (for checkbutton)
Name: variable
Class: Variable
Switch: -variable
Specifies reference to a variable to set to indicate whether or
not this button is selected. Defaults to \$widget->{'Value'} member of
the widget's hash. In general perl variables are undef unless
specifically initialized which will not match either default -onvalue
or default -offvalue.

Also, you can always use
http://ruby.activeventure.com/programmingruby/book/e... as a
substitute for the pickaxe paper copy.

But yeah, Tk documentation is fairly confusing. It's mostly because
Tk documentation itself is so confusing.


Hidetoshi NAGAI

7/15/2005 5:46:00 AM

0

Hidetoshi NAGAI

7/15/2005 5:53:00 AM

0