Thread: [Fxruby-users] Disconnecting Foxtails Elements
Status: Inactive
Brought to you by:
lyle
From: Will M. <wi...@co...> - 2003-12-10 00:18:28
|
Hi, This question is mostly for Joel VanderWerf, but if any one else has any ideas please jump in. The question is how to cancel the observation of a variable in a Foxtails element? As you can see in the included code below, (Yes its the same code I included in my other message today.) I am adding several FTTextFields to watch some variables in another object. The object I wish to observe changes from time to time so these fields need to be added dynamically. So the specific question is: when I stop observing one object and start observing a new object what do I need to do to clean up the observations on the old object? In the Observable library that you wrote there are cancel_when_* methods that do this job, what are the equivilent methods for Foxtails? Thanks, --Will ==================== begin include ================= #!/usr/bin/env ruby require 'fox' require 'fox/responder' require 'observable' require 'foxtails' include Fox include Observable include FoxTails class ObjectInspector include Responder extend Observable def initialize(app, proj) @targetObject = nil createWindow(app, proj) end def createWindow(app, proj) @app = app @project = proj @inspectordlg = FXDialogBox.new(app, "Inspector", DECOR_BORDER|DECOR_RESIZE|DECOR_TITLE, 0, 0, 150, 300) @matrix = FXMatrix.new(@inspectordlg, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X) end def clear() @matrix.hide end def set(newobj) @targetObject = newobj @matrix = FXMatrix.new(@propertyFrame, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X) # First row FXLabel.new(@matrix, "Property", nil, LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, "Value", nil, LAYOUT_FILL_COLUMN) # First row FXLabel.new(@matrix, "Type", nil, LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, @targetObject.name, nil, LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, "Left", nil, LAYOUT_FILL_COLUMN) FTTextField.new(@matrix, 17, @targetObject, :left, FRAME_SUNKEN|LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, "Right", nil, LAYOUT_FILL_COLUMN) FTTextField.new(@matrix, 17, @targetObject, :right, FRAME_SUNKEN|LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, "Top", nil, LAYOUT_FILL_COLUMN) FTTextField.new(@matrix, 17, @targetObject, :top, FRAME_SUNKEN|LAYOUT_FILL_COLUMN) FXLabel.new(@matrix, "Bottom", nil, LAYOUT_FILL_COLUMN) FTTextField.new(@matrix, 17, @targetObject, :bottom, FRAME_SUNKEN|LAYOUT_FILL_COLUMN) @inspectordlg.create @inspectordlg.show # @inspectordlg.update # @inspectordlg.repaint @inspectordlg.resize(@inspectordlg.width + 1, @inspectordlg.height) @inspectordlg.resize(@inspectordlg.width - 1, @inspectordlg.height) end # Close the Inspector Windows def close @inspectordlg.hide end # Create and show the main window def create # Create the windows @inspectordlg.create @inspectordlg.show(PLACEMENT_DEFAULT) end end ===================== end include ================== |
From: Joel V. <vj...@PA...> - 2003-12-11 04:16:44
|
Will Merrell wrote: > In the Observable library that you wrote there are cancel_when_* methods > that do this job, what are the equivilent methods for Foxtails? That's a good question. I think it can be done with the latest versions of Observable and FoxTails, and I will come up with a simple example... -- Joel VanderWerf California PATH, UC Berkeley mailto:vj...@pa... Ph. (510) 231-9446 http://www.path.berkeley.edu FAX (510) 231-9565 |
From: Joel V. <vj...@PA...> - 2003-12-11 04:39:47
|
Joel VanderWerf wrote: > Will Merrell wrote: > >> In the Observable library that you wrote there are cancel_when_* methods >> that do this job, what are the equivilent methods for Foxtails? > > > That's a good question. I think it can be done with the latest versions > of Observable and FoxTails, and I will come up with a simple example... > Short answer: use #retarget. This is a method of all the FTTargeted widgets. Sorry about the docs... Long answer below. This will be in the examples dir in the next FoxTails release. ==== disconnect.rb ==== #!/usr/bin/env ruby require 'foxtails' include Fox include FoxTails class MainWindow < FXMainWindow observable :data, :t2, :t3 def initialize(*args) super self.t2 = true self.t3 = true frame = FXVerticalFrame.new(self) f1 = FXHorizontalFrame.new(self) FXLabel.new(f1, "One", nil, LAYOUT_FIX_WIDTH).width = 50 @text1 = FTTextField.new(f1, 60, self, :data) @text1.dynamic = true f2 = FXHorizontalFrame.new(self) FXLabel.new(f2, "Two", nil, LAYOUT_FIX_WIDTH).width = 50 @text2 = FTTextField.new(f2, 60, self, :data) @text2.dynamic = true @check2 = FTCheckButton.new(f2, "connected to One", self, :t2) when_t2 CHANGES do |val| @text2.retarget(val ? self : nil) end f3 = FXHorizontalFrame.new(self) FXLabel.new(f3, "Three", nil, LAYOUT_FIX_WIDTH).width = 50 @text3 = FTTextField.new(f3, 60, self, :data) @text3.dynamic = true @check3 = FTCheckButton.new(f3, "connected to One", self, :t3) when_t3 CHANGES do |val| @text3.retarget(val ? self : nil) end end def create super show(PLACEMENT_OWNER) end end class TestApp < FTApp def initialize super("Test", "TEST") MainWindow.new(self, "Test") end end TestApp.new.run |