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

Propertymap update #76

Merged
merged 11 commits into from
Jul 2, 2020
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ authors = ["Bart Janssens <[email protected]>"]
version = "0.5.0"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Fontconfig_jll = "a3f928ae-7b40-5064-980b-68af3947d34b"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
jlqml_jll = "6b5019fb-a83d-5b4e-a9f7-678a36c28df7"

[extras]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,5 @@ This should display the result of the plotting command in the QML window.
* Signals in `JuliaSignals` must have arguments of type `var`
* Role indices are 1-based now on the Julia side
* The interface of some functions has changed because of the way CxxWrap handles references and pointers more strictly now
* No more automatic conversion from `String` to `QUrl`, use the `QUrl("mystring")` constructor
* No more automatic conversion from `String` to `QUrl`, use the `QUrl("mystring")` constructor
* Setting a `QQmlPropertyMap` as context object is not supported as of Qt 5.12
14 changes: 0 additions & 14 deletions deps/build.jl

This file was deleted.

10 changes: 0 additions & 10 deletions deps/imports.qml

This file was deleted.

36 changes: 11 additions & 25 deletions example/fizzbuzz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,37 @@ using Observables
Translation of the FizzBuzz example from http://seanchas116.github.io/ruby-qml/
"""

mutable struct FizzBuzz
result::Observable{String}
count::Observable{Int}
success::Observable{Bool}
FizzBuzz() = new(Observable(""), Observable(0), Observable(false))
end

function do_fizzbuzz(input::AbstractString, fb::FizzBuzz)
function do_fizzbuzz(input::AbstractString, fb::AbstractDict)
if isempty(input)
return
end
i = Int32(0)
outputmessage = fb["message"]
try
i = parse(Int32, input)
catch
fb.result[] = "parse error"
fb["message"][] = "parse error"
end
if i % 15 == 0
fb.result[] = "FizzBuzz"
fb.success[] = true
outputmessage[] = "FizzBuzz"
fb["success"] = true
@emit fizzBuzzFound(i)
elseif i % 3 == 0
fb.result[] = "Fizz"
outputmessage[] = "Fizz"
elseif i % 5 == 0
fb.result[] = "Buzz"
outputmessage[] = "Buzz"
else
fb.result[] = input
outputmessage[] = input
end
if fb.count[] == 2 && !fb.success[]
if fb["count"] == 2 && !fb["success"]
@emit fizzBuzzFail()
end
fb.count[] += 1
fb["count"] += 1
nothing
end

@qmlfunction do_fizzbuzz

the_fizzbuzz = FizzBuzz()

qmlfile = joinpath(dirname(Base.source_path()), "qml", "fizzbuzz.qml")
load(qmlfile, fizzbuzz=the_fizzbuzz, fizzbuzzMessage=the_fizzbuzz.result)
load(qmlfile, fizzbuzz=JuliaPropertyMap("message" => Observable(""), "count" => 0, "success" => false))
exec()

print("""
State of fizzbuzz at exit:
result: $(the_fizzbuzz.result[])
count: $(the_fizzbuzz.count[])
""")
4 changes: 1 addition & 3 deletions example/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ end

load(qmlfile,
paint_cfunction = @safe_cfunction(paint, Cvoid, (CxxPtr{QPainter}, CxxPtr{JuliaPaintedItem})),
frequency = f,
amplitude = A
)
parameters = JuliaPropertyMap("frequency" => f, "amplitude" => A))
exec()

"""
Expand Down
2 changes: 1 addition & 1 deletion example/gui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end
qml_file = joinpath(dirname(@__FILE__), "qml", "gui.qml")

# Load the QML file
load(qml_file, timer=QTimer(), oldcounter=oldcounter, bg_counter=bg_counter_slow)
load(qml_file, guiproperties = JuliaPropertyMap("timer" => QTimer(), "oldcounter" => oldcounter, "bg_counter" => bg_counter_slow))

# Run the application
exec()
Expand Down
10 changes: 6 additions & 4 deletions example/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ using QML
using Makie

const catangle = Observable(0.0)
const cat = mesh(Makie.loadasset("cat.obj"))
const cat = mesh(Makie.loadasset("cat.obj"), color = :blue)
const lastrot = Ref(0.0)

# Render function that takes a parameter t from a QML slider
function render_function(screen)
rotate!(cat, Vec3f0(0, 0, 1), catangle[]*π/180)
rotate_cam!(cat, (catangle[] - lastrot[])*π/180, 0.0, 0.0)
lastrot[] = catangle[]
display(screen, cat)
end

load(joinpath(dirname(@__FILE__), "qml", "makie.qml"),
catangle=catangle,
render_callback=@safe_cfunction(render_function, Cvoid, (Any,))
cat = JuliaPropertyMap("angle" => catangle),
render_callback = @safe_cfunction(render_function, Cvoid, (Any,))
)
exec()
2 changes: 1 addition & 1 deletion example/observable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on(output) do x
println("Output changed to ", x)
end

load(qml_file, input=input, output=output)
load(qml_file, observables = JuliaPropertyMap("input" => input, "output" => output))

if isinteractive()
exec_async()
Expand Down
21 changes: 11 additions & 10 deletions example/progressbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,21 @@ function step(sim::Simulation)
progress[] = getprogress(sim)
end

# Observables does something special to Channels, so we need to wrap it
struct ChannelSim
channel::Channel
end

# Track the simulation in a channel
function simulate_chan(c::Channel)
function simulate_chan(channel::Channel)
sim = Simulation()
while !isfinished(sim)
dostep(sim)
put!(c, getprogress(sim))
put!(channel, getprogress(sim))
end
end
function step(c::Channel)
progress[] = take!(c)
function step(cs::ChannelSim)
progress[] = take!(cs.channel)
end

# Track the simulation in a ResumableFunction
Expand All @@ -93,14 +98,13 @@ function setup(observablesim, simtype)
if simtype == :direct
observablesim[] = Simulation()
elseif simtype == :channel
observablesim[] = Channel(simulate_chan)
observablesim[] = ChannelSim(Channel(simulate_chan))
elseif simtype == :resumable
observablesim[] = simulate_resumable()
else
error("Unknown simulation type $simtype")
end
progress[] = 0.0
println("set up simulation $(simulation[])")
end

# set up initial simulation
Expand Down Expand Up @@ -131,12 +135,9 @@ end
# All arguments after qmlfile are context properties:
load(
qmlfile,
progress=progress,
timer=timer,
ticks=ticks,
simulationTypes=ListModel(first.(simulation_types)),
selectedSimType=selectedsimtype,
stepsize=stepsize)
parameters = JuliaPropertyMap("progress" => progress, "ticks" => ticks, "selectedSimType" => selectedsimtype, "stepsize" => stepsize))

exec()

Expand Down
2 changes: 1 addition & 1 deletion example/qml/fizzbuzz.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ApplicationWindow {
}
Text {
id: text
text: fizzbuzzMessage
text: fizzbuzz.message
}
Button {
text: 'Quit'
Expand Down
4 changes: 2 additions & 2 deletions example/qml/gr.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ApplicationWindow {
minimumValue: 0.1
maximumValue: 5.0
onValueChanged: {
amplitude = value;
parameters.amplitude = value;
painter.update()
}
}
Expand All @@ -46,7 +46,7 @@ ApplicationWindow {
minimumValue: 1.0
maximumValue: 50.
onValueChanged: {
frequency = value;
parameters.frequency = value;
painter.update()
}
}
Expand Down
12 changes: 6 additions & 6 deletions example/qml/gui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ApplicationWindow {
visible: true

Connections {
target: timer
onTimeout: Julia.counter_slot()
target: guiproperties.timer
function onTimeout() { Julia.counter_slot(); }
}

ColumnLayout {
Expand Down Expand Up @@ -56,24 +56,24 @@ ApplicationWindow {

Text {
Layout.alignment: Qt.AlignCenter
text: Julia.string(oldcounter, ", ", upperOut.text)
text: Julia.string(guiproperties.oldcounter, ", ", upperOut.text)
}

Button {
Layout.alignment: Qt.AlignCenter
text: "Start counting"
onClicked: timer.start()
onClicked: guiproperties.timer.start()
}

Text {
Layout.alignment: Qt.AlignCenter
text: bg_counter.toString()
text: guiproperties.bg_counter.toString()
}

Button {
Layout.alignment: Qt.AlignCenter
text: "Stop counting"
onClicked: timer.stop()
onClicked: guiproperties.timer.stop()
}
}
}
2 changes: 1 addition & 1 deletion example/qml/makie.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ApplicationWindow {
minimumValue: 0.0
maximumValue: 360.0
onValueChanged: {
catangle = value;
cat.angle = value;
viewport.update();
}
}
Expand Down
8 changes: 4 additions & 4 deletions example/qml/observable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ ApplicationWindow {
anchors.fill: parent

Slider {
value: input
value: observables.input
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
minimumValue: 0.0
maximumValue: 100.0
stepSize: 1.0
tickmarksEnabled: true
onValueChanged: {
input = value;
output = 2*input;
observables.input = value;
observables.output = 2*observables.input;
}
}

Text {
Layout.alignment: Qt.AlignCenter
text: output
text: observables.output
font.pixelSize: 0.1*root.height
}
}
Expand Down
14 changes: 7 additions & 7 deletions example/qml/progressbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ApplicationWindow {
// Set up timer connection
Connections {
target: timer
onTimeout: ticks += 1
function onTimeout() { parameters.ticks += 1; }
}

ColumnLayout {
Expand All @@ -21,28 +21,28 @@ ApplicationWindow {

ComboBox {
Layout.alignment: Qt.AlignCenter
currentIndex: selectedSimType-1
currentIndex: parameters.selectedSimType-1
model: simulationTypes
width: 300
onCurrentIndexChanged: selectedSimType = currentIndex+1
onCurrentIndexChanged: parameters.selectedSimType = currentIndex+1
}

RowLayout {
Layout.alignment: Qt.AlignCenter
Text { text: "Step size (ms)" }
Slider {
from: 0
value: stepsize
value: parameters.stepsize
stepSize: 1
to: 100
onValueChanged: stepsize = value
onValueChanged: parameters.stepsize = value
}
Text { text: stepsize }
Text { text: parameters.stepsize }
}

ProgressBar {
Layout.alignment: Qt.AlignCenter
value: progress
value: parameters.progress
}

Button {
Expand Down
Loading