diff --git a/REQUIRE b/REQUIRE index 13eee6a..721e80b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,5 @@ -julia 0.5 -Compat 0.17.0 +julia 0.6 +Compat 0.48.0 Cairo Graphics 0.1 BinDeps 0.2.2- diff --git a/deps/build.jl b/deps/build.jl index 9ed09a2..c6547b6 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,15 +1,16 @@ using BinDeps -using Compat; import Compat.String +using Compat +using Compat.Libdl @BinDeps.setup tcl = library_dependency("tcl",aliases=["libtcl8.6","tcl86g","tcl86t","libtcl","libtcl8.6.so.0","libtcl8.5","libtcl8.5.so.0","tcl85"]) tk = library_dependency("tk",aliases=["libtk8.6","libtk","libtk8.6.so.0","libtk8.5","libtk8.5.so.0","tk85","tk86","tk86t"], depends=[tcl], validate = function(p,h) - is_apple() && (return @compat Libdl.dlsym_e(h,:TkMacOSXGetRootControl) != C_NULL) + Compat.Sys.isapple() && (return Libdl.dlsym_e(h,:TkMacOSXGetRootControl) != C_NULL) return true end) -if is_windows() +if Compat.Sys.iswindows() using WinRPM provides(WinRPM.RPM,"tk",tk,os = :Windows) provides(WinRPM.RPM,"tcl",tcl,os = :Windows) @@ -21,12 +22,12 @@ provides(AptGet,"tk8.5",tk) provides(Sources,URI("http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz"),tcl,unpacked_dir = "tcl8.6.0") provides(Sources,URI("http://prdownloads.sourceforge.net/tcl/tk8.6.0-src.tar.gz"),tk,unpacked_dir = "tk8.6.0") -is64bit = @compat Sys.WORD_SIZE == 64 +is64bit = Sys.WORD_SIZE == 64 -provides(BuildProcess,Autotools(configure_subdir = "unix", configure_options = [is64bit?"--enable-64bit":"--disable-64bit"]),tcl, os = :Unix) -provides(BuildProcess,Autotools(configure_subdir = "unix", configure_options = [is64bit?"--enable-64bit":"--disable-64bit"]),tk, os = :Unix) +provides(BuildProcess,Autotools(configure_subdir = "unix", configure_options = [is64bit ? "--enable-64bit" : "--disable-64bit"]),tcl, os = :Unix) +provides(BuildProcess,Autotools(configure_subdir = "unix", configure_options = [is64bit ? "--enable-64bit" : "--disable-64bit"]),tk, os = :Unix) -if @compat Sys.WORD_SIZE == 64 +if Sys.WORD_SIZE == 64 # Unfortunately the mingw-built tc segfaults since some function signatures # are different between VC and mingw. This is fixed on tcl trunk. For now, # just use VC to build tcl (Note requlres Visual Studio Express in the PATH) @@ -48,8 +49,8 @@ if @compat Sys.WORD_SIZE == 64 end end),tk) else - provides(BuildProcess,Autotools(libtarget = "tcl86.dll", configure_subdir = "win", configure_options = [is64bit?"--enable-64bit":"--disable-64bit","--enable-threads"]),tcl, os = :Windows) - provides(BuildProcess,Autotools(libtarget = "tk86.dll", configure_subdir = "win", configure_options = [is64bit?"--enable-64bit":"--disable-64bit"]),tk, os = :Windows) + provides(BuildProcess,Autotools(libtarget = "tcl86.dll", configure_subdir = "win", configure_options = [is64bit ? "--enable-64bit" : "--disable-64bit","--enable-threads"]),tcl, os = :Windows) + provides(BuildProcess,Autotools(libtarget = "tk86.dll", configure_subdir = "win", configure_options = [is64bit ? "--enable-64bit" : "--disable-64bit"]),tk, os = :Windows) end -@BinDeps.install @compat(Dict(:tk => :libtk, :tcl=>:libtcl)) +@BinDeps.install Dict(:tk => :libtk, :tcl=>:libtcl) diff --git a/examples/manipulate.jl b/examples/manipulate.jl index 4ee05fb..e7b0819 100644 --- a/examples/manipulate.jl +++ b/examples/manipulate.jl @@ -25,10 +25,10 @@ using Winston end -@compat abstract type ManipulateWidget end +abstract type ManipulateWidget end get_label(widget::ManipulateWidget) = widget.label -type SliderWidget <: ManipulateWidget +mutable struct SliderWidget <: ManipulateWidget nm label initial @@ -44,7 +44,7 @@ slider(nm::AbstractString, label::AbstractString, rng::UnitRange, initial::Integ slider(nm::AbstractString, label::AbstractString, rng::UnitRange) = slider(nm, label, rng, minimum(rng)) slider(nm::AbstractString, rng::UnitRange) = slider(nm, nm, rng, minimum(rng)) -type PickerWidget <: ManipulateWidget +mutable struct PickerWidget <: ManipulateWidget nm label initial @@ -60,14 +60,14 @@ function make_widget(parent, widget::PickerWidget) end -picker{T <: AbstractString}(nm::AbstractString, label::AbstractString, vals::Vector{T}, initial) = PickerWidget(nm, label, initial, vals) -picker{T <: AbstractString}(nm::AbstractString, label::AbstractString, vals::Vector{T}) = picker(nm, label, vals, vals[1]) -picker{T <: AbstractString}(nm::AbstractString, vals::Vector{T}) = picker(nm, nm, vals) +picker(nm::AbstractString, label::AbstractString, vals::Vector{T}, initial) where {T <: AbstractString} = PickerWidget(nm, label, initial, vals) +picker(nm::AbstractString, label::AbstractString, vals::Vector{T}) where {T <: AbstractString} = picker(nm, label, vals, vals[1]) +picker(nm::AbstractString, vals::Vector{T}) where {T <: AbstractString} = picker(nm, nm, vals) picker(nm::AbstractString, label::AbstractString, vals::Dict, initial) = PickerWidget(nm, label, vals, initial) picker(nm::AbstractString, label::AbstractString, vals::Dict) = PickerWidget(nm, label, vals, [string(k) for (k,v) in vals][1]) picker(nm::AbstractString, vals::Dict) = picker(nm, nm, vals) -type CheckboxWidget <: ManipulateWidget +mutable struct CheckboxWidget <: ManipulateWidget nm label initial @@ -83,7 +83,7 @@ checkbox(nm::AbstractString, label::AbstractString, initial::Bool) = CheckboxWid checkbox(nm::AbstractString, label::AbstractString) = checkbox(nm, label, false) -type ButtonWidget <: ManipulateWidget +mutable struct ButtonWidget <: ManipulateWidget label nm end @@ -93,7 +93,7 @@ button(label::AbstractString) = ButtonWidget(label, nothing) ## Add text widget to gather one-line of text -type EntryWidget <: ManipulateWidget +mutable struct EntryWidget <: ManipulateWidget nm label initial @@ -105,7 +105,7 @@ entry(nm::AbstractString) = EntryWidget(nm, nm, "{}") ## Expression returns a plot object. Use names as values -function manipulate(ex::(@compat Union{Symbol,Expr}), controls...) +function manipulate(ex::(Union{Symbol,Expr}), controls...) widgets = Array(Tk.Widget, 0) w = Toplevel("Manipulate", 800, 500) @@ -127,7 +127,7 @@ function manipulate(ex::(@compat Union{Symbol,Expr}), controls...) d = Dict() # return Dict of values vals = get_values(); keys = get_nms() for i in 1:length(vals) - if !isa(keys[i], @compat Void) + if !isa(keys[i], Nothing) d[keys[i]] = vals[i] end end diff --git a/examples/sketch.jl b/examples/sketch.jl index 5a2f68f..18c3c6f 100644 --- a/examples/sketch.jl +++ b/examples/sketch.jl @@ -1,9 +1,5 @@ using Tk -if VERSION < v"0.4.0-dev+3275" - using Base.Graphics -else - using Graphics -end +using Graphics function sketch_window() w = Window("drawing", 400, 300) diff --git a/examples/test.jl b/examples/test.jl index 9405dd5..87ecd51 100644 --- a/examples/test.jl +++ b/examples/test.jl @@ -6,7 +6,7 @@ using Compat; import Compat.String w = Toplevel("Test window", false) ## pack in tk frame for themed widgets f = Frame(w) -configure(f, @compat Dict(:padding => [3,3,2,2], :relief=>"groove")) +configure(f, Dict(:padding => [3,3,2,2], :relief=>"groove")) pack(f, expand=true, fill="both") ## widgets @@ -26,11 +26,11 @@ pack_style = ["pack", "grid", "formlayout"][3] if pack_style == "pack" map(pack, widgets) - map(u -> pack_configure(u, @compat Dict(:anchor => "w")), widgets) + map(u -> pack_configure(u, Dict(:anchor => "w")), widgets) elseif pack_style == "grid" for i in 1:length(widgets) grid(widgets[i], i, 1) - grid_configure(widgets[i], @compat Dict(:sticky => "we")) + grid_configure(widgets[i], Dict(:sticky => "we")) end else map(u -> formlayout(u, "label"), widgets) diff --git a/examples/workspace.jl b/examples/workspace.jl index e7bd4e7..88a8caa 100644 --- a/examples/workspace.jl +++ b/examples/workspace.jl @@ -7,7 +7,7 @@ function get_names(m::Module) end unique_id(v::Symbol, m::Module) = isdefined(m,v) ? unique_id(eval(m,v)) : "" -unique_id(x) = string(object_id(x)) +unique_id(x) = string(objectid(x)) ## short_summary ## can customize description here @@ -31,8 +31,8 @@ end negate(x::Bool, val::Bool) = val ? !x : x -const MaybeRegex = Union{Void, Regex} -const MaybeType = Union{Void, DataType} +const MaybeRegex = Union{Nothing, Regex} +const MaybeType = Union{Nothing, DataType} ## get array of names and summaries ## m module diff --git a/src/Tk.jl b/src/Tk.jl index 0ad64d8..2164f24 100644 --- a/src/Tk.jl +++ b/src/Tk.jl @@ -1,4 +1,4 @@ -VERSION >= v"0.4.0-dev+6521" && __precompile__(false) +__precompile__(false) # julia tk interface # TODO: @@ -14,9 +14,8 @@ VERSION >= v"0.4.0-dev+6521" && __precompile__(false) module Tk -using Base using Cairo -using Compat; import Compat.String +using Compat if isfile(joinpath(dirname(@__FILE__),"..","deps","deps.jl")) include("../deps/deps.jl") @@ -26,11 +25,7 @@ end import Base: ==, bind, getindex, isequal, parent, setindex!, show, string, Text -if VERSION < v"0.4.0-dev+3275" - import Base.Graphics: width, height, getgc -else - import Graphics: width, height, getgc -end +import Graphics: width, height, getgc import Cairo: destroy diff --git a/src/containers.jl b/src/containers.jl index 007f2b1..d1abc1b 100644 --- a/src/containers.jl +++ b/src/containers.jl @@ -1,9 +1,9 @@ ## Types -type Tk_Toplevel <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end -type Tk_Frame <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end -type Tk_Labelframe <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end -type Tk_Notebook <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end -type Tk_Panedwindow <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end +mutable struct Tk_Toplevel <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end +mutable struct Tk_Frame <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end +mutable struct Tk_Labelframe <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end +mutable struct Tk_Notebook <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end +mutable struct Tk_Panedwindow <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} end ==(a::TTk_Container, b::TTk_Container) = isequal(a.w, b.w) && typeof(a) == typeof(b) @@ -23,7 +23,7 @@ width(widget::Tk_Toplevel) = parse(Int, winfo(widget, "width")) height(widget::Tk_Toplevel) = parse(Int, winfo(widget, "height")) get_size(widget::Tk_Toplevel) = [width(widget), height(widget)] set_size(widget::Tk_Toplevel, width::Integer, height::Integer) = wm(widget, "geometry", "$(string(width))x$(string(height))") -set_size{T <: Integer}(widget::Tk_Toplevel, widthheight::Vector{T}) = set_size(widget, widthheight[1], widthheight[2]) +set_size(widget::Tk_Toplevel, widthheight::Vector{T}) where {T <: Integer} = set_size(widget, widthheight[1], widthheight[2]) @@ -52,7 +52,7 @@ function set_position(widget::Tk_Toplevel, x::Integer, y::Integer) p_or_m(x) = x < 0 ? "$x" : "+$x" wm(widget, "geometry", I(p_or_m(x) * p_or_m(y))) end -set_position{T <: Integer}(widget::Tk_Toplevel, pos::Vector{T}) = set_position(w, pos[1], pos[2]) +set_position(widget::Tk_Toplevel, pos::Vector{T}) where {T <: Integer} = set_position(w, pos[1], pos[2]) set_position(widget::Tk_Toplevel, pos::Tk_Widget) = set_position(widget, Integer[parse(Int, winfo(pos, i)) for i in ["x", "y"]] + [10,10]) update(widget::Tk_Toplevel) = wm(widget, "geometry") diff --git a/src/core.jl b/src/core.jl index e8c673b..5074cad 100644 --- a/src/core.jl +++ b/src/core.jl @@ -16,14 +16,14 @@ get_path(widget::Canvas) = get_path(widget.c) # Tk.Canvas object ## Coversion of julia objects into tcl strings for inclusion via tcl() call to_tcl(x) = string(x) -to_tcl(x::Void) = "" +to_tcl(x::Nothing) = "" has_space = r" " to_tcl(x::AbstractString) = ismatch(has_space, x) ? "{$x}" : x -type I x::MaybeString end # avoid wrapping in {} and ismatch call. +mutable struct I x::MaybeString end # avoid wrapping in {} and ismatch call. macro I_str(s) I(s) end to_tcl(x::I) = x.x == nothing ? "" : x.x -to_tcl{T <: Number}(x::Vector{T}) = "\"" * string(join(x, " ")) * "\"" -function to_tcl{T <: AbstractString}(x::Vector{T}) +to_tcl(x::Vector{T}) where {T <: Number} = "\"" * string(join(x, " ")) * "\"" +function to_tcl(x::Vector{T}) where T <: AbstractString tmp = join(["{$i}" for i in x], " ") "[list $tmp ]" end @@ -80,7 +80,7 @@ function configure(widget::Widget, args...; kwargs...) tcl(widget, "configure", args...; kwargs...) end -setindex!(widget::Widget, value, prop::Symbol) = configure(widget, @compat Dict(prop=>value)) +setindex!(widget::Widget, value, prop::Symbol) = configure(widget, Dict(prop=>value)) ## Get values ## cget @@ -110,13 +110,7 @@ winfo(widget::Widget, prop::AbstractString) = winfo(widget, prop, nothing) wm(window::Widget, prop::AbstractString, args...; kwargs...) = tcl("wm", prop, window, args...; kwargs...) -if VERSION >= v"0.6.0-pre.alpha.244" - _slots(m::Method) = (Base.uncompressed_ast(m).slotnames, m.nargs) -elseif VERSION >= v"0.6.0-dev.624" - _slots(m::Method) = (m.source.slotnames, m.nargs) -else - _slots(m::Method) = (m.lambda_template.slotnames, m.lambda_template.nargs) -end +_slots(m::Method) = (Base.uncompressed_ast(m).slotnames, m.nargs) ## Take a function, get its args as array of symbols. There must be better way... ## Helper functions for bind callback @@ -164,7 +158,7 @@ function bindwheel(widget::Widget, modifier::AbstractString, callback::Function, tkargs = string(" ", tkargs) end ccb = tcl_callback(callback) - if is_linux() + if Compat.Sys.islinux() tcl_eval("bind $(path) <$(modifier)Button-4> {$ccb -120$tkargs}") tcl_eval("bind $(path) <$(modifier)Button-5> {$ccb 120$tkargs}") else @@ -174,7 +168,7 @@ end ## add most typical callback function callback_add(widget::Tk_Widget, callback::Function) - events = @compat Dict( + events = Dict( :Tk_Window => "", :Tk_Frame => nothing, :Tk_Labelframe => nothing, @@ -222,11 +216,11 @@ end ## function after a delay of ms milliseconds. This is started with ## obj.start() and stopped, if desired, with obj.stop(). To restart is ## possible, but first set obj.run=true. -type TclAfter +mutable struct TclAfter cb::Function run::Bool - start::Union{Void, Function} - stop::Union{Void, Function} + start::Union{Nothing, Function} + stop::Union{Nothing, Function} ms::Int function TclAfter(ms, cb::Function) diff --git a/src/dialogs.jl b/src/dialogs.jl index a7e447e..3e65f84 100644 --- a/src/dialogs.jl +++ b/src/dialogs.jl @@ -8,7 +8,7 @@ ChooseDirectory() = tcl("tk_chooseDirectory") ## Message box function Messagebox(parent::MaybeWidget; title::AbstractString="", message::AbstractString="", detail::AbstractString="") args = Dict() - if !isa(parent, Void) args["parent"] = get_path(parent) end + if !isa(parent, Nothing) args["parent"] = get_path(parent) end if length(title) > 0 args["title"] = title end if length(message) > 0 args["message"] = message end if length(detail) > 0 args["detail"] = detail end diff --git a/src/menu.jl b/src/menu.jl index fa41b08..6b3f193 100644 --- a/src/menu.jl +++ b/src/menu.jl @@ -54,7 +54,7 @@ function menu_add(widget::Tk_Menu, rb::Tk_Radio) end function tk_popup(widget::Tk_Widget, menu::Tk_Menu) - if is_apple() + if Compat.Sys.isapple() tcl_eval("bind $(widget.w.path) <2> {tk_popup $(menu.w.path) %X %Y}") tcl_eval("bind $(widget.w.path) {tk_popup $(menu.w.path) %X %Y}") else @@ -63,7 +63,7 @@ function tk_popup(widget::Tk_Widget, menu::Tk_Menu) end function tk_popup(c::Canvas, menu::Tk_Menu) - if is_apple() + if Compat.Sys.isapple() tcl_eval("bind $(c.c.path) <2> {tk_popup $(menu.w.path) %X %Y}") tcl_eval("bind $(c.c.path) {tk_popup $(menu.w.path) %X %Y}") else diff --git a/src/tkwidget.jl b/src/tkwidget.jl index dd33c5e..667ece4 100644 --- a/src/tkwidget.jl +++ b/src/tkwidget.jl @@ -4,9 +4,9 @@ const TCL_RETURN = convert(Int32, 2) const TCL_BREAK = convert(Int32, 3) const TCL_CONTINUE = convert(Int32, 4) -const TCL_VOLATILE = convert(Ptr{Void}, 1) -const TCL_STATIC = convert(Ptr{Void}, 0) -const TCL_DYNAMIC = convert(Ptr{Void}, 3) +const TCL_VOLATILE = convert(Ptr{Cvoid}, 1) +const TCL_STATIC = convert(Ptr{Cvoid}, 0) +const TCL_DYNAMIC = convert(Ptr{Cvoid}, 3) tcl_doevent() = tcl_doevent(nothing,0) function tcl_doevent(timer,status=0) @@ -24,19 +24,20 @@ end global timeout = nothing # fetch first word from struct -tk_display(w) = pointer_to_array(convert(Ptr{Ptr{Void}},w), (1,), false)[1] +tk_display(w) = pointer_to_array(convert(Ptr{Ptr{Cvoid}},w), (1,), false)[1] function init() - @static if is_apple() ccall(:CFBundleCreate, Ptr{Void}, (Ptr{Void}, Ptr{Void}), C_NULL, - ccall(:CFURLCreateWithFileSystemPath, Ptr{Void}, (Ptr{Void}, Ptr{Void}, Cint, Cint), C_NULL, - ccall(:CFStringCreateWithFileSystemRepresentation, Ptr{Void}, (Ptr{Void}, Ptr{UInt8}), C_NULL, "/System/Library/Frameworks/Tk.framework"), - 0, 1)) + @static if Compat.Sys.isapple() + ccall(:CFBundleCreate, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}), C_NULL, + ccall(:CFURLCreateWithFileSystemPath, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint), C_NULL, + ccall(:CFStringCreateWithFileSystemRepresentation, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{UInt8}), C_NULL, "/System/Library/Frameworks/Tk.framework"), + 0, 1)) end - ccall((:Tcl_FindExecutable,libtcl), Void, (Ptr{UInt8},), - joinpath(JULIA_HOME, "julia")) - ccall((:g_type_init,Cairo._jl_libgobject),Void,()) - tclinterp = ccall((:Tcl_CreateInterp,libtcl), Ptr{Void}, ()) - @static if is_windows() + ccall((:Tcl_FindExecutable,libtcl), Cvoid, (Ptr{UInt8},), + joinpath(Compat.Sys.BINDIR, "julia")) + ccall((:g_type_init,Cairo._jl_libgobject),Cvoid,()) + tclinterp = ccall((:Tcl_CreateInterp,libtcl), Ptr{Cvoid}, ()) + @static if Compat.Sys.iswindows() htcl = ccall((:GetModuleHandleA,:kernel32),stdcall,Csize_t, (Ptr{UInt8},),libtcl) tclfile = Vector{UInt8}(260) @@ -55,33 +56,33 @@ function init() tcl_eval(takebuf_string(libpath),tclinterp) end end - if ccall((:Tcl_Init,libtcl), Int32, (Ptr{Void},), tclinterp) == TCL_ERROR + if ccall((:Tcl_Init,libtcl), Int32, (Ptr{Cvoid},), tclinterp) == TCL_ERROR throw(TclError(string("error initializing Tcl: ", tcl_result(tclinterp)))) end - if ccall((:Tk_Init,libtk), Int32, (Ptr{Void},), tclinterp) == TCL_ERROR + if ccall((:Tk_Init,libtk), Int32, (Ptr{Cvoid},), tclinterp) == TCL_ERROR throw(TclError(string("error initializing Tk: ", tcl_result(tclinterp)))) end global timeout - timeout = Timer(tcl_doevent,0.1,0.01) + timeout = Timer(tcl_doevent,0.1, interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval = interval =0.01) tclinterp end mainwindow(interp) = - ccall((:Tk_MainWindow,libtk), Ptr{Void}, (Ptr{Void},), interp) + ccall((:Tk_MainWindow,libtk), Ptr{Cvoid}, (Ptr{Cvoid},), interp) mainwindow() = mainwindow(tcl_interp) -type TclError <: Exception +mutable struct TclError <: Exception msg::AbstractString end tcl_result() = tcl_result(tcl_interp) function tcl_result(tcl_interp) unsafe_string(ccall((:Tcl_GetStringResult,libtcl), - Ptr{UInt8}, (Ptr{Void},), tcl_interp)) + Ptr{UInt8}, (Ptr{Cvoid},), tcl_interp)) end function tcl_evalfile(name) - if ccall((:Tcl_EvalFile,libtcl), Int32, (Ptr{Void}, Ptr{UInt8}), + if ccall((:Tcl_EvalFile,libtcl), Int32, (Ptr{Cvoid}, Ptr{UInt8}), tcl_interp, name) != 0 throw(TclError(tcl_result())) end @@ -90,7 +91,7 @@ end tcl_eval(cmd) = tcl_eval(cmd,tcl_interp) function tcl_eval(cmd,tclinterp) - code = ccall((:Tcl_Eval,libtcl), Int32, (Ptr{Void}, Ptr{UInt8}), + code = ccall((:Tcl_Eval,libtcl), Int32, (Ptr{Cvoid}, Ptr{UInt8}), tclinterp, cmd) result = tcl_result(tclinterp) if code != 0 @@ -100,10 +101,10 @@ function tcl_eval(cmd,tclinterp) end end -type TkWidget +mutable struct TkWidget path::String kind::String - parent::Union{TkWidget,Void} + parent::Union{TkWidget,Nothing} let ID::Int = 0 function TkWidget(parent::TkWidget, kind) @@ -130,8 +131,8 @@ Window(title) = Window(title, 200, 200) place(widget::TkWidget, x::Int, y::Int) = tcl_eval("place $(widget.path) -x $x -y $y") function nametowindow(name) - ccall((:Tk_NameToWindow,libtk), Ptr{Void}, - (Ptr{Void}, Ptr{UInt8}, Ptr{Void}), + ccall((:Tk_NameToWindow,libtk), Ptr{Cvoid}, + (Ptr{Cvoid}, Ptr{UInt8}, Ptr{Cvoid}), tcl_interp, name, mainwindow(tcl_interp)) end @@ -151,23 +152,23 @@ function jl_tcl_callback(fptr, interp, argc::Int32, argv::Ptr{Ptr{UInt8}}) return TCL_ERROR end if isa(result,String) - ccall((:Tcl_SetResult,libtcl), Void, (Ptr{Void}, Ptr{UInt8}, Int32), + ccall((:Tcl_SetResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, Int32), interp, result, TCL_VOLATILE) else - ccall((:Tcl_SetResult,libtcl), Void, (Ptr{Void}, Ptr{UInt8}, Int32), + ccall((:Tcl_SetResult,libtcl), Cvoid, (Ptr{Cvoid}, Ptr{UInt8}, Int32), interp, empty_str, TCL_STATIC) end return TCL_OK end jl_tcl_callback_ptr = cfunction(jl_tcl_callback, - Int32, (Ptr{Void}, Ptr{Void}, Int32, Ptr{Ptr{UInt8}})) + Int32, (Ptr{Cvoid}, Ptr{Cvoid}, Int32, Ptr{Ptr{UInt8}})) function tcl_callback(f) - cname = string("jl_cb", repr(object_id(f))) + cname = string("jl_cb", repr(objectid(f))) # TODO: use Tcl_CreateObjCommand instead - ccall((:Tcl_CreateCommand,libtcl), Ptr{Void}, - (Ptr{Void}, Ptr{UInt8}, Ptr{Void}, Ptr{Void}, Ptr{Void}), + ccall((:Tcl_CreateCommand,libtcl), Ptr{Cvoid}, + (Ptr{Cvoid}, Ptr{UInt8}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), tcl_interp, cname, jl_tcl_callback_ptr, pointer_from_objref(f), C_NULL) # TODO: use a delete proc (last arg) to remove this _callbacks[f] = true @@ -179,7 +180,7 @@ height(w::TkWidget) = parse(Int, tcl_eval("winfo height $(w.path)")) const default_mouse_cb = (w, x, y)->nothing -type MouseHandler +mutable struct MouseHandler button1press button1release button2press @@ -196,7 +197,7 @@ end # TkCanvas is the plain Tk canvas widget. This one is double-buffered # and built on Cairo. -type Canvas +mutable struct Canvas c::TkWidget back::CairoSurface # backing store backcc::CairoContext @@ -265,15 +266,15 @@ function reveal(c::Canvas) tcl_doevent() end -@static if is_apple() +@static if Compat.Sys.isapple() if Sys.WORD_SIZE == 32 const CGFloat = Float32 else const CGFloat = Float64 end - function objc_msgSend{T}(id, uid, ::Type{T}=Ptr{Void}) - convert(T, ccall(:objc_msgSend, Ptr{Void}, (Ptr{Void}, Ptr{Void}), - id, ccall(:sel_getUid, Ptr{Void}, (Ptr{UInt8},), uid))) + function objc_msgSend(id, uid, ::Type{T}=Ptr{Void}) where T + convert(T, ccall(:objc_msgSend, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}), + id, ccall(:sel_getUid, Ptr{Cvoid}, (Ptr{UInt8},), uid))) end end @@ -282,7 +283,7 @@ end function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) win = nametowindow(w.path) win == C_NULL && error("invalid window") - @static if is_linux() + @static if Compat.Sys.islinux() disp = jl_tkwin_display(win) d = jl_tkwin_id(win) vis = jl_tkwin_visual(win) @@ -294,14 +295,14 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) destroy(surf) return end - @static if is_apple() + @static if Compat.Sys.isapple() ## TkMacOSXSetupDrawingContext() drawable = jl_tkwin_id(win) - view = ccall((:TkMacOSXGetRootControl,libtk), Ptr{Void}, (Int,), drawable) # NSView* + view = ccall((:TkMacOSXGetRootControl,libtk), Ptr{Cvoid}, (Int,), drawable) # NSView* if view == C_NULL error("Invalid OS X window at getView") end - focusView = objc_msgSend(ccall(:objc_getClass, Ptr{Void}, (Ptr{UInt8},), "NSView"), "focusView"); + focusView = objc_msgSend(ccall(:objc_getClass, Ptr{Cvoid}, (Ptr{UInt8},), "NSView"), "focusView"); focusLocked = false if view != focusView focusLocked = objc_msgSend(view, "lockFocusIfCanDraw", Int32) != 0 @@ -316,7 +317,7 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) objc_msgSend(window, "disableFlushWindow") context = objc_msgSend(objc_msgSend(window, "graphicsContext"), "graphicsPort") if !focusLocked - ccall(:CGContextSaveGState, Void, (Ptr{Void},), context) + ccall(:CGContextSaveGState, Cvoid, (Ptr{Cvoid},), context) end try ## TkMacOSXGetClipRgn @@ -326,7 +327,7 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) if macDraw.winPtr != C_NULL TK_CLIP_INVALID = 0x02 # 8.4, 8.5, 8.6 if macDraw.flags & TK_CLIP_INVALID != 0 - ccall((:TkMacOSXUpdateClipRgn,libtk), Void, (Ptr{Void},), macDraw.winPtr) + ccall((:TkMacOSXUpdateClipRgn,libtk), Cvoid, (Ptr{Cvoid},), macDraw.winPtr) macDraw = unsafe_load(convert(Ptr{TkWindowPrivate}, drawable)) end clipRgn = if macDraw.drawRgn != C_NULL @@ -338,16 +339,16 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) end end ## - ccall(:CGContextTranslateCTM, Void, (Ptr{Void}, CGFloat, CGFloat), context, 0, height(toplevel(w))) - ccall(:CGContextScaleCTM, Void, (Ptr{Void}, CGFloat, CGFloat), context, 1, -1) + ccall(:CGContextTranslateCTM, Cvoid, (Ptr{Cvoid}, CGFloat, CGFloat), context, 0, height(toplevel(w))) + ccall(:CGContextScaleCTM, Cvoid, (Ptr{Cvoid}, CGFloat, CGFloat), context, 1, -1) if clipRgn != C_NULL - if ccall(:HIShapeIsEmpty, UInt8, (Ptr{Void},), clipRgn) != 0 + if ccall(:HIShapeIsEmpty, UInt8, (Ptr{Cvoid},), clipRgn) != 0 return end - @assert 0 == ccall(:HIShapeReplacePathInCGContext, Cint, (Ptr{Void}, Ptr{Void}), clipRgn, context) - ccall(:CGContextEOClip, Void, (Ptr{Void},), context) + @assert 0 == ccall(:HIShapeReplacePathInCGContext, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), clipRgn, context) + ccall(:CGContextEOClip, Cvoid, (Ptr{Cvoid},), context) end - ccall(:CGContextTranslateCTM, Void, (Ptr{Void}, CGFloat, CGFloat), context, macDraw.xOff, macDraw.yOff) + ccall(:CGContextTranslateCTM, Cvoid, (Ptr{Cvoid}, CGFloat, CGFloat), context, macDraw.xOff, macDraw.yOff) ## end surf = CairoQuartzSurface(context, wi, hi) @@ -358,26 +359,26 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true) end finally ## TkMacOSXRestoreDrawingContext - ccall(:CGContextSynchronize, Void, (Ptr{Void},), context) + ccall(:CGContextSynchronize, Cvoid, (Ptr{Cvoid},), context) objc_msgSend(window, "enableFlushWindow") if focusLocked objc_msgSend(view, "unlockFocus") else - ccall(:CGContextRestoreGState, Void, (Ptr{Void},), context) + ccall(:CGContextRestoreGState, Cvoid, (Ptr{Cvoid},), context) end end ## return end - @static if is_windows() + @static if Compat.Sys.iswindows() state = Vector{UInt8}(sizeof(Int)*2) # 8.4, 8.5, 8.6 drawable = jl_tkwin_id(win) - hdc = ccall((:TkWinGetDrawableDC,libtk), Ptr{Void}, (Ptr{Void}, Int, Ptr{UInt8}), + hdc = ccall((:TkWinGetDrawableDC,libtk), Ptr{Cvoid}, (Ptr{Cvoid}, Int, Ptr{UInt8}), jl_tkwin_display(win), drawable, state) surf = CairoWin32Surface(hdc, width(w), height(w)) f(surf) destroy(surf) - ccall((:TkWinReleaseDrawableDC,libtk), Void, (Int, Int, Ptr{UInt8}), + ccall((:TkWinReleaseDrawableDC,libtk), Cvoid, (Int, Int, Ptr{UInt8}), drawable, hdc, state) return end @@ -459,41 +460,41 @@ const tk_version = convert(VersionNumber,tcl_eval("return \$tk_version")) tcl_eval("wm withdraw .") if tk_version >= v"8.4-" && tk_version < v"8.7-" -jl_tkwin_display(tkwin::Ptr{Void}) = unsafe_load(convert(Ptr{Ptr{Void}},tkwin), 1) # 8.4, 8.5, 8.6 -jl_tkwin_visual(tkwin::Ptr{Void}) = unsafe_load(convert(Ptr{Ptr{Void}},tkwin), 4) # 8.4, 8.5, 8.6 -jl_tkwin_id(tkwin::Ptr{Void}) = unsafe_load(convert(Ptr{Int},tkwin), 6) # 8.4, 8.5, 8.6 -if is_apple() +jl_tkwin_display(tkwin::Ptr{Cvoid}) = unsafe_load(convert(Ptr{Ptr{Cvoid}},tkwin), 1) # 8.4, 8.5, 8.6 +jl_tkwin_visual(tkwin::Ptr{Cvoid}) = unsafe_load(convert(Ptr{Ptr{Cvoid}},tkwin), 4) # 8.4, 8.5, 8.6 +jl_tkwin_id(tkwin::Ptr{Cvoid}) = unsafe_load(convert(Ptr{Int},tkwin), 6) # 8.4, 8.5, 8.6 +if Compat.Sys.isapple() if tk_version >= v"8.5-" - immutable TkWindowPrivate - winPtr::Ptr{Void} - view::Ptr{Void} - context::Ptr{Void} + struct TkWindowPrivate + winPtr::Ptr{Cvoid} + view::Ptr{Cvoid} + context::Ptr{Cvoid} xOff::Cint yOff::Cint sizeX::CGFloat; sizeY::CGFloat; - visRgn::Ptr{Void} - aboveVisRgn::Ptr{Void} - drawRgn::Ptr{Void} - referenceCount::Ptr{Void} - toplevel::Ptr{Void} + visRgn::Ptr{Cvoid} + aboveVisRgn::Ptr{Cvoid} + drawRgn::Ptr{Cvoid} + referenceCount::Ptr{Cvoid} + toplevel::Ptr{Cvoid} flags::Cint end else - immutable TkWindowPrivate - winPtr::Ptr{Void} - grafPtr::Ptr{Void} - view::Ptr{Void} - context::Ptr{Void} + struct TkWindowPrivate + winPtr::Ptr{Cvoid} + grafPtr::Ptr{Cvoid} + view::Ptr{Cvoid} + context::Ptr{Cvoid} xOff::Cint yOff::Cint sizeX::CGFloat; sizeY::CGFloat; - visRgn::Ptr{Void} - aboveVisRgn::Ptr{Void} - drawRgn::Ptr{Void} - referenceCount::Ptr{Void} - toplevel::Ptr{Void} + visRgn::Ptr{Cvoid} + aboveVisRgn::Ptr{Cvoid} + drawRgn::Ptr{Cvoid} + referenceCount::Ptr{Cvoid} + toplevel::Ptr{Cvoid} flags::Cint end end diff --git a/src/types.jl b/src/types.jl index 36c0608..67cf9ed 100644 --- a/src/types.jl +++ b/src/types.jl @@ -1,15 +1,15 @@ ## Abstract types -@compat abstract type Tk_Widget end -@compat abstract type TTk_Widget <: Tk_Widget end ## for ttk::widgets -@compat abstract type TTk_Container <: Tk_Widget end ## for containers (frame, labelframe, ???) +abstract type Tk_Widget end +abstract type TTk_Widget <: Tk_Widget end ## for ttk::widgets +abstract type TTk_Container <: Tk_Widget end ## for containers (frame, labelframe, ???) const Widget = Union{TkWidget, Tk_Widget, Canvas, AbstractString} ## Maybe -- can this be parameterized? ## https://groups.google.com/forum/?fromgroups=#!topic/julia-dev/IbbWwplrqlc (takeaway -- this style is frowned upon) -const MaybeFunction = Union{Function, Void} -const MaybeString = Union{AbstractString, Void} -const MaybeStringInteger = Union{AbstractString, Integer, Void} # for at in tree insert -const MaybeVector = Union{Vector, Void} -const MaybeWidget = Union{Widget, Void} -const MaybeBool = Union{Bool, Void} +const MaybeFunction = Union{Function, Nothing} +const MaybeString = Union{AbstractString, Nothing} +const MaybeStringInteger = Union{AbstractString, Integer, Nothing} # for at in tree insert +const MaybeVector = Union{Vector, Nothing} +const MaybeWidget = Union{Widget, Nothing} +const MaybeBool = Union{Bool, Nothing} diff --git a/test/runtests.jl b/test/runtests.jl index b71bbb4..42bc7e1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ ## Tests using Tk -using Base.Test +using Compat +using Compat.Test @testset "Toplevel" begin w = Toplevel("Toplevel", 400, 400)