Пример #1
0
    def set_v1_colors(self):
        rclr = self.cmx_model.chunk_map[cmx_const.RCLR_ID]
        colors = rclr.data['colors']
        for model, _pal, vals in colors:
            model = cmx_const.COLOR_MODEL_MAP.get(model, cmx_const.CMX_INVALID)
            clr = sk2const.CMYK_BLACK
            if model == cmx_const.CMX_CMYK:
                vals = cms.val_100_to_dec(vals)
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_CMYK255:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_CMY:
                vals = cms.val_255_to_dec(vals) + (0.0, )
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_RGB:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_RGB, vals, 1.0, '']
            elif model == cmx_const.CMX_HSB:
                first = vals[0] * 255 + vals[1] \
                    if self.rifx else vals[0] + vals[1] * 255
                vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0)
                r, g, b = colorsys.hsv_to_rgb(*vals)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_HLS:
                first = vals[0] * 255 + vals[1] \
                    if self.rifx else vals[0] + vals[1] * 255
                vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0)
                r, g, b = colorsys.hls_to_rgb(*vals)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_BW:
                vals = [1.0, 1.0, 1.0] if vals[0] else [0.0, 0.0, 0.0]
                clr = [uc2const.COLOR_RGB, vals, 1.0, '']
            elif model == cmx_const.CMX_GRAY:
                clr = [uc2const.COLOR_GRAY, [
                    vals[0] / 255.0,
                ], 1.0, '']
            elif model == cmx_const.CMX_YIQ255:
                y = vals[0] / 255.0
                i = 2.0 * vals[1] / 255.0 - 1.0
                q = 2.0 * vals[2] / 255.0 - 1.0
                r, g, b = colorsys.yiq_to_rgb(y, i, q)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_LAB:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_LAB, vals, 1.0, '']

            self._colors.append(clr)
Пример #2
0
 def add_color(self, line):
     if line[0] == '#' or not line: return
     r = int(line[:4])
     g = int(line[4:8])
     b = int(line[8:12])
     name = ''
     if len(line) > 11:
         name = line[12:].strip().decode('utf-8')
     if not name and self.config.set_color_name:
         name = cms.rgb_to_hexcolor(cms.val_255_to_dec((r, g, b)))
     self.model.colors.append([r, g, b, name])
Пример #3
0
	def add_color(self, line):
		if line[0] == '#' or not line:return
		parts = line.replace('\t', ' ')
		parts = parts.replace('  ', ' ').replace('  ', ' ').strip().split(' ')
		name = ''
		if len(parts) > 3:
			name = ' '.join(parts[3:]).decode('utf-8')
		if len(parts) < 3:return
		vals = parts[:3]
		r, g, b = map(lambda x:int(x), vals)
		if not name and self.config.set_color_name:
			name = cms.rgb_to_hexcolor(cms.val_255_to_dec((r, g, b)))
		self.model.colors.append([r, g, b, name])
Пример #4
0
 def add_color(self, line):
     if line[0] == '#' or not line: return
     parts = line.replace('\t', ' ')
     parts = parts.replace('  ', ' ').replace('  ', ' ').strip().split(' ')
     name = ''
     if len(parts) > 3:
         name = ' '.join(parts[3:]).decode('utf-8')
     if len(parts) < 3: return
     vals = parts[:3]
     r, g, b = map(lambda x: int(x), vals)
     if not name and self.config.set_color_name:
         name = cms.rgb_to_hexcolor(cms.val_255_to_dec((r, g, b)))
     self.model.colors.append([r, g, b, name])
Пример #5
0
	def convert_to_skp(self, skp_doc):
		skp_model = skp_doc.model
		skp_model.name = '' + self.model.name
		skp_model.source = '' + self.config.source
		skp_model.columns = self.model.columns
		skp_model.comments = '' + self.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 item in self.model.colors:
			r, g, b, name = item
			r, g, b = cms.val_255_to_dec((r, g, b))
			skp_model.colors.append([COLOR_RGB, [r, g, b], 1.0, name])
Пример #6
0
    def convert_to_skp(self, skp_doc):
        skp_model = skp_doc.model
        skp_model.name = self.model.name
        skp_model.source = self.config.source
        skp_model.columns = self.model.columns
        skp_model.comments = self.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 item in self.model.colors:
            r, g, b, name = item
            r, g, b = cms.val_255_to_dec((r, g, b))
            skp_model.colors.append([COLOR_RGB, [r, g, b], 1.0, name])
Пример #7
0
 def draw_cairo_background(self, ctx):
     w, h = self.get_size()
     x1 = y1 = 0
     flag_y = self.even_odd
     while y1 < h:
         flag_x = flag_y
         while x1 < w:
             clr = wal.WHITE
             if not flag_x: clr = wal.LIGHT_GRAY
             ctx.set_source_rgb(*val_255_to_dec(clr.Get()))
             ctx.rectangle(x1, y1, self.pattern_size, self.pattern_size)
             ctx.fill()
             flag_x = not flag_x
             x1 += self.pattern_size
         flag_y = not flag_y
         y1 += self.pattern_size
         x1 = 0
Пример #8
0
	def draw_cairo_background(self, ctx):
		w, h = self.get_size()
		x1 = y1 = 0
		flag_y = self.even_odd
		while y1 < h:
			flag_x = flag_y
			while x1 < w:
				clr = wal.WHITE
				if not flag_x: clr = wal.LIGHT_GRAY
				ctx.set_source_rgb(*val_255_to_dec(clr.Get()))
				ctx.rectangle(x1, y1, self.pattern_size, self.pattern_size)
				ctx.fill()
				flag_x = not flag_x
				x1 += self.pattern_size
			flag_y = not flag_y
			y1 += self.pattern_size
			x1 = 0
Пример #9
0
 def mouse_left_up(self, point):
     if self.state and self.color and self.callback:
         self.callback(cms.val_255_to_dec(self.color))
Пример #10
0
 def rgbcolor(self, r, g, b, name=''):
     rgb = cms.val_255_to_dec([r, g, b])
     name = name or cms.rgb_to_hexcolor(rgb)
     name = name.encode('utf-8') if isinstance(name, unicode) else name
     self.model.colors.append([uc2const.COLOR_RGB, rgb, 1.0, name])
Пример #11
0
 def rgbcolor(self, r, g, b, name=''):
     rgb = cms.val_255_to_dec([r, g, b])
     if not name: name = cms.rgb_to_hexcolor(rgb)
     self.model.colors.append([uc2const.COLOR_RGB, rgb, 1.0, name])
Пример #12
0
	def rgbcolor(self, r, g, b, name=''):
		rgb = cms.val_255_to_dec([r, g, b])
		if not name: name = cms.rgb_to_hexcolor(rgb)
		self.model.colors.append([uc2const.COLOR_RGB, rgb, 1.0, name])
Пример #13
0
	def mouse_left_up(self, point):
		if self.state and self.color and self.callback:
			self.callback(cms.val_255_to_dec(self.color))