# Drawing on widgets defined in a layout produced from Glade

**URL:** https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197
**Category:** Visualization
**Created:** [August 6, 2019, 2:37am UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197 "2019-08-06T02:37:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)
#### Post date: [August 6, 2019, 2:37am UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/1 "2019-08-06T02:37:18Z")

</div>

I can draw on canvases (created via `Gtk.Canvas`) which are are then pushed onto containers, and have their draw functions set to functions I have written (eg. `canvasA.draw = drawFnA`) and in that draw function use the some alteration from the examples for drawing.

Using the Gtkbuilder I can import glade layouts to produce windows and in the tool options for a panel to draw or place images I see there are ‘images’ and ‘drawing areas’. It appears that ‘images’ would be the most flexible and the XML output from glade is:

```julia
 <object class="GtkImage" id="imageOne">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="stock">gtk-missing-image</property>
          </object>

```

How can I reference this object class to then define the methods that will be called by either Gtk or myself explicitly in order to draw images, or place images upon that area?

I tried using an example from `https://github.com/tknopp/Winston.jl/blob/master/src/gtk.jl`, where there is the macro usage `c = Gtk.@Canvas()` but does not compile as it has ‘too few arguments’.

**In general I am struggling to see how I can translate the Gtk documentation into Julia code that I can utilize.** ([gtk on images](https://developer.gnome.org/gtkmm-tutorial/stable/sec-draw-images.html.en)

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [August 6, 2019, 5:51am UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/2 "2019-08-06T05:51:32Z")

</div>

I wish i could help. I just wanted to say that I’m also interested in the answer to your question, and hoping someone can help.

I’m also very interested in seeing your canvas code, if it’s possible for you to share it.

I’m just getting started with it and having problems just figuring out how to get it to be created properly in glade using some sort of container.

(obviously i 'm very new to Gtk).

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [August 6, 2019, 8:21am UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/3 "2019-08-06T08:21:20Z")

</div>

The macros for widget creation have been deprecated in Gtk.jl - so most likely you need a different call to create a Canvas.

The examples that use getgc have some problems in general Gtk usage, as Gtk.jl actually replaces the ‘plain’ GtkCanvas with julia code that does own logic for keeping a background cairo surface bitmap and redraws from that to the widget on screen. The getgc afaiu is only defined for that setup. I have somehwere an example to use a ‘plain’ canvas and use the cairo context it provides.

---

<div class="post-metadata">

### Author: ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)
#### Post date: [August 6, 2019, 2:42pm UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/4 "2019-08-06T14:42:02Z")

</div>

In this thread `https://discourse.julialang.org/t/resetting-the-canvas-within-cairo-jl-and-gtk-jl-for-an-image-selection-viewing-gui/24251` there is the key material for the painting on the canvas, but not on an object defined in glade. Tell me if you’d like more info on how I used it.

---

<div class="post-metadata">

### Author: ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)
#### Post date: [August 6, 2019, 3:00pm UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/5 "2019-08-06T15:00:12Z")

</div>

`getgc()` can be used in the drawing function for the function that handles the drawing of a specified `canvas` of Gtk. My specific question relates to capturing the drawing canvas for the object produced in _GLADE_ so that the layout does not have to be completely defined manually. GLADE appears to describe objects of drawing areas and images; and I cannot see how Gtk.jl can capture that object (Widget) to draw on it.

I am wondering if a work around is to create a canvas that gets pushed onto a container defined in GLADE and then draw onto that…

(just found `https://github.com/JuliaGraphics/Gtk.jl/issues/423` in the issues section of `Gtk.jl` which describes a similar situation and also a similar _workaround_)

---

<div class="post-metadata">

### Author: ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)
#### Post date: [August 7, 2019, 3:38am UTC](https://discourse.julialang.org/t/drawing-on-widgets-defined-in-a-layout-produced-from-glade/27197/6 "2019-08-07T03:38:37Z")

</div>

Yes, the approach of pushing new Widgets onto the boxes does work

```julia
build = GtkBuilder(filename="try1.glade")
vBox1 = build["vBox1"]
    canvas1 = Gtk.Canvas(500,700)
    push!(vBox1,canvas1)
    canvas1.draw = draw1

```

not a well curated example but the point is that the build array can address the containers which can then have new widgets pushed to it and those will show even if not originally present in the  
XML file produce by GLADE
