Skip to content

Commit

Permalink
Deprecate FileIO use
Browse files Browse the repository at this point in the history
Fixes issue #110
  • Loading branch information
barche committed Apr 5, 2021
1 parent 0f03c09 commit 52f8e67
Show file tree
Hide file tree
Showing 35 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jlqml_jll = "6b5019fb-a83d-5b4e-a9f7-678a36c28df7"
[compat]
ColorTypes = "0.10"
CxxWrap = "0.11"
FileIO = "1.3"
FileIO = "~1.3"
MacroTools = "0.5"
Observables = "0.3"
Requires = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion example/board.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cols = 3
qml_file = joinpath(dirname(@__FILE__), "qml", "board.qml")

# create the app, with cols and emojiModel exposed as QML context properties
load(qml_file,cols=cols,emojiModel=emojiModel)
loadqml(qml_file,cols=cols,emojiModel=emojiModel)

# Start the GUI
exec()
Expand Down
2 changes: 1 addition & 1 deletion example/canvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function paint_circle(buffer)
return
end

load(qmlfile,
loadqml(qmlfile,
parameters=JuliaPropertyMap("diameter" => diameter),
paint_cfunction = CxxWrap.@safe_cfunction(paint_circle, Cvoid,
(Array{UInt32,1}, Int32, Int32)))
Expand Down
2 changes: 1 addition & 1 deletion example/canvas_alpha.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function paint_square(buffer::Array{UInt32, 1}, width32::Int32, height32::Int32)
return
end

load(qmlfile,
loadqml(qmlfile,
parameters=JuliaPropertyMap("diameter" => diameter, "alpha" => alpha),
circle_cfunction = CxxWrap.@safe_cfunction(paint_circle, Cvoid, (Array{UInt32,1}, Int32, Int32)),
square_cfunction = CxxWrap.@safe_cfunction(paint_square, Cvoid, (Array{UInt32,1}, Int32, Int32)))
Expand Down
2 changes: 1 addition & 1 deletion example/canvas_and_gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ onany(amplitude, frequency, invert_sin, diameter) do amp, freq, inv, dia
end
end

load(qmlfile,
loadqml(qmlfile,
parameters = JuliaPropertyMap(
"invert_sin" => invert_sin,
"amplitude" => amplitude,
Expand Down
2 changes: 1 addition & 1 deletion example/canvas_twice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function paint_square(buffer::Array{UInt32, 1}, width32::Int32, height32::Int32)
return
end

load(qmlfile,
loadqml(qmlfile,
parameters=JuliaPropertyMap("diameter" => diameter, "side" => side),
circle_cfunction = CxxWrap.@safe_cfunction(paint_circle, Cvoid, (Array{UInt32,1}, Int32, Int32)),
square_cfunction = CxxWrap.@safe_cfunction(paint_square, Cvoid, (Array{UInt32,1}, Int32, Int32)))
Expand Down
2 changes: 1 addition & 1 deletion example/checkboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end

@qmlfunction plot_diagram

load(joinpath(dirname(Base.source_path()), "qml", "checkboxes.qml"))
loadqml(joinpath(dirname(Base.source_path()), "qml", "checkboxes.qml"))
exec()

return
2 changes: 1 addition & 1 deletion example/colors.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using QML

load(joinpath(dirname(Base.source_path()), "qml", "tutorial.qml"))
loadqml(joinpath(dirname(Base.source_path()), "qml", "tutorial.qml"))
exec()

return
Expand Down
2 changes: 1 addition & 1 deletion example/drag.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using QML

@qmlfunction println
load(joinpath(dirname(@__FILE__), "qml", "drag.qml"))
loadqml(joinpath(dirname(@__FILE__), "qml", "drag.qml"))
exec()
2 changes: 1 addition & 1 deletion example/filedialog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ end

@qmlfunction singlefile multifile

load(joinpath(dirname(Base.source_path()), "qml", "filedialog.qml"))
loadqml(joinpath(dirname(Base.source_path()), "qml", "filedialog.qml"))
exec()
2 changes: 1 addition & 1 deletion example/fizzbuzz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ end
@qmlfunction do_fizzbuzz

qmlfile = joinpath(dirname(Base.source_path()), "qml", "fizzbuzz.qml")
load(qmlfile, fizzbuzz=JuliaPropertyMap("message" => Observable(""), "count" => 0, "success" => false))
loadqml(qmlfile, fizzbuzz=JuliaPropertyMap("message" => Observable(""), "count" => 0, "success" => false))
exec()
2 changes: 1 addition & 1 deletion example/gltriangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function render()
end

# Pass the triangle as a context property
load(joinpath(dirname(@__FILE__), "qml", "gltriangle.qml"),
loadqml(joinpath(dirname(@__FILE__), "qml", "gltriangle.qml"),
cornersModel=ListModel(corners),
render_triangle=@safe_cfunction(render, Cvoid, ()))
exec()
2 changes: 1 addition & 1 deletion example/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function paint(p::CxxPtr{QPainter}, item::CxxPtr{JuliaPaintedItem})
return
end

load(qmlfile,
loadqml(qmlfile,
paint_cfunction = @safe_cfunction(paint, Cvoid, (CxxPtr{QPainter}, CxxPtr{JuliaPaintedItem})),
parameters = JuliaPropertyMap("frequency" => f, "amplitude" => A))
exec()
Expand Down
2 changes: 1 addition & 1 deletion example/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
qml_file = joinpath(dirname(@__FILE__), "qml", "grid.qml")

# create the app, with cols and emojiModel exposed as QML context properties
load(qml_file, cols=3, emojiModel=ListModel(emoji))
loadqml(qml_file, cols=3, emojiModel=ListModel(emoji))

# Start the GUI
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, guiproperties = JuliaPropertyMap("timer" => QTimer(), "oldcounter" => oldcounter, "bg_counter" => bg_counter_slow))
loadqml(qml_file, guiproperties = JuliaPropertyMap("timer" => QTimer(), "oldcounter" => oldcounter, "bg_counter" => bg_counter_slow))

# Run the application
exec()
Expand Down
2 changes: 1 addition & 1 deletion example/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function test_display(d::JuliaDisplay)
end
@qmlfunction test_display

load(joinpath(dirname(@__FILE__), "qml", "image.qml"))
loadqml(joinpath(dirname(@__FILE__), "qml", "image.qml"))


# Run the application
Expand Down
2 changes: 1 addition & 1 deletion example/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function render_function(screen)
display(screen, cat)
end

load(joinpath(dirname(@__FILE__), "qml", "makie.qml"),
loadqml(joinpath(dirname(@__FILE__), "qml", "makie.qml"),
cat = JuliaPropertyMap("angle" => catangle),
render_callback = @safe_cfunction(render_function, Cvoid, (Any,))
)
Expand Down
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, observables = JuliaPropertyMap("input" => input, "output" => output))
loadqml(qml_file, observables = JuliaPropertyMap("input" => input, "output" => output))

if isinteractive()
exec_async()
Expand Down
2 changes: 1 addition & 1 deletion example/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
@qmlfunction plotsin init_backend

qml_file = joinpath(dirname(@__FILE__), "qml", "plot.qml")
load(qml_file)
loadqml(qml_file)

# Run the application
exec()
2 changes: 1 addition & 1 deletion example/progressbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end
simtypes = ListModel(first.(simulation_types))

# All arguments after qmlfile are context properties:
load(
loadqml(
qmlfile,
timer=timer,
simulationTypes=simtypes,
Expand Down
2 changes: 1 addition & 1 deletion example/repl-background.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using QML
qml_file = joinpath(dirname(@__FILE__), "qml", "repl-background.qml")

@qmlfunction pushdisplay
load(qml_file)
loadqml(qml_file)
exec_async()

using GR
Expand Down
2 changes: 1 addition & 1 deletion example/sketch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on(x) do px
nb_moves[] += 1
end

load(qmlfile, position=JuliaPropertyMap("x" => x, "y" =>y))
loadqml(qmlfile, position=JuliaPropertyMap("x" => x, "y" =>y))
exec()

"""
Expand Down
2 changes: 1 addition & 1 deletion example/tableview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end

# Load QML after setting context properties, to avoid errors on initialization
qml_file = joinpath(dirname(@__FILE__), "qml", "tableview.qml")
load(qml_file, properties=JuliaPropertyMap("years" => years), nuclidesModel=nuclidesModel)
loadqml(qml_file, properties=JuliaPropertyMap("years" => years), nuclidesModel=nuclidesModel)

# Run the application
exec()
2 changes: 1 addition & 1 deletion example/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fromfunction() = "From function call"
@qmlfunction fromfunction

# All keyword arguments to load are added as context properties on the QML side
load(qmlfile, fromcontext="From context property")
loadqml(qmlfile, fromcontext="From context property")
exec()

"""
Expand Down
25 changes: 15 additions & 10 deletions src/QML.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module QML

export QVariant, QString, QUrl
export QQmlContext, root_context, load, qt_prefix_path, set_source, engine, QByteArray, to_string, QQmlComponent, set_data, create, QQuickItem, content_item, QTimer, context_property, emit, JuliaDisplay, JuliaCanvas, init_application, qmlcontext, init_qmlapplicationengine, init_qmlengine, init_qquickview, exec, exec_async, ListModel, addrole, setconstructor, removerole, setrole, roles, QVariantMap
export QQmlContext, root_context, loadqml, qt_prefix_path, set_source, engine, QByteArray, to_string, QQmlComponent, set_data, create, QQuickItem, content_item, QTimer, context_property, emit, JuliaDisplay, JuliaCanvas, init_application, qmlcontext, init_qmlapplicationengine, init_qmlengine, init_qquickview, exec, exec_async, ListModel, addrole, setconstructor, removerole, setrole, roles, QVariantMap
export JuliaPropertyMap
export QStringList, QVariantList
export QPainter, device, width, height, logicalDpiX, logicalDpiY, QQuickWindow, effectiveDevicePixelRatio, window, JuliaPaintedItem
Expand Down Expand Up @@ -48,19 +48,24 @@ function load_qml(qmlfilename, engine)
end

"""
function load(qml_file::String; properties...)
function loadqml(qmlfilename; properties...)
Load a QML file, creating a [`QML.QQmlApplicationEngine`](@ref), and setting the context
`properties` supplied in the keyword arguments. Will create and return a
`QQmlApplicationEngine`. See the example for [`QML.QQmlApplicationEngine`](@ref).
"""
function FileIO.load(f::FileIO.File{format"QML"}; kwargs...)
function loadqml(qmlfilename; kwargs...)
qml_engine = init_qmlapplicationengine()
ctx = root_context(CxxRef(qml_engine))
for (key,value) in kwargs
set_context_property(ctx, String(key), value)
end
return load_qml(filename(f), qml_engine)
return load_qml(qmlfilename, qml_engine)
end

function FileIO.load(f::FileIO.File{format"QML"}; kwargs...)
Base.depwarn("load(qmlfile;...) is deprecated, please use loadqml(qmlfile;...)", :load)
return loadqml(filename(f))
end

@static if Sys.iswindows()
Expand Down Expand Up @@ -215,7 +220,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path; observables = JuliaPropertyMap("output" => output))
loadqml(path; observables = JuliaPropertyMap("output" => output))
exec()
end
```
Expand Down Expand Up @@ -364,7 +369,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path)
loadqml(path)
exec()
end
```
Expand Down Expand Up @@ -407,7 +412,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path)
loadqml(path)
exec()
end
```
Expand Down Expand Up @@ -595,7 +600,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path; fruits = fruits)
loadqml(path; fruits = fruits)
exec()
end
```
Expand Down Expand Up @@ -675,7 +680,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path; array_model = array_model)
loadqml(path; array_model = array_model)
exec()
end
Expand Down Expand Up @@ -794,7 +799,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path; array_model = array_model)
loadqml(path; array_model = array_model)
exec()
end
```
Expand Down
6 changes: 3 additions & 3 deletions src/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path)
loadqml(path)
exec()
end
Expand Down Expand Up @@ -231,7 +231,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path; greeting = "Hello, World!")
loadqml(path; greeting = "Hello, World!")
exec()
end
```
Expand Down Expand Up @@ -365,7 +365,7 @@ julia> mktempdir() do folder
}
}
\""")
load(path, timer=QTimer())
loadqml(path, timer=QTimer())
exec()
end
```
Expand Down
2 changes: 1 addition & 1 deletion test/badqml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Test
qmlfile = joinpath(dirname(@__FILE__), "qml", "badqml.qml")

try
load(qmlfile)
loadqml(qmlfile)
exec()
catch e
@test e.msg == "Failed to load QML file $qmlfile"
Expand Down
2 changes: 1 addition & 1 deletion test/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ set_state2 = TestModuleFunction.set_state2
qmlfunction("unexported_return_two", UnExported.return_two)
qmlfunction("unexported_check", UnExported.check)

load(joinpath(dirname(@__FILE__), "qml", "functions.qml"))
loadqml(joinpath(dirname(@__FILE__), "qml", "functions.qml"))
exec()

@test typeof(call_results1[1]) == Bool
Expand Down
2 changes: 1 addition & 1 deletion test/julia_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ custom_list = [ListElem("a",1), ListElem("b", 2)]
custom_model = ListModel(custom_list)

@qmlfunction get_array
load(qml_file,
loadqml(qml_file,
arrays=arrays,
array_model=array_model,
array_model2=array_model2,
Expand Down
2 changes: 1 addition & 1 deletion test/julia_object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ qml_file = joinpath(dirname(@__FILE__), "qml", "julia_object.qml")
observed_object = Observable(JuliaTestType(0,InnerType(0.0)))
@qmlfunction modify_julia_object replace_julia_object julia_object_check geta getx logx

load(qml_file, objects=JuliaPropertyMap("julia_object" => JuliaTestType(1, InnerType(2.0)), "observed_object" => observed_object))
loadqml(qml_file, objects=JuliaPropertyMap("julia_object" => JuliaTestType(1, InnerType(2.0)), "observed_object" => observed_object))

# Run the application
exec()
Expand Down
2 changes: 1 addition & 1 deletion test/julia_signal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
# absolute path in case working dir is overridden
qml_file = joinpath(dirname(@__FILE__), "qml", "julia_signal.qml")

load(qml_file)
loadqml(qml_file)

# Run the application
exec()
2 changes: 1 addition & 1 deletion test/listviews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ removerole_c() = removerole(tablemodel, "c")
setrole_a() = setrole(tablemodel, 1, "abc", (x::TableItem) -> x.a*x.b*x.c)

@qmlfunction testfail removerole_b removerole_c setrole_a
load(qml_file, array_model=array_model, array_model2=array_model2, tablemodel=tablemodel)
loadqml(qml_file, array_model=array_model, array_model2=array_model2, tablemodel=tablemodel)

exec()

Expand Down
2 changes: 1 addition & 1 deletion test/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ end
@qmlfunction check_property check_pi
qmlfile = joinpath(dirname(@__FILE__), "qml", "properties.qml")

load(qmlfile, properties=propmap)
loadqml(qmlfile, properties=propmap)
exec()
2 changes: 1 addition & 1 deletion test/qml_propertymap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ob[] = expected_ob
@test propmap["ob"][] == expected_ob

# Load the QML file, setting the property map as context object
load(qml_file; propmap=propmap)
loadqml(qml_file; propmap=propmap)

# Run the application
exec()
Expand Down
Loading

0 comments on commit 52f8e67

Please sign in to comment.