Tk.jl example on OS X

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?

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

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

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



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

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:

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.


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

QML file:

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

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.

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.

1 Like

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”.

GtkBuilder looks like a lot of fun though!

@lobingera I’ll go through your example on one of these days.

I had to replace

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


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

in the gist example to get working. gave an error:

ERROR: LoadError: 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.

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?

it should be

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

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

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

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.