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
def add_brick(self, brick_type, parent): """Adds brick to the gui :param brick_type: brick type :type brick_type: class :param parent: parent :type parent: widget """ 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 = load_brick(brick_type, brick_name) error = parent.add_child( BaseLayoutItems.BrickCfg(brick_name, brick_type, brick)) if len(error) == 0: self.bricks[brick_name] = parent["children"][-1] self.has_changed = True return parent["children"][-1] else: brick.close(True) return error
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]
def reload_brick(self, brick_cfg): """Reloads brick """ if isinstance(brick_cfg, bytes): brick_cfg = self.find_item(brick_cfg) brick_name = brick_cfg["name"] brick_type = brick_cfg["type"] parent, index = self.find_parent(brick_name, self.windows_list) if parent is not None: brick = load_brick(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.set_properties(old_brick_cfg["properties"]) return new_brick_cfg