Exemplo n.º 1
0
        def loadChildren(children):
            i = 0
            for child in children:
                newItem = None

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

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

                if newItem is not None:
                    if type(child["properties"]) == bytes:
                        try:
                            #print "loading properties for %s" % child["name"]
                            newItem.setProperties(
                                pickle.loads(child["properties"]))
                        except:
                            logging.getLogger().exception(
                                "Error: could not load properties for %s",
                                child["name"])
                            newItem.properties = PropertyBag.PropertyBag()
                    else:
                        newItem.setProperties(child["properties"])

                    child["properties"] = newItem.properties

                    try:
                        newItemSignals = newItem["signals"]
                        newItemSlots = newItem["slots"]
                    except:
                        newItem.__dict__ = child
                    else:
                        newItem.__dict__ = child
                        newItem.slots = newItemSlots
                        newItem.signals = newItemSignals

                    children[i] = newItem

                    loadChildren(child["children"])
                i += 1
Exemplo n.º 2
0
        def loadChildren(children):
            i = 0
            for child in children:
                newItem = None

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

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

                if newItem is not None:
                    if isinstance(child["properties"], types.StringType):
                        try:
                            #print "loading properties for %s" % child["name"]
                            newItem.setProperties(
                                cPickle.loads(child["properties"]))
                        except BaseException:
                            logging.getLogger().exception(
                                "Error: could not load properties for %s",
                                child["name"])
                            newItem.properties = PropertyBag.PropertyBag()
                    else:
                        newItem.setProperties(child["properties"])

                    child["properties"] = newItem.properties

                    newItem.__dict__ = child
                    children[i] = newItem

                    loadChildren(child["children"])
                i += 1
Exemplo n.º 3
0
    def addWindow(self):
        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.hasChanged = True

        return self.windows_list[-1]
Exemplo n.º 4
0
    def reload_brick(self, brick_cfg):
        if type(brick_cfg) == types.StringType:
            brick_cfg = self.findItem(brick_cfg)

        brick_name = brick_cfg["name"]
        brick_type = brick_cfg["type"]

        #print 'reloading', brick_name
        parent, index = self.findParent(brick_name, self.windows_list)

        if parent is not None:
            brick = loadBrick(brick_type, brick_name)

            old_brick_cfg = parent["children"][index]
            new_brick_cfg = BaseLayoutItems.BrickCfg(brick_name, brick_type,
                                                     brick)
            parent["children"][index] = new_brick_cfg

            new_brick_cfg.setProperties(old_brick_cfg["properties"])

            return new_brick_cfg
Exemplo n.º 5
0
    def addBrick(self, brick_type, parent):
        i = sum([x.startswith(brick_type) and 1 or 0 for x in self.bricks])
        brick_name = "%s%d" % (brick_type, i)
        while brick_name in self.bricks:
            i += 1
            brick_name = "%s%d" % (brick_type, i)

        brick = loadBrick(brick_type, brick_name)

        error = parent.addChild(
            BaseLayoutItems.BrickCfg(brick_name, brick_type, brick))

        if len(error) == 0:
            self.bricks[brick_name] = parent["children"][-1]

            self.hasChanged = True

            return parent["children"][-1]
        else:
            brick.close(True)

            return error