many tanks for this - that looks perfect.

 unfortunately my Gtk installation seems broken, so it will be a while 
until I can try this out.

Christoph


On Friday, 15 April 2016 15:42:45 UTC+1, Andreas Lobinger wrote:
>
> Hello colleague,
>
> On Friday, April 15, 2016 at 4:00:34 PM UTC+2, Christoph Ortner wrote:
>>
>>
>> I am trying to use Compose.jl directly instead of going through a 
>> plotting package. From iPython notebooks invoking compose will immediately 
>> create the output. 
>>
>> But when I am in the REPL, how do I plot to a window, similar as in 
>> PyPlot?
>>
>
>  the following works on my REPL with Gtk, and Compose (incl. Cairo):
>
>                _
>    _       _ _(_)_     |  A fresh approach to technical computing
>   (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
>    _ _   _| |_  __ _   |  Type "?help" for help.
>   | | | | | | |/ _` |  |
>   | | |_| | | | (_| |  |  Version 0.4.4-pre+218 (2016-01-29 21:53 UTC)
>  _/ |\__'_|_|_|\__'_|  |  Commit 386d77b* (76 days old release-0.4)
> |__/                   |  x86_64-linux-gnu
>
> julia> using Gtk
>
> julia> c = Gtk.@GtkCanvas(400,300);
>
> julia> w = Gtk.@GtkWindow(c,"data win");
>
> julia> show(c);
>
> julia> using Compose
> WARNING: using Compose.w in module Main conflicts with an existing 
> identifier.
>
> julia> function sierpinski(n)
>            if n == 0
>                compose(context(), polygon([(1,1), (0,1), (1/2, 0)]))
>            else
>                t = sierpinski(n - 1)
>                compose(context(),
>                        (context(1/4,   0, 1/2, 1/2), t),
>                        (context(  0, 1/2, 1/2, 1/2), t),
>                        (context(1/2, 1/2, 1/2, 1/2), t))
>            end
>        end
> sierpinski (generic function with 1 method)
>
> julia> co = sierpinski(3);
>
> julia> Gtk.draw(c) do widget
>        Compose.draw(CAIROSURFACE(c.back),co)
>        end
>
> julia> co = sierpinski(5);
>
> julia> co = sierpinski(2);
>
> julia> Gtk.draw(c)
>
>
>    - I use GtkCanvas and a Window around it.
>    - Then the sierpinski demo from the Compose Readme, with the Compose 
>    context as output.
>    - Then i connect Gtk.draw function for c (=GtkCanvas) with the 
>    Compose.draw function drawing to CAIROSURFACE as backend and use the 
> c.back 
>    - which is something like a Cairo surface (actually it's a pointer to a 
>    Cairo context, but the surface can be reconstructed with that).
>    - The drawing (co) is redrawn everytime there is an expose signal from 
>    the window to the canvas, usually when you resize or map the window. You 
>    can call Gtk.draw(c) manually if you updated the co.
>
> Should work with standard Gtk and Compose (please report if not, i might 
> need some PR then).
>
>
>

Reply via email to