From: tobbyd d. <rub...@an...> - 2007-10-08 18:51:05
|
I am trying to build a small program that loops trough and dynamically creates a number of buttons. Is there any methods available to remove already created widgets from the main window? Lets say I would like to remove one of the buttons below, how could I do that. Thanks in advance @buttons = {} 10.times do |i| @buttons["button#{i}"] Gtk::Button.new("button #{i}") end -- Posted via http://www.ruby-forum.com/. |
From: <dp...@gm...> - 2007-10-08 19:23:36
Attachments:
dpblnt.vcf
|
a Gtk::Window can hold only one widget since it's a Gtk::Bin, so you used a Container when to which you added the Buttons. the Container which has an add(widget) method usually also have a remove(widget) method. tobbyd dubbyd wrote: > I am trying to build a small program that loops trough and dynamically > creates a number of buttons. Is there any methods available to remove > already created widgets from the main window? > Lets say I would like to remove one of the buttons below, how could I do > that. > > Thanks in advance > > > @buttons = {} > 10.times do |i| > @buttons["button#{i}"] Gtk::Button.new("button #{i}") > end > |
From: tobbyd d. <rub...@an...> - 2007-11-27 20:45:08
|
I dont really get it. I have packed my buttons i a vBox but perhaps I should have used something else. If someone could provide a snippet with 3 buttons packet in some container and at the click on one of the buttons another button should be removed/deleted, I would be very thankful. dubbyd -- Posted via http://www.ruby-forum.com/. |
From: tobbyd d. <rub...@an...> - 2007-11-29 22:46:14
|
Did not take very long until next problem showed up =( When I click my button I would like to create a new slot consisting of one Entry and a normal button. So when myButton is clicked the function below is running and it is supposed to create only one slot. What happens is that the first time I click myButton one slot is created and everything is fine. Then when I want to create one more, two slots are created. Next time three and so on but what I want is only one new slot per click. Why is it increased and how do I get rid of it? Thanks def addSlotCallBack( myButton ) e = e + 1 @Entrys["entry#{e}"] = Gtk::Entry.new @Entrys["entry#{e}"].set_text("Entry#{e}") @Entrys["entry#{e}"].show #dynamic buttons @buttons["button#{e}"] = Gtk::Button.new("button#{e}") @buttons["button#{e}"].show @hBoxes["hBox#{e}"] = Gtk::HBox.new( false, 10 ) @hBoxes["hBox#{e}"].pack_start( @buttons["button#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].pack_start(@Entrys["entry#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].show #pack rows of buttons in to VBox $vBox.pack_start( @hBoxes["vBox#{e}"], true, true, 0 ) end -- Posted via http://www.ruby-forum.com/. |
From: tobbyd d. <rub...@an...> - 2007-11-30 21:03:48
|
Thanks for the input Martin and that "VBox" thing was actually a type error I made yesterday, sorry bout that. The function below is now exactly the way it is in my program. My problem remains though. When I click my button that runs this function the first time it creates a hbox with an entry and a button just as it is supposed to. The problem is next time I press the button then it creates two hBoxes with corresponding buttons etc. The next time 4 and so on and I just can not figure out why. I just want it to create on hBox per click. Even if I set e = constant this still happens? def addSlotCallBack( widget ) $rowsTotal = $rowsTotal + 1 e = $rowsTotal @Entrys["entry#{e}"] = Gtk::Entry.new @Entrys["entry#{e}"].set_text("Entry#{e}") #dynamic buttons @buttons["button#{e}"] = Gtk::Button.new("button#{e}") createPickUpButtonStates(@buttons["button#{e}"],e,@Entrys["entry#{e}"]) @hBoxes["hBox#{e}"] = Gtk::HBox.new( false, 10 ) @hBoxes["hBox#{e}"].pack_start( @buttons["button#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].pack_start(@Entrys["entry#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].show_all #pack rows of buttons in to VBox $vBox.pack_start( @hBoxes["hBox#{e}"], true, true, 0 ) end -- Posted via http://www.ruby-forum.com/. |
From: Detlef R. <det...@gm...> - 2007-10-08 19:30:26
|
Hi, but remove only works for sub classes of Gtk::Container. The simplest way is to destroy the widget with your_button.destroy. That will automaticaly remove the widget from its parent. Cheers detlef Am Montag, den 08.10.2007, 22:23 +0300 schrieb Dobai-Pataky Bálint: > a Gtk::Window can hold only one widget since it's a Gtk::Bin, > so you used a Container when to which you added the Buttons. > the Container which has an add(widget) method usually also have a > remove(widget) method. > > tobbyd dubbyd wrote: > > I am trying to build a small program that loops trough and dynamically > > creates a number of buttons. Is there any methods available to remove > > already created widgets from the main window? > > Lets say I would like to remove one of the buttons below, how could I do > > that. > > > > Thanks in advance > > > > > > @buttons = {} > > 10.times do |i| > > @buttons["button#{i}"] Gtk::Button.new("button #{i}") > > end > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ ruby-gnome2-devel-en mailing list rub...@li... https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: tobbyd d. <rub...@an...> - 2007-11-22 19:58:12
|
Detlef Reichl wrote: > Hi, > > but remove only works for sub classes of Gtk::Container. The simplest > way is to destroy the widget with your_button.destroy. That will > automaticaly remove the widget from its parent. > > Cheers > detlef > I have put all my buttons in a vBox and I would like to be able to delete them. How is this possible? dubbyd -- Posted via http://www.ruby-forum.com/. |
From: Martin P. <mar...@ip...> - 2007-11-28 07:42:58
|
tobbyd dubbyd wrote: > I dont really get it. I have packed my buttons i a vBox but perhaps I > should have used something else. If someone could provide a snippet with > 3 buttons packet in some container and at the click on one of the > buttons another button should be removed/deleted, I would be very > thankful. does this help? ====== require 'gtk2' Gtk.init win = Gtk::Window.new button1 = Gtk::Button.new("button 1") button2 = Gtk::Button.new("button 2") button3 = Gtk::Button.new("button 3") hb = Gtk::HBox.new(false) hb.pack_start( button1 ) hb.pack_start( button2 ) hb.pack_start( button3 ) button1.signal_connect("clicked"){ hb.remove( button2 ) } win.add( hb ) win.show_all Gtk.main ============= Note that only the first click will work properly. The second (and so on) click will not do anything, and cause GTK to fire a (non fatal) assertion. martin |
From: tobbyd d. <rub...@an...> - 2007-11-29 19:46:30
|
Thanks alot Martin =) Exactly what I needed. -- Posted via http://www.ruby-forum.com/. |
From: Martin P. <mar...@ip...> - 2007-11-30 09:33:03
|
tobbyd dubbyd wrote: > Did not take very long until next problem showed up =( > When I click my button I would like to create a new slot consisting of > one Entry and a normal button. So when myButton is clicked the function > below is running and it is supposed to create only one slot. > What happens is that the first time I click myButton one slot is created > and everything is fine. Then when I want to create one more, two slots > are created. Next time three and so on but what I want is only one new > slot per click. Why is it increased and how do I get rid of it? > Thanks > > def addSlotCallBack( myButton ) > > > e = e + 1 > > @Entrys["entry#{e}"] = Gtk::Entry.new > @Entrys["entry#{e}"].set_text("Entry#{e}") > @Entrys["entry#{e}"].show > > #dynamic buttons > @buttons["button#{e}"] = Gtk::Button.new("button#{e}") > @buttons["button#{e}"].show > > > @hBoxes["hBox#{e}"] = Gtk::HBox.new( false, 10 ) > @hBoxes["hBox#{e}"].pack_start( @buttons["button#{e}"], true, true, 0 > ) > @hBoxes["hBox#{e}"].pack_start(@Entrys["entry#{e}"], true, true, 0 ) > @hBoxes["hBox#{e}"].show > > #pack rows of buttons in to VBox > $vBox.pack_start( @hBoxes["vBox#{e}"], true, true, 0 ) typo here ^^^^^ you've created @hBoxes["hBox#{e}"] but you're trying to show the entry called "vBox#{e}", which I guess is lying around elsewhere... Gtk style is to create a widget, put it in its container, and _then_ show it. in the above you can simplify things by removing all the .show lines and having a @hBoxes["hBox#{e}"].show_all at the end. martin. |
From: Martin P. <mar...@ip...> - 2007-12-03 08:51:23
|
tobbyd dubbyd wrote: > Thanks for the input Martin and that "VBox" thing was actually a type > error I made yesterday, sorry bout that. The function below is now > exactly the way it is in my program. > My problem remains though. When I click my button that runs this > function the first time it creates a hbox with an entry and a button > just as it is supposed to. The problem is next time I press the button > then it creates two hBoxes with corresponding buttons etc. The next time > 4 and so on and I just can not figure out why. I just want it to create > on hBox per click. Even if I set e = constant this still happens? > > def addSlotCallBack( widget ) > could you include the code which sets up the callback for the button. i suspect the problem is around there as the code you've shown so far looks ok. martin. |
From: tobbyd d. <rub...@an...> - 2007-12-19 19:59:33
|
Better late than never =) def addSlotCallBack( widget ) puts "Hello again - #{widget} was pressed." $rowsTotal = $rowsTotal + 1 e = $rowsTotal @Entrys["entry#{e}"] = Gtk::Entry.new @Entrys["entry#{e}"].set_text("Entry#{e}") #@Entrys["entry#{e}"].show_all #dynamic buttons @buttons["button#{e}"] = Gtk::Button.new("button#{e}") createPickUpButtonStates(@buttons["button#{e}"], e,@Entrys["entry#{e}"]) #@buttons["button#{e}"].show_all @hBoxes["hBox#{e}"] = Gtk::HBox.new( false, 10 ) @hBoxes["hBox#{e}"].pack_start( @buttons["button#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].pack_start(@Entrys["entry#{e}"], true, true, 0 ) @hBoxes["hBox#{e}"].show_all #pack rows of buttons in to VBox $vBox.pack_start( @hBoxes["hBox#{e}"], true, true, 0 ) puts "rows are",$rowsTotal end -- Posted via http://www.ruby-forum.com/. |
From: Marc H. <rub...@an...> - 2007-12-20 06:36:24
|
Hmm i think it might be even better to include the whole sample... ;) -- Posted via http://www.ruby-forum.com/. |