Joey Kinsella
2010-May-05 14:14 UTC
[fxruby-users] Preventing a parent window from closing
FXRuby users,
Is it possible to prevent a parent window from closing when a child window
is open. I know I could probably do this with some kind of global variable
in the main window object, and basically have some kind of "reference"
count
that if not equal to 0, it will not close the window. Then each time a child
window closes the reference count gets decremented by 1. ie:
--- BEGIN SNIPPET ---
#! /usr/bin/env ruby
require ''fox16''
include Fox
class SimpleApp < FXMainWindow
def initialize(app)
super(app,"Simple Test App", nil,nil, DECOR_ALL, 0,0, 640,480)
@winref = 0
FXButton.new(self, "Click Me").connect(SEL_COMMAND) do
@winref += 1
aw = AnotherWin.new(app)
aw.create
aw.connect(SEL_CLOSE) do
@winref -= 1
end
end
end
def close(notify = false)
## popup a message. ##
return if(@winref != 0)
super(notify)
end
def create
super
show(PLACEMENT_SCREEN)
end
end
class AnotherWin < FXMainWindow
def initialize(app)
super(app,"Another window", nil,nil, DECOR_ALL, 0,0, 320,260)
end
def create
super
show(PLACEMENT_SCREEN)
end
end
app = FXApp.new("Test","Test")
SimpleApp.new(app)
app.create
app.run
--- END SNIPPET ---
I was curious if there was a better way of doing this, perhaps something in
the underlying routines in the Fox library. Perhaps I shouldn''t be
using
FXMainWindow as a child window? For now, I will probably end up using this
implementation, but I hope to hear back on a better way of doing this.
--
If you are not the intended recipient, you are hereby notified
that any dissemination, distribution, copying or other use of
this communication is strictly prohibited. If you have
received this communication in error, please notify us
immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/fxruby-users/attachments/20100505/ded47c96/attachment.html>