Skip to content

Commit

Permalink
Merge pull request #112 from rened/rc2fixes
Browse files Browse the repository at this point in the history
fixes for 0.4rc2
  • Loading branch information
timholy committed Oct 13, 2015
2 parents 7153599 + 5f780e9 commit c29edfd
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 151 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
language: julia
os:
- osx
- linux
julia:
- release
- 0.3
- 0.4
- nightly
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- xvfb-run julia -e 'Pkg.clone(pwd()); Pkg.build("Tk"); Pkg.test("Tk"; coverage=true)';
- julia -e 'Pkg.clone("Winston"); Pkg.checkout("Tk")'
- xvfb-run julia -e 'Pkg.build("Tk"); Pkg.test("Tk"; coverage=true)';
# - xvfb-run julia -e 'Pkg.clone(pwd()); Pkg.build("Tk"); Pkg.test("Tk"; coverage=true)';
after_success:
- julia -e 'cd(Pkg.dir("Tk")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
35 changes: 18 additions & 17 deletions examples/manipulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using Winston
using Tk
using Compat


function render(c, p)
Expand Down Expand Up @@ -39,9 +40,9 @@ function make_widget(parent, widget::SliderWidget)
sl
end

slider(nm::String, label::String, rng::UnitRange, initial::Integer) = SliderWidget(nm, label, initial, rng)
slider(nm::String, label::String, rng::UnitRange) = slider(nm, label, rng, minimum(rng))
slider(nm::String, rng::UnitRange) = slider(nm, nm, rng, minimum(rng))
slider(nm::AbstractString, label::AbstractString, rng::UnitRange, initial::Integer) = SliderWidget(nm, label, initial, rng)
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
nm
Expand All @@ -59,12 +60,12 @@ function make_widget(parent, widget::PickerWidget)
end


picker{T <: String}(nm::String, label::String, vals::Vector{T}, initial) = PickerWidget(nm, label, initial, vals)
picker{T <: String}(nm::String, label::String, vals::Vector{T}) = picker(nm, label, vals, vals[1])
picker{T <: String}(nm::String, vals::Vector{T}) = picker(nm, nm, vals)
picker(nm::String, label::String, vals::Dict, initial) = PickerWidget(nm, label, vals, initial)
picker(nm::String, label::String, vals::Dict) = PickerWidget(nm, label, vals, [string(k) for (k,v) in vals][1])
picker(nm::String, vals::Dict) = picker(nm, nm, vals)
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::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
nm
Expand All @@ -78,8 +79,8 @@ function make_widget(parent, widget::CheckboxWidget)
end
get_label(widget::CheckboxWidget) = nothing

checkbox(nm::String, label::String, initial::Bool) = CheckboxWidget(nm, label, initial)
checkbox(nm::String, label::String) = checkbox(nm, label, false)
checkbox(nm::AbstractString, label::AbstractString, initial::Bool) = CheckboxWidget(nm, label, initial)
checkbox(nm::AbstractString, label::AbstractString) = checkbox(nm, label, false)


type ButtonWidget <: ManipulateWidget
Expand All @@ -88,7 +89,7 @@ type ButtonWidget <: ManipulateWidget
end
make_widget(parent, widget::ButtonWidget) = Button(parent, widget.label)
get_label(widget::ButtonWidget) = nothing
button(label::String) = ButtonWidget(label, nothing)
button(label::AbstractString) = ButtonWidget(label, nothing)


## Add text widget to gather one-line of text
Expand All @@ -98,13 +99,13 @@ type EntryWidget <: ManipulateWidget
initial
end
make_widget(parent, widget::EntryWidget) = Entry(parent, widget.initial)
entry(nm::String, label::String, initial::String) = EntryWidget(nm, label, initial)
entry(nm::String, initial::String) = EntryWidget(nm, nm, initial)
entry(nm::String) = EntryWidget(nm, nm, "{}")
entry(nm::AbstractString, label::AbstractString, initial::AbstractString) = EntryWidget(nm, label, initial)
entry(nm::AbstractString, initial::AbstractString) = EntryWidget(nm, nm, initial)
entry(nm::AbstractString) = EntryWidget(nm, nm, "{}")


## Expression returns a plot object. Use names as values
function manipulate(ex::Union(Symbol,Expr), controls...)
function manipulate(ex::(@compat Union{Symbol,Expr}), controls...)
widgets = Array(Tk.Widget, 0)

w = Toplevel("Manipulate", 800, 500)
Expand All @@ -126,7 +127,7 @@ function manipulate(ex::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], Nothing)
if !isa(keys[i], @compat Void)
d[keys[i]] = vals[i]
end
end
Expand Down
12 changes: 6 additions & 6 deletions examples/workspace.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## simple workspace browser for julia
using Tk
using Tk, Compat

## Some functions to work with a module
function get_names(m::Module)
Expand All @@ -12,10 +12,10 @@ unique_id(x) = string(object_id(x))
## short_summary
## can customize description here
short_summary(x) = summary(x)
short_summary(x::String) = "A string"
short_summary(x::AbstractString) = "A string"

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


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

## get array of names and summaries
## m module
## pat regular expression to filter by
## dtype: DataType or UnionType to filter out by.
## dtype: DataType or Union to filter out by.
## dtypefilter: If true not these types, if false only these types
function get_names_summaries(m::Module, pat::MaybeRegex, dtype::MaybeType, dtypefilter::Bool)
nms = get_names(m)
Expand Down
28 changes: 14 additions & 14 deletions src/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ type Tk_Panedwindow <: TTk_Container w::TkWidget; children::Vector{Tk_Widget} en
==(a::TTk_Container, b::TTk_Container) = isequal(a.w, b.w) && typeof(a) == typeof(b)

## Toplevel window
function Toplevel(;title::String="Toplevel Window", width::Integer=200, height::Integer=200, visible::Bool=true)
function Toplevel(;title::AbstractString="Toplevel Window", width::Integer=200, height::Integer=200, visible::Bool=true)
w = Window(title, width, height, visible)
Tk_Toplevel(w, Tk_Widget[])
end
Toplevel(title::String, width::Integer, height::Integer, visible::Bool) = Toplevel(title=title, width=width, height=height, visible=visible)
Toplevel(title::String, width::Integer, height::Integer) = Toplevel(title=title, width=width, height=height)
Toplevel(title::String, visible::Bool) = Toplevel(title=title, visible=visible)
Toplevel(title::String) = Toplevel(title=title)
Toplevel(title::AbstractString, width::Integer, height::Integer, visible::Bool) = Toplevel(title=title, width=width, height=height, visible=visible)
Toplevel(title::AbstractString, width::Integer, height::Integer) = Toplevel(title=title, width=width, height=height)
Toplevel(title::AbstractString, visible::Bool) = Toplevel(title=title, visible=visible)
Toplevel(title::AbstractString) = Toplevel(title=title)


## Sizing of toplevel windows should refer to the geometry
Expand All @@ -30,7 +30,7 @@ set_size{T <: Integer}(widget::Tk_Toplevel, widthheight::Vector{T}) = set_size(w


get_value(widget::Tk_Toplevel) = wm(widget, "title")
set_value(widget::Tk_Toplevel, value::String) = wm(widget, "title", value)
set_value(widget::Tk_Toplevel, value::AbstractString) = wm(widget, "title", value)

function set_visible(widget::Tk_Toplevel, value::Bool)
value = value ? "normal" : "withdrawn"
Expand Down Expand Up @@ -62,18 +62,18 @@ destroy(widget::Tk_Toplevel) = tcl("destroy", widget)
## nothing to add...

## Labelframe
Labelframe(parent::Widget, text::String) = Labelframe(parent, text=text)
Labelframe(parent::Widget, text::AbstractString) = Labelframe(parent, text=text)
get_value(widget::Tk_Labelframe) = cget(widget, "text")
set_value(widget::Tk_Labelframe, text::String) = configure(widget, @compat Dict(:text=> text))
set_value(widget::Tk_Labelframe, text::AbstractString) = configure(widget, @compat Dict(:text=> text))

## Notebook
function page_add(child::Widget, label::String)
function page_add(child::Widget, label::AbstractString)
parent = winfo(child, "parent")
tcl(parent, "add", child, text = label)
end


function page_insert(child::Widget, index::Integer, label::String)
function page_insert(child::Widget, index::Integer, label::AbstractString)
parent = winfo(child, "parent")
tcl(parent, "insert", index, child, text = label)
end
Expand All @@ -85,7 +85,7 @@ no_tabs(widget::Tk_Notebook) = length(split(tcl(widget, "tabs")))

## Panedwindow
## orient in "horizontal" or "vertical"
Panedwindow(widget::Widget, orient::String) = Panedwindow(widget, orient = orient)
Panedwindow(widget::Widget, orient::AbstractString) = Panedwindow(widget, orient = orient)

function page_add(child::Widget, weight::Integer)
parent = winfo(child, "parent")
Expand Down Expand Up @@ -132,7 +132,7 @@ function forget(parent::TTk_Container, child::Widget)
end

## grid ...
IntOrRange = Union(Integer, UnitRange)
IntOrRange = (@compat 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 @@ -168,7 +168,7 @@ function formlayout(child::Tk_Widget, label::MaybeString)
sz = map(x->parse(Int, x), split(tcl_eval("grid size $master"))) ## columns, rows
nrows = sz[2]

if isa(label, String)
if isa(label, AbstractString)
l = Label(child.w.parent, label)
grid(l, nrows + 1, 1)
grid_configure(l, sticky = "ne")
Expand Down Expand Up @@ -211,7 +211,7 @@ 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::Union(TkWidget, Tk_Widget, Canvas))
function toplevel(w::(@compat Union{TkWidget, Tk_Widget, Canvas}))
p = parent(w)
pold = p
while !is(p, nothing)
Expand Down
46 changes: 23 additions & 23 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ show(io::IO, widget::Tk_Widget) = print(io, "Tk widget of type $(typeof(widget))


tcl_eval("set auto_path")
tcl_add_path(path::String) = tcl_eval("lappend auto_path $path")
tcl_require(pkg::String) = tcl_eval("package require $pkg")
tcl_add_path(path::AbstractString) = tcl_eval("lappend auto_path $path")
tcl_require(pkg::AbstractString) = tcl_eval("package require $pkg")


## helper to get path
## assumes Tk_Widgets have w property storing TkWidget
get_path(path::String) = path
get_path(path::AbstractString) = path
get_path(widget::Tk_Widget) = get_path(widget.w)
get_path(widget::TkWidget) = get_path(widget.path)
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::Nothing) = ""
to_tcl(x::(@compat Void)) = ""
has_space = r" "
to_tcl(x::String) = ismatch(has_space, x) ? "{$x}" : x
to_tcl(x::AbstractString) = ismatch(has_space, x) ? "{$x}" : x
type 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 <: String}(x::Vector{T})
function to_tcl{T <: AbstractString}(x::Vector{T})
tmp = join(["{$i}" for i in x], " ")
"[list $tmp ]"
end
Expand Down Expand Up @@ -51,20 +51,20 @@ end
## escape a string
## http://stackoverflow.com/questions/5302120/general-string-quoting-for-tcl
## still need to escape \ (but not {})
function tk_string_escape(x::String)
function tk_string_escape(x::AbstractString)
tcl_eval("set stringescapevariable [subst -nocommands -novariables {$x}]")
"\$stringescapevariable"
end
## tclvar for textvariables
## Work with a text variable. Stores values as strings. Must coerce!
## getter -- THIS FAILS IN A CALLBACK!!!
#function tclvar(nm::String)
#function tclvar(nm::AbstractString)
# cmd = "return \$::" * nm
# tcl(cmd)
#end

## setter
function tclvar(nm::String, value)
function tclvar(nm::AbstractString, value)
tcl("set", nm, value)
end

Expand All @@ -84,30 +84,30 @@ setindex!(widget::Widget, value, prop::Symbol) = configure(widget, @compat Dict(

## Get values
## cget
function cget(widget::Widget, prop::String, coerce::MaybeFunction)
function cget(widget::Widget, prop::AbstractString, coerce::MaybeFunction)
out = tcl(widget, "cget", "-$prop")
isa(coerce, Function) ? coerce(out) : out
end
cget(widget::Widget, prop::String) = cget(widget, prop, nothing)
cget(widget::Widget, prop::AbstractString) = cget(widget, prop, nothing)
## convenience
getindex(widget::Widget, prop::Symbol) = cget(widget, string(prop))

## Identify widget at x,y
identify(widget::Widget, x::Integer, y::Integer) = tcl(widget, "identify", "%x", "%y")

## state(w, "!disabled")
state(widget::Widget, state::String) = tcl(widget, "state", state)
instate(widget::Widget, state::String) = tcl(widget, "instate", state) == "1" # return Bool
state(widget::Widget, state::AbstractString) = tcl(widget, "state", state)
instate(widget::Widget, state::AbstractString) = tcl(widget, "instate", state) == "1" # return Bool

## tkwinfo
function winfo(widget::Widget, prop::String, coerce::MaybeFunction)
function winfo(widget::Widget, prop::AbstractString, coerce::MaybeFunction)
out = tcl("winfo", prop, widget)
isa(coerce, Function) ? coerce(out) : out
end
winfo(widget::Widget, prop::String) = winfo(widget, prop, nothing)
winfo(widget::Widget, prop::AbstractString) = winfo(widget, prop, nothing)

## wm.
wm(window::Widget, prop::String, args...; kwargs...) = tcl("wm", prop, window, args...; kwargs...)
wm(window::Widget, prop::AbstractString, args...; kwargs...) = tcl("wm", prop, window, args...; kwargs...)


## Take a function, get its args as array of symbols. There must be better way...
Expand Down Expand Up @@ -144,7 +144,7 @@ end
## Function callbacks have first argument path that is ignored
## others match percent substitution
## e.g. (path, W, x, y) -> x will have W, x and y available through %W %x %y bindings
function bind(widget::Widget, event::String, callback::Function)
function bind(widget::Widget, event::AbstractString, callback::Function)
if event == "command"
configure(widget, command = callback)
else
Expand All @@ -160,13 +160,13 @@ function bind(widget::Widget, event::String, callback::Function)
tcl_eval(cmd)
end
end
bind(widget::Canvas, event::String, callback::Function) = bind(widget.c, event, callback)
bind(widget::Canvas, event::AbstractString, callback::Function) = bind(widget.c, event, callback)

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

## Binding to mouse wheel
function bindwheel(widget::Widget, modifier::String, callback::Function, tkargs::String = "")
function bindwheel(widget::Widget, modifier::AbstractString, callback::Function, tkargs::AbstractString = "")
path = get_path(widget)
if !isempty(modifier) && !endswith(modifier,"-")
modifier = string(modifier, "-")
Expand Down Expand Up @@ -217,7 +217,7 @@ end

## Need this pattern to make a widget
## Parent is not a string, but TkWidget or Tk_Widget instance
function make_widget(parent::Widget, str::String; kwargs...)
function make_widget(parent::Widget, str::AbstractString; kwargs...)
path = isa(parent, Tk_Widget) ? parent.w : parent
w = TkWidget(path, str)
tcl(str, w; kwargs...)
Expand All @@ -236,8 +236,8 @@ end
type TclAfter
cb::Function
run::Bool
start::Union(Nothing, Function)
stop::Union(Nothing, Function)
start::(@compat Union{(@compat Void), Function})
stop::(@compat Union{(@compat Void), Function})
ms::Int

function TclAfter(ms, cb::Function)
Expand Down
8 changes: 4 additions & 4 deletions src/dialogs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ GetSaveFile() = tcl("tk_getSaveFile")
ChooseDirectory() = tcl("tk_chooseDirectory")

## Message box
function Messagebox(parent::MaybeWidget; title::String="", message::String="", detail::String="")
function Messagebox(parent::MaybeWidget; title::AbstractString="", message::AbstractString="", detail::AbstractString="")
args = Dict()
if !isa(parent, Nothing) args["parent"] = get_path(parent) end
if !isa(parent, (@compat 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 All @@ -17,5 +17,5 @@ function Messagebox(parent::MaybeWidget; title::String="", message::String="", d
tcl("tk_messageBox", args)
end
Messagebox(;kwargs...) = Messagebox(nothing; kwargs...)
Messagebox(parent::Widget, message::String) = Messagebox(parent, message=message)
Messagebox(message::String) = Message(nothing, message=message)
Messagebox(parent::Widget, message::AbstractString) = Messagebox(parent, message=message)
Messagebox(message::AbstractString) = Message(nothing, message=message)
Loading

0 comments on commit c29edfd

Please sign in to comment.