Hi all, I am new to FxRuby. I am learning it by studying some code samples. Now I am confused about a method call in the following script:? which class? defines method? create,?class FXApp or HelloWindow/FXMainWindow? Based on the code, class HelloWindow/FXMainWindow defines method ''create''. If this is true , the object from this class can response to the message. But here?why does an object created by a different class FXApp response to method ''create''? Thanks, Li require ''fox16'' include Fox class HelloWindow < FXMainWindow ? def initialize(app) ??? super(app, "Hello, World!", :width => 200, :height => 100) ? end ? def create ??? super ??? show(PLACEMENT_SCREEN) ? end end app = FXApp.new HelloWindow.new(app) app.create app.run
I''m also relatively new, but I understand it as follows: All the widgets in the hierarchy define (or inherit) the create method that is used to setup widget. When you call the create method on FXApp object it recursively calls this method on all the child widgets and because of this all the widgets have a chance to execute their initialization/setup logic. On Mon, Oct 27, 2008 at 9:53 PM, chen li <chen_li3 at yahoo.com> wrote:> Hi all, > > I am new to FxRuby. I am learning it by studying some code samples. Now I > am confused about a method call in the following script: which class > defines method create, class FXApp or HelloWindow/FXMainWindow? Based on > the code, class HelloWindow/FXMainWindow defines method ''create''. If this is > true , the object from this class can response to the message. But here why > does an object created by a different class FXApp response to method > ''create''? > > Thanks, > > Li > > > > > > > require ''fox16'' > > include Fox > > class HelloWindow < FXMainWindow > def initialize(app) > super(app, "Hello, World!", :width => 200, :height => 100) > end > > def create > super > show(PLACEMENT_SCREEN) > end > end > > app = FXApp.new > HelloWindow.new(app) > app.create > app.run > > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081029/620d7780/attachment.html>
On Mon, Oct 27, 2008 at 12:53 PM, chen li <chen_li3 at yahoo.com> wrote:> Hi all, > > I am new to FxRuby. I am learning it by studying some code samples. Now I > am confused about a method call in the following script: which class > defines method create, class FXApp or HelloWindow/FXMainWindow? Based on > the code, class HelloWindow/FXMainWindow defines method ''create''. If this is > true , the object from this class can response to the message. But here why > does an object created by a different class FXApp response to method > ''create''? >Hello, Li - Any class can have its own method create. Even Object has several create methods. In your sample, both HelloWindow and FXApp have methods named create. If you look at the docs on http://www.fxruby.org/doc/api/, you will see the method create, but you can''t see its source code because it''s just a call to the Fox Toolkit''s create in compiled C++ code. When looking at methods, if you don''t see one defined, look to the next higher class in the inheritance. Sooner or later you''ll find one, even if you have to go all the way up to object. Remember that the name ''create'' is only a symbol referring to the function; it could have been FXApp::magicalAppPopper() and HelloWindow::magicalWindowpopper. Also note how HelloWindow makes use of ''super'' to get the behavior defined in FXMainWindow and then add some trimming to it. HTH. -- :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081029/dfcbd78b/attachment.html>
On Oct 27, 2008, at 12:53 PM, chen li wrote:> I am new to FxRuby. I am learning it by studying some code samples. > Now I am confused about a method call in the following script: > which class defines method create, class FXApp or HelloWindow/ > FXMainWindow?Both FXApp and FXMainWindow define create() methods. In your example program, your HelloWindow class is overriding the base class version of create() defined in FXMainWindow. You also call the FXApp object''s create() method later.> Based on the code, class HelloWindow/FXMainWindow defines method > ''create''. If this is true , the object from this class can response > to the message. But here why does an object created by a different > class FXApp response to method ''create''?Calling create() on the FXApp in turn leads to calls to create() on all of the application windows, including your HelloWindow instance. Hope this helps, Lyle --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby
> Calling create() on the FXApp in turn leads to calls to create() on all of > the application windows, including your HelloWindow instance. > > Hope this helps, > > Lyle > > Lyle, you''re awesome. I thought I had Li covered but you added more gooddata. -- :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081030/542509f6/attachment.html>
Hi everyone, Thank all for the explanations. I read all the feedbacks,go back and read Lyle''s the book about Fxruby again. Then I add some lines to find out 1) object and its corresponding class 2) class and its corresponding superclass(up to final superclass). Here are what I find: app object is created by class FXApp and its parent class is FXObject. hello object is created by class HelloWindow and its parent class is FXMainWindow. The final parent for class HelloWindow is FXObject(by repeating calling method superclass 6-7 times. I call all the parents in this chain as one of parent chain). And class FXApp never appears in the parernt chain. Here is my conclusion: 1) the relationship between class FXApp and HelloWindow/FXMainWindow is horizontal or brother/sister. Their final parent is class FXObject(whose final parent should be class Object.) The point here is that in line app.create(),app objcet REALLY receives message of create() defined by its corresponding class FXApp but not by create() defined by class HelloWindow/FXMainWindow. There is no inherence issues between class FXApp and class HelloWindow/FXMainWindow. 2) But what really happens after app.create() is excuted: it causes #create() defined by each widget to be called(HelloWindow widget in this case). This is why class HelloWindow/FXMainWindow has to define #create() in its class. This might be called window hierarchy but it is NOT class inherence in Ruby. If I understand correctly it looks like it is a design strategy for FxRuby: client object and server resource... I guess this is what Lyle mentions how Rxruby works on page 90 in chapter 7. Li
Hi everyone, I didn''t put my modified codes in the pervious email. and here they are. Li ############# if __FILE__ == $0 FXApp.new do |app| puts "app belongs to class: #{app.class}" puts "FXApp has superclasss: #{FXApp.superclass}" puts hello=HelloWindow.new(app) puts "hello belongs to class: #{hello.class}" puts "HelloWindow has superclasss: #{HelloWindow.superclass}" app.create app.run end
Hi! Does anybody know where I can find the getApp method? I''m trying to call FXApp::beep when a user makes a mistake in an application, but calling getApp.beep gives me ./acc.rb:63:in `trat'': undefined method `getApp'' for #<Acc:0x7fbba8582a30> (NoMethodError) from op.rb:95:in `aEditor'' from /usr/lib/ruby/gems/1.8/gems/fxruby-1.6.16/lib/fox16/responder2.rb:55:in `call'' from /usr/lib/ruby/gems/1.8/gems/fxruby-1.6.16/lib/fox16/responder2.rb:55:in `onHandleMsg'' from op.rb:291:in `run'' from op.rb:291 from /usr/lib/ruby/gems/1.8/gems/fxruby-1.6.16/lib/fox16/kwargs.rb:267:in `old_initialize'' from /usr/lib/ruby/gems/1.8/gems/fxruby-1.6.16/lib/fox16/kwargs.rb:267:in `initialize'' from op.rb:287:in `new'' from op.rb:287 Thanks, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I ------ contatos: email: angico at angico.org skype: an.gi.co ------ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081030/3ac162d3/attachment.html>
On Oct 30, 2008, at 2:34 PM, angico wrote:> Does anybody know where I can find the getApp method? I''m trying to > call FXApp::beep when a user makes a mistake in an application, but > calling getApp.beep gives me<snip> The getApp() method is defined on the FXId class, which is way up in the class hierarchy and is an ancestor class for FXWindow and many other FXRuby classes. But you obviously need to have your hands on an instance of FXId or one of its subclasses to be able to call that method. A more general option (and what I suspect you''ll need to use) is to just call the FXApp.instance method, which returns the (single) FXApp instance, e.g. FXApp.instance.beep Hope this helps, Lyle --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby
Em Qui, 2008-10-30 ?s 15:45 -0500, Lyle Johnson escreveu:> The getApp() method is defined on the FXId class, which is way up in > the class hierarchy and is an ancestor class for FXWindow and many > other FXRuby classes. But you obviously need to have your hands on an > instance of FXId or one of its subclasses to be able to call that > method. > > A more general option (and what I suspect you''ll need to use) is to > just call the FXApp.instance method, which returns the (single) FXApp > instance, e.g. > > FXApp.instance.beep > > Hope this helps, > > Lyle > > --- > "FXRuby: Create Lean and Mean GUIs with Ruby" > Now available from the Pragmatic Bookshelf! > http://www.pragprog.com/titles/fxruby > >Hi, Lyle. According to the documentation on http://www.fxruby.org/doc/api/, the only methods available in FXId are: create created? destroy detach but it does have an attribute called "app". I guess when you say to use the method getApp you''re really saying to use this app attribute which, as you explained here, is inherited by FXWindow. Am I right in thinking so? I''m just asking because I couldn''t find ANY method named getApp neither on this documentation nor on the documentation for Ruby core. Sorry if these questions are boring, but I''m new to Ruby and FXRuby, and I want to understand it very well, in order to use it in depth. Thanks, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I ------ contatos: email: angico at angico.org skype: an.gi.co ------
On Oct 31, 2008, at 3:33 AM, angico wrote:> According to the documentation on http://www.fxruby.org/doc/api/, the > only methods available in FXId are: > > create created? destroy detach > > but it does have an attribute called "app". I guess when you say to > use > the method getApp you''re really saying to use this app attribute > which, > as you explained here, is inherited by FXWindow. Am I right in > thinking > so?Yes. --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby