Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I open the same window twice #45

Open
murathptest opened this issue Mar 23, 2018 · 2 comments
Open

How can I open the same window twice #45

murathptest opened this issue Mar 23, 2018 · 2 comments

Comments

@murathptest
Copy link

Hi,
I am trying to use fxruby to open a FileDialog multiple times through out the execution of the main ruby program which is not a GUI program. The main program executes, then there is a need to open a directory to pick a file and submit. And then pick another file and submit, so it is in a loop.
I see the following error: attempted to create more than one FXApp instance (RuntimeError)

To simplify my question, I am copying the following code.
If a user wanted to reopen the Hello World box twice in the same program once the first box is closed by clicking on the red (x) of the windows (upper right corner), how would he restart it again in the same program. I tried .exit, .destroy with subsequent object recreations and that did not work.

require 'fox16'
include Fox

class HelloWorld < FXMainWindow
def initialize(app)
super(app, "Hello, World!" , :width => 200, :height => 50)
end
def create
super
show(PLACEMENT_SCREEN)
end
end

app = FXApp.new
HelloWorld.new(app)
app.create
app.run
app.exit
HelloWorld.new(app)
app.create
app.run

@larskanis
Copy link
Owner

larskanis commented Mar 23, 2018

create is a bit tricky in FXRuby: It is called while the initial FXApp.create call, but subsequently allocated Widgets needs to be created explicitly. In addition to this there's currently no way to destroy a FXApp once created. So you have to reuse it like so:

require 'fox16'
include Fox

class HelloWorld < FXMainWindow
  def initialize(app, t)
    super(app, "Hello, #{t}" , :width => 200, :height => 50)
  end
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

def show_window(t)
  app = FXApp.instance || FXApp.new
  app.create
  w = HelloWorld.new(app, t)
  w.create
  app.run
end

show_window(1)
show_window(2)
show_window(3)

It is not allowed to create more than one FXApp instances at the same time. Nevertheless I think there should be a way to destroy a FXApp instance and create a new one. I'll check if I can add such a method.

@murathptest
Copy link
Author

murathptest commented Mar 23, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants