From: Georgios Petasis on
I think I have found a solution, from the "friently" objects in the
wiki: http://wiki.tcl.tk/21595#pagetocf3097447

I have written a proc that returns the current style object
(ELEP::Style::getStyle), and used the "forward" method:

oo::class create ELEP::FlowControl::Item {
forward getStyle [ELEP::Style::getStyle] initFlowControlItem
..
}

It seems to work. However, this is executed when the class is defined,
which means that once I have created a style object, the name of this
object must always be the same, even if a new style object is created.

Is there a way to use a variable in forward, instead of a command?

George



στις 12/4/2010 19:38, O/H Georgios Petasis έγραψε:
> Hi all,
>
> I am wondering the following:
>
> I have a class A. This class A has a variable named "background".
>
> Then, I have a class B. This class has a method (init) that sets a value
> to the variable background:
>
> class create B {
> method init {} {
> my variable background
> set background red
> }
> }
>
> If I have an object from class A, is there a way to execute the init
> method (from a B's object) into the context of the A object?
>
> Why I need this?
> I had a set of classes, that implement "items" on a canvas:
> http://www.ellogon.org/~petasis/tcl/TkRibbon/images/Ellogon-Ribbon-System-Logs.png
>
> There are two major kinds of "items", a "block" and a "connector" (the
> arrows).
>
> Right now, colours are coded inside the code (not a good approach). I am
> looking for a way to "theme" these classes, where the values for a set
> of variables can be retrieved from a "style" object.
>
> There is the alternative for the "item" object to query the value of
> each variable from the style object, but many variables and a few items
> (it may be slow).
>
> Any ideas?
>
> George

From: Georgios Petasis on
Finally, it does not work :D

I have connected the variables of the two objects.

George

στις 12/4/2010 20:01, O/H Georgios Petasis έγραψε:
> I think I have found a solution, from the "friently" objects in the
> wiki: http://wiki.tcl.tk/21595#pagetocf3097447
>
> I have written a proc that returns the current style object
> (ELEP::Style::getStyle), and used the "forward" method:
>
> oo::class create ELEP::FlowControl::Item {
> forward getStyle [ELEP::Style::getStyle] initFlowControlItem
> ..
> }
>
> It seems to work. However, this is executed when the class is defined,
> which means that once I have created a style object, the name of this
> object must always be the same, even if a new style object is created.
>
> Is there a way to use a variable in forward, instead of a command?
>
> George
>
>
>
> στις 12/4/2010 19:38, O/H Georgios Petasis έγραψε:
>> Hi all,
>>
>> I am wondering the following:
>>
>> I have a class A. This class A has a variable named "background".
>>
>> Then, I have a class B. This class has a method (init) that sets a value
>> to the variable background:
>>
>> class create B {
>> method init {} {
>> my variable background
>> set background red
>> }
>> }
>>
>> If I have an object from class A, is there a way to execute the init
>> method (from a B's object) into the context of the A object?
>>
>> Why I need this?
>> I had a set of classes, that implement "items" on a canvas:
>> http://www.ellogon.org/~petasis/tcl/TkRibbon/images/Ellogon-Ribbon-System-Logs.png
>>
>>
>> There are two major kinds of "items", a "block" and a "connector" (the
>> arrows).
>>
>> Right now, colours are coded inside the code (not a good approach). I am
>> looking for a way to "theme" these classes, where the values for a set
>> of variables can be retrieved from a "style" object.
>>
>> There is the alternative for the "item" object to query the value of
>> each variable from the style object, but many variables and a few items
>> (it may be slow).
>>
>> Any ideas?
>>
>> George
>

From: Georgios Petasis on
I think I find a solution (a really simple one):

The style object does not need to define the variables in its object. It
just defines the variables in the context of the caller.

class create B {
method init {} {
set my [uplevel namespace which my]
$my variable background
set background red
}
}

So, calling anywhere in any object of A the method init from an object B
does the trick.

I don't know if inheritance works in style objects yet.

George

στις 12/4/2010 20:11, O/H Georgios Petasis έγραψε:
> Finally, it does not work :D
>
> I have connected the variables of the two objects.
>
> George
>
> στις 12/4/2010 20:01, O/H Georgios Petasis έγραψε:
>> I think I have found a solution, from the "friently" objects in the
>> wiki: http://wiki.tcl.tk/21595#pagetocf3097447
>>
>> I have written a proc that returns the current style object
>> (ELEP::Style::getStyle), and used the "forward" method:
>>
>> oo::class create ELEP::FlowControl::Item {
>> forward getStyle [ELEP::Style::getStyle] initFlowControlItem
>> ..
>> }
>>
>> It seems to work. However, this is executed when the class is defined,
>> which means that once I have created a style object, the name of this
>> object must always be the same, even if a new style object is created.
>>
>> Is there a way to use a variable in forward, instead of a command?
>>
>> George
>>
>>
>>
>> στις 12/4/2010 19:38, O/H Georgios Petasis έγραψε:
>>> Hi all,
>>>
>>> I am wondering the following:
>>>
>>> I have a class A. This class A has a variable named "background".
>>>
>>> Then, I have a class B. This class has a method (init) that sets a value
>>> to the variable background:
>>>
>>> class create B {
>>> method init {} {
>>> my variable background
>>> set background red
>>> }
>>> }
>>>
>>> If I have an object from class A, is there a way to execute the init
>>> method (from a B's object) into the context of the A object?
>>>
>>> Why I need this?
>>> I had a set of classes, that implement "items" on a canvas:
>>> http://www.ellogon.org/~petasis/tcl/TkRibbon/images/Ellogon-Ribbon-System-Logs.png
>>>
>>>
>>>
>>> There are two major kinds of "items", a "block" and a "connector" (the
>>> arrows).
>>>
>>> Right now, colours are coded inside the code (not a good approach). I am
>>> looking for a way to "theme" these classes, where the values for a set
>>> of variables can be retrieved from a "style" object.
>>>
>>> There is the alternative for the "item" object to query the value of
>>> each variable from the style object, but many variables and a few items
>>> (it may be slow).
>>>
>>> Any ideas?
>>>
>>> George
>>
>