示例#1
0
 def load(cls, node, builder, parent):
     obj_class = cls._get_class(node)
     cls._load_required_fields(node)
     config = node.attrib
     if obj_class == ttk.PanedWindow and "orient" in config.get("attr", {}):
         orient = config["attr"].pop("orient")
         obj = obj_class(parent, orient=orient)
     else:
         obj = obj_class(parent)
     parent_node = node.parent
     kwargs = {
         "parent_node": parent_node,
         "parent": parent,
         "node": node,
         "builder": builder,
     }
     dispatch_to_handlers(obj, config, **kwargs)
     name = node.attrib.get("name")
     if name:
         # if name attribute is missing calling setattr will raise errors
         setattr(builder, name, obj)
     for sub_node in node:
         if sub_node.type == "event":
             builder._event_map[obj].append(dict(sub_node.attrib))
         elif sub_node.type == "grid":
             if sub_node.attrib.get("column"):
                 column = sub_node.attrib.pop("column")
                 obj.columnconfigure(column, **sub_node.attrib)
             elif sub_node.attrib.get("row"):
                 row = sub_node.attrib.pop("row")
                 obj.rowconfigure(row, **sub_node.attrib)
     return obj
示例#2
0
    def load(cls, node, builder, parent):
        canvas = BaseLoaderAdapter.load(node, builder, parent)
        for sub_node in node:
            if sub_node.type in builder._ignore_tags:
                continue
            # just additional options that may be needed down the line
            kwargs = {
                "parent_node": sub_node.parent,
                "node": sub_node,
                "builder": builder,
            }

            _id = sub_node.attrib.pop("name", None)
            coords = sub_node.attrib.pop("coords", "").split(",")
            item_id = canvas._create(sub_node.type.lower(), coords, {})

            def handle(**config):
                canvas.itemconfig(item_id, config)

            dispatch_to_handlers(canvas,
                                 sub_node.attrib,
                                 **kwargs,
                                 handle_method=handle)
            if _id:
                setattr(builder, _id, item_id)

        return canvas
示例#3
0
 def from_xml(cls, node, builder, parent):
     obj_class = cls._get_class(node)
     config = cls.attrib(node)
     if obj_class == ttk.PanedWindow and "orient" in config.get("attr", {}):
         orient = config["attr"].pop("orient")
         obj = obj_class(parent, orient=orient)
     else:
         obj = obj_class(parent)
     parent_node = node.getparent()
     kwargs = {
         "parent_node": parent_node,
         "parent": parent,
         "node": node,
         "builder": builder,
     }
     dispatch_to_handlers(obj, config, **kwargs)
     name = node.attrib.get("name")
     if name:
         # if name attribute is missing calling setattr will raise errors
         setattr(builder, name, obj)
     return obj
示例#4
0
 def _menu_load(cls, node, builder, menu=None, widget=None):
     for sub_node in node:
         if sub_node.type == "event":
             continue
         attrib = sub_node.attrib
         kwargs = {
             "parent_node": sub_node.parent,
             "node": sub_node,
             "builder": builder,
         }
         if sub_node.type in MenuLoaderAdapter._types and menu is not None:
             menu.add(sub_node.type)
             index = menu.index(tk.END)
             dispatch_to_handlers(menu,
                                  attrib,
                                  **kwargs,
                                  menu=menu,
                                  index=index)
         elif cls._get_class(sub_node) == tk.Menu:
             obj_class = cls._get_class(sub_node)
             menu_obj = obj_class(widget)
             if widget:
                 widget.configure(menu=menu_obj)
                 dispatch_to_handlers(menu_obj, attrib, **kwargs)
             elif menu:
                 menu.add(tk.CASCADE, menu=menu_obj)
                 index = menu.index(tk.END)
                 dispatch_to_handlers(menu_obj,
                                      attrib,
                                      **kwargs,
                                      menu=menu,
                                      index=index)
             cls._menu_load(sub_node, builder, menu_obj)
示例#5
0
 def _menu_from_xml(cls, node, builder, menu=None, widget=None):
     for sub_node in node:
         attrib = cls.attrib(sub_node)
         kwargs = {
             "parent_node": sub_node.getparent(),
             "node": sub_node,
             "builder": builder,
         }
         if sub_node.tag in MenuConverter._types and menu is not None:
             menu.add(sub_node.tag)
             index = menu.index(tk.END)
             dispatch_to_handlers(menu,
                                  attrib,
                                  **kwargs,
                                  menu=menu,
                                  index=index)
         elif cls._get_class(sub_node) == tk.Menu:
             obj_class = cls._get_class(sub_node)
             menu_obj = obj_class(widget)
             if widget:
                 widget.configure(menu=menu_obj)
                 dispatch_to_handlers(menu_obj, attrib, **kwargs)
             elif menu:
                 menu.add(tk.CASCADE, menu=menu_obj)
                 index = menu.index(tk.END)
                 dispatch_to_handlers(menu_obj,
                                      attrib,
                                      **kwargs,
                                      menu=menu,
                                      index=index)
             cls._menu_from_xml(sub_node, builder, menu_obj)