Thread: [Fxruby-users] FXPopup questions
Status: Inactive
Brought to you by:
lyle
From: Adam W. <ad...@ta...> - 2004-05-17 16:35:24
|
Hi everyone -- I'm new to Fox and fxruby, and I like what I've seen so far! These questions may not be specific to fxruby -- please let me know if I should post to the foxgui list instead. 1. How can I remove all items from a FXPopup? I've tried destroying its children, but then I get empty menu items: myPopup.children.each { | option | option.destroy } Alternatively I'd be happy to destroy the FXPopup and associated FXOptionMenu and create new ones, but my attempts to do that were unsuccessful. 2. I am able to add new FXOption items to the popup: opt = FXOption.new(myPopup, ...) opt.create() Now I'd like to choose which one is selected. How can I do that? I've checked the Fox FAQ and the mailing lists archives to no avail. Any tips will be appreciated! -- Adam Wildavsky Extreme Programmer Tameware, LLC ad...@ta... http://www.tameware.com |
From: Oliver S. <ol...@mo...> - 2004-05-17 17:44:58
|
> 1. How can I remove all items from a FXPopup? I've tried destroying > its children, but then I get empty menu items: > > myPopup.children.each { | option | > option.destroy > } You should probably use 'myPopup.removeChild(child)'. I believe the destroy function is always handled by Fox or FXRuby internally, so you don't ever need to call it. Watch out for 'children.each', though...the iterator can screw up when you remove a child from the array in the middle of recursing through it. You may want to duplicate the array first. > 2. I am able to add new FXOption items to the popup: > > opt = FXOption.new(myPopup, ...) > opt.create() > > Now I'd like to choose which one is selected. How can I do that? I'm not sure what FXOption/FXOptionMenu are...I thought FXOption was a radio button at first, but now it looks like something else. If what you want is a radio button in a menu; i.e. you have a few options and the selected one has a little circle next to it, you should do: opt = FXMenuCommand.new(myPopup, "a fun radio button") opt.checkRadio It looks like you have to manually uncheck the other options: opt.connect(SEL_COMMAND) { |sender, message, data| # uncheck other options here with uncheckRadio... sender.checkRadio } So I guess I don't know what FXOption is, but the sample program dialog.rb seems to use it, if that helps. -- Oliver |
From: Adam W. <ad...@ta...> - 2004-05-17 20:05:05
|
At 10:45 AM -0700 5/17/04, Oliver Smith wrote: > > 1. How can I remove all items from a FXPopup? I've tried destroying >> its children, but then I get empty menu items: >> > > myPopup.children.each { | option | >> option.destroy >> } > >You should probably use 'myPopup.removeChild(child)'. I believe the destroy >function is always handled by Fox or FXRuby internally, so you don't ever >need to call it. Watch out for 'children.each', though...the iterator can >screw up when you remove a child from the array in the middle of recursing >through it. You may want to duplicate the array first. Thanks for the quick reply! I used children.each instead of each_child for that reason. children.dup.each doesn't seems to behave any differently. As for removeChild, I should have mentioned that I had tried it. The result is a Segmentation Fault (in Windows 98) when I click on the popup. I tried rewriting the loop to avoid the iteration issue, with no better results: while myPopup.children.length > 0 myPopup.removeChild myPopup.children[0] end > > Now I'd like to choose which one is selected. How can I do that? > >I'm not sure what FXOption/FXOptionMenu are...I thought FXOption was a radio >button at first, but now it looks like something else. If what you want is >a radio button in a menu; i.e. you have a few options and the selected one >has a little circle next to it, you should do: The class takes care of selecting the appropriate item automatically when the user clicks it -- it becomes the item displayed when the user lets go of the mouse button and menu pops closed. I should have been clearer about what I want to do, which is to select an item in the same way, but programmatically. That said, checkRadio and uncheckRadio might be the way to do it -- I'll experiment! >So I guess I don't know what FXOption is, but the sample program dialog.rb >seems to use it, if that helps. I cribbed my initial code from the samples, as usual... -- Adam Wildavsky Extreme Programmer Tameware, LLC ad...@ta... http://www.tameware.com |
From: Oliver S. <ol...@mo...> - 2004-05-17 21:01:37
|
> Thanks for the quick reply! > [snip] Oh, I see, after looking through the dialog.rb sample some more. Have you tried the FXOptionMenu class attributes for setting the currently selected option? This works for me: popup = FXPopup.new(self) thing1 = FXOption.new(popup, "thing 1") thing2 = FXOption.new(popup, "thing 2") menu_button = FXOptionMenu.new(self, popup) menu_button.currentNo = 1 # could also do menu_button.current = thing2 As to removing the children, this also works for me under Win2k: FXButton.new(self, "click me").connect(SEL_COMMAND) { |sender, message, data| popup.children.each { |child| popup.removeChild(child) } thing3 = FXOption.new(popup, "thing 3") thing4 = FXOption.new(popup, "thing 4") thing3.create thing4.create # note - the menu text doesn't seem to update itself, so you have to click # on a new item...don't know what's wrong there } After testing, the children.each thing seems to work...I remember it screwing me up once, but I think that was with a tree list and I may have been doing something weird. Anyway, I hope this is a little more useful. :) Sorry if I'm still off-base. Oliver |
From: Adam W. <ad...@ta...> - 2004-05-18 05:20:05
|
At 2:01 PM -0800 3/17/04, Oliver Smith wrote: >As to removing the children, this also works for me under Win2k: ... > popup.children.each { |child| popup.removeChild(child) } It now works for me as well. The problem that I had thought was caused by removeChild was in fact caused by the fact that I had not reset FXOptionMenu.current. This must have caused a stale reference -- it was left pointing to one of the children I had removed. Thanks again! -- Adam Wildavsky Extreme Programmer Tameware, LLC ad...@ta... http://www.tameware.com |
From: Mohammad K. <mk...@le...> - 2004-05-21 16:08:59
|
when we will have FXRuby that will work with fox 1.2.x ? Mohammad |
From: Adam W. <ad...@ta...> - 2004-05-21 16:40:03
|
At 12:08 PM -0400 5/21/04, Mohammad Khan wrote: >when we will have FXRuby that will work with fox 1.2.x ? On May 17 in the (aptly titled) thread "The inevitable question..." Lyle wrote: >So, the short answer is, I don't yet know when I'll have a first cut >at FXRuby 1.2. ... >I think the best I can shoot for at this point is "sometime in June" >for an FXRuby-1.2.0 release. -- Adam Wildavsky Extreme Programmer Tameware, LLC ad...@ta... http://www.tameware.com |
From: Adam W. <ad...@ta...> - 2004-05-17 21:12:05
|
At 4:02 PM -0400 5/17/04, Adam Wildavsky wrote: >The class takes care of selecting the appropriate item automatically >when the user clicks it -- it becomes the item displayed when the >user lets go of the mouse button and menu pops closed. I should have >been clearer about what I want to do, which is to select an item in >the same way, but programmatically. Something like this seems to do the trick: myOptionMenu.current = myPopup.children[0] I'm still trying to figure out how to remove the "empty" slots taken up by FXOption items I've destroyed. More generally, I'd like to know the proper fxruby way to remove a component FXWindow from a FXComposite. -- Adam Wildavsky Extreme Programmer Tameware, LLC ad...@ta... http://www.tameware.com |