News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
removing/replacing widgets
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
removing/replacing widgets

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?

06-29-2007 02:01 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #2
RE: removing/replacing widgets

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()

06-29-2007 06:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #3
RE: removing/replacing widgets

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.

06-29-2007 07:43 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: removing/replacing widgets

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)

06-29-2007 08:26 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #5
RE: removing/replacing widgets

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();

This post was last modified: 06-30-2007 10:08 AM by JohnMurga.

06-30-2007 10:06 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: removing/replacing widgets

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?

06-30-2007 04:49 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #7
RE: removing/replacing widgets

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

06-30-2007 07:36 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: