Re: Gtk2::Simple::* example/sample code



On Tue, 2004-03-30 at 00:51, James Curbo wrote:
Carl Nygard wrote:
  > Not bored;)  Started with tied version.  Then realized that the tied
vars depend on the widgets being around and the var still hooked to the
widget.  My app has many instances of common set of data, and the
different instances get swapped in and out to allow editing.  untie
states that the original value of the var gets restored upon untie, so
swapping a new struct into place blows the old away.  Hence the bind
version, which stores modifications as they happen.

Later, I added some code to try to store the value as the var is untied,
but that's not quite working when the widget gets destroyed.

You're stretching the limits of my perl-fu here, but I think I 
understand after looking at some more code. Since the bound variables 
are not contained within the widget's structure itself, you can freely 
attach/detach them at will. But since the tied widgets are linked to the 
actual instances of the tie/untie, the data is destroyed when you untie.

With the bound widget you have to remember to call update_widget when 
you change the data in the variable, correct? The tied version 
automatically updates, which is the advantage there.

Now I see why you wrote both :)

Yeah, I think of it this way.  With tied data, the data transfer happens
at var access time, i.e. when you use the var.  With the Bind data, the
transfer happens when the user makes a change with the widget, so the
var is always updated.



IMHO those looking for 'simple' modules will not particularly care about 
if they are tied or binded; I know that when I first used SimpleList I 
was just happy to not have to mess with the MVC stuff, much less worry 
about the internal implementation. I'd like to see a plain 
Gtk2::Simple::<widgetname>.pm breakout.

I would have liked to as well, and that's how I started until I realized
the above.  There is a difference, at least for my usage.

With regards to the above, I am not against the tied/bound approach, but 
I am still wondering about the namespace itself.

For example, you used:

Gtk2::Simple::{Tie,Bind}::OptionMenu

I am curious about alternatives to this, with respect to readability and 
   making it easier to remember which module to use. Perhaps:

Gtk2::Simple::OptionMenu::{Tie,Bind}

I don't like this, because ultimately the object is a widget, not a Tie
or a Bind.


or perhaps encasing the tie/bind choice within the module itself, 
perhaps as a argument to new_from_widget:

$optionmenu = Gtk2::Simple::OptionMenu->new('type' => 'tie', ... );

I don't know if this is feasible however.

Probably, but I was trying to avoid the spaghetti baggage, and there's a
runtime penalty to be paid always checking the type.  

However, muppet pointed me in a direction to extract the tie/bind logic
away from the widget itself, so perhaps we can all be happy with that
method.  But I haven't looked at that closely yet.

The only suggestion I have is one that comes to me from looking at the 
('', 1, '', '', 1) structure... perhaps return a hash instead of an 
array, and set selected items to 1 and unselected items to 0. You'd 
still have to traverse the hash to get what is selected though... so I 
don't know if it's a good idea or not.


I don't see what that gets you, it's still not the same interface as the
Bind version.


Regards,
Carl




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]