Created
December 2, 2024 12:56
-
-
Save sulincix/446c6db7c3b3270db5a2cb3bc24a625f to your computer and use it in GitHub Desktop.
Automatically define all glade objects by id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gi | |
| gi.require_version("Gtk", "3.0") | |
| from gi.repository import Gtk | |
| import xml.etree.ElementTree as ET | |
| def glade_loader(ctx, glade): | |
| builder = Gtk.Builder() | |
| builder.add_from_file(glade) | |
| # Parse the Glade XML file | |
| tree = ET.parse(glade) | |
| root = tree.getroot() | |
| # Find all objects and print their IDs | |
| for obj in root.findall('.//object'): | |
| obj_id = obj.get('id') | |
| if obj_id: | |
| exec("ctx."+ obj_id +" = builder.get_object(\""+obj_id+"\")") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment