Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Add destroyall #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/windows.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
9 changes: 9 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down