def __init__(self, appdata, cnf={}, filepath=None): self.config = PDXF_Config() config_file = os.path.join(appdata.app_config_dir, 'pdxf_config.xml') self.config.load(config_file) self.config.update(cnf) self.appdata = appdata self.doc_id = generate_id() self.loader = PDXF_Loader() self.saver = PDXF_Saver() self.methods = PDXF_Methods(self) self.rm = ResourceManager(self) self.create_cache_structure() if filepath is None: self.new() else: self.load(filepath)
def add_palette(self, palette): palette.model.name = str(palette.model.name) pname = palette.model.name i = 1 while palette.model.name in self.palettes.keys(): palette.model.name = pname + '(%u)' % i i += 1 name = palette.model.name self.palettes[name] = palette pf = generate_id() + "." + uc2const.FORMAT_EXTENSION[uc2const.SKP][0] filepath = os.path.join(self.app.appdata.app_palette_dir, pf) palette.save(filepath) if config.palette_files: config.palette_files[name] = pf else: files = {name: pf} config.palette_files = files
def add_palette(self, palette): palette.model.name = str(palette.model.name) pname = '' + palette.model.name i = 1 while palette.model.name in self.palettes.keys(): palette.model.name = pname + '(%u)' % i i += 1 name = palette.model.name self.palettes[name] = palette pf = generate_id() + "." + uc2const.FORMAT_EXTENSION[uc2const.SKP][0] filepath = os.path.join(self.app.appdata.app_palette_dir, pf) palette.save(filepath) if config.palette_files: config.palette_files[name] = pf else: files = {} files[name] = pf config.palette_files = files
def registry_file(self, filepath, place, id=None): """ Copies and registers file into specified place (one of document structure directories). If id is not provided, generates new unique id. """ ret = None if os.path.isfile(filepath): if id is None: id = generate_id() filename = os.path.basename(filepath) ext = os.path.splitext(filename)[1] dst_filename = id + ext dst_dir = os.path.join(self.doc_dir, place) dst = os.path.join(dst_dir, dst_filename) try: shutil.copyfile(filepath, dst) res_dict = self.presenter.model.resources res_dict[id] = place + '/' + dst_filename ret = id except: pass return ret