« Return to Thread: foxGUIb first program problems

Re: foxGUIb first program problems

by cag :: Rate this Message:

Reply to Author | View in Thread

The name of the actual *class* that was generated is MainWindow and you need to extend it as follows:
============
require 'inches2'
class MainWindow
def init
 
  convertButton.connect(Fox::SEL_COMMAND){
    cmLabel.text = (inchesField.text.to_f * 2.54).to_s
 }
=============
I think you can also remove the @ from @convertButton as they have been assigned to attr_reader(s)

Now I'm off to see if I can easily reconcile the syntax differences between the FxRuby tutorial and this one - for example:
This
   require 'libGUIb16'
   app=FX::App.new
   w=MainWindow.new app
   w.topwin.show(Fox::PLACEMENT_SCREEN)
   app.create
   app.run

Compared to this:
  require 'fox16'
  include Fox
  theApp = FXApp.new
  theMainWindow = FXMainWindow.new(theApp, "Hello")
  theApp.create
  theMainWindow.show

I understand the need for
  require 'libGUIb16'
but I am not clear on why FX::App.new versus FXApp.new

The reason is because I think all examples in the Pragmatic programmers book use the later which is not generated by the code generator. Perhaps there is a way to alias or something.

Also I'd like to find a clean way to just initialise the events with calls to methods outside the extended class. I think that would be a lot cleaner.

Cheers,
  Carl








dglnz wrote:
Hope some one can help.

I've had a look at the user guide online and followed the initial steps of the 1st program.

It works no problems now i looked at the separation of event handlers (code I as a developer want to have included in the code that is generated by GUIb generator and i'm hitting problems - getting no response!

here is the the GUIb generated code for my first version and it works - .

# source generated by foxGUIb 1.0.0
class MainWindow
 def initialize( parent)
  construct_widget_tree( parent)
  init if respond_to? 'init'
 end
 
 def construct_widget_tree( parent)
  @topwin=
  FX::MainWindow.new(parent){|w|
   @mainWindow=w
   w.wdg_name='mainWindow'
   w.width=500
   w.shown=true
   w.y=302
   w.height=400
   w.x=215
   FX::Button.new(@mainWindow){|w|
    @convertButton=w
    w.wdg_name='convertButton'
    w.text="Convert to cm"
        @convertButton.connect(Fox::SEL_COMMAND)
    w.width=98
    w.height=23
   }
   FX::TextField.new(@mainWindow){|w|
    @inchesField=w
    w.wdg_name='inchesField'
    w.width=86
    w.y=27
    w.height=21
    w.numColumns=10
   }
   FX::Label.new(@mainWindow){|w|
    @cmLabel=w
    w.wdg_name='cmLabel'
    w.width=38
    w.y=52
    w.height=19
   }
  }
 end
 attr_reader :topwin
 attr_reader :mainWindow
 attr_reader :convertButton
 attr_reader :inchesField
 attr_reader :cmLabel
end
#unit test
if __FILE__==$0
 require 'libGUIb16'
 app=FX::App.new
 w=MainWindow.new app
 w.topwin.show(Fox::PLACEMENT_SCREEN)
 app.create
 app.run
end


here is the same code _BUT_ without the code i entered.

# source generated by foxGUIb 1.0.0 - File name is inches2.rbin
class MainWindow
 def initialize( parent)
  construct_widget_tree( parent)
  init if respond_to? 'init'
 end
 
 def construct_widget_tree( parent)
  @topwin=
  FX::MainWindow.new(parent){|w|
   @mainWindow=w
   w.wdg_name='mainWindow'
   w.width=532
   w.shown=true
   w.y=181
   w.height=536
   w.x=64
   FX::Button.new(@mainWindow){|w|
    @button1=w
    w.wdg_name='button1'
    w.text="convert to inches"
    w.width=91
    w.height=21
   }
   FX::TextField.new(@mainWindow){|w|
    @textfield1=w
    w.wdg_name='textfield1'
    w.width=66
    w.y=25
    w.height=19
    w.numColumns=10
   }
   FX::Label.new(@mainWindow){|w|
    @label1=w
    w.wdg_name='label1'
    w.width=29
    w.y=48
    w.height=17
   }
  }
 end
 attr_reader :topwin
 attr_reader :mainWindow
 attr_reader :button1
 attr_reader :textfield1
 attr_reader :label1
end
#unit test
if __FILE__==$0
 require 'libGUIb16'
 app=FX::App.new
 w=MainWindow.new app
 w.topwin.show(Fox::PLACEMENT_SCREEN)
 app.create
 app.run
end

here is the code i've done to handle the events.

require 'inches2'
def init
 
  @convertButton.connect(Fox::SEL_COMMAND){
    cmLabel.text = (inchesField.text.to_f * 2.54).to_s
 }
 
end

#unit test
if __FILE__==$0
 require 'libGUIb16'
 app=FX::App.new
 w=MainWindow.new app
 w.topwin.show(Fox::PLACEMENT_SCREEN)
 app.create
 app.run
end

Advise please as to what to do - I'd like to use GUIb but i'm finding it hard to understand how to use the events as explained in the tutorial at http://www.mikeparr.info/rubyguib/firstprog.htm

Dave.



_______________________________________________
fxruby-users mailing list
fxruby-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/fxruby-users

 « Return to Thread: foxGUIb first program problems