Murga-Projects Forums
removing/replacing widgets - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: removing/replacing widgets (/showthread.php?tid=64)


removing/replacing widgets - mikshaw - 06-29-2007 02:01 AM

I've been struggling with a way to dynamically replace existing widgets or groups of widgets.
FlBig Grinelete_widget() causes a segmentation fault, which I assume is my main problem with this task. The FLTK documentation lists Fl_Group::~Fl_Group() is supposed to destroy a group, but I have no idea how to translate this to murgaLua.
Are both instances of "Fl_Group" to be replaced with the name of the group? Is it name:~Fl_Group()? name:~name()? name:fltk:~FL_Group()? Maybe it doesn't translate to murgaLua?


RE: removing/replacing widgets - JohnMurga - 06-29-2007 06:26 AM

You have to hide it first (always) ... Not hiding it causes a crash on Windows too ...

This example should work on Linux, I am about to test it :

Code:
local object = fltk:Fl_Double_Window(200, 100)

window = object

button1 = fltk:Fl_Button(25, 25, 150, 25, "Remove Button")
button2 = fltk:Fl_Button(25, 60, 150, 25, "Will go")

function remove_callback(data)
  button2:hide()
  Fl:delete_widget(button2)
end

button1:callback(remove_callback)

window:show()
Fl:run()




RE: removing/replacing widgets - JohnMurga - 06-29-2007 07:43 AM

OK, this appears to work correctly on Windows, however under Linux it only works when removing windows for some reason (!!) ... Ummm, will look into this.


RE: removing/replacing widgets - mikshaw - 06-29-2007 08:26 AM

It seems to work for me. Thank you. I didn't try your example, but used delete_widget() after hiding the widget I was already testing (a browser).
There is still a strange behaviour causing a segfault, though. There seems to be data left over somewhere relating to the deleted widget. If I try to show the deleted widget, or even check to see if it exists, the segfault occurs (where normally it would be an error message). If I set a new value to the widget's name after deleting it, segfault doesn't occur unless I get trigger-happy with the button that checks for it. Either way, it doesn't seem possible to create a new widget using the name of the deleted widget, so I still don't know if dynamically replacing widgets is possible. I know I could hide/show overlapping stuff, but that does not fit with my plan (simplicity and modularity). I'll be messing around with it for a while, though, so I'll keep you updated =o)


RE: removing/replacing widgets - JohnMurga - 06-30-2007 10:06 AM

I found the issue !! :-)

Again, Linux being a little sensitive about the sequence.

This was tested on both Windows and Linux and never segfaults.

Code:
local object = fltk:Fl_Double_Window(200, 100);

window = object;

button1 = fltk:Fl_Button(25, 25, 150, 25, "Remove Button");
button2 = fltk:Fl_Button(25, 60, 150, 25, "Will go");

function remove_callback(data)
  window:remove(button2)
  Fl:delete_widget(button2)
  window:redraw()
  button2=nil
end

button1:callback(remove_callback)

window:show();
Fl:run();




RE: removing/replacing widgets - mikshaw - 06-30-2007 04:49 PM

Yes, that does stop the segfaults. Thank you very much for this help.
One thing I should mention relating to my original post:
In order to dynamically replace the removed widget with a new one, apparently you need to use window:add(button2) after creating a new button2 widget. It took me a bit to figure out why it wasn't showing while I could still access its properties, even after button2:redraw() and window:redraw().

Also, what is the purpose of creating "local object" and then setting "window" to the same value?


RE: removing/replacing widgets - JohnMurga - 06-30-2007 07:36 PM

mikshaw Wrote:
Also, what is the purpose of creating "local object" and then setting "window" to the same value?


Err ... I was hacking the generated FLUID code (been playing with the converter), it makes NO sense ;-)

Cheers
JohnM