Files
YMS/yms/gtkutils.py
T
2024-04-09 14:03:13 +01:00

33 lines
969 B
Python

from gi.repository import Gtk
def init_named_controls(window, builder):
ctrltype = {
'lbl': 'label',
'ent': 'entry',
'but': 'button',
'cmb': 'combo',
'tvw': 'tree',
'spi': 'spin',
'txt': 'text',
'chk': 'check',
'opt': 'radio',
'vbx': 'vbox',
'hbx': 'hbox',
'box': 'box',
'tbl': 'table',
'mnu': 'menu',
'img': 'image',
'drw': 'area'
}
for ctrl in ctrltype.values():
setattr(window, ctrl, {})
for widget in builder.get_objects():
if type(widget) in (Gtk.Adjustment, Gtk.CellRendererText, Gtk.TreeSelection):
continue
widgetname = Gtk.Buildable.get_name(widget)
nameparts = widgetname.partition('_')
if (not nameparts[0] in ctrltype.keys()) or (not nameparts[2]):
continue
var = getattr(window, ctrltype[nameparts[0]])
var[nameparts[2]] = widget