Exemple #1
0
        def load_children(children):
            """Loads children"""
            index = 0
            for child in children:
                new_item = None

                if "brick" in child:
                    brick = load_brick(child["type"], child["name"])
                    child["brick"] = brick

                    new_item = BaseLayoutItems.BrickCfg(
                        child["name"], child["type"])

                    new_item["brick"] = brick
                    self.bricks[child["name"]] = new_item
                else:
                    if child["type"] == "window":
                        new_item = BaseLayoutItems.WindowCfg(child["name"])
                        self.windows[child["name"]] = new_item
                    else:
                        NewItemClass = Configuration.classes[child["type"]]
                        new_item = NewItemClass(child["name"], child["type"])
                        self.items[child["name"]] = new_item

                if new_item is not None:
                    if isinstance(child["properties"], bytes):
                        # if type(child["properties"]) == str:
                        try:
                            new_item.set_properties(
                                pickle.loads(child["properties"]))
                            # newItem.set_properties(pickle.loads(child["properties"].encode('utf8')))
                        except BaseException:
                            logging.getLogger().exception(
                                "Error: could not load properties " + "for %s",
                                child["name"],
                            )
                            new_item.properties = PropertyBag.PropertyBag()
                    else:
                        new_item.set_properties(child["properties"])

                    child["properties"] = new_item.properties
                    new_item.__dict__ = child

                    # try:
                    #    new_item_signals = new_item["signals"]
                    #    new_item_slots = new_item["slots"]
                    # except:
                    #    new_item.__dict__ = child
                    # else:
                    #    new_item.__dict__ = child
                    #    new_item.slots = new_item_slots
                    #    new_item.signals = new_item_signals
                    #    children[index] = new_item
                    children[index] = new_item
                    load_children(child["children"])
                index += 1
Exemple #2
0
    def add_window(self):
        """Adds window to the list of windows

        :returns: added Window
        """
        i = sum([x.startswith("window") and 1 or 0 for x in self.windows])
        window_name = "window%d" % i
        while window_name in self.windows:
            i += 1
            window_name = "window%d" % i

        self.windows_list.append(BaseLayoutItems.WindowCfg(window_name))
        self.windows[window_name] = self.windows_list[-1]
        self.has_changed = True

        return self.windows_list[-1]