Search code examples
rubyfxruby

Exit dialog box after clicking


I am using fxruby to create a dialog box which has few options. Here is the part where I display one option and what happens after clicking that one.

# Download file
dwd_file= FXButton.new(contents,
  "&Download\tDownload file",
  :opts => FRAME_RAISED|FRAME_THICK|LAYOUT_BOTTOM |LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,
  :width => 150, :height => 50)
  dwd_file.connect(SEL_COMMAND, method(:download))


def download(sender, sel, ptr)
  # Doing something which will take time. 
end

The dwd_file.connect will execute the download method which does somthing which takes time.

Question: The dialog box hangs around till that method is executed, how do we close it on clicking and later the method gets executed?

Thanks for any tip?


Solution

  • def download(sender, sel, ptr)
      self.close
      # Do that which will take time. 
    end
    

    In fxruby you will create your own class and inherit FXMainWindow clss or any other class from the fxruby lib for example.

    self will point to your class which actually creates the dialog box according to your example thus self.close will close the dialog box first and then you can continue the heavy work.