Thread: [Fxruby-users] Creating new frames
Status: Inactive
Brought to you by:
lyle
From: Phil S. <ps...@oz...> - 2003-10-08 12:55:12
|
I want to create different entry fields depending upon which button is selected. I would like to do this by calling a function (see example below, pressing <Add> should create one label and one text entry box). This does not work and I thought it was because it was created but hidden, however adding a .show had no effect. If someone could enlighten me I would appreciate it. #!/usr/bin/env ruby require 'fox' include Fox class Test < FXMainWindow def initialize(app) super(app, "Test", nil, nil, DECOR_ALL, 0, 0, 640, 480, 0, 0) body = FXHorizontalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH ) topbuttons=FXHorizontalFrame.new(body, LAYOUT_SIDE_TOP|FRAME_RAISED|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 20, 20, 20, 20) FXButton.new(topbuttons, "Add").connect(SEL_COMMAND) {add(body) } FXButton.new(topbuttons, "&Quit", nil, app, FXApp::ID_QUIT) end def add(body) FXLabel.new(body,"text 1") FXTextField.new(body,numcolumns=20) body.show end def create super show(PLACEMENT_SCREEN) end end application = FXApp.new("Test", "FoxTest") Test.new(application) application.create application.run |
From: meinrad r. <mei...@gm...> - 2003-10-08 15:01:13
|
Phil Sharp wrote: > I want to create different entry fields depending upon which button is > selected. I would like to do this by calling a function (see example > below, pressing <Add> should create one label and one text entry box). > > This does not work and I thought it was because it was created but hidden, > however adding a .show had no effect. you have to call the create method on all widgets that have been instanciated later than your call to application.create. also you have to call the reaclc method on the containing widget, in order to tell it, that it should make its layout new. > If someone could enlighten me I > would appreciate it. > here is your working code: #!/usr/bin/env ruby require 'fox' include Fox class Test < FXMainWindow def initialize(app) super(app, "Test", nil, nil, DECOR_ALL, 0, 0, 640, 480, 0, 0) body = FXVerticalFrame.new(self,LAYOUT_SIDE_TOP|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH ) topbuttons=FXHorizontalFrame.new(body,LAYOUT_SIDE_TOP|FRAME_RAISED|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH, 0, 0, 0, 0,20, 20, 20, 20) FXButton.new(topbuttons, "Add").connect(SEL_COMMAND) {add(body) } FXButton.new(topbuttons, "&Quit", nil, app, FXApp::ID_QUIT) end def add(body) lbl=FXLabel.new(body,"text 1") tf=FXTextField.new(body,numcolumns=20) lbl.create tf.create body.recalc end def create super show(PLACEMENT_SCREEN) end end application = FXApp.new("Test", "FoxTest") Test.new(application) application.create application.run regards, -- henon -------------- % cat "food in cans" cat: can't open food in cans |
From: Phil S. <ps...@oz...> - 2003-10-08 15:20:05
|
Thank you. I have been struggling with this *much* longer than I would care to admit. On Wed, 8 Oct 2003, meinrad recheis wrote: > Phil Sharp wrote: > > I want to create different entry fields depending upon which button is > > selected. I would like to do this by calling a function (see example > > below, pressing <Add> should create one label and one text entry box). > > > > This does not work and I thought it was because it was created but hidden, > > however adding a .show had no effect. > > you have to call the create method on all widgets that have been > instanciated later than your call to application.create. > > also you have to call the reaclc method on the containing widget, in > order to tell it, that it should make its layout new. |
From: meinrad r. <mei...@gm...> - 2003-10-08 15:34:35
|
Phil Sharp wrote: > Thank you. > > I have been struggling with this *much* longer than I would care to admit. > it is an unecessary complication or even a design error of the fox-tk that has troubled everyone of us once. did you allready happen to have some segmentation faults? this is the other thing that troubles fxruby users much. for instance: if you call create in the wrong place you will definitely have some. good luck, -- henon -------------- % cat "food in cans" cat: can't open food in cans |
From: Phil S. <ps...@oz...> - 2003-10-09 15:18:55
|
After adding an FXLabel to a FXHorizontalFrame, I destroyed the label, then attempted to add a new one. The new one was created ok except that it's placement was offset as if the one that I just deleted was still there. Is there another step that must be taken to cause the frame to "forget" about the just deleted widget? Thanks. |
From: Meinrad R. <mei...@av...> - 2003-10-10 09:11:28
|
Phil Sharp wrote: > After adding an FXLabel to a FXHorizontalFrame, I destroyed the label, > then attempted to add a new one. The new one was created ok except that > it's placement was offset as if the one that I just deleted was still > there. > > Is there another step that must be taken to cause the frame to "forget" > about the just deleted widget? i think again recalc will do the job. you might want to go to the fox-toolkit site and read the faq. there is an entry about update, recalc and forceRefresh. > > Thanks. > cheers, henon |
From: Phil S. <ps...@oz...> - 2003-10-10 13:58:28
|
On Fri, 10 Oct 2003, Meinrad Recheis wrote: > Phil Sharp wrote: > > > After adding an FXLabel to a FXHorizontalFrame, I destroyed the label, > > then attempted to add a new one. The new one was created ok except that > > it's placement was offset as if the one that I just deleted was still > > there. > > > > Is there another step that must be taken to cause the frame to "forget" > > about the just deleted widget? > > i think again recalc will do the job. > you might want to go to the fox-toolkit site and read the faq. there is > an entry about update, recalc and forceRefresh. > > > > > Thanks. > > > > cheers, > henon > I had only been reading the docs available at fxruby.sourceforge.net so I will be sure to check the fox-toolkit site as well. I did discover that if I did a .hide, before the .detach and .destroy it worked as expected. Phil Sharp |
From: Lyle J. <ly...@kn...> - 2003-10-12 23:12:39
|
Phil Sharp wrote: > After adding an FXLabel to a FXHorizontalFrame, I destroyed the label, > then attempted to add a new one. The new one was created ok except that > it's placement was offset as if the one that I just deleted was still > there. > > Is there another step that must be taken to cause the frame to "forget" > about the just deleted widget? The correct way to cause a parent frame to forget about one of its child widgets is to use the removeChild() method: aHorizontalFrame.removeChild(aLabel) Calling destroy() on the label widget destroys the server-side representation (i.e. the X window or Windows HWND associated with the label) but it doesn't destroy the client-side representation, namely the C++ or Ruby object associated with the label. Calling removeChild() is the proper approach because it takes care of all of the bookkeeping associated with "forgetting" a child widget. First, it removes the widget from the parent's list of child widgets and nulls out any references to the child widget. Next, it calls recalc() on the parent (as suggested by Henon) to mark the parent's layout as dirty. Finally, it calls destroy() on the widget, to destroy the server-side resource. |