From bf042e34772665542b326faf00a6217a7b9e76c7 Mon Sep 17 00:00:00 2001 From: timholy Date: Fri, 3 Jan 2014 06:05:09 -0600 Subject: [PATCH] Add destroyall --- src/Gtk.jl | 4 ++-- src/windows.jl | 17 +++++++++++++++++ test/tests.jl | 9 +++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Gtk.jl b/src/Gtk.jl index ae240032..c44e6325 100644 --- a/src/Gtk.jl +++ b/src/Gtk.jl @@ -15,7 +15,7 @@ import Cairo: destroy # generic interface: export width, height, #minsize, maxsize reveal, configure, draw, cairo_context, - visible, destroy, + visible, destroy, destroyall, hasparent, toplevel #property, margin, padding, align @@ -155,7 +155,7 @@ module ShortNames # generic interface (keep this synchronized with above) export width, height, #minsize, maxsize reveal, configure, draw, cairo_context, - visible, destroy, + visible, destroy, destroyall, hasparent, toplevel # Gtk objects diff --git a/src/windows.jl b/src/windows.jl index 1ed531e1..7090fcae 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -1,5 +1,6 @@ @GType GtkWindow <: GtkWindow function GtkWindow(title=nothing, w=-1, h=-1, resizable=true, toplevel=true) + global allwindows hnd = ccall((:gtk_window_new,libgtk),Ptr{GObject},(Enum,), toplevel?GtkWindowType.TOPLEVEL:GtkWindowType.POPUP) if title !== nothing @@ -12,9 +13,25 @@ function GtkWindow(title=nothing, w=-1, h=-1, resizable=true, toplevel=true) ccall((:gtk_widget_set_size_request,libgtk),Void,(Ptr{GObject},Int32,Int32),hnd,w,h) end widget = GtkWindow(hnd) + push!(allwindows, widget) + on_signal_destroy(_delete!, widget) show(widget) widget end +const allwindows = Set() +function _delete!(ptr::Ptr, win::GtkWindowI) + global allwindows + delete!(allwindows, win) + nothing +end + +function destroyall() + global allwindows + for win in allwindows + destroy(win) + end +end + #GtkScrolledWindow #GtkSeparator — A separator widget diff --git a/test/tests.jl b/test/tests.jl index 8caa1c77..e983fc00 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -23,6 +23,15 @@ w=WeakRef(w) gc(); gc(); sleep(.1); gc(); gc() @assert w.value === nothing || w.value.handle == C_NULL +win1 = Window("window 1") +win2 = Window("window 2") +win3 = Window("window 3") +@assert length(Gtk.allwindows) == 3 +destroy(win2) +@assert length(Gtk.allwindows) == 2 +destroyall() +@assert length(Gtk.allwindows) == 0 + ## Frame w = Window( Frame(),