TkText no -textvariable workaround?

I think what Tom is after is a neat way to have the widget’s display
automatically whenever the value of some variable is changed. I’ve a
vague recollection of hitting this problem sometime ago (using Tk with
perl) but I think I just bodged my way round the problem by using a
different widget. Or I may have written a lot of code that sent delete
messages etc.
cheers,
Jon

···

-----Original Message-----
From: Peter Hickman [mailto:peter@semantico.com]
Sent: 16 July 2002 15:29
To: ruby-talk ML
Subject: Re: TkText no -textvariable workaround?

Tom Sawyer wrote:

well, i’ve been busy adding tk support to my gui template tool (Miter),
but i’ve sadly come across a limitation with the TkText widget. it
dosen’t support -textvariable, hence there’s no way to bind it to a
ruby
instance variable, as i can with all the other widgets. i did figure
out
a way of automatically set the instance varaible when the TkText value
changes using bind. but i can not find a way to do the reverse. how do
i
get the TkText’s value to automatically change when the instance
variable does? i looked to see if there’s was a ruby callback method
for
such, but i didn’t find one. anyone?

With TkText you go…

@text = TkText.new(… blah blah blah …)

and then later on you can go

@text.value
@text.delete(1.0,‘end’)

and all that jazz.

is that what you wanted?


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk



This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp


Any views or personal opinions expressed within this email may not be those of Talis Information Ltd.
The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.

J- you hit the nail on the head!

to the rest, beleive me i’ve scowerd the tcl/tk docs. i don’t have any
problem editing the value of the TkText widget via the methods you-all
have now relayed to me. thanks for the attempt though. that’s just not
the problem. what i want to do is directly bind a variable to the
widget, a la -textarea, in order to create a mixin module that links an
object to a form --instantly. so if the object changes, the form
changes, and vice-versa. well, at least that was the hope. now it looks
like i’ll have to settle on some sort of ‘refresh form’ method. that is
unless anyone else has thought of way…

i still wonder if a ruby callback of some sort could pull it off. is
there a way to callback on method invocations?

p.s. by the way, mike, i’m not a newbie

···

On Tue, 2002-07-16 at 09:08, J.Hawkesworth wrote:

I think what Tom is after is a neat way to have the widget’s display
automatically whenever the value of some variable is changed. I’ve a
vague recollection of hitting this problem sometime ago (using Tk with
perl) but I think I just bodged my way round the problem by using a

well,


~transami

(") dobee dobee do…
\v/
^ ^

What you’re looking to implement is the Controller portion of the
Model-View-Controller pattern.

In Tcl/Tk, they simplified this by putting the Controller in the
View using the -textvariable argument to denote the Model that the
View should use.

When Tk was implemented for Ruby, I guess making this work wasn’t
as straightforward? So, you’ll have to implement the Controller
seperately, I guess.

– Dossy

···

On 2002.07.17, Tom Sawyer transami@transami.net wrote:

i still wonder if a ruby callback of some sort could pull it off. is
there a way to callback on method invocations?


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Michael (above) is correct. TkText is not a normal widget, but rather a kind
of super widget. You could build a great word processor or spreadsheet with
it. A single string value is just not appropriate.

When Tk was implemented for Ruby, I guess making this work wasn't
as straightforward?

No, in tcl/tk the option -textvariable don't exist for text

Guy Decoux

actually, Dossy, your post was a bit helpful. what i’m after also sort
of relates to the observer pattern. but in attempting to get ruby to
help me out with this i’ve stumbled upon an interesting question in its
own right (IMHO):

in this simple example:

a = 1

who is the receiver and what is the method? …long pause

i wondered this b/c i had the bright idea that i’d just modify the
Object class with an obverser pattern of sorts, to solve my problem,
but, well obviously that didn’t go as planned and hence this question.

~transami

···

On Tue, 2002-07-16 at 10:23, Dossy wrote:

On 2002.07.17, Tom Sawyer transami@transami.net wrote:

i still wonder if a ruby callback of some sort could pull it off. is
there a way to callback on method invocations?

What you’re looking to implement is the Controller portion of the
Model-View-Controller pattern.

In Tcl/Tk, they simplified this by putting the Controller in the
View using the -textvariable argument to denote the Model that the
View should use.

When Tk was implemented for Ruby, I guess making this work wasn’t
as straightforward? So, you’ll have to implement the Controller
seperately, I guess.

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)


~transami

(") dobee dobee do…
\v/
^ ^

well, that’s actually somewhat dissapointing. i don’t need all this
extra functionality. all i need is a multi-line TkEntry.

···

On Tue, 2002-07-16 at 18:06, Albert Wagner wrote:

Michael (above) is correct. TkText is not a normal widget, but rather a kind
of super widget. You could build a great word processor or spreadsheet with
it. A single string value is just not appropriate.


~transami

(") dobee dobee do…
\v/
^ ^

I must be thinking of something else, then. In Tcl/Tk, there's
a way to bind a variable to a widget (and the widget takes care
of the View and Controller portions for you).

Never mind, then.

-- Dossy

···

On 2002.07.17, ts <decoux@moulon.inra.fr> wrote:

> When Tk was implemented for Ruby, I guess making this work wasn't
> as straightforward?

No, in tcl/tk the option -textvariable don't exist for text

--
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)

in this simple example:
  a = 1
who is the receiver and what is the method?

In this example, you have one variable, one object and no method

Guy Decoux

actually, Dossy, your post was a bit helpful. what i’m after also sort
of relates to the observer pattern. but in attempting to get ruby to
help me out with this i’ve stumbled upon an interesting question in its
own right (IMHO):

in this simple example:

a = 1

who is the receiver and what is the method? …long pause

Speaking academically, the receiver is object a, the method is =(x).

Ruby may have optimized some of this away, but it’s essentially the
idea.

Sadly, you can’t do this:

irb(main):011:0> class Object
irb(main):012:1> def =(x)
irb(main):013:2> puts “You just set me to #{x}!”
irb(main):014:2> end
irb(main):015:1> end
SyntaxError: compile error
(irb):12: parse error
def =(x)
^
(irb):15: parse error
from (irb):15

Since I’m dumb, there’s probably a really good reason for
this but I can’t think of it – I just ate a ham and provolone
sandwich.

i wondered this b/c i had the bright idea that i’d just modify the
Object class with an obverser pattern of sorts, to solve my problem,
but, well obviously that didn’t go as planned and hence this question.

Look at Test::Unit – Nathaniel has nicely implemented the Observer
pattern in Ruby.

– Dossy

···

On 2002.07.17, Tom Sawyer transami@transami.net wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

in this simple example:

a = 1

who is the receiver and what is the method? …long pause

It depends where ‘a’ is declared:

If self has an attribute named ‘a’, then the receiver is self, and the
method is ‘a=’.

If ‘a’ is a local variable, then (conceptually) the receiver is the stack
frame containing ‘a’, and the method is ‘a=’.

Cheers,
Nat.

···

From: “Tom Sawyer” transami@transami.net


Dr. Nathaniel Pryce
B13media Ltd.
Studio 3a, Aberdeen Business Centre, 22/24 Highbury Grove, London, N5 2EA
http://www.b13media.com

I must be thinking of something else, then. In Tcl/Tk, there's
a way to bind a variable to a widget (and the widget takes care
of the View and Controller portions for you).

Yes, but this option don't exist for the text widget

Guy Decoux

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).

What is the class of ‘object a’ before the assignment?

Dave

If self has an attribute named 'a', then the receiver is self, and the
method is 'a='.

No, `a' is always interpreted as a local variable in this example

Guy Decoux

If it existed, then it would be whatever class it was.

Otherwise, Object. Like an undifferentiated stem cell … :stuck_out_tongue_winking_eye:

– Dossy

···

On 2002.07.17, Dave Thomas Dave@PragmaticProgrammer.com wrote:

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).

What is the class of ‘object a’ before the assignment?


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Very perceptive. True even if
you do this:

class Object
attr_accessor :a
end

Within the object, I guess you
always need self to access something
like this. Any exceptions to this?

Hal Fulton

···

----- Original Message -----
From: “ts” decoux@moulon.inra.fr
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Cc: ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 12:23 PM
Subject: Re: TkText no -textvariable workaround?

If self has an attribute named ‘a’, then the receiver is self, and the
method is ‘a=’.

No, `a’ is always interpreted as a local variable in this example

:slight_smile:

What is the sound of one hand clapping? What is the color
of an unexposed roll of film? What is the speed of sound
in a vacuum?

But seriously, I think Dossy is mistaken… except in the
special case of attribute writers and accessors, assignment
is never considered to be a method call in Ruby. Correct?

Hal Fulton

···

----- Original Message -----
From: “Dave Thomas” Dave@PragmaticProgrammer.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 12:15 PM
Subject: Re: TkText no -textvariable workaround?

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).

What is the class of ‘object a’ before the assignment?

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).
[…]
But seriously, I think Dossy is mistaken… except in the
special case of attribute writers and accessors, assignment
is never considered to be a method call in Ruby. Correct?

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

I wonder how Ruby would have been different if Object#=(x) were defined
as an alias to #replace

– Dossy

···

On 2002.07.17, Hal E. Fulton hal9000@hypermetrics.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Hal E. Fulton wrote:

What is the class of ‘object a’ before the assignment?

:slight_smile:

What is the sound of one hand clapping? What is the color
of an unexposed roll of film? What is the speed of sound
in a vacuum?

The answer for the last is 0 m/sec. Would have to think to find the
answer for the others. The second is something close to gray/black.
The first is probably “any sound of 0 dB” ?

(Ok, drifting off topic here …)

···


Giuseppe “Oblomov” Bilotta

Axiom I of the Giuseppe Bilotta
theory of IT:
Anything is better than MS

Hi –

From: “ts” decoux@moulon.inra.fr
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Cc: ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 12:23 PM
Subject: Re: TkText no -textvariable workaround?

If self has an attribute named ‘a’, then the receiver is self, and the
method is ‘a=’.

No, `a’ is always interpreted as a local variable in this example

Very perceptive. True even if
you do this:

class Object
attr_accessor :a
end

Within the object, I guess you
always need self to access something
like this. Any exceptions to this?

I think that the only case you have to use self is when you’re doing
assignment (to prevent it from being taken for a local variable). If
you’re calling a reader method, you can do just ‘a’:

irb(main):001:0> class Thing; attr_accessor :a; def thing; puts a;
end; end
nil
irb(main):002:0> t = Thing.new; t.a = 3; t.thing
3

David

···

On Wed, 17 Jul 2002, Hal E. Fulton wrote:

----- Original Message -----


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav