def get_body(self, tag): body = OBJ.Body() body.value = Gtk.VBox() body.children = [] tagID = GLOB.get_attribute(tag, "id") for widget_tag in tag.children: if isinstance(widget_tag, Tag): obj = self.assembler.get_object(widget_tag) if widget_tag.name in NAMES.WIDGETS: expand = GLOB.get_str_bool_attribute( widget_tag, Sizes.EXPAND) fill = GLOB.get_str_bool_attribute(widget_tag, Sizes.FILL) margin = GLOB.get_str_num_attribute( widget_tag, Sizes.MARGIN) body.value.pack_start(obj.value, expand=expand, fill=fill, padding=margin) elif widget_tag.name in NAMES.UNIVERSAL: body.append(obj) elif widget_tag.name == "appmenu": expand = GLOB.get_str_bool_attribute( widget_tag, Sizes.EXPAND) body.value.pack_start(obj.value, expand=expand, fill=True, padding=0) OBJECT_POOL.set_object(tagID, body, []) return body
def get_menu_item(self, tag): menuitem = OBJ.AppMenuItem() menuitem_gtk = Gtk.MenuItem(GLOB.get_attribute(tag, "title")) menuitem.value = menuitem_gtk tagID = GLOB.get_attribute(tag, "id") OBJECT_POOL.set_object(tagID, menuitem, []) return menuitem
def get_application(self, tag): name = GLOB.get_attribute(tag, "name") tagID = GLOB.get_attribute(tag, "id") components = [] for component in tag.children: if isinstance(component, Tag): if component.name not in NAMES.APPLICATION_CHILDREN: raise GtkmlException("Invalid child") components.append(self.assembler.get_object(component)) app = OBJ.Application() app.name = name app.components = components OBJECT_POOL.set_object(tagID, app, []) return app
def get_window(self, tag): title = GLOB.get_attribute(tag, "title") visible = GLOB.get_str_bool_attribute(tag, "show") width = GLOB.get_attribute(tag, "width") height = GLOB.get_attribute(tag, "height") tagID = GLOB.get_attribute(tag, "id") window = OBJ.Window() win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) window.body = OBJ.Body() window.body.children = [] window.body.value = Gtk.VBox() window.value = win children = [] for component in tag.children: if isinstance(component, Tag): if component.name not in NAMES.WINDOW_CHILDREN: raise GtkmlException( "Invalid child: {} cannot be embedded into {}".format( component.name, tag.name)) elif component.name == "body": window.body = self.assembler._get_body(component) window.value.add(window.body.value) elif component.name == "appmenu": window.value.add( self.assembler.get_object(component).value) if title is not None: win.set_title(title) else: win.set_title("") if height is not None and width is not None: win.set_size_request(int(width), int(height)) if visible: window.show() else: window.hide() OBJECT_POOL.set_object(tagID, window, []) return window
def get_appmenu(self, tag): appmenu = OBJ.AppMenu() menubar_gtk = Gtk.MenuBar() appmenu.value = menubar_gtk tagID = GLOB.get_attribute(tag, "id") if isinstance(menubar_gtk, Gtk.MenuBar): print("ASD") for item in tag.children: obj = self.assembler.get_object(item) name = item.name if name == "submenu": appmenu.value.append(obj.value) OBJECT_POOL.set_object(tagID, appmenu, []) return appmenu
def get_entry(self, tag): entry = OBJ.Entry() entry.value = Gtk.Entry() tagID = GLOB.get_attribute(tag, "id") text = tag.text if isinstance(entry.value, Gtk.Entry): entry.value.set_text(text) for tag in tag.children: if isinstance(tag, Tag): if tag.name in NAMES.UNIVERSAL: pass else: raise GtkmlException("Invalid child!") OBJECT_POOL.set_object(tagID, entry, []) return entry
def get_label(self, tag): label = OBJ.Label() label.value = Gtk.Label() tagID = GLOB.get_attribute(tag, "id") text = tag.text if isinstance(label.value, Gtk.Label): label.value.set_text(text) for tag in tag.children: if isinstance(tag, Tag): if tag.name in NAMES.UNIVERSAL: pass else: raise GtkmlException("Invalid child!") OBJECT_POOL.set_object(tagID, label, "") return label
def get_submenu(self, tag): submenu = OBJ.AppSubMenu() menuitem_gtk = Gtk.MenuItem(GLOB.get_attribute(tag, "title")) menu = Gtk.Menu() has_child = False tagID = GLOB.get_attribute(tag, "id") if isinstance(menuitem_gtk, Gtk.MenuItem): for menuitem in tag.children: has_child = True obj = self.assembler.get_object(menuitem) if menuitem.name == "menu-item": menu.add(obj.value) if has_child: menuitem_gtk.set_submenu(menu) submenu.value = menuitem_gtk OBJECT_POOL.set_object(tagID, submenu, []) return submenu
def get_grid(self, tag): grid = OBJ.Grid() grid.value = Gtk.Grid() grid.children = [] tagID = GLOB.get_attribute(tag, "id") i = 0 for component in tag.children: if isinstance(component, Tag): obj = self.assembler.get_object(component) if component.name in NAMES.WIDGETS: if i == 0: grid.value.add(obj.value) else: left = GLOB.get_str_num_attribute(component, "left") top = GLOB.get_str_num_attribute(component, "top") right = GLOB.get_str_num_attribute(component, "right") bottom = GLOB.get_str_num_attribute( component, "bottom") width = right - left height = bottom - top if GLOB.numbers_are_0(left, top, width, height, right, bottom): grid.value.add(obj.value) else: print("{}, {}, {}, {}".format( left, top, width, height)) grid.value.attach(child=obj.value, left=left, top=top, width=width, height=height) elif component.name in NAMES.UNIVERSAL: grid.append(obj) i += 1 OBJECT_POOL.set_object(tagID, grid, []) return grid
def get_vbox(self, tag): vbox = OBJ.VBox() vbox.value = Gtk.VBox() vbox.children = [] tagID = GLOB.get_attribute(tag, "id") for widget_tag in tag.children: if isinstance(widget_tag, Tag): obj = self.assembler.get_object(widget_tag) if widget_tag.name in NAMES.WIDGETS: expand = GLOB.get_str_bool_attribute( widget_tag, Sizes.EXPAND) fill = GLOB.get_str_bool_attribute(widget_tag, Sizes.FILL) margin = GLOB.get_str_num_attribute( widget_tag, Sizes.MARGIN) vbox.value.pack_start(obj.value, expand=expand, fill=fill, padding=margin) elif widget_tag.name in NAMES.UNIVERSAL: vbox.append(obj) OBJECT_POOL.set_object(tagID, vbox, "") return vbox
def get_button(self, tag): button = OBJ.Button() button.value = Gtk.Button() tagID = GLOB.get_attribute(tag, "id") onclick_str = GLOB.get_attribute(tag, "onclick") text = tag.text if isinstance(button.value, Gtk.Button): button.value.set_label(text) if onclick_str is not None: print(onclick_str) button.onclick = ENVIRONMENT[onclick_str] for tag in tag.children: if isinstance(tag, Tag): print(tag.name) if tag.name in NAMES.UNIVERSAL: pass else: raise GtkmlException("Invalid child!") OBJECT_POOL.set_object(tagID, button, []) return button
def _get(self, tag): obj = self.assembler.get_object(tag) if hasattr(tag, "id"): OBJECT_POOL.set_object(id, obj, []) return obj
def __get_by_id(self, id): return OBJECT_POOL.get("id", id)