def new(self): self.model = ASE_Palette() self.model.childs = []
class ASE_Presenter(BinaryModelPresenter): cid = uc2const.ASE config = None doc_file = '' model = None def __init__(self, appdata, cnf={}): self.config = ASE_Config() config_file = os.path.join(appdata.app_config_dir, self.config.filename) self.config.load(config_file) self.config.update(cnf) self.appdata = appdata self.loader = ASE_Loader() self.saver = ASE_Saver() self.new() def new(self): self.model = ASE_Palette() self.model.childs = [] def get_palette_name(self): ret = '' for child in self.model.childs: if child.identifier == ase_const.ASE_GROUP: ret = '' + child.group_name break if not ret: ret = 'ASE palette' return ret def convert_from_skp(self, skp_doc): skp_model = skp_doc.model self.model.childs.append(ASE_Group('' + skp_model.name)) for item in skp_model.colors: if item[0] == uc2const.COLOR_SPOT: marker = ase_const.ASE_SPOT if item[1][0] and item[1][0]: if self.config.prefer_cmyk_for_spot: cs = ase_const.ASE_CMYK vals = tuple(deepcopy(item[1][1])) else: cs = ase_const.ASE_RGB vals = tuple(deepcopy(item[1][0])) elif item[1][0] and not item[1][0]: cs = ase_const.ASE_RGB vals = tuple(deepcopy(item[1][0])) else: cs = ase_const.ASE_CMYK vals = tuple(deepcopy(item[1][1])) else: marker = ase_const.ASE_PROCESS cs = ase_const.CS_MATCH[item[0]] vals = tuple(deepcopy(item[1])) if item[3]: name = '' + item[3] else: name = cms.verbose_color(item) self.model.childs.append(ASE_Color(name, cs, vals, marker)) self.model.childs.append(ASE_Group_End()) self.model.do_update(self) def convert_to_skcolor(self, obj): if obj.color_marker == ase_const.ASE_SPOT: if obj.colorspace == ase_const.ASE_RGB: vals = [list(obj.color_vals), []] return [uc2const.COLOR_SPOT, vals, 1.0, '' + obj.color_name] elif obj.colorspace == ase_const.ASE_CMYK: vals = [[], list(obj.color_vals)] return [uc2const.COLOR_SPOT, vals, 1.0, '' + obj.color_name] cs = ase_const.CS_MATCH[obj.colorspace] return [cs, list(obj.color_vals), 1.0, '' + obj.color_name] def convert_to_skp(self, skp_doc): skp_model = skp_doc.model skp_model.name = self.get_palette_name() skp_model.source = '' + self.config.source skp_model.comments = '' if self.doc_file: filename = os.path.basename(self.doc_file) if skp_model.comments: skp_model.comments += 'n' skp_model.comments += 'Converted from %s' % filename for child in self.model.childs: if child.identifier == ase_const.ASE_COLOR: clr = self.convert_to_skcolor(child) if clr: skp_model.colors.append(clr)
class ASE_Presenter(BinaryModelPresenter): cid = uc2const.ASE config = None doc_file = '' model = None def __init__(self, appdata, cnf={}): self.config = ASE_Config() config_file = os.path.join(appdata.app_config_dir, self.config.filename) self.config.load(config_file) self.config.update(cnf) self.appdata = appdata self.loader = ASE_Loader() self.saver = ASE_Saver() self.new() def new(self): self.model = ASE_Palette() self.model.childs = [] def get_palette_name(self): ret = '' for child in self.model.childs: if child.identifier == ase_const.ASE_GROUP: ret = '' + child.group_name break if not ret: ret = 'ASE palette' return ret def convert_from_skp(self, skp_doc): skp_model = skp_doc.model self.model.childs.append(ASE_Group('' + skp_model.name)) for item in skp_model.colors: if item[0] == uc2const.COLOR_SPOT: marker = ase_const.ASE_SPOT if item[1][0] and item[1][0]: if self.config.prefer_cmyk_for_spot: cs = ase_const.ASE_CMYK vals = tuple(deepcopy(item[1][1])) else: cs = ase_const.ASE_RGB vals = tuple(deepcopy(item[1][0])) elif item[1][0] and not item[1][0]: cs = ase_const.ASE_RGB vals = tuple(deepcopy(item[1][0])) else: cs = ase_const.ASE_CMYK vals = tuple(deepcopy(item[1][1])) else: marker = ase_const.ASE_PROCESS cs = ase_const.CS_MATCH[item[0]] vals = tuple(deepcopy(item[1])) if item[3]: name = '' + item[3] else: name = cms.verbose_color(item) self.model.childs.append(ASE_Color(name, cs, vals, marker)) self.model.childs.append(ASE_Group_End()) self.model.do_update(self) def convert_to_skcolor(self, obj): if obj.color_marker == ase_const.ASE_SPOT: if obj.colorspace == ase_const.ASE_RGB: vals = [list(obj.color_vals), []] return [uc2const.COLOR_SPOT, vals, 1.0, '' + obj.color_name] elif obj.colorspace == ase_const.ASE_CMYK: vals = [[], list(obj.color_vals)] return [uc2const.COLOR_SPOT, vals, 1.0, '' + obj.color_name] cs = ase_const.CS_MATCH[obj.colorspace] return [cs, list(obj.color_vals), 1.0, '' + obj.color_name] def convert_to_skp(self, skp_doc): skp_model = skp_doc.model skp_model.name = self.get_palette_name() skp_model.source = '' + self.config.source skp_model.comments = '' if self.doc_file: filename = os.path.basename(self.doc_file) if skp_model.comments:skp_model.comments += 'n' skp_model.comments += 'Converted from %s' % filename for child in self.model.childs: if child.identifier == ase_const.ASE_COLOR: clr = self.convert_to_skcolor(child) if clr: skp_model.colors.append(clr)