diff --git a/src/container.jl b/src/container.jl index 32957c59..afa13022 100644 --- a/src/container.jl +++ b/src/container.jl @@ -41,6 +41,7 @@ Base.:|>(parent::GtkContainer, child::Union{GObject, AbstractString}) = push!(pa start_(w::GtkContainer) = glist_iter(ccall((:gtk_container_get_children, libgtk), Ptr{_GList{GObject}}, (Ptr{GObject},), w)) iterate(w::GtkContainer, list=start_(w)) = iterate(list[1], list) length(w::GtkContainer) = length(start_(w)[1]) +Base.keys(w::GtkContainer) = Base.OneTo(length(w)) getindex(w::GtkContainer, i::Integer) = convert(GtkWidget, start_(w)[1][i])::GtkWidget function start_(w::GtkBin) diff --git a/src/layout.jl b/src/layout.jl index f8d427a9..81986b95 100644 --- a/src/layout.jl +++ b/src/layout.jl @@ -162,6 +162,8 @@ function setindex!(pane::GtkPaned, child, i::Integer, resize::Bool, shrink::Bool end end +Base.keys(::GtkPaned) = Base.OneTo(2) + ### GtkLayout function GtkLayoutLeaf(width::Real, height::Real) layout = ccall((:gtk_layout_new, libgtk), Ptr{GObject}, diff --git a/src/lists.jl b/src/lists.jl index d4dcd13e..7f1de7be 100644 --- a/src/lists.jl +++ b/src/lists.jl @@ -194,6 +194,10 @@ function length(listStore::GtkListStore) end size(listStore::GtkListStore) = (length(listStore), ncolumns(GtkTreeModel(listStore))) +Base.axes(listStore::GtkListStore) = Base.OneTo.(size(listStore)) +Base.axes(listStore::GtkListStore, d::Integer) = axes(listStore)[d] + +Base.keys(listStore::GtkListStore) = CartesianIndices(size(listStore)) getindex(store::GtkListStore, row::Int, column) = getindex(store, iter_from_index(store, row), column) getindex(store::GtkListStore, row::Int) = getindex(store, iter_from_index(store, row)) @@ -201,6 +205,11 @@ getindex(store::GtkListStore, row::Int) = getindex(store, iter_from_index(store, function setindex!(store::GtkListStore, value, index::Int, column::Integer) setindex!(store, value, Gtk.iter_from_index(store, index), column) end +setindex!(store::GtkListStore, value, index::Union{Int,CartesianIndex}, column::Union{Integer,CartesianIndex}) = + setindex!(store, value, _integer(index), _integer(column)) + +_integer(i::Integer) = i +_integer(i::CartesianIndex) = convert(Int, i) ### GtkTreeStore diff --git a/src/toolbar.jl b/src/toolbar.jl index d63f2645..8adb4afd 100644 --- a/src/toolbar.jl +++ b/src/toolbar.jl @@ -31,6 +31,7 @@ end length(toolbar::GtkToolbar) = ccall((:gtk_toolbar_get_n_items, libgtk), Cint, (Ptr{GObject},), toolbar) +Base.keys(toolbar::GtkToolbar) = 0:length(toolbar)-1 # FIXME zero-based indexing ### GtkToolButton GtkToolButtonLeaf(stock_id::AbstractString) = GtkToolButtonLeaf( diff --git a/test/glist.jl b/test/glist.jl index f2881a16..c2875fac 100644 --- a/test/glist.jl +++ b/test/glist.jl @@ -60,6 +60,7 @@ end @test length(g2)==8 @test length(g)==10 +@test eachindex(g) == 1:10 insert!(g,8,string(25)) @test length(g)==11 diff --git a/test/gui.jl b/test/gui.jl index 082cba12..0eb42e3c 100755 --- a/test/gui.jl +++ b/test/gui.jl @@ -1,4 +1,5 @@ ## Tests +using Test using Gtk.ShortNames, Gtk.GConstants, Gtk.Graphics import Gtk.deleteat!, Gtk.libgtk_version, Gtk.GtkToolbarStyle, Gtk.GtkFileChooserAction, Gtk.GtkResponseType @@ -195,6 +196,8 @@ push!(w, pw) push!(pw, Button("one")) push!(pw, pw2) @test pw[2]==pw2 +@test length(pw) == 2 +@test eachindex(pw) == 1:2 pw2[1]=Button("two") pw2[2,true,false]=Button("three") showall(w) @@ -207,6 +210,7 @@ l = Layout(600,600) push!(w,l) l[300,300]=Button("Button") s=size(l) +@test s == (600, 600) @test width(l)==600 @test height(l)==600 showall(w) @@ -224,6 +228,8 @@ g2 = Gtk.GtkBox(:h) push!(f,g1) push!(f,g2) @test f[1]==g1 +@test length(f) == 2 +@test eachindex(f) == 1:2 b11 = Button("first") push!(g1, b11) @@ -281,6 +287,7 @@ end grid[2,3] = Button("2,3") grid[1,1] = "grid" grid[3,1:3] = Button("Tall button") + @test_broken eachindex(grid) == CartesianIndices(size(grid)) insert!(grid,1,:top) insert!(grid,3,:bottom) insert!(grid,grid[1,2],:right) @@ -499,11 +506,13 @@ for c in choices push!(combo, c) end c = cells(CellLayout(combo)) +@test eachindex(c) == 1:1 set_gtk_property!(c[1],"max_width_chars", 5) w = Window(combo, "ComboGtkBoxText")|>showall lsl = ListStoreLeaf(combo) @test length(lsl) == 3 +@test eachindex(lsl) == CartesianIndices(size(lsl)) empty!(combo) @test length(lsl) == 0 @@ -718,6 +727,8 @@ push!(ls,(33,true)) pushfirst!(ls,(22,false)) popfirst!(ls) @test size(ls)==(2,2) +@test eachindex(ls) == CartesianIndices(size(ls)) +@test axes(ls, 1) == axes(ls, 2) == 1:2 insert!(ls, 2, (35, false)) tv=TreeView(TreeModel(ls)) r1=CellRendererText() @@ -796,6 +807,7 @@ push!(toolbar,tb3) push!(toolbar,SeparatorToolItem(), ToggleToolButton("gtk-open"), MenuToolButton("gtk-new")) @test toolbar[0]==tb2 # FIXME: uses zero based indexing @test length(toolbar)==6 +@test eachindex(toolbar) == 0:5 # FIXME zero-based indexing G_.style(toolbar,GtkToolbarStyle.BOTH) w = Window(toolbar, "Toolbar")|>showall destroy(w) diff --git a/test/list.jl b/test/list.jl index 88a246bf..2d1b882e 100644 --- a/test/list.jl +++ b/test/list.jl @@ -1,4 +1,5 @@ using Gtk +using Test @testset "list" begin diff --git a/test/text.jl b/test/text.jl index e7911bdd..468d4742 100644 --- a/test/text.jl +++ b/test/text.jl @@ -107,6 +107,7 @@ place_cursor(b, ite) # GtkTextRange range=its:ite +@test_broken eachindex(range) == 1:5 @test range[1] == 'l' @test range[5] == '2' @test_throws BoundsError range[10]