From 1a49e6bb7ff5b3daff8fab2f73b0fdbc18ba08d7 Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Thu, 26 May 2016 21:15:23 +0200 Subject: [PATCH 1/2] generate for each Gtk type a constructor that does not require a macro to be invoked --- gen/gbox3 | 20 --- src/GLib/gtype.jl | 4 + src/gl_area.jl | 4 +- src/long_exports.jl | 1 + src/long_leaf_exports.jl | 4 +- src/selectors.jl | 7 +- src/short_exports.jl | 2 + src/short_leaf_exports.jl | 4 +- src/text.jl | 4 +- src/windows.jl | 6 +- test/gui.jl | 289 +++++++++++++++++++------------------- test/misc.jl | 4 +- 12 files changed, 170 insertions(+), 179 deletions(-) diff --git a/gen/gbox3 b/gen/gbox3 index d2087538..866e92ee 100644 --- a/gen/gbox3 +++ b/gen/gbox3 @@ -15,9 +15,6 @@ $(Expr(:toplevel, :(module GAccessor ccall((:g_object_set_property,Gtk.GLib.libgobject),Void,(Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),object,property_name,value) return object end - function property(object::Gtk.GObject,property_name,value) - return ccall((:g_object_get_property,Gtk.GLib.libgobject),Void,(Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),object,property_name,value) - end function qdata(object::Gtk.GObject,quark) return ccall((:g_object_get_qdata,Gtk.GLib.libgobject),Ptr{Void},(Ptr{Gtk.GObject},UInt32),object,quark) end @@ -596,9 +593,6 @@ $(Expr(:toplevel, :(module GAccessor ccall((:gtk_container_child_set_property,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),container,child,property_name,value) return container end - function property(container::Gtk.GtkContainer,child,property_name,value) - return ccall((:gtk_container_child_get_property,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),container,child,property_name,value) - end function path_for_child(container::Gtk.GtkContainer,child) return convert(Gtk.GtkWidgetPath,ccall((:gtk_container_get_path_for_child,Gtk.libgtk),Ptr{Gtk.GtkWidgetPath},(Ptr{Gtk.GObject},Ptr{Gtk.GObject}),container,child)) end @@ -1546,9 +1540,6 @@ $(Expr(:toplevel, :(module GAccessor ccall((:gtk_cell_area_cell_set_property,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),area,renderer,property_name,value) return area end - function property(area::Gtk.GtkCellArea,renderer,property_name,value) - return ccall((:gtk_cell_area_cell_get_property,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject},Ptr{UInt8},Ptr{Void}),area,renderer,property_name,value) - end function focus_cell(area::Gtk.GtkCellArea,renderer) ccall((:gtk_cell_area_set_focus_cell,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject}),area,renderer) return area @@ -1797,13 +1788,6 @@ $(Expr(:toplevel, :(module GAccessor function track_motion(widget::Gtk.GtkWidget) return convert(Bool,ccall((:gtk_drag_dest_get_track_motion,Gtk.libgtk),Cint,(Ptr{Gtk.GObject},),widget)) end - function target_list(widget::Gtk.GtkWidget) - return convert(Gtk.GtkTargetList,ccall((:gtk_drag_source_get_target_list,Gtk.libgtk),Ptr{Gtk.GtkTargetList},(Ptr{Gtk.GObject},),widget)) - end - function target_list(widget::Gtk.GtkWidget,target_list_) - ccall((:gtk_drag_source_set_target_list,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GtkTargetList}),widget,target_list_) - return widget - end function icon_pixbuf(widget::Gtk.GtkWidget,pixbuf) ccall((:gtk_drag_source_set_icon_pixbuf,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Gtk.GObject}),widget,pixbuf) return widget @@ -2843,10 +2827,6 @@ $(Expr(:toplevel, :(module GAccessor function rgba(chooser::Gtk.GtkColorChooser,color) return ccall((:gtk_color_chooser_get_rgba,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Void}),chooser,color) end - function rgba(chooser::Gtk.GtkColorChooser,color) - ccall((:gtk_color_chooser_set_rgba,Gtk.libgtk),Void,(Ptr{Gtk.GObject},Ptr{Void}),chooser,color) - return chooser - end function use_alpha(chooser::Gtk.GtkColorChooser) return convert(Bool,ccall((:gtk_color_chooser_get_use_alpha,Gtk.libgtk),Cint,(Ptr{Gtk.GObject},),chooser)) end diff --git a/src/GLib/gtype.jl b/src/GLib/gtype.jl index 34703b30..f98d613e 100644 --- a/src/GLib/gtype.jl +++ b/src/GLib/gtype.jl @@ -219,8 +219,12 @@ function get_type_decl(name,iname,gtyp,gtype_decl) end gtype_wrappers[$(QuoteNode(iname))] = $ename macro $einame(args...) + Base.depwarn(string("\@",$einame," is deprecated, use ", $einame, " instead."), :Gtk) Expr(:call, $ename, map(esc,args)...) end + function $einame(args...; kwargs...) + $ename(args...; kwargs...) + end $gtype_decl nothing end diff --git a/src/gl_area.jl b/src/gl_area.jl index 9432c91a..58f5c27e 100644 --- a/src/gl_area.jl +++ b/src/gl_area.jl @@ -7,8 +7,6 @@ if libgtk_version >= v"3.16.0" #TODO: gtk_gl_area_get_error alpha(w::GtkGLArea, value::Bool) = (ccall((:gtk_gl_area_set_has_alpha,libgtk),Void,(Ptr{GObject},Cint),w, value); w) - depth_buffer(w::GtkGLArea, value::Bool) = - (ccall((:gtk_gl_area_set_has_depth_buffer,libgtk),Void,(Ptr{GObject},Cint),w, value); w) alpha(w::GtkGLArea) = Bool(ccall((:gtk_gl_area_set_has_alpha,libgtk),Cint,(Ptr{GObject},),w)) depth_buffer(w::GtkGLArea, value::Bool) = @@ -19,7 +17,7 @@ if libgtk_version >= v"3.16.0" Bool(ccall((:gtk_gl_area_get_has_stencil_buffer,libgtk),Cint,(Ptr{GObject},),w)) auto_render(w::GtkGLArea, value::Bool) = (ccall((:gtk_gl_area_set_auto_render,libgtk),Void,(Ptr{GObject},Cint),w, value); w) - stencil_buffer(w::GtkGLArea) = + auto_render(w::GtkGLArea) = Bool(ccall((:gtk_gl_area_get_auto_render,libgtk),Cint,(Ptr{GObject},),w)) #TODO: gtk_gl_area_get_required_version #TODO: gtk_gl_area_set_required_version diff --git a/src/long_exports.jl b/src/long_exports.jl index 23fc4943..6b8368ea 100644 --- a/src/long_exports.jl +++ b/src/long_exports.jl @@ -46,6 +46,7 @@ export GObject, GtkPaned, GtkProgressBar, GtkRadioButton, + GtkRadioButtonGroup, GtkScale, GtkScrolledWindow, GtkSeparatorMenuItem, diff --git a/src/long_leaf_exports.jl b/src/long_leaf_exports.jl index f06782ea..1a15fd90 100644 --- a/src/long_leaf_exports.jl +++ b/src/long_leaf_exports.jl @@ -152,9 +152,9 @@ export # Gtk3 objects -export @GtkGrid, @GtkGLArea +export GtkGrid, GtkGLArea export GtkGridLeaf, GtkGLAreaLeaf # Gtk2 objects -export @GtkTable, @GtkAlignment +export GtkTable, GtkAlignment export GtkTableLeaf, GtkAlignmentLeaf diff --git a/src/selectors.jl b/src/selectors.jl index 6385d73b..af099d63 100755 --- a/src/selectors.jl +++ b/src/selectors.jl @@ -67,12 +67,12 @@ if libgtk_version >= v"3" ### should work with v >= 2.4, but there is a bug function makefilters!(dlgp::GtkFileChooser, filters::Union{AbstractVector,Tuple}) for f in filters - ccall((:gtk_file_chooser_add_filter,libgtk), Void, (Ptr{GObject}, Ptr{GObject}), dlgp, @GtkFileFilter(f)) + ccall((:gtk_file_chooser_add_filter,libgtk), Void, (Ptr{GObject}, Ptr{GObject}), dlgp, GtkFileFilter(f)) end end function open_dialog(title::AbstractString, parent = GtkNullContainer(), filters::Union{AbstractVector,Tuple} = String[]; kwargs...) - dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.OPEN, + dlg = GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.OPEN, (("_Cancel", GConstants.GtkResponseType.CANCEL), ("_Open", GConstants.GtkResponseType.ACCEPT)); kwargs...) dlgp = GtkFileChooser(dlg) @@ -103,7 +103,7 @@ if libgtk_version >= v"3" ### should work with v >= 2.4, but there is a bug end function save_dialog(title::AbstractString, parent = GtkNullContainer(), filters::Union{AbstractVector,Tuple} = String[]; kwargs...) - dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.SAVE, + dlg = GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.SAVE, (("_Cancel", GConstants.GtkResponseType.CANCEL), ("_Save", GConstants.GtkResponseType.ACCEPT)), kwargs...) dlgp = GtkFileChooser(dlg) @@ -120,5 +120,4 @@ if libgtk_version >= v"3" ### should work with v >= 2.4, but there is a bug destroy(dlg) selection end - end diff --git a/src/short_exports.jl b/src/short_exports.jl index a2debbae..f00cc524 100644 --- a/src/short_exports.jl +++ b/src/short_exports.jl @@ -46,6 +46,7 @@ const Paned = GtkPaned const Pixbuf = GdkPixbuf const ProgressBar = GtkProgressBar const RadioButton = GtkRadioButton +const RadioButtonGroup = GtkRadioButtonGroup const Scale = GtkScale const ScrolledWindow = GtkScrolledWindow const SeparatorMenuItem = GtkSeparatorMenuItem @@ -122,6 +123,7 @@ export G_, GObject, Pixbuf, ProgressBar, RadioButton, + RadioButtonGroup, Scale, ScrolledWindow, SeparatorMenuItem, diff --git a/src/short_leaf_exports.jl b/src/short_leaf_exports.jl index bdd5fb76..a3474d99 100644 --- a/src/short_leaf_exports.jl +++ b/src/short_leaf_exports.jl @@ -225,11 +225,11 @@ export G_Leaf, # Gtk 3 @g_type_delegate Grid = GtkGrid @g_type_delegate GLArea = GtkGLArea -export @Grid, @GLArea +export Grid, GLArea export GridLeaf, GLAreaLeaf # Gtk 2 @g_type_delegate Table = GtkTable @g_type_delegate Alignment = GtkAlignment -export @Table, @Aligment +export Table, Aligment export TableLeaf, AligmentLeaf diff --git a/src/text.jl b/src/text.jl index f60a357f..51b62dd8 100644 --- a/src/text.jl +++ b/src/text.jl @@ -19,7 +19,7 @@ GtkLabelLeaf(title) = GtkLabelLeaf( GtkTextBufferLeaf() = GtkTextBufferLeaf( ccall((:gtk_text_buffer_new,libgtk),Ptr{GObject},(Ptr{GObject},),C_NULL)) -GtkTextViewLeaf(buffer::GtkTextBuffer=@GtkTextBuffer()) = GtkTextViewLeaf( +GtkTextViewLeaf(buffer::GtkTextBuffer=GtkTextBuffer()) = GtkTextViewLeaf( ccall((:gtk_text_view_new_with_buffer,libgtk),Ptr{GObject},(Ptr{GObject},),buffer)) GtkTextMarkLeaf(left_gravity::Bool=false) = GtkTextMarkLeaf( @@ -353,7 +353,7 @@ function user_action(f::Function, buffer::GtkTextBuffer) end function create_tag(buffer::GtkTextBuffer, tag_name::AbstractString; properties...) - tag = @GtkTextTag(ccall((:gtk_text_buffer_create_tag,libgtk), Ptr{GObject}, + tag = GtkTextTag(ccall((:gtk_text_buffer_create_tag,libgtk), Ptr{GObject}, (Ptr{GObject},Ptr{UInt8},Ptr{Void}), buffer, bytestring(tag_name), C_NULL)) for (k,v) in properties diff --git a/src/windows.jl b/src/windows.jl index 6a93091c..804d3e2e 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -71,7 +71,7 @@ ask_dialog(message::AbstractString, parent = GtkNullContainer()) = ask_dialog(message, "No", "Yes", parent) function ask_dialog(message::AbstractString, no_text, yes_text, parent = GtkNullContainer()) - dlg = @GtkMessageDialog(message, ((no_text,0), (yes_text,1)), + dlg = GtkMessageDialog(message, ((no_text,0), (yes_text,1)), GtkDialogFlags.DESTROY_WITH_PARENT, GtkMessageType.QUESTION, parent) response = run(dlg) destroy(dlg) @@ -94,9 +94,9 @@ for (func, flag) in ( end function input_dialog(message::AbstractString, entry_default::AbstractString, buttons=(("Cancel",0), ("Accept",1)), parent = GtkNullContainer()) - widget = @GtkMessageDialog(message, buttons, GtkDialogFlags.DESTROY_WITH_PARENT, GtkMessageType.INFO, parent) + widget = GtkMessageDialog(message, buttons, GtkDialogFlags.DESTROY_WITH_PARENT, GtkMessageType.INFO, parent) box = content_area(widget) - entry = @GtkEntry(;text=entry_default) + entry = GtkEntry(;text=entry_default) push!(box, entry) showall(widget) resp = run(widget) diff --git a/test/gui.jl b/test/gui.jl index 2e86983b..3901848a 100755 --- a/test/gui.jl +++ b/test/gui.jl @@ -40,7 +40,7 @@ wdth, hght = screen_size() @test wdth > 0 && hght > 0 @testset "Window" begin -w = @Window("Window", 400, 300) |> showall +w = Window("Window", 400, 300) |> showall @test width(w) == 400 @test height(w) == 300 @test size(w) == (400, 300) @@ -75,7 +75,7 @@ end @testset "change Window size" begin if libgtk_version >= v"3.16.0" - w = @Window("Window", 400, 300) + w = Window("Window", 400, 300) fullscreen(w) sleep(1) unfullscreen(w) @@ -93,8 +93,8 @@ end end @testset "Frame" begin -w = @Window( - @Frame(), +w = Window( + Frame(), "Frame", 400, 400) @test size(w) == (400, 400) showall(w) @@ -102,20 +102,20 @@ destroy(w) end @testset "Initially Hidden Canvas" begin -nb = @Notebook() -vbox = @Box(:v) -c = @Canvas() +nb = Notebook() +vbox = Gtk.Box(:v) +c = Canvas() push!(nb, vbox, "A") push!(nb, c, "B") -w = @Window("TestDataViewer",600,600) +w = Window("TestDataViewer",600,600) push!(w,nb) showall(w) destroy(w) end @testset "Labelframe" begin -f = @Frame("Label") -w = @Window(f, "Labelframe", 400, 400) +f = Frame("Label") +w = Window(f, "Labelframe", 400, 400) setproperty!(f,:label,"new label") @test getproperty(f,:label,AbstractString) == "new label" showall(w) @@ -123,11 +123,11 @@ destroy(w) end @testset "notebook" begin -nb = @Notebook() -w = push!(@Window("Notebook"),nb) -push!(nb, @Button("o_ne"), "tab _one") -push!(nb, @Button("t_wo"), "tab _two") -push!(nb, @Button("th_ree"), "tab t_hree") +nb = Notebook() +w = push!(Window("Notebook"),nb) +push!(nb, Button("o_ne"), "tab _one") +push!(nb, Button("t_wo"), "tab _two") +push!(nb, Button("th_ree"), "tab t_hree") push!(nb, "fo_ur", "tab _four") showall(w) @test length(nb) == 4 @@ -138,14 +138,14 @@ destroy(w) end @testset "Panedwindow" begin -w = @Window("Panedwindow", 400, 400) -pw = @Paned(:h) -pw2 = @Paned(:v) +w = Window("Panedwindow", 400, 400) +pw = Paned(:h) +pw2 = Paned(:v) push!(w, pw) -push!(pw, @Button("one")) +push!(pw, Button("one")) push!(pw, pw2) -push!(pw2,@Button("two")) -push!(pw2,@Button("three")) +push!(pw2,Button("two")) +push!(pw2,Button("three")) showall(w) destroy(w) end @@ -153,21 +153,21 @@ end @testset "Iteration and toplevel" begin ## example of last in first covered ## Create this GUI, then shrink window with the mouse -f = @Box(:v) -w = @Window(f, "Last in, first covered", 400, 400) +f = Gtk.Box(:v) +w = Window(f, "Last in, first covered", 400, 400) -g1 = @Box(:h) -g2 = @Box(:h) +g1 = Gtk.Box(:h) +g2 = Gtk.Box(:h) push!(f,g1) push!(f,g2) -b11 = @Button("first") +b11 = Button("first") push!(g1, b11) -b12 = @Button("second") +b12 = Button("second") push!(g1, b12) -b21 = @Button("first") +b21 = Button("first") push!(g2, b21) -b22 = @Button("second") +b22 = Button("second") push!(g2, b22) strs = ["first", "second"] @@ -188,37 +188,44 @@ destroy(w) end @testset "ButtonBox" begin -bb = @ButtonBox(:h) -w = @Window(bb, "ButtonBox") -cancel = @Button("Cancel") -ok = @Button("OK") +bb = ButtonBox(:h) +w = Window(bb, "ButtonBox") +cancel = Button("Cancel") +ok = Button("OK") +## ButtonBox +bb = ButtonBox(:h) +w = Window(bb, "ButtonBox") +cancel = Button("Cancel") +ok = Button("OK") push!(bb, cancel) push!(bb, ok) # Expander delete!(w, bb) -ex = @Expander(bb, "Some buttons") +ex = Expander(bb, "Some buttons") push!(w, ex) showall(w) destroy(w) end @testset "Table" begin -grid = @Table(3,3) -w = @Window(grid, "Grid", 400, 400) -grid[2,2] = @Button("2,2") -grid[2,3] = @Button("2,3") -grid[1,1] = "grid" -showall(w) -destroy(w) +if libgtk_version < v"3" + grid = Table(3,3) + w = Window(grid, "Grid", 400, 400) + grid[2,2] = Button("2,2") + grid[2,3] = Button("2,3") + grid[1,1] = "grid" + showall(w) + destroy(w) + end end @testset "Grid" begin if libgtk_version >= v"3" - grid = @Grid() - w = @Window(grid, "Grid", 400, 400) - grid[2,2] = @Button("2,2") - grid[2,3] = @Button("2,3") + grid = Grid() + w = Window(grid, "Grid", 400, 400) + grid[2,2] = Button("2,2") + grid[2,3] = Button("2,3") grid[1,1] = "grid" insert!(grid,1,:top) libgtk_version >= v"3.10.0" && deleteat!(grid,1,:row) @@ -231,10 +238,10 @@ end ## Widgets @testset "button, label" begin -w = @Window("Widgets") -f = @Box(:v); push!(w,f) -l = @Label("label"); push!(f,l) -b = @Button("button"); push!(f,b) +w = Window("Widgets") +f = Gtk.Box(:v); push!(w,f) +l = Label("label"); push!(f,l) +b = Button("button"); push!(f,b) setproperty!(l,:label,"new label") @test getproperty(l,:label,AbstractString) == "new label" @@ -268,15 +275,15 @@ end icon = Array(Gtk.RGB, 40, 20) fill!(icon, Gtk.RGB(0,0xff,0)) icon[5:end-5, 3:end-3] = Gtk.RGB(0,0,0xff) -b = @Button(@Image(@Pixbuf(data=icon, has_alpha=false))) -w = @Window(b, "Icon button", 60, 40) +b = Button(Image(Pixbuf(data=icon, has_alpha=false))) +w = Window(b, "Icon button", 60, 40) showall(w) destroy(w) end @testset "checkbox" begin -w = @Window("Checkbutton") -check = @CheckButton("check me"); push!(w,check) +w = Window("Checkbutton") +check = CheckButton("check me"); push!(w,check) setproperty!(check,:active,true) @test getproperty(check,:active,AbstractString) == "TRUE" setproperty!(check,:label,"new label") @@ -290,20 +297,20 @@ destroy(w) end @testset "radio" begin -choices = ["choice one", "choice two", "choice three", @RadioButton("choice four"), @Label("choice five")] -w = @Window("Radio") -f = @Box(:v); push!(w,f) +choices = ["choice one", "choice two", "choice three", RadioButton("choice four"), Label("choice five")] +w = Window("Radio") +f = Gtk.Box(:v); push!(w,f) r = Array(RadioButton,3) -r[1] = @RadioButton(choices[1]); push!(f,r[1]) -r[2] = @RadioButton(r[1],choices[2]); push!(f,r[2]) -r[3] = @RadioButton(r[2],choices[3],active=true); push!(f,r[3]) +r[1] = RadioButton(choices[1]); push!(f,r[1]) +r[2] = RadioButton(r[1],choices[2]); push!(f,r[2]) +r[3] = RadioButton(r[2],choices[3],active=true); push!(f,r[3]) @test [getproperty(b,:active,Bool) for b in r] == [false, false, true] setproperty!(r[1],:active,true) @test [getproperty(b,:active,Bool) for b in r] == [true, false, false] showall(w) destroy(w) -r = @RadioButtonGroup(choices,2) +r = RadioButtonGroup(choices,2) @test length(r) == 5 @test sum([getproperty(b,:active,Bool) for b in r]) == 1 itms = Array(Any,length(r)) @@ -317,13 +324,13 @@ end @test setdiff(choices, itms) == [choices[4],] @test setdiff(itms, choices) == ["choice four",] @test getproperty(getproperty(r,:active),:label,AbstractString) == choices[2] -w = @Window(r,"RadioGroup")|>showall +w = Window(r,"RadioGroup")|>showall destroy(w) end @testset "ToggleButton" begin -tb = @ToggleButton("Off") -w = @Window(tb, "ToggleButton")|>showall +tb = ToggleButton("Off") +w = Window(tb, "ToggleButton")|>showall function toggled(ptr,evt,widget) state = getproperty(widget,:label,AbstractString) if state == "Off" @@ -343,8 +350,8 @@ destroy(w) end @testset "ToggleButton repeat 1" begin -tb = @ToggleButton("Off") -w = @Window(tb, "ToggleButton")|>showall +tb = ToggleButton("Off") +w = Window(tb, "ToggleButton")|>showall # TODO: uncomment these next lines on_signal_button_press(tb) do ptr, evt, widget state = getproperty(widget,:label,AbstractString) @@ -364,8 +371,8 @@ destroy(w) end @testset "ToggleButton repeat 2" begin -tb = @ToggleButton("Off") -w = @Window(tb, "ToggleButton")|>showall +tb = ToggleButton("Off") +w = Window(tb, "ToggleButton")|>showall signal_connect(tb, :button_press_event) do widget, evt state = getproperty(widget,:label,AbstractString) if state == "Off" @@ -384,24 +391,24 @@ destroy(w) end @testset "LinkButton" begin -b = @LinkButton("https://github.com/JuliaLang/Gtk.jl", "Gtk.jl") -w = @Window(b, "LinkButton")|>showall +b = LinkButton("https://github.com/JuliaLang/Gtk.jl", "Gtk.jl") +w = Window(b, "LinkButton")|>showall destroy(w) end @testset "VolumeButton" begin -b = @VolumeButton(0.3) -w = @Window(b, "VolumeButton", 50, 50)|>showall +b = VolumeButton(0.3) +w = Window(b, "VolumeButton", 50, 50)|>showall destroy(w) end @testset "combobox" begin -combo = @ComboBoxText() +combo = ComboBoxText() choices = ["Strawberry", "Vanilla", "Chocolate"] for c in choices push!(combo, c) end -w = @Window(combo, "ComboBoxText")|>showall +w = Window(combo, "ComboGtkBoxText")|>showall lsl = ListStoreLeaf(combo) @test length(lsl) == 3 if libgtk_version >= v"3" @@ -410,44 +417,44 @@ if libgtk_version >= v"3" end destroy(w) -combo = @ComboBoxText(true) +combo = ComboBoxText(true) for c in choices push!(combo, c) end -w = @Window(combo, "ComboBoxText with entry")|>showall +w = Window(combo, "ComboBoxText with entry")|>showall destroy(w) end @testset "slider/scale" begin -sl = @Scale(true, 1:10) -w = @Window(sl, "Scale")|>showall +sl = Scale(true, 1:10) +w = Window(sl, "Scale")|>showall G_.value(sl, 3) @test G_.value(sl) == 3 -adj = @Adjustment(sl) +adj = Adjustment(sl) @test getproperty(adj,:value,Float64) == 3 setproperty!(adj,:upper,11) destroy(w) end @testset "spinbutton" begin -sp = @SpinButton(1:10) -w = @Window(sp, "SpinButton")|>showall +sp = SpinButton(1:10) +w = Window(sp, "SpinButton")|>showall G_.value(sp, 3) @test G_.value(sp) == 3 destroy(w) end @testset "progressbar" begin -pb = @ProgressBar() -w = @Window(pb, "Progress bar")|>showall +pb = ProgressBar() +w = Window(pb, "Progress bar")|>showall setproperty!(pb,:fraction,0.7) @test getproperty(pb,:fraction,Float64) == 0.7 destroy(w) end @testset "spinner" begin -s = @Spinner() -w = @Window(s, "Spinner")|>showall +s = Spinner() +w = Window(s, "Spinner")|>showall setproperty!(s,:active,true) @test getproperty(s,:active,Bool) == true setproperty!(s,:active,false) @@ -456,8 +463,8 @@ destroy(w) end @testset "Entry" begin -e = @Entry() -w = @Window(e, "Entry")|>showall +e = Entry() +w = Window(e, "Entry")|>showall setproperty!(e,:text,"initial") setproperty!(e,:sensitive,false) @@ -472,13 +479,13 @@ destroy(w) end @testset "Statusbar" begin -vbox = @Box(:v) -w = @Window(vbox, "Statusbar") -global sb = @Statusbar() # closures are not yet c-callable +vbox = Gtk.Box(:v) +w = Window(vbox, "Statusbar") +global sb = Statusbar() # closures are not yet c-callable push!(vbox, sb) ctxid = Gtk.context_id(sb, "Statusbar example") -bpush = @Button("push item") -bpop = @Button("pop item") +bpush = Button("push item") +bpop = Button("pop item") push!(vbox, bpush) push!(vbox, bpop) showall(w) @@ -499,8 +506,8 @@ end @testset "Canvas & AspectFrame" begin c = Canvas() -f = @AspectFrame(c, "AspectFrame", 0.5, 1, 0.5) -w = @Window(f, "Canvas")|>showall +f = AspectFrame(c, "AspectFrame", 0.5, 1, 0.5) +w = Window(f, "Canvas")|>showall c.draw = function(_) ctx = getgc(c) set_source_rgb(ctx, 1.0, 0.0, 0.0) @@ -511,39 +518,39 @@ destroy(w) end @testset "Menus" begin -file = @MenuItem("_File") -filemenu = @Menu(file) -new_ = @MenuItem("New") +file = MenuItem("_File") +filemenu = Menu(file) +new_ = MenuItem("New") idnew = signal_connect(new_, :activate) do widget println("New!") end push!(filemenu, new_) -open_ = @MenuItem("Open") +open_ = MenuItem("Open") push!(filemenu, open_) -push!(filemenu, @SeparatorMenuItem()) -quit = @MenuItem("Quit") +push!(filemenu, SeparatorMenuItem()) +quit = MenuItem("Quit") push!(filemenu, quit) -mb = @MenuBar() +mb = MenuBar() push!(mb, file) # notice this is the "File" item, not filemenu -win = @Window(mb, "Menus", 200, 40)|>showall +win = Window(mb, "Menus", 200, 40)|>showall destroy(win) end @testset "Popup menu" begin -contrast = @MenuItem("Adjust contrast...") -popupmenu = @Menu() +contrast = MenuItem("Adjust contrast...") +popupmenu = Menu() push!(popupmenu, contrast) c = Canvas() -win = @Window(c, "Popup")|>showall +win = Window(c, "Popup")|>showall showall(popupmenu) c.mouse.button3press = (widget,event) -> popup(popupmenu, event) destroy(win) end ## Text -#w = @Window("Text") +#w = Window("Text") #pack_stop_propagate(w) -#f = @Frame(w); pack(f, {:expand=>true, :fill=>"both"}) +#f = Frame(w); pack(f, {:expand=>true, :fill=>"both"}) #txt = Text(w) #scrollbars_add(f, txt) #set_value(txt, "new text\n") @@ -551,9 +558,9 @@ end #destroy(w) ## tree. Listbox -#w = @Window("Listbox") +#w = Window("Listbox") #pack_stop_propagate(w) -#f = @Frame(w); pack(f, {:expand=>true, :fill=>"both"}) +#f = Frame(w); pack(f, {:expand=>true, :fill=>"both"}) #tr = Treeview(f, choices) #scrollbars_add(f, tr) #set_value(tr, 2) @@ -563,9 +570,9 @@ end ## tree grid -#w = @Window("Array") +#w = Window("Array") #pack_stop_propagate(w) -#f = @Frame(w); pack(f, {:expand=>true, :fill=>"both"}) +#f = Frame(w); pack(f, {:expand=>true, :fill=>"both"}) #tr = Treeview(f, hcat(choices, choices)) #tree_key_header(tr, "right"); tree_key_width(tr, 50) #tree_headers(tr, ["left"], [50]) @@ -576,7 +583,7 @@ end @testset "Selectors" begin if libgtk_version >= v"3" ### should work with v >= 2.4, but there is a bug for v < 3 - dlg = @FileChooserDialog("Select file", @Null(), GtkFileChooserAction.OPEN, + dlg = FileChooserDialog("Select file", Null(), GtkFileChooserAction.OPEN, (("_Cancel", GtkResponseType.CANCEL), ("_Open", GtkResponseType.ACCEPT))) destroy(dlg) @@ -584,18 +591,18 @@ end end @testset "List view" begin -ls=@ListStore(Int32,Bool) +ls=ListStore(Int32,Bool) push!(ls,(44,true)) push!(ls,(33,true)) insert!(ls, 2, (35, false)) -tv=@TreeView(TreeModel(ls)) -r1=@CellRendererText() -r2=@CellRendererToggle() -c1=@TreeViewColumn("A", r1, Dict([("text",0)])) -c2=@TreeViewColumn("B", r2, Dict([("active",1)])) +tv=TreeView(TreeModel(ls)) +r1=CellRendererText() +r2=CellRendererToggle() +c1=TreeViewColumn("A", r1, Dict([("text",0)])) +c2=TreeViewColumn("B", r2, Dict([("active",1)])) push!(tv,c1) push!(tv,c2) -w = @Window(tv, "List View")|>showall +w = Window(tv, "List View")|>showall ## selection @@ -608,7 +615,7 @@ iter = selected(selmodel) deleteat!(ls, iter) @test isvalid(ls, iter) == false -tmSorted=@TreeModelSort(ls) +tmSorted=TreeModelSort(ls) G_.model(tv,tmSorted) G_.sort_column_id(TreeSortable(tmSorted),0,GtkSortType.ASCENDING) it = convert_child_iter_to_iter(tmSorted,Gtk.iter_from_index(ls, 1)) @@ -621,15 +628,15 @@ end @testset "Tree view" begin -ts=@TreeStore(AbstractString) +ts=TreeStore(AbstractString) iter1 = push!(ts,("one",)) iter2 = push!(ts,("two",),iter1) iter3 = push!(ts,("three",),iter2) -tv=@TreeView(TreeModel(ts)) -r1=@CellRendererText() -c1=@TreeViewColumn("A", r1, Dict([("text",0)])) +tv=TreeView(TreeModel(ts)) +r1=CellRendererText() +c1=TreeViewColumn("A", r1, Dict([("text",0)])) push!(tv,c1) -w = @Window(tv, "Tree View")|>showall +w = Window(tv, "Tree View")|>showall iter = Gtk.iter_from_index(ts, [1]) @@ -641,22 +648,22 @@ destroy(w) end @testset "Toolbar" begin -tb1 = @ToolButton("gtk-open") -tb2 = @ToolButton("gtk-new") -tb3 = @ToolButton("gtk-media-next") -toolbar = @Toolbar() +tb1 = ToolButton("gtk-open") +tb2 = ToolButton("gtk-new") +tb3 = ToolButton("gtk-media-next") +toolbar = Toolbar() push!(toolbar,tb1) unshift!(toolbar,tb2) push!(toolbar,tb3) -push!(toolbar,@SeparatorToolItem(), @ToggleToolButton("gtk-open"), @MenuToolButton("gtk-new")) +push!(toolbar,SeparatorToolItem(), ToggleToolButton("gtk-open"), MenuToolButton("gtk-new")) G_.style(toolbar,GtkToolbarStyle.BOTH) -w = @Window(toolbar, "Toolbar")|>showall +w = Window(toolbar, "Toolbar")|>showall destroy(w) end @testset "FileFilter" begin if libgtk_version >= v"3" -emptyfilter = @FileFilter() +emptyfilter = FileFilter() @test name(emptyfilter) == nothing fname = "test.csv" @@ -667,19 +674,19 @@ println("file info contains: ", csvfileinfo.contains) # Should reject anything really @test filter(emptyfilter, csvfileinfo) == false # Name is set internally as the pattern if no name is given -csvfilter1 = @FileFilter("*.csv") +csvfilter1 = FileFilter("*.csv") @test name(csvfilter1) == "*.csv" @test needed(csvfilter1) & Gtk.GtkFileFilterFlags.DISPLAY_NAME > 0 @test filter(csvfilter1, csvfileinfo) -csvfilter2 = @FileFilter("*.csv"; name="Comma Separated Format") +csvfilter2 = FileFilter("*.csv"; name="Comma Separated Format") @test name(csvfilter2) == "Comma Separated Format" @test needed(csvfilter2) & Gtk.GtkFileFilterFlags.DISPLAY_NAME > 0 @test filter(csvfilter2, csvfileinfo) -csvfilter3 = @FileFilter(; mimetype="text/csv") +csvfilter3 = FileFilter(; mimetype="text/csv") @test name(csvfilter3) == "text/csv" @test needed(csvfilter3) & Gtk.GtkFileFilterFlags.MIME_TYPE > 0 @test filter(csvfilter3, csvfileinfo) -csvfilter4 = @FileFilter(; pattern="*.csv", mimetype="text/csv") +csvfilter4 = FileFilter(; pattern="*.csv", mimetype="text/csv") # Pattern takes precedence over mime-type, causing mime-type to be ignored @test name(csvfilter4) == "*.csv" @test needed(csvfilter4) & Gtk.GtkFileFilterFlags.MIME_TYPE == 0 @@ -689,8 +696,8 @@ end # Canvas mouse callback stack operations @testset "Canvas mouse callback stack operations" begin -c = @Canvas() -w = @Window(c) +c = Canvas() +w = Window(c) showall(w) io = IOBuffer() c.mouse.button1press = (widget,evt) -> println(io, "cb1_1") @@ -721,8 +728,8 @@ destroy(w) end @testset "overlay" begin -o = @Overlay() -w = @Window(o, "overlay")|>showall +o = Overlay() +w = Window(o, "overlay")|>showall destroy(w) end @@ -732,8 +739,8 @@ end if libgtk_version >= v"3" style_file = joinpath(dirname(Base.source_path()), "style_test.css") - l = @Label "I am some large blue text!" - w = @Window(l) + l = Label("I am some large blue text!") + w = Window(l) screen = Gtk.GAccessor.screen(w) provider = CssProviderLeaf(filename=style_file) diff --git a/test/misc.jl b/test/misc.jl index 3f151b62..41d54db4 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -33,8 +33,8 @@ are expected and a sign of normal operation. @test bar4(3,5) == unhandled # Do-block syntax -c = @GtkCanvas() -win = @GtkWindow(c) +c = GtkCanvas() +win = GtkWindow(c) showall(win) @guarded draw(c) do widget error("oops") From adfb2fd541ac4e52590628d7960d359d42b0353e Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Tue, 3 Jan 2017 14:19:49 +0100 Subject: [PATCH 2/2] fix tests on Julia 0.4 --- test/gui.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/gui.jl b/test/gui.jl index 3901848a..93dcaa49 100755 --- a/test/gui.jl +++ b/test/gui.jl @@ -103,7 +103,7 @@ end @testset "Initially Hidden Canvas" begin nb = Notebook() -vbox = Gtk.Box(:v) +vbox = Gtk.GtkBox(:v) c = Canvas() push!(nb, vbox, "A") push!(nb, c, "B") @@ -153,11 +153,11 @@ end @testset "Iteration and toplevel" begin ## example of last in first covered ## Create this GUI, then shrink window with the mouse -f = Gtk.Box(:v) +f = Gtk.GtkBox(:v) w = Window(f, "Last in, first covered", 400, 400) -g1 = Gtk.Box(:h) -g2 = Gtk.Box(:h) +g1 = Gtk.GtkBox(:h) +g2 = Gtk.GtkBox(:h) push!(f,g1) push!(f,g2) @@ -239,7 +239,7 @@ end @testset "button, label" begin w = Window("Widgets") -f = Gtk.Box(:v); push!(w,f) +f = Gtk.GtkBox(:v); push!(w,f) l = Label("label"); push!(f,l) b = Button("button"); push!(f,b) @@ -299,7 +299,7 @@ end @testset "radio" begin choices = ["choice one", "choice two", "choice three", RadioButton("choice four"), Label("choice five")] w = Window("Radio") -f = Gtk.Box(:v); push!(w,f) +f = Gtk.GtkBox(:v); push!(w,f) r = Array(RadioButton,3) r[1] = RadioButton(choices[1]); push!(f,r[1]) r[2] = RadioButton(r[1],choices[2]); push!(f,r[2]) @@ -479,7 +479,7 @@ destroy(w) end @testset "Statusbar" begin -vbox = Gtk.Box(:v) +vbox = Gtk.GtkBox(:v) w = Window(vbox, "Statusbar") global sb = Statusbar() # closures are not yet c-callable push!(vbox, sb)