Skip to content

Commit

Permalink
Updates for Julia 0.6, drop 0.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Mar 13, 2017
1 parent c44f11b commit 32ee8c0
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 345 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: julia
os:
- linux
julia:
- 0.4
- 0.5
- nightly
notifications:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Julia interface to the Tk windowing toolkit.

[![Tk](http://pkg.julialang.org/badges/Tk_0.3.svg)](http://pkg.julialang.org/?pkg=Tk&ver=0.3)
[![Tk](http://pkg.julialang.org/badges/Tk_0.4.svg)](http://pkg.julialang.org/?pkg=Tk&ver=0.4)
[![Build Status](https://travis-ci.org/JuliaLang/Tk.jl.svg?branch=master)](https://travis-ci.org/JuliaLang/Tk.jl)
[![Coverage Status](https://coveralls.io/repos/JuliaLang/Tk.jl/badge.svg)](https://coveralls.io/r/JuliaLang/Tk.jl)
[![Tk](http://pkg.julialang.org/badges/Tk_0.5.svg)](http://pkg.julialang.org/?pkg=Tk)
[![Tk](http://pkg.julialang.org/badges/Tk_0.6.svg)](http://pkg.julialang.org/?pkg=Tk)
[![Build Status](https://travis-ci.org/JuliaGraphics/Tk.jl.svg?branch=master)](https://travis-ci.org/JuliaGraphics/Tk.jl)
[![Coverage Status](https://coveralls.io/repos/JuliaGraphics/Tk.jl/badge.svg)](https://coveralls.io/r/JuliaGraphics/Tk.jl)

The documentation for this package is in the `examples` directory.
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.4
Compat 0.7.20
julia 0.5
Compat 0.17.0
Cairo
Graphics 0.1
BinDeps 0.2.2-
Expand Down
2 changes: 1 addition & 1 deletion examples/manipulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using Winston
end


abstract ManipulateWidget
@compat abstract type ManipulateWidget end
get_label(widget::ManipulateWidget) = widget.label

type SliderWidget <: ManipulateWidget
Expand Down
6 changes: 3 additions & 3 deletions examples/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ short_summary(x) = summary(x)
short_summary(x::AbstractString) = "A string"

## update ids, returning false if the same, true if not
__ids__ = Array(AbstractString, 0)
__ids__ = Vector{AbstractString}(0)
function update_ids(m::Module)
global __ids__
nms = get_names(m)
Expand All @@ -31,8 +31,8 @@ end


negate(x::Bool, val::Bool) = val ? !x : x
MaybeRegex = (@compat Union{(@compat Void), Regex})
MaybeType = (@compat Union{(@compat Void), DataType})
const MaybeRegex = Union{Void, Regex}
const MaybeType = Union{Void, DataType}

## get array of names and summaries
## m module
Expand Down
8 changes: 4 additions & 4 deletions src/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ destroy(widget::Tk_Toplevel) = tcl("destroy", widget)
## Labelframe
Labelframe(parent::Widget, text::AbstractString) = Labelframe(parent, text=text)
get_value(widget::Tk_Labelframe) = cget(widget, "text")
set_value(widget::Tk_Labelframe, text::AbstractString) = configure(widget, @compat Dict(:text=> text))
set_value(widget::Tk_Labelframe, text::AbstractString) = configure(widget, Dict(:text=> text))

## Notebook
function page_add(child::Widget, label::AbstractString)
Expand Down Expand Up @@ -132,7 +132,7 @@ function forget(parent::TTk_Container, child::Widget)
end

## grid ...
IntOrRange = (@compat Union{Integer, UnitRange})
IntOrRange = Union{Integer, UnitRange}
function grid(child::Widget, row::IntOrRange, column::IntOrRange; kwargs...)
path = get_path(child)
if isa(row, UnitRange) rowspan = 1 + maximum(row) - minimum(row) else rowspan = 1 end
Expand Down Expand Up @@ -211,10 +211,10 @@ parent(w::Tk_Widget) = parent(w.w)
parent(c::Canvas) = parent(c.c)

# For toplevel it's obvious how to wrap it...
function toplevel(w::(@compat Union{TkWidget, Tk_Widget, Canvas}))
function toplevel(w::Union{TkWidget, Tk_Widget, Canvas})
p = parent(w)
pold = p
while !is(p, nothing)
while p !== nothing
pold = p
p = parent(p)
end
Expand Down
64 changes: 13 additions & 51 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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::(@compat Void)) = ""
to_tcl(x::Void) = ""
has_space = r" "
to_tcl(x::AbstractString) = ismatch(has_space, x) ? "{$x}" : x
type I x::MaybeString end # avoid wrapping in {} and ismatch call.
Expand Down Expand Up @@ -112,55 +112,17 @@ wm(window::Widget, prop::AbstractString, args...; kwargs...) = tcl("wm", prop, w

## Take a function, get its args as array of symbols. There must be better way...
## Helper functions for bind callback
if VERSION > v"0.5-"
function get_args(li::LambdaInfo)
argnames = li.slotnames[1:li.nargs]
if _arg_offset == 0
return argnames
else
return argnames[_arg_offset:end]
end
end

get_args(m::Method) = get_args(m.lambda_template)
get_args(f::Function) = get_args(first(methods(f)).lambda_template)

else

function get_args(li::LambdaStaticData)
e = li.ast
if !isa(e, Expr)
e = Base.uncompressed_ast(li)
end
argnames = e.args[1]
## return array of symbols -- not args
if isa(argnames[1], Expr)
argnames = map(u -> u.args[1], argnames)
end

if _arg_offset == 0
return argnames
else
return argnames[_arg_offset:end]
end
end

function get_args(m::Method)
li = m.func
if !isa(li,LambdaStaticData)
li = li.code
end
get_args(li)
end

function get_args(f::Function)
try
get_args(first(methods(f)).func)
catch e
get_args(f.code)
m = first(methods(f))
@static if VERSION >= v"0.6.0-dev.624"
slots = m.source.slotnames
n = m.nargs
else
slots = m.lambda_template.slotnames
n = m.lambda_template.nargs
end
end

argnames = slots[1:n]
return _arg_offset == 0 ? argnames : argnames[_arg_offset:end]
end

_arg_offset = 0
Expand Down Expand Up @@ -189,7 +151,7 @@ end
bind(widget::Canvas, event::AbstractString, callback::Function) = bind(widget.c, event, callback)

## for use with do style
bind(callback::Function, widget::(@compat Union{Widget, Canvas}), event::AbstractString) = bind(widget, event, callback)
bind(callback::Function, widget::Union{Widget, Canvas}, event::AbstractString) = bind(widget, event, callback)

## Binding to mouse wheel
function bindwheel(widget::Widget, modifier::AbstractString, callback::Function, tkargs::AbstractString = "")
Expand Down Expand Up @@ -262,8 +224,8 @@ end
type TclAfter
cb::Function
run::Bool
start::(@compat Union{(@compat Void), Function})
stop::(@compat Union{(@compat Void), Function})
start::Union{Void, Function}
stop::Union{Void, Function}
ms::Int

function TclAfter(ms, cb::Function)
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, (@compat Void)) args["parent"] = get_path(parent) end
if !isa(parent, Void) 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
Expand Down
10 changes: 5 additions & 5 deletions src/tkwidget.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function init()
@static if is_windows()
htcl = ccall((:GetModuleHandleA,:kernel32),stdcall,Csize_t,
(Ptr{UInt8},),libtcl)
tclfile = Array(UInt8,260)
tclfile = Vector{UInt8}(260)
len = ccall((:GetModuleFileNameA,:kernel32),stdcall,Cint,
(Csize_t,Ptr{UInt8},Cint),htcl,tclfile,length(tclfile))
if len > 0
Expand Down Expand Up @@ -103,7 +103,7 @@ end
type TkWidget
path::String
kind::String
parent::(@compat Union{TkWidget,Void})
parent::Union{TkWidget,Void}

let ID::Int = 0
function TkWidget(parent::TkWidget, kind)
Expand Down Expand Up @@ -267,9 +267,9 @@ end

@static if is_apple()
if @compat Sys.WORD_SIZE == 32
typealias CGFloat Float32
const CGFloat = Float32
else
typealias CGFloat Float64
const CGFloat = Float64
end
objc_msgSend{T}(id, uid, ::Type{T}=Ptr{Void}) = ccall(:objc_msgSend, T, (Ptr{Void}, Ptr{Void}),
id, ccall(:sel_getUid, Ptr{Void}, (Ptr{UInt8},), uid))
Expand Down Expand Up @@ -368,7 +368,7 @@ function render_to_cairo(f::Function, w::TkWidget, clipped::Bool=true)
return
end
@static if is_windows()
state = Array(UInt8, sizeof(Int)*2) # 8.4, 8.5, 8.6
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}),
jl_tkwin_display(win), drawable, state)
Expand Down
20 changes: 10 additions & 10 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## Abstract types
abstract Tk_Widget
abstract TTk_Widget <: Tk_Widget ## for ttk::widgets
abstract TTk_Container <: Tk_Widget ## for containers (frame, labelframe, ???)
@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, ???)

Widget = (@compat Union{TkWidget, Tk_Widget, Canvas, AbstractString})
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)
MaybeFunction = (@compat Union{Function, (@compat Void)})
MaybeString = (@compat Union{AbstractString, (@compat Void)})
MaybeStringInteger = (@compat Union{AbstractString, Integer, (@compat Void)}) # for at in tree insert
MaybeVector = (@compat Union{Vector, (@compat Void)})
MaybeWidget = (@compat Union{Widget, (@compat Void)})
MaybeBool = (@compat Union{Bool, (@compat Void)})
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}
14 changes: 7 additions & 7 deletions src/widgets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ end
Label(parent::Widget, text::AbstractString, image::Tk_Image) = Label(parent, text=tk_string_escape(text), image=image, compound="left")
Label(parent::Widget, text::AbstractString) = Label(parent, text=tk_string_escape(text))
Label(parent::Widget, image::Tk_Image) = Label(parent, image=image, compound="image")
get_value(widget::(@compat Union{Tk_Button, Tk_Label})) = widget[:text]
function set_value(widget::(@compat Union{Tk_Label, Tk_Button}), value::AbstractString)
get_value(widget::Union{Tk_Button, Tk_Label}) = widget[:text]
function set_value(widget::Union{Tk_Label, Tk_Button}, value::AbstractString)
variable = cget(widget, "textvariable")
(variable == "") ? widget[:text] = tk_string_escape(value) : tclvar(variable, value)
end
Expand Down Expand Up @@ -103,7 +103,7 @@ set_items(widget::Tk_Checkbutton, value::AbstractString) = widget[:text] = tk_st
type Tk_Radiobutton <: TTk_Widget
w::TkWidget
end
MaybeTkRadioButton = (@compat Union{Void, Tk_Radiobutton})
MaybeTkRadioButton = Union{Void, Tk_Radiobutton}

function Radiobutton(parent::Widget, group::MaybeTkRadioButton, label::AbstractString)

Expand All @@ -125,12 +125,12 @@ set_items(widget::Tk_Radiobutton, value::AbstractString) = configure(widget, tex
type Tk_Radio <: TTk_Widget
w::TkWidget
buttons::Vector
orient::(@compat Union{Void, AbstractString})
orient::Union{Void, AbstractString}
end

function Radio{T<:AbstractString}(parent::Widget, labels::Vector{T}, orient::AbstractString)
n = size(labels)[1]
rbs = Array(Tk_Radiobutton, n)
rbs = Vector{Tk_Radiobutton}(n)
frame = Frame(parent)

rbs[1] = Radiobutton(frame, tk_string_escape(labels[1]))
Expand Down Expand Up @@ -314,7 +314,7 @@ get_value(widget::Tk_Progressbar) = round(Int, float(widget[:value]))
set_value(widget::Tk_Progressbar, value::Integer) = widget[:value] = min(100, max(0, value))

## Image
MaybeImage = (@compat Union{Void, Tk_Image})
MaybeImage = Union{Void, Tk_Image}
to_tcl(x::Tk_Image) = x.w

function Image(fname::AbstractString)
Expand Down Expand Up @@ -440,7 +440,7 @@ type Tk_Treeview <: TTk_Widget
end
type TreeNode node::AbstractString end
to_tcl(x::TreeNode) = x.node
MaybeTreeNode = (@compat Union{TreeNode, Void})
MaybeTreeNode = Union{TreeNode, Void}

## Special Tree cases

Expand Down
Loading

0 comments on commit 32ee8c0

Please sign in to comment.