updata of a value from outside

View: New views
2 Messages — Rating Filter:   Alert me  

updata of a value from outside

by jabowen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a button in the test gui that runs a random number generator class outside of the gui.  How do I get the field to update inside the gui?  It creates the number but and puts it but does not update the field.  

require 'fox16'
include Fox
class GenNum
        def current_addr
                $current_addr = rand(0)
        end
end
class TestRun < FXMainWindow
        def initialize(app)
                super(app, "Test Run", :width => 400, :height => 100)
                        @rand_num = GenNum.new
                        p = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_CENTER_Y)
                        $intTarget = FXDataTarget.new($current_addr.to_s)

                        FXTextField.new(p, 20, $intTarget, FXDataTarget::ID_VALUE,
                                LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_ROW)
                       
                        activate_button = FXButton.new(p, "test_run",
                                :opts => BUTTON_NORMAL|LAYOUT_CENTER_X)
                        activate_button.connect(SEL_COMMAND) do |sender, sel, data|
                                @rand_num.current_addr
                                p $current_addr
                        end
                end
        def create
                super
                show(PLACEMENT_SCREEN)
        end
end
if __FILE__ == $0
  FXApp.new do |app|
    TestRun.new(app)
    app.create
    app.run
  end
end

Re: updata of a value from outside

by Lyle Johnson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 13, 2009, at 4:23 PM, jabowen wrote:

> I have a button in the test gui that runs a random number generator  
> class
> outside of the gui.  How do I get the field to update inside the  
> gui?  It
> creates the number but and puts it but does not update the field.

You need to be sure to update the value of the data target. Try  
changing your button action to this:

        activate_button.connect(SEL_COMMAND) do
                @rand_num.current_addr
                @intTarget.value = $current_addr
        end

Hope this helps,

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