Tk.jl example on OS X


#1

I’m trying the sketch.jl example from the Tk.jl package:

On OS X this gives a drawing canvas that is only updated when I switch windows, i.e., force the drawing to be updated. When I add an explicit Tk.update() after line 27, I get spurious lines in the drawing:

Anyone knows how to solve this? Is this also a reported issue on linux?


#2

With linux i can sketch. When i switch windows (MAP/UNMAP in X11) i get a sigfault…


#3

Gtk.jl does the job!

using Gtk.ShortNames, Graphics

function sketch_window()
    widget = @Canvas()
    window = @Window(widget, "MyCanvas")

    lastx = 0; lasty = 0;

    widget.mouse.button1press = @guarded function (widget, event)
        lastx = event.x; lasty = event.y
    end

    widget.mouse.button1motion = @guarded function (widget, event)
        ctx = getgc(widget)
        move_to(ctx, lastx, lasty)
        line_to(ctx, event.x, event.y)
        stroke(ctx)
        reveal(widget)
        lastx = event.x; lasty = event.y
    end

    show(widget)
end

sketch_window()

#4

I was about to mention this (use Gtk), but you sounded like, you’re focused on Tk…


#5

I was just trying out some of the possibilities for designing a GUI with Julia. Other comments/tricks I should know about are welcome :slight_smile:


#6

I’m a gtk user and apart from some BinDeps problems quite satisfied. Recently we had this GUI thread: Julia for GUI app with other ideas for GUI implementations.


#7

I couldn’t resist taking a stab at this with QML.jl :slight_smile:
Julia code:

QML file:


#8

~20 lines vs. ~40 lines -> Gtk is more efficient (SCNR)


#9

Yes, but on the other hand you get clean separation between GUI (the QML) and data (just the Point here). The QML file, which is the longest, could easily be generated using a GUI designer such as Qt Creator.


#10

I’m not seriously (SCNR-> sorry, could not resist…) comparing the efficiency of different UI toolkits. We see convergence here: Similar code for similar problems.
btw: about the code and GUI split: GtkBuilder exists and you can do an xml desciption of a GUI or build it with glade and run it or change it dynamically. Convergence again.


#11

Yes, I figured as much (though I had to google SCNR) :slight_smile:
It’s good to have options for sure, as there is no “one size fits all”.


#12

GtkBuilder looks like a lot of fun though!

@lobingera I’ll go through your example on https://gist.github.com/lobingera/9722861 one of these days.


#13

I had to replace

b = Gtk.GtkBuilder(filename=ARGS[1]);

with

b = Gtk.GtkBuilderLeaf(filename=ARGS[1]);

in the gist example to get fwindow2.glade working.

gui1.glade gave an error:

ERROR: LoadError: gui1.glade:247:1 Invalid object type 'EMC_ToggleAction_ESTOP'
 in Gtk.GLib.GError(::Gtk.##181#184{String,Gtk.GtkBuilderLeaf}) at /home/kjwiik/.julia/v0.5/Gtk/src/GLib/gerror.jl:17
 in #push!#179(::Void, ::String, ::Void, ::Function, ::Gtk.GtkBuilderLeaf) at /home/kjwiik/.julia/v0.5/Gtk/src/builder.jl:20
 in (::Base.#kw##push!)(::Array{Any,1}, ::Base.#push!, ::Gtk.GtkBuilderLeaf) at ./<missing>:0
 in #GtkBuilderLeaf#178(::Void, ::String, ::Void, ::Type{T}) at /home/kjwiik/.julia/v0.5/Gtk/src/builder.jl:4
 in (::Core.#kw#Type)(::Array{Any,1}, ::Type{Gtk.GtkBuilderLeaf}) at ./<missing>:0
 in include_from_node1(::String) at ./loading.jl:488
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318

Maybe something has changed after the example was written.


#14

i think this was (see gist 3 years ago) pre-v0.4 and for sure something is different since then. @tknopp is known to be a glade/GtkBuilder user; Do you have a more recent working example?


#15

it should be

b = Gtk.@GtkBuilder(filename=ARGS[1]);

All Gtk types got this macro constructor since they are actually abstract.


#16

The gui1.glade error seems to be coming from a deprecated Gtk2 widget.


#17

Yes indeed one should try to ensure using Gtk3 widgets. Gtk.jl itself has some support for Gtk2 but it is far from complete and in my opinion not advisable to use Gtk2 anymore.