Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk4 port #53

Merged
merged 14 commits into from
Aug 18, 2023
Merged
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
8 changes: 3 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['1.3', '1.6', '1', 'nightly']
version: ['1.6', '1', 'nightly']
arch: [x64, x86]
include:
- os: ubuntu-latest
prefix: xvfb-run
exclude:
- os: macOS-latest
arch: x86
- version: '1.3'
arch: x86
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-docdeploy@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
Gtk4 = "9db2cae5-386f-4011-9d63-a5602296539b"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Expand All @@ -21,13 +21,13 @@ Cairo = "1"
Colors = "0.12"
FixedPointNumbers = "0.8"
Graphics = "1"
Gtk = "1"
Gtk4 = "0.5"
IntervalSets = "0.5, 0.6, 0.7"
Observables = "0.4, 0.5"
PrecompileTools = "1"
Reexport = "0.2, 1"
RoundingIntegers = "0.2, 1"
julia = "1.3"
julia = "1.6"

[extras]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
Gtk4 = "9db2cae5-386f-4011-9d63-a5602296539b"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

Expand Down
30 changes: 12 additions & 18 deletions docs/src/controls.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# A first example: GUI controls

Let's create a `slider` object:
```jldoctest demo1

Check failure on line 4 in docs/src/controls.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/controls.md:4-12 ```jldoctest demo1 julia> using Gtk4, GtkObservables julia> sl = slider(1:11) GtkScaleLeaf with Observable(6) julia> typeof(sl) GtkObservables.Slider{Int64} ``` Subexpression: sl = slider(1:11) Evaluated output: (process:2629): Gtk-WARNING **: 22:31:04.798: Unable to acquire the address of the accessibility bus: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files. If you are attempting to run GTK without a11y support, GTK_A11Y should be set to 'none'. GtkScaleLeaf with Observable(6) Expected output: GtkScaleLeaf with Observable(6) diff = Warning: Diff output requires color. (process:2629): Gtk-WARNING **: 22:31:04.798: Unable to acquire the address of the accessibility bus: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files. If you are attempting to run GTK without a11y support, GTK_A11Y should be set to 'none'. GtkScaleLeaf with Observable(6)
julia> using Gtk.ShortNames, GtkObservables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be fixed in this PR, but we'd want a path towards resolving doc errors too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed -- it looks like we need to do some pattern matching to get them to pass. I will submit a new PR once I figure out how to do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely don't worry about that for this PR, unless you know of something that will make that really hard. One of us can tackle that later.

julia> using Gtk4, GtkObservables

julia> sl = slider(1:11)
Gtk.GtkScaleLeaf with Observable{Int64} with 1 listeners. Value:
6
GtkScaleLeaf with Observable(6)

julia> typeof(sl)
GtkObservables.Slider{Int64}
Expand All @@ -16,32 +15,28 @@
(encoding the "state" of the widget) and a `GtkWidget` (which controls
the on-screen display). We can extract both of these components:

```jldoctest demo1

Check failure on line 18 in docs/src/controls.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/controls.md:18-24 ```jldoctest demo1 julia> observable(sl) Observable(6) julia> typeof(widget(sl)) GtkScaleLeaf ``` Subexpression: observable(sl) Evaluated output: Observable(6) 0 => (::GtkObservables.var"#9#10")(val) @ GtkObservables ~/work/GtkObservables.jl/GtkObservables.jl/src/widgets.jl:54 Expected output: Observable(6) diff = Warning: Diff output requires color. Observable(6)Observable(6) 0 => (::GtkObservables.var"#9#10")(val) @ GtkObservables ~/work/GtkObservables.jl/GtkObservables.jl/src/widgets.jl:54
julia> observable(sl)
Observable{Int64} with 1 listeners. Value:
6
Observable(6)

julia> typeof(widget(sl))
Gtk.GtkScaleLeaf
GtkScaleLeaf
```
(If you omitted the `typeof`, you'd instead see a long display that encodes the settings of the `GtkScaleLeaf` widget.)

At present, this slider is not affiliated with any window. Let's
create one and add the slider to the window. We'll put it inside a
`Box` so that we can later add more things to this GUI (this
illustrates usage of some of
[Gtk's layout tools](http://juliagraphics.github.io/Gtk.jl/latest/manual/layout.html):
[Gtk's layout tools](https://juliagtk.github.io/Gtk4.jl/dev/manual/layout/):

```jldoctest demo1
julia> win = Window("Testing") |> (bx = Box(:v)); # a window containing a vertical Box for layout
julia> win = GtkWindow("Testing"); win[] = bx = GtkBox(:v); # a window containing a vertical Box for layout

julia> push!(bx, sl); # put the slider in the box, shorthand for push!(bx, widget(sl))

julia> Gtk.showall(win);
```

Because of the `showall`, you should now see a window with your slider
in it:
You should now see a window with your slider in it:

![slider1](assets/slider1.png)

Expand All @@ -50,13 +45,14 @@
right, and then see what happened to `sl`:

```@meta
sl[] = 11 # Updates the value of a Observable. See the Observables.jl docs.
DocTestSetup = quote
sl[] = 11 # Updates the value of a Observable. See the Observables.jl docs.
end
```

```jldoctest demo1
julia> sl
Gtk.GtkScaleLeaf with Observable{Int64} with 1 listeners. Value:
6
GtkScaleLeaf with Observable(11)
```

You can see that dragging the slider caused the value of the observable to
Expand All @@ -74,14 +70,12 @@
to adjust the value of that observable, by allowing the user to type a
value into a textbox:

```jldoctest demo1

Check failure on line 73 in docs/src/controls.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/controls.md:73-79 ```jldoctest demo1 julia> tb = textbox(Int; observable=observable(sl)) GtkEntryLeaf with Observable{Int64} with 2 listeners. Value: 1 julia> push!(bx, tb); ``` Subexpression: tb = textbox(Int; observable=observable(sl)) Evaluated output: GtkEntryLeaf with Observable(11) Expected output: GtkEntryLeaf with Observable{Int64} with 2 listeners. Value: 1 diff = Warning: Diff output requires color. GtkEntryLeaf with Observable{Int64} with 2 listeners. Value: 1Observable(11)
julia> tb = textbox(Int; observable=observable(sl))
Gtk.GtkEntryLeaf with Observable{Int64} with 2 listeners. Value:
GtkEntryLeaf with Observable{Int64} with 2 listeners. Value:
1

julia> push!(bx, tb);

julia> Gtk.showall(win);
```

![slider2](assets/slider2.png)
Expand Down
17 changes: 8 additions & 9 deletions docs/src/drawing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Let's begin by creating a window with a canvas in it:

```julia
using GtkObservables, Colors
using GtkObservables.Gtk
using GtkObservables.Gtk.ShortNames
using GtkObservables.Gtk4

win = Window("Drawing")
win = GtkWindow("Drawing")
c = canvas(UserUnit) # create a canvas with user-specified coordinates
push!(win, c)
```
Expand All @@ -34,7 +33,7 @@ We're going to set this up so that a new line is started when the user
clicks with the left mouse button; when the user releases the mouse
button, the line is finished and added to a list of previously-drawn
lines. Consequently, we need a place to store user data. We'll use
Signals, so that our Canvas will be notified when there is new
Observables, so that our Canvas will be notified when there is new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

material to draw:

```julia
Expand Down Expand Up @@ -116,9 +115,9 @@ by monitoring `lines` from the command line by clicking, dragging, and
releasing.

However, it's much more fun to see it in action. Let's set up a
[`draw`](http://juliagraphics.github.io/Gtk.jl/latest/manual/canvas.html)
[`draw`](http://juliagtk.github.io/Gtk4.jl/dev/manual/canvas.html)
method for the canvas, which will be called (1) whenever the window
resizes (this is arranged by Gtk.jl), or (2) whenever `lines` or
resizes (this is arranged by Gtk4.jl), or (2) whenever `lines` or
`newline` update (because we supply them as arguments to the `draw`
function):

Expand All @@ -127,7 +126,7 @@ function):
redraw = draw(c, lines, newline) do cnvs, lns, newl # the function body takes 3 arguments
fill!(cnvs, colorant"white") # set the background to white
set_coordinates(cnvs, BoundingBox(0, 1, 0, 1)) # set coordinates to 0..1 along each axis
ctx = Gtk.getgc(cnvs) # gets the "graphics context" object (see Cairo/Gtk)
ctx = Gtk4.getgc(cnvs) # gets the "graphics context" object (see Cairo/Gtk)
for l in lns
drawline(ctx, l, colorant"blue") # draw old lines in blue
end
Expand All @@ -148,13 +147,13 @@ end
```

**Important note:** Only modify the canvas inside the `draw` function, and pass
all observables that you want to consume as additional arguments (the example shows
all observables that you want to consume as additional arguments (the example shows
three, but you may pass as few or as many as you wish). Otherwise, you
may find the rendering behaves unexpectedly.

A lot of these commands come from Cairo.jl and/or Graphics.jl.

Our application is done! (But don't forget to `showall(win)`.) Here's a
Our application is done! Here's a
picture of me in the middle of a very fancy drawing:

![drawing](assets/drawing.png)
Expand Down
24 changes: 12 additions & 12 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Scope of this package

GtkObservables is a package building on the functionality of
[Gtk.jl](https://github.com/JuliaGraphics/Gtk.jl) and
[Gtk4.jl](https://github.com/JuliaGtk/Gtk4.jl) and
[Observables.jl](https://github.com/JuliaGizmos/Observables.jl). Its main
purpose is to simplify the handling of interactions among components
of a graphical user interface (GUI).
Expand All @@ -17,24 +17,24 @@ Creating a GUI generally involves some or all of the following:
5. (for graphical applications) canvas interaction (mouse clicks, drags, etc.)

GtkObservables is targeted primarily at items 1, 3, and 5. Layout is
handled by Gtk.jl, and drawing (with a couple of exceptions) is
handled by Gtk4.jl, and drawing (with a couple of exceptions) is
handled by plotting packages or at a lower level by
[Cairo](https://github.com/JuliaGraphics/Cairo.jl).

GtkObservables is suitable for:

- "quick and dirty" applications which you might create from the command line
- more sophisticated GUIs where layout is specified using tools like [Glade](https://glade.gnome.org/)
- more sophisticated GUIs where layout is specified using tools like GtkBuilder XML.

For usage with Glade, the [Input widgets](@ref) and
For usage with GtkBuilder XML, the [Input widgets](@ref) and
[Output widgets](@ref) defined by this package allow you to supply a
preexisting `widget` (which you might load with GtkBuilder) rather
than creating one from scratch. Users interested in using GtkObservables
with Glade are encouraged to see how the [`player`](@ref) widget is
this way are encouraged to see how the [`player`](@ref) widget is
constructed (see `src/extrawidgets.jl`).

At present, GtkObservables supports only a small subset of the
[widgets provided by Gtk](https://developer.gnome.org/gtk3/stable/ch03.html). It
[widgets provided by Gtk4](https://docs.gtk.org/gtk4/#classes). It
is fairly straightforward to add new ones, and pull requests would be
welcome.

Expand All @@ -44,24 +44,24 @@ The central concept of Observables.jl is the `Observable`, a type that allows
updating with new values that then triggers actions that may update
other `Observable`s or execute functions. Your GUI ends up being
represented as a "graph" of Observables that collectively propagate the
state of your GUI. GtkObservables couples `Observable`s to Gtk.jl's
state of your GUI. GtkObservables couples `Observable`s to Gtk4.jl's
widgets. In essence, Observables.jl allows ordinary Julia objects to
become the triggers for callback actions; the primary advantage of
using Julia objects, rather than Gtk widgets, as the "application
using Julia objects, rather than Gtk4 widgets, as the "application
logic" triggers is that it simplifies reasoning about the GUI and
seems to reduce the number of times ones needs to consult the
[Gtk documentation](https://developer.gnome.org/gtk3/stable/gtkobjects.html).
[Gtk documentation](https://docs.gtk.org/gtk4).

Please see the [Observables.jl documentation](https://juliagizmos.github.io/Observables.jl/stable/) for more information.

## Important note: The UI thread

Changes to the UI can only be performed safely if the code is run in the same
thread that the Gtk main loop is running on. `Observable` handlers may run
thread that the Gtk4 main loop is running on. `Observable` handlers may run
on a different thread. If a UI update operation occurs on a different thread,
the process (Julia) can crash. The solution is to wrap the offending code block
with `Gtk.@idle_add`, which requests Gtk to run the code block on the UI thread
when the CPU is idle. However, this also means that code inside the block will
with `Gtk4.GLib.@idle_add`, which requests Gtk4 to run the code block on the UI thread
when the main loop is idle. However, this also means that code inside the block will
not run synchronously with code outside it.
```julia
on(myobs) do val
Expand Down
7 changes: 2 additions & 5 deletions docs/src/zoom_pan.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
To illustrate these tools, let's first open a window with a drawing canvas:

```jldoctest demozoom
julia> using Gtk.ShortNames, GtkObservables, TestImages
julia> using Gtk4, GtkObservables, TestImages

julia> win = Window("Image");
julia> win = GtkWindow("Image");

julia> c = canvas(UserUnit);

Expand All @@ -33,7 +33,7 @@

Zoom and pan interactions all work through a [`ZoomRegion`](@ref) observable; let's
create one for this image:
```jldoctest demozoom

Check failure on line 36 in docs/src/zoom_pan.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/zoom_pan.md:36-40 ```jldoctest demozoom julia> zr = Observable(ZoomRegion(image)) Observable{ZoomRegion{RoundingIntegers.RInt64}} with 0 listeners. Value: ZoomRegion{RoundingIntegers.RInt64}(XY(1..768, 1..512), XY(1..768, 1..512)) ``` Subexpression: zr = Observable(ZoomRegion(image)) Evaluated output: Observable(ZoomRegion{RoundingIntegers.RInt64}(XY(1 .. 768, 1 .. 512), XY(1 .. 768, 1 .. 512))) Expected output: Observable{ZoomRegion{RoundingIntegers.RInt64}} with 0 listeners. Value: ZoomRegion{RoundingIntegers.RInt64}(XY(1..768, 1..512), XY(1..768, 1..512)) diff = Warning: Diff output requires color. Observable{ZoomRegion{RoundingIntegers.RInt64}} with 0 listeners. Value: ZoomRegion{RoundingIntegers.RInt64}(XY(1..768, 1..512), XY(1..768, 1..512))Observable(ZoomRegion{RoundingIntegers.RInt64}(XY(1 .. 768, 1 .. 512), XY(1 .. 768, 1 .. 512)))
julia> zr = Observable(ZoomRegion(image))
Observable{ZoomRegion{RoundingIntegers.RInt64}} with 0 listeners. Value:
ZoomRegion{RoundingIntegers.RInt64}(XY(1..768, 1..512), XY(1..768, 1..512))
Expand All @@ -55,7 +55,7 @@
time `zr` is modified. We then define a `draw` method for the canvas
that paints this selection to the canvas:

```jldoctest demozoom

Check failure on line 58 in docs/src/zoom_pan.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/zoom_pan.md:58-72 ```jldoctest demozoom julia> redraw = draw(c, imgroi, zr) do cnvs, img, r # Copy the pixel data to the canvas. Because `img` is the value of `imgroi`, # this will only copy the region that was selected by the `view` call above. copy!(cnvs, img) # Here we set the coordinates of the canvas to correspond # to the selected region of the image. This ensures that # every point on the canvas has coordinates that correspond # to the same position in the image. set_coordinates(cnvs, r) end 2-element Vector{Observables.ObserverFunction}: (::Observables.ObserverFunction) (generic function with 0 methods) (::Observables.ObserverFunction) (generic function with 0 methods) ``` Subexpression: redraw = draw(c, imgroi, zr) do cnvs, img, r # Copy the pixel data to the canvas. Because `img` is the value of `imgroi`, # this will only copy the region that was selected by the `view` call above. copy!(cnvs, img) # Here we set the coordinates of the canvas to correspond # to the selected region of the image. This ensures that # every point on the canvas has coordinates that correspond # to the same position in the image. set_coordinates(cnvs, r) end Evaluated output: 2-element Vector{ObserverFunction}: ObserverFunction defined at /home/runner/.julia/packages/Observables/PHGQ8/src/Observables.jl:414 operating on Observable(RGB{N0f8}[RGB{N0f8}(0.361,0.486,0.6) RGB{N0f8}(0.349,0.475,0.588) … RGB{N0f8}(0.345,0.482,0.525) RGB{N0f8}(0.349,0.49,0.529); RGB{N0f8}(0.361,0.486,0.6) RGB{N0f8}(0.361,0.498,0.608) … RGB{N0f8}(0.349,0.482,0.565) RGB{N0f8}(0.369,0.498,0.58); … ; RGB{N0f8}(0.443,0.467,0.439) RGB{N0f8}(0.443,0.467,0.439) … RGB{N0f8}(0.165,0.192,0.2) RGB{N0f8}(0.18,0.208,0.22); RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.0,0.0) … RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.0,0.0)]) ObserverFunction defined at /home/runner/.julia/packages/Observables/PHGQ8/src/Observables.jl:414 operating on Observable(ZoomRegion{RInt64}(XY(1 .. 768, 1 .. 512), XY(1 .. 768, 1 .. 512))) Expected output: 2-element Vector{Observables.ObserverFunction}: (::Observables.ObserverFunction) (generic function with 0 methods) (::Observables.ObserverFunction) (generic function with 0 methods) diff = Warning: Diff output requires color. 2-element Vector{Observables.ObserverFunction}: (::Observables.ObserverFunction) (generic function with 0 methods) (::Observables.ObserverFunction) (generic function with 0 methods)Vector{ObserverFunction}: ObserverFunction defined at /home/runner/.julia/packages/Observables/PHGQ8/src/Observables.jl:414 operating on Observable(RGB{N0f8}[RGB{N0f8}(0.361,0.486,0.6) RGB{N0f8}(0.349,0.475,0.588) … RGB{N0f8}(0.345,0.482,0.525) RGB{N0f8}(0.349,0.49,0.529); RGB{N0f8}(0.361,0.486,0.6) RGB{N0f8}(0.361,0.498,0.608) … RGB{N0f8}(0.349,0.482,0.565) RGB{N0f8}(0.369,0.498,0.58); … ; RGB{N0f8}(0.443,0.467,0.439) RGB{N0f8}(0.443,0.467,0.439) … RGB{N0f8}(0.165,0.192,0.2) RGB{N0f8}(0.18,0.208,0.22); RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.0,0.0) … RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.0,0.0)]) ObserverFunction defined at /home/runner/.julia/packages/Observables/PHGQ8/src/Observables.jl:414 operating on Observable(ZoomRegion{RInt64}(XY(1 .. 768, 1 .. 512), XY(1 .. 768, 1 .. 512)))
julia> redraw = draw(c, imgroi, zr) do cnvs, img, r
# Copy the pixel data to the canvas. Because `img` is the value of `imgroi`,
# this will only copy the region that was selected by the `view` call above.
Expand All @@ -77,9 +77,6 @@
`zr` update).

Now, let's see our image:
```jldoctest demozoom
julia> Gtk.showall(win);
```

![image1](assets/image1.png)

Expand All @@ -94,7 +91,7 @@
More useful is to couple `zr` to mouse actions. Let's turn on both
zooming (with [`init_zoom_rubberband`](@ref)) and panning (with [`init_pan_drag`](@ref)):

```jldoctest demozoom; filter=r"#\d+"

Check failure on line 94 in docs/src/zoom_pan.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/zoom_pan.md:94-110 ```jldoctest demozoom; filter=r"#\d+" julia> rb = init_zoom_rubberband(c, zr) Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#179, Observable{MouseButton{UserUnit}} with 1 … "init" => ObserverFunction(#178, Observable{MouseButton{UserUnit}} with 1 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#180, Observable{MouseButton{UserUnit}} with 1 … "enabled" => Observable{Bool} with 0 listeners. Value:… julia> pandrag = init_pan_drag(c, zr) Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#169, Observable{MouseButton{UserUnit}} with 2 … "init" => ObserverFunction(#168, Observable{MouseButton{UserUnit}} with 2 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#170, Observable{MouseButton{UserUnit}} with 2 … "enabled" => Observable{Bool} with 0 listeners. Value:… ``` Subexpression: rb = init_zoom_rubberband(c, zr) Evaluated output: Dict{String, Any} with 5 entries: "drag" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "init" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "active" => Observable(false) "finish" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "enabled" => Observable(true) Expected output: Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#179, Observable{MouseButton{UserUnit}} with 1 … "init" => ObserverFunction(#178, Observable{MouseButton{UserUnit}} with 1 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#180, Observable{MouseButton{UserUnit}} with 1 … "enabled" => Observable{Bool} with 0 listeners. Value:… diff = Warning: Diff output requires color. Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#179, Observable{MouseButton{UserUnit}} with 1 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "init" => ObserverFunction(#178, Observable{MouseButton{UserUnit}} with 1 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "active" => Observable{Bool} with 0 listeners. Value:… Observable(false) "finish" => ObserverFunction(#180, Observable{MouseButton{UserUnit}} with 1 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "enabled" => Observable{Bool} with 0 listeners. Value:…Observable(true)

Check failure on line 94 in docs/src/zoom_pan.md

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/zoom_pan.md:94-110 ```jldoctest demozoom; filter=r"#\d+" julia> rb = init_zoom_rubberband(c, zr) Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#179, Observable{MouseButton{UserUnit}} with 1 … "init" => ObserverFunction(#178, Observable{MouseButton{UserUnit}} with 1 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#180, Observable{MouseButton{UserUnit}} with 1 … "enabled" => Observable{Bool} with 0 listeners. Value:… julia> pandrag = init_pan_drag(c, zr) Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#169, Observable{MouseButton{UserUnit}} with 2 … "init" => ObserverFunction(#168, Observable{MouseButton{UserUnit}} with 2 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#170, Observable{MouseButton{UserUnit}} with 2 … "enabled" => Observable{Bool} with 0 listeners. Value:… ``` Subexpression: pandrag = init_pan_drag(c, zr) Evaluated output: Dict{String, Any} with 5 entries: "drag" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "init" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "active" => Observable(false) "finish" => ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "enabled" => Observable(true) Expected output: Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#169, Observable{MouseButton{UserUnit}} with 2 … "init" => ObserverFunction(#168, Observable{MouseButton{UserUnit}} with 2 … "active" => Observable{Bool} with 0 listeners. Value:… "finish" => ObserverFunction(#170, Observable{MouseButton{UserUnit}} with 2 … "enabled" => Observable{Bool} with 0 listeners. Value:… diff = Warning: Diff output requires color. Dict{String, Any} with 5 entries: "drag" => ObserverFunction(#169, Observable{MouseButton{UserUnit}} with 2 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "init" => ObserverFunction(#168, Observable{MouseButton{UserUnit}} with 2 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "active" => Observable{Bool} with 0 listeners. Value:… Observable(false) "finish" => ObserverFunction(#170, Observable{MouseButton{UserUnit}} with 2 … ObserverFunction defined at /home/runner/work/GtkObservables.jl/… "enabled" => Observable{Bool} with 0 listeners. Value:…Observable(true)
julia> rb = init_zoom_rubberband(c, zr)
Dict{String, Any} with 5 entries:
"drag" => ObserverFunction(#179, Observable{MouseButton{UserUnit}} with 1 …
Expand Down
6 changes: 2 additions & 4 deletions examples/drawing.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gtk.ShortNames, GtkObservables, Graphics, Colors
using Gtk4, GtkObservables, Colors, Observables

win = Window("Drawing")
win = GtkWindow("Drawing")
c = canvas(UserUnit) # create a canvas with user-specified coordinates
push!(win, c)

Expand Down Expand Up @@ -55,5 +55,3 @@ function drawline(ctx, l, color)
end
stroke(ctx)
end

Gtk.showall(win)
7 changes: 2 additions & 5 deletions examples/imageviewer.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using TestImages, GtkObservables, Gtk.ShortNames
using TestImages, GtkObservables, Gtk4

img = testimage("lighthouse")

## Build the GUI (just a Window with a Canvas in it)
# UserUnit: we'll use the indices of the image as canvas coordinates
# This makes it easy to relate the position of mouse-clicks to the image
c = canvas(UserUnit)
win = Window(c)
win = GtkWindow(c)

## Region-of-interest selection
zr = Observable(ZoomRegion(img))
Expand All @@ -33,6 +33,3 @@ redraw = draw(c, imgroi) do cnvs, image
# zoom in further, we select the correct region.
set_coordinates(cnvs, zr[])
end

## Don't forget this!
Gtk.showall(win)
16 changes: 7 additions & 9 deletions examples/widgets.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GtkObservables, Gtk.ShortNames, Colors
using GtkObservables, Gtk4, Colors

# Create some controls
n = slider(1:10)
Expand All @@ -17,22 +17,23 @@ cbhandle = on(dd.mappedsignal) do cb # assign to variable to prevent garbage co
cb()
end

# Lay out the GUI. You can alternatively use `glade` and pass the
# Lay out the GUI. You can alternatively use `GtkBuilder` XML and pass the
# widgets to the constructors above (see the implementation of
# `player` in `extrawidgets.jl` for an example).
mainwin = Window("GtkObservables")
vbox = Box(:v)
hbox = Box(:h)
mainwin = GtkWindow("GtkObservables", 300, 200)
vbox = GtkBox(:v)
hbox = GtkBox(:h)
push!(vbox, hbox)
push!(hbox, n)
push!(hbox, tb)
push!(vbox, dd)
push!(vbox, cb)
push!(mainwin, vbox)
show(mainwin)

# Create the auxillary window and link its visibility to the checkbox
cnvs = canvas()
auxwin = Window(cnvs)
auxwin = GtkWindow(cnvs)
showwin = map(cb) do val
set_gtk_property!(auxwin, "visible", val)
end
Expand All @@ -44,6 +45,3 @@ end
draw(cnvs) do c
fill!(c, colorant"orange")
end
Gtk.showall(auxwin)

Gtk.showall(mainwin)
Loading
Loading