예제 #1
0
class PatternFill(FillTab):
    name = _('Pattern Fill')
    new_fill = None
    pattern_clrs = None
    rule_keeper = None
    refpanel = None
    presets = None
    pattern_editor = None

    def activate(self, fill_style, new_color=None):
        FillTab.activate(self, fill_style)
        rule = sk2const.FILL_EVENODD
        pattern_type = sk2const.PATTERN_IMG
        pattern = DEFAULT_PATTERN
        image_style = deepcopy([sk2const.CMYK_BLACK, sk2const.CMYK_WHITE])
        trafo = [] + sk2const.NORMAL_TRAFO
        transforms = [] + sk2const.PATTERN_TRANSFORMS

        if fill_style:
            rule = fill_style[0]
            if fill_style[1] == sk2const.FILL_PATTERN:
                pattern_type = fill_style[2][0]
                pattern = deepcopy(fill_style[2][1])
                if len(fill_style[2]) > 2:
                    image_style = deepcopy(fill_style[2][2])
                if len(fill_style[2]) > 3:
                    trafo = [] + fill_style[2][3]
                if len(fill_style[2]) > 4:
                    transforms = [] + fill_style[2][4]
                else:
                    transforms = []
            elif fill_style[1] == sk2const.FILL_SOLID:
                if fill_style[2][0] in GRADIENT_CLR_MODES:
                    color0 = deepcopy(fill_style[2])
                    color0[3] = ''
                    color1 = deepcopy(sk2const.CMYK_WHITE)
                    if not color0[0] == color1[0]:
                        color1 = self.cms.get_color(color1, color0[0])
                    color1[3] = ''
                    image_style = [color0, color1]

        color0 = image_style[0]
        if new_color and new_color[0] in GRADIENT_CLR_MODES \
                and not color0 == new_color:
            color1 = deepcopy(new_color)
            if not color0[0] == color1[0]:
                color1 = self.cms.get_color(color1, color0[0])
            color1[3] = ''
            image_style[1] = color1

        self.new_fill = [
            rule, sk2const.FILL_PATTERN,
            [pattern_type, pattern, image_style, trafo, transforms]
        ]
        self.update()

    def build(self):
        panel = wal.HPanel(self)
        self.pattern_clrs = wal.HToggleKeeper(panel, GRADIENT_CLR_MODES,
                                              GRADIENT_CLR_ICONS,
                                              GRADIENT_CLR_NAMES,
                                              self.on_clr_mode_change)
        panel.pack(self.pattern_clrs)
        panel.pack(wal.HPanel(panel), fill=True, expand=True)

        self.rule_keeper = FillRuleKeeper(panel)
        panel.pack(self.rule_keeper)
        self.pack(panel, fill=True, padding_all=5)
        self.pack(wal.HLine(self), fill=True)

        default_pattern_def = [
            sk2const.PATTERN_IMG, DEFAULT_PATTERN,
            deepcopy([sk2const.CMYK_BLACK, sk2const.CMYK_WHITE]),
            [] + sk2const.NORMAL_TRAFO
        ]
        self.pattern_editor = PatternEditor(self,
                                            self.dlg,
                                            self.cms,
                                            default_pattern_def,
                                            onchange=self.on_pattern_change)
        self.pack(self.pattern_editor, fill=True, expand=True, padding_all=5)

        self.pack(wal.HLine(self), fill=True)

        panel = wal.HPanel(self)
        self.refpanel = FillFillRefPanel(self,
                                         self.cms,
                                         self.orig_fill,
                                         deepcopy(self.orig_fill),
                                         on_orig=self.set_orig_fill)
        panel.pack(self.refpanel)

        panel.pack(wal.HPanel(panel), fill=True, expand=True)

        self.presets = PatternMiniPalette(panel,
                                          self.cms,
                                          onclick=self.on_presets_select)
        panel.pack(self.presets)
        self.pack(panel, fill=True, padding_all=5)

    def set_orig_fill(self):
        self.activate(self.orig_fill)

    def on_clr_mode_change(self, mode):
        image_style = deepcopy(self.new_fill[2][2])
        image_style[0] = self.cms.get_color(image_style[0], mode)
        image_style[1] = self.cms.get_color(image_style[1], mode)
        self.new_fill[2][2] = image_style
        self.update()

    def on_presets_select(self, pattern):
        self.new_fill[2][1] = pattern
        self.new_fill[2][0] = sk2const.PATTERN_IMG
        self.update()

    def on_pattern_change(self, pattern_def):
        self.new_fill[2] = deepcopy(pattern_def)
        self.update()

    def get_result(self):
        return self.new_fill

    def update(self):
        self.pattern_clrs.set_mode(self.new_fill[2][2][0][0])
        self.rule_keeper.set_mode(self.new_fill[0])
        self.pattern_editor.set_pattern_def(self.new_fill[2])
        self.refpanel.update(self.orig_fill, self.new_fill)
        self.pattern_clrs.set_visible(
            self.new_fill[2][0] == sk2const.PATTERN_IMG)
예제 #2
0
파일: fillctrls.py 프로젝트: Scrik/sk1-wx
class PatternFill(FillTab):

	name = _('Pattern Fill')

	def activate(self, fill_style, new_color=None):
		FillTab.activate(self, fill_style)
		rule = sk2_const.FILL_EVENODD
		pattern_type = sk2_const.PATTERN_IMG
		pattern = '' + DEFAULT_PATTERN
		image_style = deepcopy([sk2_const.CMYK_BLACK, sk2_const.CMYK_WHITE])
		trafo = [] + sk2_const.NORMAL_TRAFO
		transforms = [] + sk2_const.PATTERN_TRANSFORMS

		if fill_style:
			rule = fill_style[0]
			if fill_style[1] == sk2_const.FILL_PATTERN:
				pattern_type = fill_style[2][0]
				pattern = deepcopy(fill_style[2][1])
				if len(fill_style[2]) > 2:
					image_style = deepcopy(fill_style[2][2])
				if len(fill_style[2]) > 3:
					trafo = [] + fill_style[2][3]
				if len(fill_style[2]) > 4:
					transforms = [] + fill_style[2][4]
				else:
					transforms = []
			elif fill_style[1] == sk2_const.FILL_SOLID:
				if fill_style[2][0] in GRADIENT_CLR_MODES:
					color0 = deepcopy(fill_style[2])
					color0[3] = ''
					color1 = deepcopy(sk2_const.CMYK_WHITE)
					if not color0[0] == color1[0]:
						color1 = self.cms.get_color(color1, color0[0])
					color1[3] = ''
					image_style = [color0, color1]

		color0 = image_style[0]
		if new_color and new_color[0] in GRADIENT_CLR_MODES \
								and not color0 == new_color:
			color1 = deepcopy(new_color)
			if not color0[0] == color1[0]:
				color1 = self.cms.get_color(color1, color0[0])
			color1[3] = ''
			image_style[1] = color1

		self.new_fill = [rule, sk2_const.FILL_PATTERN,
						[pattern_type, pattern, image_style, trafo, transforms]]
		self.update()


	def build(self):
		panel = wal.HPanel(self)
		self.pattern_clrs = wal.HToggleKeeper(panel, GRADIENT_CLR_MODES,
								GRADIENT_CLR_ICONS,
								GRADIENT_CLR_NAMES, self.on_clr_mode_change)
		panel.pack(self.pattern_clrs)
		panel.pack(wal.HPanel(panel), fill=True, expand=True)

		self.rule_keeper = FillRuleKeeper(panel)
		panel.pack(self.rule_keeper)
		self.pack(panel, fill=True, padding_all=5)
		self.pack(wal.HLine(self), fill=True)

		default_pattern_def = [sk2_const.PATTERN_IMG, '' + DEFAULT_PATTERN,
					deepcopy([sk2_const.CMYK_BLACK, sk2_const.CMYK_WHITE]),
					[] + sk2_const.NORMAL_TRAFO]
		self.pattern_editor = PatternEditor(self, self.dlg, self.cms,
						default_pattern_def, onchange=self.on_pattern_change)
		self.pack(self.pattern_editor, fill=True, expand=True, padding_all=5)


		self.pack(wal.HLine(self), fill=True)

		panel = wal.HPanel(self)
		self.refpanel = FillFillRefPanel(self, self.cms, self.orig_fill,
						deepcopy(self.orig_fill), on_orig=self.set_orig_fill)
		panel.pack(self.refpanel)

		panel.pack(wal.HPanel(panel), fill=True, expand=True)

		self.presets = PatternMiniPalette(panel, self.cms,
										onclick=self.on_presets_select)
		panel.pack(self.presets)
		self.pack(panel, fill=True, padding_all=5)

	def set_orig_fill(self):
		self.activate(self.orig_fill)

	def on_clr_mode_change(self, mode):
		image_style = deepcopy(self.new_fill[2][2])
		image_style[0] = self.cms.get_color(image_style[0], mode)
		image_style[1] = self.cms.get_color(image_style[1], mode)
		self.new_fill[2][2] = image_style
		self.update()

	def on_presets_select(self, pattern):
		self.new_fill[2][1] = pattern
		self.new_fill[2][0] = sk2_const.PATTERN_IMG
		self.update()

	def on_pattern_change(self, pattern_def):
		self.new_fill[2] = deepcopy(pattern_def)
		self.update()

	def get_result(self):
		return self.new_fill

	def update(self):
		self.pattern_clrs.set_mode(self.new_fill[2][2][0][0])
		self.rule_keeper.set_mode(self.new_fill[0])
		self.pattern_editor.set_pattern_def(self.new_fill[2])
		self.refpanel.update(self.orig_fill, self.new_fill)
		self.pattern_clrs.set_visible(self.new_fill[2][0] == sk2_const.PATTERN_IMG)
예제 #3
0
class GradientFill(FillTab):
    name = _('Gradient Fill')
    vector = []
    new_fill = None
    grad_keeper = None
    grad_clrs = None
    rule_keeper = None
    grad_editor = None
    refpanel = None
    presets = None

    def activate(self, fill_style, new_color=None):
        FillTab.activate(self, fill_style)
        mode = sk2const.GRADIENT_LINEAR
        rule = sk2const.FILL_EVENODD
        self.vector = []
        stops = deepcopy(DEFAULT_STOPS)
        if fill_style:
            rule = fill_style[0]
            if fill_style[1] == sk2const.FILL_GRADIENT:
                mode = fill_style[2][0]
                self.vector = deepcopy(fill_style[2][1])
                stops = deepcopy(fill_style[2][2])
            elif fill_style[1] == sk2const.FILL_SOLID:
                if fill_style[2][0] in GRADIENT_CLR_MODES:
                    color0 = deepcopy(fill_style[2])
                    color0[3] = ''
                    if new_color and new_color[0] in GRADIENT_CLR_MODES \
                            and not color0 == new_color:
                        color1 = deepcopy(new_color)
                        if not color0[0] == color1[0]:
                            color1 = self.cms.get_color(color1, color0[0])
                    else:
                        color1 = deepcopy(fill_style[2])
                        color1[2] = 0.0
                        color1[3] = ''
                    stops = [[0.0, color0], [1.0, color1]]
        self.new_fill = [
            rule, sk2const.FILL_GRADIENT, [mode, self.vector, stops]
        ]
        self.update()

    def build(self):
        panel = wal.HPanel(self)
        self.grad_keeper = wal.HToggleKeeper(panel, GRADIENT_MODES,
                                             GRADIENT_MODE_ICONS,
                                             GRADIENT_MODE_NAMES,
                                             self.on_grad_mode_change)
        panel.pack(self.grad_keeper)
        panel.pack(wal.HPanel(panel), fill=True, expand=True)

        self.grad_clrs = wal.HToggleKeeper(panel, GRADIENT_CLR_MODES,
                                           GRADIENT_CLR_ICONS,
                                           GRADIENT_CLR_NAMES,
                                           self.on_clr_mode_change)
        panel.pack(self.grad_clrs)
        panel.pack(wal.HPanel(panel), fill=True, expand=True)

        self.rule_keeper = FillRuleKeeper(panel)
        panel.pack(self.rule_keeper)
        self.pack(panel, fill=True, padding_all=5)
        self.pack(wal.HLine(self), fill=True)

        self.grad_editor = GradientEditor(self,
                                          self.dlg,
                                          self.cms,
                                          DEFAULT_STOPS,
                                          onchange=self.on_stops_change)
        self.pack(self.grad_editor, fill=True, expand=True, padding=3)
        self.pack(wal.HLine(self), fill=True)

        panel = wal.HPanel(self)
        self.refpanel = FillFillRefPanel(self,
                                         self.cms,
                                         self.orig_fill,
                                         deepcopy(self.orig_fill),
                                         on_orig=self.set_orig_fill)
        panel.pack(self.refpanel)

        panel.pack(wal.HPanel(panel), fill=True, expand=True)

        self.presets = GradientMiniPalette(panel,
                                           self.cms,
                                           onclick=self.on_presets_select)
        panel.pack(self.presets)
        self.pack(panel, fill=True, padding_all=5)

    def set_orig_fill(self):
        self.activate(self.orig_fill)

    def on_clr_mode_change(self, mode):
        conv = self.cms.get_cmyk_color
        if mode == uc2const.COLOR_RGB:
            conv = self.cms.get_rgb_color
        elif mode == uc2const.COLOR_GRAY:
            conv = self.cms.get_grayscale_color
        new_stops = []
        for stop in self.new_fill[2][2]:
            new_stops.append([stop[0], conv(stop[1])])
        self.new_fill[2][2] = new_stops
        self.update()

    def on_grad_mode_change(self, mode):
        self.new_fill[2][0] = mode
        self.update()

    def on_stops_change(self):
        self.new_fill[2][2] = self.grad_editor.get_stops()
        self.update()

    def on_presets_select(self, stops):
        self.new_fill[2][2] = stops
        self.update()

    def get_result(self):
        stops = self.grad_editor.get_stops()
        vector = self.vector
        if not self.grad_editor.use_vector():
            vector = []
        grad = [self.grad_keeper.get_mode(), vector, stops]
        return [self.rule_keeper.get_mode(), sk2const.FILL_GRADIENT, grad]

    def update(self):
        self.grad_keeper.set_mode(self.new_fill[2][0])
        self.grad_clrs.set_mode(self.new_fill[2][2][0][1][0])
        self.rule_keeper.set_mode(self.new_fill[0])
        self.grad_editor.set_stops(self.new_fill[2][2])
        self.refpanel.update(self.orig_fill, self.new_fill)
        self.presets.set_stops(self.new_fill[2][2])
예제 #4
0
파일: fillctrls.py 프로젝트: Scrik/sk1-wx
class GradientFill(FillTab):

	name = _('Gradient Fill')
	vector = []
	new_fill = None

	def activate(self, fill_style, new_color=None):
		FillTab.activate(self, fill_style)
		mode = sk2_const.GRADIENT_LINEAR
		rule = sk2_const.FILL_EVENODD
		self.vector = []
		stops = deepcopy(DEFAULT_STOPS)
		if fill_style:
			rule = fill_style[0]
			if fill_style[1] == sk2_const.FILL_GRADIENT:
				mode = fill_style[2][0]
				self.vector = deepcopy(fill_style[2][1])
				stops = deepcopy(fill_style[2][2])
			elif fill_style[1] == sk2_const.FILL_SOLID:
				if fill_style[2][0] in GRADIENT_CLR_MODES:
					color0 = deepcopy(fill_style[2])
					color0[3] = ''
					if new_color and new_color[0] in GRADIENT_CLR_MODES \
											and not color0 == new_color:
						color1 = deepcopy(new_color)
						if not color0[0] == color1[0]:
							color1 = self.cms.get_color(color1, color0[0])
					else:
						color1 = deepcopy(fill_style[2])
						color1[2] = 0.0
						color1[3] = ''
					stops = [[0.0, color0], [1.0, color1]]
		self.new_fill = [rule, sk2_const.FILL_GRADIENT,
						[mode, self.vector, stops]]
		self.update()

	def build(self):
		panel = wal.HPanel(self)
		self.grad_keeper = wal.HToggleKeeper(panel, GRADIENT_MODES,
								GRADIENT_MODE_ICONS,
								GRADIENT_MODE_NAMES, self.on_grad_mode_change)
		panel.pack(self.grad_keeper)
		panel.pack(wal.HPanel(panel), fill=True, expand=True)

		self.grad_clrs = wal.HToggleKeeper(panel, GRADIENT_CLR_MODES,
								GRADIENT_CLR_ICONS,
								GRADIENT_CLR_NAMES, self.on_clr_mode_change)
		panel.pack(self.grad_clrs)
		panel.pack(wal.HPanel(panel), fill=True, expand=True)

		self.rule_keeper = FillRuleKeeper(panel)
		panel.pack(self.rule_keeper)
		self.pack(panel, fill=True, padding_all=5)
		self.pack(wal.HLine(self), fill=True)

		self.grad_editor = GradientEditor(self, self.dlg, self.cms,
								DEFAULT_STOPS, onchange=self.on_stops_change)
		self.pack(self.grad_editor, fill=True, expand=True, padding=3)
		self.pack(wal.HLine(self), fill=True)

		panel = wal.HPanel(self)
		self.refpanel = FillFillRefPanel(self, self.cms, self.orig_fill,
						deepcopy(self.orig_fill), on_orig=self.set_orig_fill)
		panel.pack(self.refpanel)

		panel.pack(wal.HPanel(panel), fill=True, expand=True)

		self.presets = GradientMiniPalette(panel, self.cms,
										onclick=self.on_presets_select)
		panel.pack(self.presets)
		self.pack(panel, fill=True, padding_all=5)

	def set_orig_fill(self):
		self.activate(self.orig_fill)

	def on_clr_mode_change(self, mode):
		conv = self.cms.get_cmyk_color
		if mode == uc2const.COLOR_RGB:
			conv = self.cms.get_rgb_color
		elif mode == uc2const.COLOR_GRAY:
			conv = self.cms.get_grayscale_color
		new_stops = []
		for stop in self.new_fill[2][2]:
			new_stops.append([stop[0], conv(stop[1])])
		self.new_fill[2][2] = new_stops
		self.update()

	def on_grad_mode_change(self, mode):
		self.new_fill[2][0] = mode
		self.update()

	def on_stops_change(self):
		self.new_fill[2][2] = self.grad_editor.get_stops()
		self.update()

	def on_presets_select(self, stops):
		self.new_fill[2][2] = stops
		self.update()

	def get_result(self):
		stops = self.grad_editor.get_stops()
		vector = self.vector
		if not self.grad_editor.use_vector():vector = []
		grad = [self.grad_keeper.get_mode(), vector, stops]
		return [self.rule_keeper.get_mode(), sk2_const.FILL_GRADIENT, grad]

	def update(self):
		self.grad_keeper.set_mode(self.new_fill[2][0])
		self.grad_clrs.set_mode(self.new_fill[2][2][0][1][0])
		self.rule_keeper.set_mode(self.new_fill[0])
		self.grad_editor.set_stops(self.new_fill[2][2])
		self.refpanel.update(self.orig_fill, self.new_fill)
		self.presets.set_stops(self.new_fill[2][2])