I’m trying to create a GTK app with Python using libAdwaita
where I can to draw a figure with Cairo. To do this I have to create a drawing area. When I try to get the object for the drawing area it returns None.
My code looks like this:
@Gtk.Template(resource_path='/com/domain/finset/window.ui')
class FinsetWindow(Adw.Window):
__gtype_name__ = 'FinsetWindow'
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.builder = Gtk.Builder()
self.graphDrawingArea = self.builder.get_object('graphDrawingArea')
pprint(vars(self))
And my .ui
file starts
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/>
<template class="FinsetWindow" parent="AdwWindow">
<property name="default-width">640</property>
<property name="default-height">480</property>
And further down I have a child for the drawing area where I later will draw the figure:
<child>
<object class="GtkStackPage">
<property name="title" translatable="yes">Graph</property>
<property name="child">
<object class="GtkDrawingArea" id="graphDrawingArea">
</object>
</property>
</object>
</child>
When building the application it renders fine
But self.builder.get_object('graphDrawingArea')
returns None
.
{'__gtktemplate_handlers__': set(),
'builder': <Gtk.Builder object at 0x7fb3031fbf80 (GtkBuilder at 0x560a719e6f20)>,
'graphDrawingArea': None,
'init_template': <function init_template.<locals>.<lambda> at 0x7fb304296b80>}
What am I doing wrong when I try to get the object graphDrawingArea
?