Skip to content

Commit 530da45

Browse files
authored
add more tests, fix links in docs (#616)
* add misc. tests, fix links in docs fix GtkBuilder iteration, a GtkStatusbar method, and gtk_init_with_args argument type * test that GError throws
1 parent ca39439 commit 530da45

File tree

8 files changed

+119
-18
lines changed

8 files changed

+119
-18
lines changed

docs/src/doc/more_signals.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where:
1616
(i.e., one defined as `function foo(x,y,z) ... end`), and the
1717
arguments and return type should match the GTK+ documentation for
1818
the widget and signal ([see
19-
examples](https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-accel-closures-changed)).
19+
examples](https://docs.gtk.org/gtk3/signal.Widget.accel-closures-changed.html)).
2020
**In contrast with the simpler
2121
interface, when writing these
2222
callbacks you must include the `user_data` argument**. See examples below.
@@ -27,9 +27,9 @@ where:
2727
callback. Usually `Nothing` (for `void`) or `Cint` (for `gboolean`)
2828
- `parameter_type_tuple` specifies the types of the *middle* arguments
2929
to the callback function, omitting the first (the widget) and last
30-
(`user_data`). For example, for [`"clicked"`](https://developer.gnome.org/gtk3/stable/GtkButton.html#GtkButton-clicked) we have
30+
(`user_data`). For example, for [`"clicked"`](https://docs.gtk.org/gtk3/method.Button.clicked.html) we have
3131
`parameter_type_tuple = ()` (because there are no middle arguments)
32-
and for [`"button-press-event"`](https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-button-press-event) we have `parameter_type_tuple =
32+
and for [`"button-press-event"`](https://docs.gtk.org/gtk3/signal.Widget.button-press-event.html) we have `parameter_type_tuple =
3333
(Ptr{GdkEventButton},)`.
3434
- `after` is a boolean, `true` if you want your callback to run after
3535
the default handler for your signal. When in doubt, specify `false`.

docs/src/manual/signals.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ julia> GtkButton(action-name=NULL, action-target, related-action, use-action-app
5151
"Press me" was clicked!
5252
```
5353
Notice that _both_ of the callback functions executed!
54-
Gtk+ allows you to define multiple signal handlers for a given object; even the execution order can be [specified](https://developer.gnome.org/gobject/stable/gobject-Signals.html#gobject-Signals.description).
55-
Callbacks for some [signals](https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-accel-closures-changed) require that you return an `Int32`, with value 0 if you want the next handler to run or 1 if you want to prevent any other handlers from running on this event.
54+
Gtk+ allows you to define multiple signal handlers for a given object; even the execution order can be [specified](https://docs.gtk.org/gobject/concepts.html#signals).
55+
Callbacks for some [signals](https://docs.gtk.org/gtk3/signal.Widget.accel-closures-changed.html) require that you return an `Int32`, with value 0 if you want the next handler to run or 1 if you want to prevent any other handlers from running on this event.
5656

57-
The [`"clicked"` signal callback](https://developer.gnome.org/gtk3/stable/GtkButton.html#GtkButton-clicked) should return `nothing` (`void` in C parlance), so you can't prevent other callbacks from running.
57+
The [`"clicked"` signal callback](https://docs.gtk.org/gtk3/method.Button.clicked.html) should return `nothing` (`void` in C parlance), so you can't prevent other callbacks from running.
5858
However, we can disconnect the first signal handler:
5959
```julia
6060
signal_handler_disconnect(b, id)
@@ -75,7 +75,7 @@ id = signal_connect(b, "button-press-event") do widget, event
7575
end
7676
```
7777
Note that this signal requires two arguments, here `widget` and `event`, and that `event` contained useful information.
78-
Arguments and their meaning are described along with their corresponding [signals](https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-accel-closures-changed).
78+
Arguments and their meaning are described along with their corresponding [signals](https://docs.gtk.org/gtk3/signal.Widget.accel-closures-changed.html).
7979
**You should omit the final `user_data` argument described in the Gtk documentation**;
8080
keep in mind that you can always address other variables from inside your function block, or define the callback in terms of an anonymous function:
8181
```julia

docs/src/manual/textwidgets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ GAccessor.markup(label,"""<b>My bold text</b>\n
2222
<a href=\"https://www.gtk.org\"
2323
title=\"Our website\">GTK+ website</a>""")
2424
```
25-
The syntax for this markup text is borrowed from html and explained [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html).
25+
The syntax for this markup text is borrowed from html and explained [here](https://docs.gtk.org/Pango/pango_markup.html).
2626

2727
A label can be made selectable using
2828
```julia

src/Gtk.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function __init__()
155155

156156
GError() do error_check
157157
ccall((:gtk_init_with_args, libgtk), Bool,
158-
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}),
158+
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Ptr{GError}}),
159159
C_NULL, C_NULL, "Julia Gtk Bindings", C_NULL, C_NULL, error_check)
160160
end
161161

src/builder.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function push!(builder::GtkBuilder; buffer = nothing, filename = nothing, resour
3535
end
3636

3737
start_(builder::GtkBuilder) = glist_iter(ccall((:gtk_builder_get_objects, libgtk), Ptr{_GSList{GObject}}, (Ptr{GObject},), builder))
38-
iterate(w::GtkBuilder, list=start_(builder)) =
38+
iterate(builder::GtkBuilder, list=start_(builder)) =
3939
iterate(list[1], list)
4040

4141

src/displays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ slice!(status::GtkStatusbar, context, message_id) =
306306
ccall((:gtk_statusbar_remove, libgtk), Ptr{GObject}, (Ptr{GObject}, Cuint, Cuint),
307307
status, context_id(status, context), message_id)
308308
empty!(status::GtkStatusbar, context) =
309-
ccall((:gtk_statusbar_remove_all, libgtk), Ptr{GObject}, (Ptr{GObject}, Cuint, Cuint),
310-
status, context_id(status, context), context_id(context))
309+
ccall((:gtk_statusbar_remove_all, libgtk), Ptr{GObject}, (Ptr{GObject}, Cuint),
310+
status, context_id(status, context))
311311

312312
#GtkInfoBarLeaf() = GtkInfoBarLeaf(ccall((:gtk_info_bar_new, libgtk), Ptr{GObject}, ())
313313

test/gui.jl

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ mutable struct MyWindow <: Window
4848
end
4949
end
5050

51+
# For testing callbacks
52+
click(b::Button) = ccall((:gtk_button_clicked,Gtk.libgtk),Nothing,(Ptr{Gtk.GObject},),b)
53+
5154
@testset "gui" begin
5255

5356
wdth, hght = screen_size()
@@ -85,6 +88,9 @@ visible(w,false)
8588
visible(w,true)
8689
@test visible(w) == true
8790

91+
gw = Gtk.gdk_window(w)
92+
ox, oy = Gtk.get_origin(gw)
93+
8894
hide(w)
8995
show(w)
9096
grab_focus(w)
@@ -292,8 +298,6 @@ id = signal_connect(b, "clicked") do widget
292298
counter::Int += 1
293299
end
294300
@test signal_handler_is_connected(b, id)
295-
# For testing callbacks
296-
click(b::Button) = ccall((:gtk_button_clicked,Gtk.libgtk),Nothing,(Ptr{Gtk.GObject},),b)
297301

298302
@test counter == 0
299303
click(b)
@@ -320,12 +324,31 @@ pb=Pixbuf(data=icon, has_alpha=false)
320324
@test size(pb) == (40, 20)
321325
@test pb[1,1].g==0xff
322326
pb[10,10]=Gtk.RGB(0,0,0)
323-
b = Button(Image(pb))
324-
w = Window(b, "Icon button", 60, 40)
327+
pb[20:30,1:5]=Gtk.RGB(0xff,0,0)
328+
w = Window(Button(Image(pb)), "Icon button", 60, 40)
325329
showall(w)
330+
pb2=copy(pb)
331+
@test size(pb2,2) == size(pb)[2]
332+
pb3=Gtk.slice(pb2,11:20,11:20)
333+
@test size(pb3) == (10,10)
326334
destroy(w)
327335
end
328336

337+
@testset "Transparent pixbuf" begin
338+
icon = Matrix{Gtk.RGBA}(undef, 40, 20)
339+
fill!(icon, Gtk.RGBA(0,0xff,0, 0xff))
340+
icon[5:end-5, 3:end-3] .= Ref(Gtk.RGBA(0,0,0xff,0x80))
341+
pb=Pixbuf(data=icon, has_alpha=true)
342+
@test eltype(pb) == Gtk.RGBA
343+
end
344+
345+
@testset "Icon theme" begin
346+
img = Image(; icon_name = "document-open", size=:BUTTON)
347+
icon_theme = Gtk.icon_theme_get_default()
348+
pb=Gtk.icon_theme_load_icon_for_scale(icon_theme, "document-open", 60, 60, Gtk.GConstants.GtkIconLookupFlags.GTK_ICON_LOOKUP_NO_SVG)
349+
@test isa(pb,GdkPixbuf)
350+
end
351+
329352
@testset "checkbox" begin
330353
w = Window("Checkbutton")
331354
check = CheckButton("check me"); push!(w,check)
@@ -475,6 +498,9 @@ combo = ComboBoxText(true)
475498
for c in choices
476499
push!(combo, c)
477500
end
501+
pushfirst!(combo, "Rocky road")
502+
insert!(combo, 3, "Pistachio")
503+
delete!(combo, 3)
478504
w = Window(combo, "ComboBoxText with entry")|>showall
479505
destroy(w)
480506
end
@@ -503,16 +529,18 @@ pb = ProgressBar()
503529
w = Window(pb, "Progress bar")|>showall
504530
set_gtk_property!(pb,:fraction,0.7)
505531
@test get_gtk_property(pb,:fraction,Float64) == 0.7
532+
pulse(pb)
506533
destroy(w)
507534
end
508535

509536
@testset "spinner" begin
510537
s = Spinner()
511538
w = Window(s, "Spinner")|>showall
512-
set_gtk_property!(s,:active,true)
539+
start(s)
513540
@test get_gtk_property(s,:active,Bool) == true
514-
set_gtk_property!(s,:active,false)
541+
stop(s)
515542
@test get_gtk_property(s,:active,Bool) == false
543+
516544
destroy(w)
517545
end
518546

@@ -555,6 +583,10 @@ function cb_sbpop(ptr,evt,id)
555583
end
556584
on_signal_button_press(cb_sbpush, bpush, false, ctxid)
557585
on_signal_button_press(cb_sbpop, bpop, false, ctxid)
586+
587+
click(bpush)
588+
click(bpop)
589+
empty!(sb,ctxid)
558590
destroy(w)
559591
end
560592

@@ -698,6 +730,7 @@ select!(selmodel, it)
698730
iter = selected(selmodel)
699731
@test TreeModel(tmSorted)[iter, 1] == 35
700732

733+
empty!(ls)
701734

702735
destroy(w)
703736
end
@@ -835,6 +868,17 @@ end
835868
destroy(w)
836869
end
837870

871+
@testset "Builder" begin
872+
b=Builder(;filename="test.glade")
873+
widgets = [w for w in b]
874+
@test length(widgets)==length(b)
875+
button = b["a_button"]
876+
@test isa(button,Button)
877+
@test isa(b[1],Gtk.GtkWidget)
878+
879+
@test_throws ErrorException b2 = Builder(;filename="test2.glade")
880+
end
881+
838882
@testset "Subtyping from GObject" begin
839883

840884
w = MyWindow()

test/test.glade

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Generated with glade 3.38.2 -->
3+
<interface>
4+
<requires lib="gtk+" version="3.24"/>
5+
<object class="GtkAdjustment" id="adjustment1">
6+
<property name="upper">100</property>
7+
<property name="step-increment">1</property>
8+
<property name="page-increment">10</property>
9+
</object>
10+
<object class="GtkWindow">
11+
<property name="can-focus">False</property>
12+
<child>
13+
<object class="GtkBox">
14+
<property name="visible">True</property>
15+
<property name="can-focus">False</property>
16+
<property name="orientation">vertical</property>
17+
<child>
18+
<object class="GtkButton" id="a_button">
19+
<property name="label" translatable="yes">Text</property>
20+
<property name="visible">True</property>
21+
<property name="can-focus">True</property>
22+
<property name="receives-default">True</property>
23+
</object>
24+
<packing>
25+
<property name="expand">False</property>
26+
<property name="fill">True</property>
27+
<property name="position">0</property>
28+
</packing>
29+
</child>
30+
<child>
31+
<object class="GtkEntry" id="an_entry">
32+
<property name="visible">True</property>
33+
<property name="can-focus">True</property>
34+
</object>
35+
<packing>
36+
<property name="expand">False</property>
37+
<property name="fill">True</property>
38+
<property name="position">1</property>
39+
</packing>
40+
</child>
41+
<child>
42+
<object class="GtkScale" id="a_scale">
43+
<property name="visible">True</property>
44+
<property name="can-focus">True</property>
45+
<property name="adjustment">adjustment1</property>
46+
<property name="round-digits">1</property>
47+
</object>
48+
<packing>
49+
<property name="expand">False</property>
50+
<property name="fill">True</property>
51+
<property name="position">2</property>
52+
</packing>
53+
</child>
54+
</object>
55+
</child>
56+
</object>
57+
</interface>

0 commit comments

Comments
 (0)