• I need a basic tutorial for GUI creation using Cambalache

    From Chris Green@cl@isbd.net to comp.lang.python on Wed Aug 12 09:26:38 2026
    From Newsgroup: comp.lang.python

    I am a retired software engineer with a background in assembler, C and
    C++.

    I now dabble (mostly for my own amusement) in various bits and pieces,
    mostly in Python nowadays. I have written quite a lot of Python
    command line programs to run in a terminal. I have also written a
    couple of simple Python GUI programs using PyGObject and Gtk. This is
    all on Debian/Linux.

    I want to go a bit further and it appears that the most obvious next
    step is to use Cambalache which has taken over from Glade as the
    default GUI builder for Gnome/GTK.

    The problem is that there appear to be no tutorials for Cambalache. I
    can find how to install it (which I had done already without problems)
    but I can't find anywhere that simply runs through the sequence of
    actions required to build a working Python GUI using Cambalache.

    I'm sort of aware that Cambalache creates an XML file that represents
    the GUI and that XML file has to be processed somehow (by GTKBuilder?)
    to make a running GUI program. I need a bit more help in
    understanding the actual process though.

    Can anyone point me at anything that might help?
    --
    Chris Green
    -+
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Wed Aug 12 21:47:46 2026
    From Newsgroup: comp.lang.python

    On Wed, 12 Aug 2026 09:26:38 +0100, Chris Green wrote:

    I'm sort of aware that Cambalache creates an XML file that
    represents the GUI and that XML file has to be processed somehow (by GTKBuilder?) to make a running GUI program.

    Yeah, it seems in GTK4 you no longer have public access to the
    individual widget-creation calls. But you can embed the entire XML
    describing your UI inside your program code, which is convenient for
    small, simple programs.

    HererCOs an example snippet from my limited dabbling with GTK4 so far:

    ui = \
    (
    "<?xml version='1.0' encoding='utf-8'?>\n"
    "<interface>\n"
    " <requires lib='gtk' version='4.0'/>\n"
    " <object class='GtkWindow' id='main'>\n"
    " <child>\n"
    " <object class='GtkGLArea' id='draw'/>\n"
    " </child>\n"
    " </object>\n"
    "</interface>\n"
    )
    junk = XMLElementTree.fromstring(ui)
    # just to check itrCOs syntactically OK, because Gtk.Builder.new_from_string simply
    # returns a builder object with no contents instead of reporting errors.
    bld = Gtk.Builder.new_from_string(ui, -1) # donrCOt know why wrapper insists on length arg
    sys.stdout.write("objects = %s\n" % repr(bld.get_objects())) # debug
    wdw = bld.get_object("main")
    drw = bld.get_object("draw")

    Yeah, I discovered that, if there was an error in your XML, you didnrCOt
    get any error message (that I could find), the returned Builder object
    simply ended up with nothing in it.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jon Ribbens@jon+usenet@unequivocal.eu to comp.lang.python on Wed Aug 12 22:23:39 2026
    From Newsgroup: comp.lang.python

    On 2026-08-12, Lawrence DrCOOliveiro <ldo@nz.invalid> wrote:
    HererCOs an example snippet from my limited dabbling with GTK4 so far:

    ui = \
    (
    "<?xml version='1.0' encoding='utf-8'?>\n"
    "<interface>\n"
    " <requires lib='gtk' version='4.0'/>\n"
    " <object class='GtkWindow' id='main'>\n"
    " <child>\n"
    " <object class='GtkGLArea' id='draw'/>\n"
    " </child>\n"
    " </object>\n"
    "</interface>\n"
    )

    Just to say that would obviously be a lot easier and cleaner like this:

    ui = '''
    <?xml version='1.0' encoding='utf-8'?>
    <interface>
    <requires lib='gtk' version='4.0'/>
    <object class='GtkWindow' id='main'>
    <child>
    <object class='GtkGLArea' id='draw'/>
    </child>
    </object>
    </interface>
    '''
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Thu Aug 13 08:30:25 2026
    From Newsgroup: comp.lang.python

    On Wed, 12 Aug 2026 21:47:46 -0000 (UTC), I wrote:

    Yeah, it seems in GTK4 you no longer have public access to the
    individual widget-creation calls.

    Of course, I could be wrong ...
    --- Synchronet 3.22a-Linux NewsLink 1.2