Example #1
0
	def build_dlg(self):
		root = self.top

		top = TFrame(root, borderwidth=5, style='FlatFrame')
		top.pack(side=TOP, expand=0, fill=BOTH)

		top2 = TFrame(top, style='FlatFrame')
		top2.pack(side=TOP, expand=0, fill=X)

		format_label = TLabel(top2, text=_('Style name:'), borderwidth=0)
		format_label.pack(side=LEFT, pady=3)

		self.entry_name = TEntrybox(top, command=self.ok, width=15)
		self.entry_name.pack(side=TOP, fill=X)

		top2 = TFrame(top, height=5, style='FlatFrame')
		top2.pack(side=TOP, expand=0, fill=X)

		prop_cont = TLabelframe(top, text=_('Style properties'), padding=10)
		prop_cont.pack(side=TOP, fill=X)

		properties = self.object.Properties()
		self.flags = {}
		for prop in property_names:
			type = property_types[prop]
			if type == FillProperty:
				state = self.object.has_fill and NORMAL or DISABLED
			elif type == LineProperty:
				state = self.object.has_line and NORMAL or DISABLED
			elif type == FontProperty:
				state = self.object.has_font and NORMAL or DISABLED
			else:
				# unknown property type!
				continue
			long, short = property_titles[prop]
			self.flags[prop] = var = IntVar(root)
			var.set(state == NORMAL)
			radio = TCheckbutton(prop_cont, text=long, state=state, variable=var)
			radio.pack(side=TOP, anchor=W)

		top2 = TFrame(top, height=3, style='FlatFrame')
		top2.pack(side=TOP, expand=0, fill=X)

		but_frame = Frame(top)
		but_frame.pack(side=TOP, fill=X)

		button = TButton(but_frame, text=_("Cancel"), command=self.cancel)
		button.pack(side=RIGHT, padx=5)
		button = TButton(but_frame, text=_("OK"), command=self.ok)
		button.pack(side=RIGHT, padx=5)

		root.resizable (width=0, height=0)

		self.entry_name.set_focus()
Example #2
0
	def build_dlg(self):

		root = self.top
		top = TFrame(root, style='FlatFrame', borderwidth=13)
		top.pack(side=TOP)

		label = TLabel(top, text=_("Please select the object categories whose\n default properties you want to change"))
		label.pack(side=TOP, anchor=W)
		frame = TFrame(top, style='FlatFrame', borderwidth=10)
		frame.pack(side=TOP)
		self.var_graphics_style = IntVar(top)
		self.var_graphics_style.set(0)
		if self.category != 'font':
			self.var_graphics_style.set(1)
		button = TCheckbutton(frame, text=_("Graphics Objects"), state=(self.category == 'font' and DISABLED or NORMAL), variable=self.var_graphics_style)
		button.pack(side=TOP, anchor=W)
		self.var_text_style = IntVar(top)
		self.var_text_style.set(0)
		if self.category == 'font':
			self.var_text_style.set(1)
		button = TCheckbutton(frame, text=_("Text Objects"), state=(self.category == 'line' and DISABLED or NORMAL), variable=self.var_text_style)
		button.pack(side=TOP, anchor=W)

		label = TLabel(top, style="HLine")
		label.pack(side=TOP, fill=BOTH)

		but_frame = TFrame(top, style='FlatFrame')
		but_frame.pack(side=TOP, fill=BOTH, expand=1)

		button = TButton(but_frame, text=_("Cancel"), command=self.cancel)
		button.pack(side=RIGHT, expand=1)

		button = TButton(but_frame, text=_("OK"), command=self.ok)
		button.pack(side=RIGHT, expand=1)


		root.resizable (width=0, height=0)
class AlignPlugin(PluginPanel):

    name = 'Alignment'
    title = _("Alignment")

    def init(self, master):
        PluginPanel.init(self, master)
        root = self.mw.root
        self.var_reference = StringVar(root)
        self.var_reference.set(SELECT)

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------
        label = TLabel(top,
                       text=" " + _("Relative to") + " ",
                       style="FlatLabel")
        label.pack(side=TOP, fill=BOTH, padx=5)
        rel_frame = TLabelframe(top,
                                labelwidget=label,
                                style='Labelframe',
                                borderwidth=3)
        rel_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.reference = TCombobox(rel_frame,
                                   state='readonly',
                                   values=self.make_cs_list(),
                                   style='ComboNormal',
                                   width=14,
                                   textvariable=self.var_reference,
                                   postcommand=self.set_cs)
        self.reference.pack(side=TOP)
        #---------------------------------------------------------

        label = TLabel(top,
                       text=" " + _("Alignment type") + " ",
                       style="FlatLabel")
        label.pack(side=TOP, fill=BOTH, padx=5)
        framec = TLabelframe(top,
                             labelwidget=label,
                             style='Labelframe',
                             borderwidth=3)
        framec.pack(side=TOP, fill=X, padx=5, pady=2)

        framex = TFrame(framec, style='FlatFrame')
        framex.pack(side=TOP, expand=0, padx=5, pady=5)

        framey = TFrame(framec, style='FlatFrame')
        framey.pack(side=TOP, expand=0, padx=5, pady=5)

        x_pixmaps = ['aoleft', 'aocenterh', 'aoright']
        y_pixmaps = ['aotop', 'aocenterv', 'aobottom']
        x_tooltips = [
            _('Align left sides'),
            _('Center on vertical axis'),
            _('Align right sides')
        ]

        y_tooltips = [
            _('Align tops'),
            _('Center on horizontal axis'),
            _('Align bottoms')
        ]

        self.var_x = IntVar(top)
        self.var_x.set(0)
        self.value_x = 0
        self.var_y = IntVar(top)
        self.var_y.set(0)
        self.value_y = 0

        for i in range(1, 4):
            button = make_button(framex,
                                 image=x_pixmaps[i - 1],
                                 value=i,
                                 variable=self.var_x,
                                 command=self.apply_x)
            tooltips.AddDescription(button, x_tooltips[i - 1])
            button.pack(side=LEFT, padx=3)
            button = make_button(framey,
                                 image=y_pixmaps[i - 1],
                                 value=i,
                                 variable=self.var_y,
                                 command=self.apply_y)
            tooltips.AddDescription(button, y_tooltips[i - 1])
            button.pack(side=LEFT, padx=3)

        #---------------------------------------------------------
        # Auto Apply Check
        self.var_auto_apply = IntVar(top)
        self.var_auto_apply.set(0)

        self.auto_apply_check = TCheckbutton(top,
                                             text=_("Auto Apply"),
                                             variable=self.var_auto_apply,
                                             command=self.reset)
        self.auto_apply_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Button frame

        self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        self.button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button_apply = TButton(self.button_frame,
                                    text=_("Apply"),
                                    command=self.apply)

        self.apply_button_show(1)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)

    def init_from_doc(self):
        self.Update()
        self.issue(SELECTION)

    def Update(self, *arg):
        reference = self.var_reference.get()
        if self.is_selection(reference):
            state = NORMAL
        else:
            state = DISABLED
        self.button_apply['state'] = state

    def apply_button_show(self, state):
        if not state:
            self.button_apply.pack_forget()
        else:
            self.button_apply.pack(side=BOTTOM, expand=1, fill=X, pady=3)

    def make_cs_list(self):
        cs = ()
        cs += (SELECT, LOWERMOST, PAGE)
        return cs

    def set_cs(self):
        self.Update()

    def is_selection(self, reference=SELECT):
        if not self.var_auto_apply.get(
        ) and self.value_x == 0 and self.value_y == 0:
            return 0
        if reference == PAGE:
            return (len(self.document.selection) > 0)
        else:
            return (len(self.document.selection) > 1)

    def apply_x(self):
        x = self.var_x.get()
        if self.var_auto_apply.get():
            self.reset()
            self.apply(x=x)
        else:
            if self.value_x == x:
                self.var_x.set(0)
                self.value_x = 0
            else:
                self.value_x = x
            self.Update()

    def apply_y(self):
        y = self.var_y.get()
        if self.var_auto_apply.get():
            self.reset()
            self.apply(y=y)
        else:
            if self.value_y == y:
                self.var_y.set(0)
                self.value_y = 0
            else:
                self.value_y = y
            self.Update()

    def apply(self, x=None, y=None, reference=None):
        reference = self.var_reference.get()
        if not self.is_selection(reference):
            return

        if x is None:
            x = self.var_x.get()

        if y is None:
            y = self.var_y.get()

        if reference is None:
            reference = self.var_reference.get()

        reference = self.reference_command(reference)

        self.document.AlignSelection(x, y, reference=reference)

    def reference_command(self, reference):
        if reference == SELECT:
            return 'selection'
        if reference == LOWERMOST:
            return 'lowermost'
        if reference == PAGE:
            return 'page'

    def reset(self):
        self.var_x.set(0)
        self.value_x = 0
        self.var_y.set(0)
        self.value_y = 0
        ##		self.apply_button_show(not self.var_auto_apply.get())
        self.Update()
Example #4
0
	def init(self, master):
		PluginPanel.init(self, master)

		self.width_priority=1
		
		root=self.mw.root
		self.var_width=DoubleVar(root)
		self.var_height=DoubleVar(root)
		
		unit='%'
		jump=5
		
		self.var_proportional = IntVar(root)
		self.var_proportional.set(0)
		
		self.var_basepoint = StringVar(root)
		self.var_basepoint.set('C')
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		# Horisontal size
		size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameH.pack(side = TOP, fill = BOTH)
		
		label = TLabel(size_frameH, style='FlatLabel', image='size_h')
		label.pack(side = LEFT, padx=5)
		self.entry_width = TSpinbox(size_frameH,  var=100, vartype=1, textvariable = self.var_width, 
									min = -30000, max = 30000, step = jump, width = 6, command=self.apply_scale)
		self.entry_width.pack(side = LEFT)

		self.entry_width.down_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.down_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusOut>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusIn>', self.entry_width_FocusIn)
		
		self.labelwunit = TLabel(size_frameH, style='FlatLabel', text = unit)
		self.labelwunit.pack(side = LEFT, padx=5)
		
		self.hflip=BooleanVar(root)
		self.hflip.set(0)
		button = TCheckbutton(size_frameH, image = "pstrip_hflip", style='ToolBarCheckButton', variable = self.hflip, command = None)
		button.pack(side = LEFT)
		
		#---------------------------------------------------------
		# Vertical 
		
		size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameV.pack(side = TOP, fill = BOTH)
		label = TLabel(size_frameV, style='FlatLabel', image='size_v')
		label.pack(side = LEFT, padx=5)
		
		self.entry_height = TSpinbox(size_frameV, var=100, vartype=1, textvariable = self.var_height, 
									min = -30000, max = 30000, step = jump, width = 6, command=self.apply_scale)
		self.entry_height.pack(side = LEFT)
		
		self.entry_height.down_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.down_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusOut>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusIn>', self.entry_height_FocusIn)
		
		self.labelhunit = TLabel(size_frameV, style='FlatLabel', text = unit)
		self.labelhunit.pack(side = LEFT, padx=5)
		
		self.vflip=BooleanVar(root)
		self.vflip.set(0)
		button = TCheckbutton(size_frameV, image = "pstrip_vflip", style='ToolBarCheckButton', variable = self.vflip, command = None)
		button.pack(side = LEFT)
		
		#---------------------------------------------------------
		# Proportional chek
		
		self.proportional_check = TCheckbutton(top, text = _("Proportional"), variable = self.var_proportional, command = self.proportional)
		self.proportional_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Basepoint check
		label = TLabel(top, style='FlatLabel', text = _("Basepoint:"))
		label.pack(side = TOP, fill = BOTH, padx=5)
		basepoint_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		basepoint_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.Basepoint = BasePointSelector(basepoint_frame, anchor=self.var_basepoint)
		self.Basepoint.pack(side = LEFT, fill = BOTH, padx=5)
		
		label = TLabel(basepoint_frame, style='FlatLabel', image = 'coordinate_sys')
		label.pack(side = LEFT, fill = BOTH, padx=10)
		
		#---------------------------------------------------------
		# Button frame 
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		button_frame.pack(side = BOTTOM, fill = BOTH)

		self.update_buttons = []
		self.button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_scale)
		self.button.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X, pady=3)

		self.button_copy = UpdatedButton(top, text = _("Apply to Copy"),
								command = self.apply_to_copy)
		self.button_copy.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X)
		
		self.init_from_doc()
		self.subscribe_receivers()
Example #5
0
class RotatePanel(PluginPanel):
    name = "Rotate"
    title = _("Rotate")

    def init(self, master):
        PluginPanel.init(self, master)

        root = self.mw.root

        self.var_angle = DoubleVar(root)
        self.var_angle.set(0)

        self.var_width_number = DoubleVar(root)
        self.var_height_number = DoubleVar(root)

        self.var_width_base = DoubleVar(root)
        self.var_height_base = DoubleVar(root)

        self.cnt_x_absolute = None
        self.cnt_y_absolute = None

        var_width_unit = StringVar(root)
        var_height_unit = StringVar(root)

        unit = config.preferences.default_unit
        self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit)
        self.var_height = LengthVar(10, unit, self.var_height_number, var_height_unit)

        jump = config.preferences.default_unit_jump
        self.var_width.set(0)
        self.var_height.set(0)

        self.var_width_base.set(0)
        self.var_height_base.set(0)

        self.var_position = StringVar(root)
        self.var_position.set(ABSOLUTE)

        self.var_basepoint = StringVar(root)
        self.var_basepoint.set("C")

        # ---------------------------------------------------------
        top = TFrame(self.panel, style="FlatFrame")
        top.pack(side=TOP, fill=BOTH)
        # ---------------------------------------------------------

        angle_frame = TFrame(top, style="FlatFrame", borderwidth=3)
        angle_frame.pack(side=TOP, fill=BOTH)
        label = TLabel(angle_frame, style="FlatLabel", text=" " + _("Angle:") + " ")
        label.pack(side=LEFT, padx=5)

        self.entry_angle = TSpinbox(
            angle_frame,
            var=0,
            vartype=1,
            textvariable=self.var_angle,
            min=-360,
            max=360,
            step=5,
            width=6,
            command=self.apply_rotate,
        )
        self.entry_angle.pack(side=LEFT, anchor=E)
        label = TLabel(angle_frame, style="FlatLabel", text=_("deg"))
        label.pack(side=LEFT, padx=5)
        # ---------------------------------------------------------
        label = TLabel(top, style="FlatLabel", text=_("Center:"))
        label.pack(side=TOP, fill=BOTH, padx=5)

        # ---------------------------------------------------------
        # Horisontal
        size_frameH = TFrame(top, style="FlatFrame", borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style="FlatLabel", image="center_h")
        label.pack(side=LEFT, padx=5)
        self.entry_width = TSpinbox(
            size_frameH,
            var=0,
            vartype=1,
            textvariable=self.var_width_number,
            min=-50000,
            max=50000,
            step=jump,
            width=10,
            command=self.apply_rotate,
        )
        self.entry_width.pack(side=LEFT)

        self.labelwunit = TLabel(size_frameH, style="FlatLabel", text=self.var_width.unit)
        self.labelwunit.pack(side=LEFT, padx=5)
        # ---------------------------------------------------------
        # Vertical

        size_frameV = TFrame(top, style="FlatFrame", borderwidth=3)
        size_frameV.pack(side=TOP, fill=BOTH)
        label = TLabel(size_frameV, style="FlatLabel", image="center_v")
        label.pack(side=LEFT, padx=5)

        self.entry_height = TSpinbox(
            size_frameV,
            var=0,
            vartype=1,
            textvariable=self.var_height_number,
            min=-50000,
            max=50000,
            step=jump,
            width=10,
            command=self.apply_rotate,
        )
        self.entry_height.pack(side=LEFT)

        self.labelhunit = TLabel(size_frameV, style="FlatLabel", text=self.var_height.unit)
        self.labelhunit.pack(side=LEFT, padx=5)

        # ---------------------------------------------------------
        # position chek

        self.position_check = TCheckbutton(
            top,
            text=_("Absolute Center"),
            variable=self.var_position,
            onvalue=ABSOLUTE,
            offvalue=RELATIVE,
            command=self.position,
        )
        self.position_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        # ---------------------------------------------------------
        # Basepoint check

        label = TLabel(top, style="FlatLabel", text=_("Basepoint:"))
        label.pack(side=TOP, fill=BOTH, padx=5)
        basepoint_frame = TLabelframe(top, labelwidget=label, style="Labelframe", borderwidth=4)
        basepoint_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.Basepoint = BasePointSelector(basepoint_frame, anchor=self.var_basepoint, command=self.apply_basepoint)
        self.Basepoint.pack(side=LEFT, fill=BOTH, padx=5)

        label = TLabel(basepoint_frame, style="FlatLabel", image="coordinate_deg")
        label.pack(side=LEFT, fill=BOTH, padx=10)

        self.position_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        # ---------------------------------------------------------
        # Button frame

        button_frame = TFrame(top, style="FlatFrame", borderwidth=5)
        button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button = UpdatedButton(top, text=_("Apply"), command=self.apply_rotate)
        self.button.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X, pady=3)

        self.button_copy = UpdatedButton(top, text=_("Apply to Copy"), command=self.apply_to_copy)
        self.button_copy.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X)

        self.init_from_doc()
        self.subscribe_receivers()

    ###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)
        self.document.Subscribe(EDITED, self.update_var)
        config.preferences.Subscribe(CHANGED, self.update_pref)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)
        self.document.Unsubscribe(EDITED, self.update_var)
        config.preferences.Unsubscribe(CHANGED, self.update_pref)

    def init_from_doc(self, *arg):
        self.Update()

    def Update(self, *arg):
        if self.is_selection():
            self.entry_angle.set_state(NORMAL)
            self.entry_width.set_state(NORMAL)
            self.entry_height.set_state(NORMAL)
            self.position_check["state"] = NORMAL
            self.button["state"] = NORMAL
            self.button_copy["state"] = NORMAL
            self.TestBasepoint()
        else:
            self.entry_angle.set_state(DISABLED)
            self.entry_width.set_state(DISABLED)
            self.entry_height.set_state(DISABLED)
            self.position_check["state"] = DISABLED
            self.button["state"] = DISABLED
            self.button_copy["state"] = DISABLED

        self.update_pref()

    def apply_basepoint(self):
        self.update_var()

    def position(self):
        self.update_var()

    def RotateSelected(self, angle, cnt=None):
        text = _("Rotation")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    if cnt is None:
                        cnt = self.document.selection.coord_rect.center()
                    angle = angle * degrees
                    trafo = Rotation(angle, cnt)
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def RotateAndCopy(self, angle, cnt=None):
        text = _("Rotation&Copy")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    if cnt is None:
                        cnt = self.document.selection.coord_rect.center()
                    angle = angle * degrees
                    trafo = Rotation(angle, cnt)
                    self.document.ApplyToDuplicate()
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def apply_rotate(self, *arg):
        if self.button["state"] == DISABLED:
            return

        try:
            var_x = self.var_width.get()
            var_y = self.var_height.get()
            var_a = self.var_angle.get()
        except:
            return

        if var_a < 0:
            if var_a < -360:
                var_a += int(var_a / 360) * 360
            var_a += 360

        if self.var_basepoint.get() != "USER":
            self.cnt_x_absolute, self.cnt_y_absolute = self.coordinates(ABSOLUTE)
            self.var_basepoint.set("USER")

        if self.var_width_base != var_x or self.var_height_base != var_y:

            if self.var_position.get() == ABSOLUTE:
                self.cnt_x_absolute = var_x
                self.cnt_y_absolute = var_y
            else:
                x, y = self.coordinates(ABSOLUTE, "C")
                self.cnt_x_absolute = var_x + x
                self.cnt_y_absolute = var_y + y

            self.var_basepoint.set("USER")

        if arg and arg[0] == "Duplicate":
            self.RotateAndCopy(var_a, Point(self.cnt_x_absolute, self.cnt_y_absolute))
        else:
            self.RotateSelected(var_a, Point(self.cnt_x_absolute, self.cnt_y_absolute))

    def apply_to_copy(self):
        self.apply_rotate("Duplicate")

    def coordinates(self, position, anchor=None):
        br = self.document.selection.coord_rect
        hor_sel = br.right - br.left
        ver_sel = br.top - br.bottom

        if position == RELATIVE:
            left, bottom = -hor_sel / 2.0, -ver_sel / 2.0
        else:
            left, bottom = br.left, br.bottom

        cnt_x, cnt_y = self.Basepoint.get_basepoint(hor_sel, ver_sel, left, bottom, anchor)
        return cnt_x, cnt_y

    def TestBasepoint(self):
        if self.cnt_x_absolute is None:
            return
        base = ["C", "NW", "N", "NE", "W", "E", "SW", "S", "SE"]
        for b in xrange(len(base)):
            cnt_x, cnt_y = self.coordinates(ABSOLUTE, base[b])
            if round(cnt_x, 2) == round(self.cnt_x_absolute, 2) and round(cnt_y, 2) == round(self.cnt_y_absolute, 2):
                self.var_basepoint.set(base[b])
                return
        self.var_basepoint.set("USER")

    def update_pref(self, *arg):
        self.labelwunit["text"] = config.preferences.default_unit
        self.labelhunit["text"] = config.preferences.default_unit
        self.entry_width.step = config.preferences.default_unit_jump
        self.entry_height.step = config.preferences.default_unit_jump
        self.update_var()

    def update_var(self, *arg):
        if len(self.document.selection.GetInfo()):

            self.var_width.unit = config.preferences.default_unit
            self.var_height.unit = config.preferences.default_unit

            if self.var_basepoint.get() == "USER":

                if self.var_position.get() == ABSOLUTE:
                    self.var_width.set(self.cnt_x_absolute)
                    self.var_height.set(self.cnt_y_absolute)
                else:
                    x, y = self.coordinates(ABSOLUTE, "C")
                    self.var_width.set(self.cnt_x_absolute - x)
                    self.var_height.set(self.cnt_y_absolute - y)

            else:
                x, y = self.coordinates(self.var_position.get())
                self.var_width.set(x)
                self.var_height.set(y)
                self.var_width_base = self.var_width.get()
                self.var_height_base = self.var_height.get()

    def is_selection(self):
        return len(self.document.selection) > 0
class FindReplacePanel(PluginPanel):
    name = 'Text Find & Replace'
    title = _("Text Find & Replace")

    def init(self, master):
        PluginPanel.init(self, master)
        top = self.panel

        top = TFrame(top, borderwidth=2, style='FlatFrame')
        top.pack(side=TOP, expand=1, fill=X)

        button_frame = TFrame(top, borderwidth=2, style='FlatFrame')
        button_frame.pack(side=BOTTOM, fill=BOTH, expand=1)

        button = TButton(button_frame, text=_('Apply'), command=self.replace)
        button.pack(side=TOP)

        #----------------------------------------------------------
        main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        main_frame.pack(side=TOP, fill=X)

        self.find_var = StringVar(top)
        self.find_var.set('')
        findField = TEntryExt(main_frame, textvariable=self.find_var)
        findField.pack(side=RIGHT)

        label = TLabel(main_frame, style='FlatLabel', text=_("Find:") + " ")
        label.pack(side=RIGHT, anchor=E)
        #---------------------------------------------------------
        main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        main_frame.pack(side=TOP, fill=X)

        self.replace_var = StringVar(top)
        self.replace_var.set('')
        replaceField = TEntryExt(main_frame, textvariable=self.replace_var)
        replaceField.pack(side=RIGHT)

        label = TLabel(main_frame,
                       style='FlatLabel',
                       text=_("Replace to:") + " ")
        label.pack(side=RIGHT, anchor=E)

        main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        main_frame.pack(side=TOP)
        #---------------------------------------------------------
        label = TLabel(top,
                       text=" " + _("Parameters") + " ",
                       style="FlatLabel")
        label.pack()

        parametersFrameLabel = TLabelframe(top,
                                           labelwidget=label,
                                           style='Labelframe',
                                           borderwidth=4)

        parametersFrameLabel.pack(side=TOP, fill=X, pady=4, padx=4)

        parametersFrame = TFrame(parametersFrameLabel, style='FlatFrame')

        self.var_case_sensitive = BooleanVar(top)
        self.var_case_sensitive.set(False)
        self.case_sensitive_check = TCheckbutton(
            parametersFrame,
            text=_("Case sensitive"),
            variable=self.var_case_sensitive)
        self.case_sensitive_check.pack(side=TOP, anchor=W, padx=5)

        self.var_whole_word = BooleanVar(top)
        self.var_whole_word.set(False)
        self.whole_word_check = TCheckbutton(parametersFrame,
                                             text=_("Whole word"),
                                             variable=self.var_whole_word)
        self.whole_word_check.pack(side=TOP, anchor=W, padx=5)

        self.var_regexp = BooleanVar(top)
        self.var_regexp.set(False)
        self.regexpCheck = TCheckbutton(parametersFrame,
                                        text=_("RegExp search"),
                                        variable=self.var_regexp,
                                        command=self.disable_enable_action)
        self.regexpCheck.pack(side=TOP, anchor=W, padx=5)

        parametersFrame.pack(side=TOP, fill=X, pady=2)
################################################################

    def replace_text(self, objects, toReplace, replaceTo):
        for object in objects:
            if object.is_Text:

                if self.var_regexp.get():
                    if self.var_case_sensitive.get():
                        p = re.compile(toReplace)
                    else:
                        p = re.compile(toReplace, re.I)
                    text = p.sub(replaceTo, object.text)
                    app.mw.document.SelectObject(object)
                    app.mw.document.CallObjectMethod(object.__class__,
                                                     _('Text Replace'),
                                                     'SetText', text)
                    continue

                if self.var_whole_word.get():
                    if not self.var_case_sensitive.get():
                        if object.text.lower() == toReplace.lower():
                            text = replaceTo
                            app.mw.document.SelectObject(object)
                            app.mw.document.CallObjectMethod(
                                object.__class__, _('Text Replace'), 'SetText',
                                text)
                    else:
                        if object.text == toReplace:
                            text = replaceTo
                            app.mw.document.SelectObject(object)
                            app.mw.document.CallObjectMethod(
                                object.__class__, _('Text Replace'), 'SetText',
                                text)

                else:
                    if object.text.lower().find(toReplace.lower(), 0,
                                                len(object.text)) != -1:
                        if not self.var_case_sensitive.get():
                            text = object.text.lower().replace(
                                toReplace.lower(), replaceTo)
                        else:
                            text = object.text.replace(toReplace, replaceTo)
                        app.mw.document.SelectObject(object)
                        app.mw.document.CallObjectMethod(
                            object.__class__, _('Text Replace'), 'SetText',
                            text)

            if object.is_Group:
                self.replace_text(object.objects)
################################################################

    def replace(self):
        textObjects = []
        textToReplace = self.find_var.get().decode('utf-8')
        replaceTo = self.replace_var.get().decode('utf-8')

        for layer in app.mw.document.layers:
            self.replace_text(layer.objects, textToReplace, replaceTo)
        app.mw.canvas.ForceRedraw()
################################################################

    def disable_enable_action(self):
        if self.var_regexp.get():
            self.whole_word_check['state'] = DISABLED
        else:
            self.whole_word_check['state'] = NORMAL
################################################################

    def whole_word_action(self):
        pass
Example #7
0
class PagePanel(CtxSubPanel):

	name = 'PagePanel'

	def __init__(self, parent):
		CtxSubPanel.__init__(self, parent)

		self.USER_SPECIFIC = _("<Custom Size>")

		root = self.mw.root
		self.var_format_name = StringVar(root)
		self.var_format_name.set(config.preferences.default_paper_format)
		self.page_orientation = config.preferences.default_page_orientation

		label = TLabel(self.panel, text=_("Page:"))
		label.pack(side=LEFT, padx=2)
		self.page_formats = TCombobox(self.panel, state='readonly', postcommand=self.set_format,
									 values=self.make_formats(), width=17, style='ComboNormal',
									 textvariable=self.var_format_name)
		tooltips.AddDescription(self.page_formats, _("Page formats"))
		self.page_formats.pack(side=LEFT, padx=2)

		#--------------
		sep = FlatFrame(self.panel, width=5, height=2)
		sep.pack(side=LEFT)
		#--------------

		var_width_number = DoubleVar(root)
		var_height_number = DoubleVar(root)
		var_width_unit = StringVar(root)
		var_height_unit = StringVar(root)
		unit = config.preferences.default_unit
		self.var_width = LengthVar(10, unit, var_width_number, var_width_unit)
		self.var_height = LengthVar(10, unit, var_height_number, var_height_unit)
		jump = config.preferences.default_unit_jump

		label = TLabel(self.panel, text=_("H:"))
		label.pack(side=LEFT)
		self.widthentry = TSpinbox(self.panel, textvariable=var_width_number, command=self.applyResize,
								vartype=1, min=5, max=50000, step=jump, width=7)
		tooltips.AddDescription(self.widthentry, _("Page width"))
		self.widthentry.pack(side=LEFT, padx=2)

		#--------------
		sep = FlatFrame(self.panel, width=5, height=2)
		sep.pack(side=LEFT)
		#--------------

		label = TLabel(self.panel, text=_("V:"))
		label.pack(side=LEFT)
		self.heightentry = TSpinbox(self.panel, textvariable=var_height_number, command=self.applyResize,
		 						vartype=1, min=5, max=50000, step=jump, width=7)
		tooltips.AddDescription(self.heightentry, _("Page height"))
		self.heightentry.pack(side=LEFT, padx=2)

		self.portrait_val = StringVar(root)
		self.landscape_val = StringVar(root)

		self.portrait = TCheckbutton(self.panel, image='context_portrait', variable=self.portrait_val,
								   command=self.set_portrait, style='ToolBarCheckButton')
		tooltips.AddDescription(self.portrait, _("Portrait"))
		self.portrait.pack(side=LEFT, padx=2)
		self.landscape = TCheckbutton(self.panel, image='context_landscape', variable=self.landscape_val,
									command=self.set_landscape, style='ToolBarCheckButton')
		tooltips.AddDescription(self.landscape, _("Landscape"))
		self.landscape.pack(side=LEFT)
		config.preferences.Subscribe(CHANGED, self.update_pref)
		self.doc.Subscribe(PAGE, self.update_pref)
		self.doc.Subscribe(UNDO, self.update_pref)


	def init_from_doc(self):
		self.page_orientation = self.doc.Layout().Orientation()

		formatname = self.doc.Layout().FormatName()
		if formatname == '':
			formatname = self.USER_SPECIFIC
			width, height = self.doc.PageSize()
			if width <= height:
				self.page_orientation = 0
			else:
				self.page_orientation = 1
			self.update_size(width, height)

		self.var_format_name.set(formatname)
		self.update()

	def ReSubscribe(self):
		self.init_from_doc()

	def make_formats(self):
		formats = ()
		for format in PapersizesList:
			formats += (format[0],)
		formats += (self.USER_SPECIFIC,)
		return formats

	def set_portrait(self):
		self.page_orientation = 0
		width = min(self.var_width.get(), self.var_height.get())
		height = max(self.var_width.get(), self.var_height.get())
		self.update_size(width, height)
		self.set_size()

	def set_landscape(self):
		self.page_orientation = 1
		width = max(self.var_width.get(), self.var_height.get())
		height = min(self.var_width.get(), self.var_height.get())
		self.update_size(width, height)
		self.set_size()

	def set_size(self):
		self.var_width.UpdateNumber()
		self.var_height.UpdateNumber()
		self.update()
		self.apply_settings()

	def set_format(self):
		if not self.var_format_name.get() == self.doc.page_layout.paperformat:
			self.set_size()

	def update_pref(self, *arg):
		self.var_width.unit = config.preferences.default_unit
		self.var_height.unit = config.preferences.default_unit
		width, height = self.doc.PageSize()
		self.var_format_name.set(self.doc.page_layout.paperformat)
		if self.doc.page_layout.paperformat == "":
			self.var_format_name.set(self.USER_SPECIFIC)
			self.set_entry_sensitivity()
		self.page_orientation = self.doc.page_layout.orientation
		self.update_size(width, height)
		self.update()

	def update(self):
		self.set_entry_sensitivity()
		self.update_size_from_name(self.var_format_name.get())
		if self.page_orientation:
			self.portrait_val.set('')
			self.landscape_val.set('1')
		else:
			self.portrait_val.set('1')
			self.landscape_val.set('')

	def set_entry_sensitivity(self):
		formatname = self.var_format_name.get()
		if formatname != self.USER_SPECIFIC:
			self.widthentry.set_state(DISABLED)
			self.heightentry.set_state(DISABLED)
		else:
			self.widthentry.set_state(NORMAL)
			self.heightentry.set_state(NORMAL)

	def update_size(self, width, height):
		self.var_width.set(width)
		self.var_height.set(height)

	def update_size_from_name(self, formatname):
		if formatname == "":
			formatname = self.USER_SPECIFIC
		if not formatname == self.USER_SPECIFIC:
			width, height = Papersize[formatname]
			if self.page_orientation:
				width, height = height, width
			self.update_size(width, height)

	def applyResize (self, event):
		try:
			width = self.var_width.get()
			height = self.var_height.get()
			if width <= height:
				self.set_portrait()
			else:
				self.set_landscape()
		except:
			return

	def apply_settings(self):
		formatname = self.var_format_name.get()
		if formatname == self.USER_SPECIFIC:
			layout = PageLayout(width=self.var_width.get(),
								height=self.var_height.get(),
								orientation=0)
		else:
			layout = PageLayout(formatname,
								orientation=self.page_orientation)
		self.mw.canvas.bitmap_buffer = None
		self.doc.SetLayout(layout)
		self.doc.pages[self.doc.active_page].page_layout = layout
Example #8
0
class MovePanel(PluginPanel):
	name='Move'
	title = _("Move")


	def init(self, master):
		PluginPanel.init(self, master)

		root=self.mw.root
		self.var_width_number=DoubleVar(root)
		self.var_height_number=DoubleVar(root)
		
		self.var_width_base=DoubleVar(root)
		self.var_height_base=DoubleVar(root)

		var_width_unit = StringVar(root)
		var_height_unit = StringVar(root)
		
		unit = config.preferences.default_unit
		self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit)
		self.var_height = LengthVar(10, unit,self.var_height_number,var_height_unit)
		
		jump=config.preferences.default_unit_jump
		self.var_width.set(0)
		self.var_height.set(0)
		
		self.var_width_base.set(0)
		self.var_height_base.set(0)
		
		self.var_position = StringVar(root)
		self.var_position.set(ABSOLUTE)
		
		self.var_basepoint = StringVar(root)
		self.var_basepoint.set('C')
		 
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		# Horisontal size
		size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameH.pack(side = TOP, fill = BOTH)
		
		label = TLabel(size_frameH, style='FlatLabel', image='move_h')
		label.pack(side = LEFT, padx=5)
		self.entry_width = TSpinbox(size_frameH,  var=0, vartype=1, textvariable = self.var_width_number, 
									min = -50000, max = 50000, step = jump, width = 10, command=self.apply_move)
		self.entry_width.pack(side = LEFT)

		self.labelwunit = TLabel(size_frameH, style='FlatLabel', text = self.var_width.unit)
		self.labelwunit.pack(side = LEFT, padx=5)
		#---------------------------------------------------------
		# Vertical 
		
		size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameV.pack(side = TOP, fill = BOTH)
		label = TLabel(size_frameV, style='FlatLabel', image='move_v')
		label.pack(side = LEFT, padx=5)
		
		self.entry_height = TSpinbox(size_frameV, var=0, vartype=1, textvariable = self.var_height_number, 
									min = -50000, max = 50000, step = jump, width = 10, command=self.apply_move)
		self.entry_height.pack(side = LEFT)
		
		self.labelhunit = TLabel(size_frameV, style='FlatLabel', text = self.var_height.unit)
		self.labelhunit.pack(side = LEFT, padx=5)
		
		#---------------------------------------------------------
		# position chek
		
		self.position_check = TCheckbutton(top, text = _("Absolute Coordinates"), variable = self.var_position,
												onvalue=ABSOLUTE, offvalue=RELATIVE, command = self.position)
		self.position_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Basepoint check
		
		label = TLabel(top, style='FlatLabel', text = _("Basepoint:"))
		label.pack(side = TOP, fill = BOTH, padx=5)
		basepoint_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		basepoint_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.Basepoint = BasePointSelector(basepoint_frame, anchor=self.var_basepoint, command = self.apply_basepoint)
		self.Basepoint.pack(side = LEFT, fill = BOTH, padx=5)
		
		label = TLabel(basepoint_frame, style='FlatLabel', image = 'coordinate_sys')
		label.pack(side = LEFT, fill = BOTH, padx=10)
			
		#---------------------------------------------------------
		# Button frame 
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		button_frame.pack(side = BOTTOM, fill = BOTH)
		
		self.update_buttons = []
		self.button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_move)
		self.button.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X, pady=3)
		
		self.button_copy = UpdatedButton(top, text = _("Apply to Copy"),
								command = self.apply_to_copy)
		self.button_copy.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X)
		
		self.init_from_doc()
		self.subscribe_receivers()


###############################################################################

	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.Update)
		self.document.Subscribe(EDITED, self.update_var)
		config.preferences.Subscribe(CHANGED, self.update_pref)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.Update)
		self.document.Unsubscribe(EDITED, self.update_var)
		config.preferences.Unsubscribe(CHANGED, self.update_pref)

	def init_from_doc(self, *arg):
			self.Update()

	def Update(self, *arg):
		if self.is_selection():
			self.entry_width.set_state(NORMAL)
			self.entry_height.set_state(NORMAL)
			self.position_check['state']=NORMAL
			self.button['state']=NORMAL
			self.button_copy['state']=NORMAL
		else:
			self.entry_width.set_state(DISABLED)
			self.entry_height.set_state(DISABLED)
			self.position_check['state']=DISABLED
			self.button['state']=DISABLED
			self.button_copy['state']=DISABLED
			
		self.update_pref()

	def apply_basepoint(self):
		self.Update()

	def position(self):
		if self.var_position.get()==ABSOLUTE and self.var_basepoint.get()=='USER':
			self.var_basepoint.set('C')
		self.update_var()

	def apply_move(self, *arg):
		if self.button["state"]==DISABLED:
			return
		try:
				var_x=self.var_width.get()
				var_y=self.var_height.get()
		except:
				return
		
		x, y = self.coordinates(self.var_position.get())
		
		if self.var_position.get()==RELATIVE:
			if self.var_width_base != self.var_width.get() or self.var_height_base != self.var_height.get():
				self.var_basepoint.set('USER')
			x,y = var_x, var_y
		else:
			x,y = var_x-x, var_y-y
		
		if arg and arg[0] == 'Duplicate':
			self.document.MoveAndCopy(x, y, Point(0,0))
		else:
			self.document.MoveSelected(x, y)

	def apply_to_copy(self):
		self.apply_move('Duplicate')


	def coordinates(self, position):
		br=self.document.selection.coord_rect
		hor_sel=br.right - br.left
		ver_sel=br.top - br.bottom
		
		if position == RELATIVE:
			left, bottom = -hor_sel/2, -ver_sel/2
		else:
			left, bottom = br.left, br.bottom
		
		cnt_x,cnt_y=self.Basepoint.get_basepoint(hor_sel,ver_sel,left,bottom)
		
		if position == RELATIVE and cnt_x!=None:
			return cnt_x*2, cnt_y*2
		else:
			return cnt_x, cnt_y

	def update_pref(self, *arg):
		self.labelwunit['text']=config.preferences.default_unit
		self.labelhunit['text']=config.preferences.default_unit
		self.entry_width.step=config.preferences.default_unit_jump
		self.entry_height.step=config.preferences.default_unit_jump
		self.update_var()

	def update_var(self, *arg):
		if len(self.document.selection.GetInfo()):
			if self.var_basepoint.get() == 'USER':
				x=self.var_width.get()
				y=self.var_height.get()
				self.var_width.unit=config.preferences.default_unit
				self.var_height.unit=config.preferences.default_unit
				self.var_width.set(x)
				self.var_height.set(y)
				
			else:
				self.var_width.unit=config.preferences.default_unit
				self.var_height.unit=config.preferences.default_unit
				x, y = self.coordinates(self.var_position.get())
				self.var_width.set(x)
				self.var_height.set(y)
				self.var_width_base=self.var_width.get()
				self.var_height_base=self.var_height.get()

	def is_selection(self):
		return (len(self.document.selection) > 0)
Example #9
0
class DistributePlugin(PluginPanel):

    name = 'Distribute'
    title = _("Distribution")

    def init(self, master):
        PluginPanel.init(self, master)
        root = self.mw.root
        self.var_reference = StringVar(root)
        self.var_reference.set(SELECT)

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------
        label = TLabel(top,
                       text=" " + _("Relative to") + " ",
                       style="FlatLabel")
        label.pack(side=TOP, fill=BOTH, padx=5)
        rel_frame = TLabelframe(top,
                                labelwidget=label,
                                style='Labelframe',
                                borderwidth=4)
        rel_frame.pack(side=TOP, fill=X, padx=5, pady=2)
        button_frame = TFrame(rel_frame, style='FlatFrame')
        button_frame.pack(side=TOP, fill=BOTH, padx=5)

        self.reference = TCombobox(button_frame,
                                   state='readonly',
                                   values=self.make_cs_list(),
                                   style='ComboNormal',
                                   width=14,
                                   textvariable=self.var_reference,
                                   postcommand=self.set_cs)
        self.reference.pack(side=TOP)
        #---------------------------------------------------------
        label = TLabel(top,
                       text=" " + _("Distribute type") + " ",
                       style="FlatLabel")
        label.pack(side=TOP, fill=BOTH, padx=5)
        framec = TLabelframe(top,
                             labelwidget=label,
                             style='Labelframe',
                             borderwidth=3)
        framec.pack(side=TOP, fill=X, padx=5, pady=2)

        framex = TFrame(framec, style='FlatFrame')
        framex.pack(side=TOP, expand=0, padx=5, pady=5)

        framey = TFrame(framec, style='FlatFrame')
        framey.pack(side=TOP, expand=0, padx=5, pady=5)

        x_pixmaps = ['doleft', 'docenterh', 'dospacingh', 'doright']
        y_pixmaps = ['dotop', 'docenterv', 'dospacingv', 'dobottom']
        x_tooltips = [
            _('Distribute left sides equidistantly'),
            _('Distribute centers equidistantly horizontally'),
            _('Make horizontal gaps between objects equal'),
            _('Distribute right sides equidistantly')
        ]

        y_tooltips = [
            _('Distribute tops sides equidistantly'),
            _('Distribute centers equidistantly vertically'),
            _('Make vertical gaps between objects equal'),
            _('Distribute bottoms sides equidistantly')
        ]

        self.var_x = IntVar(top)
        self.var_x.set(0)
        self.value_x = 0
        self.var_y = IntVar(top)
        self.var_y.set(0)
        self.value_y = 0

        for i in range(1, 5):
            button = make_button(framex,
                                 image=x_pixmaps[i - 1],
                                 value=i,
                                 variable=self.var_x,
                                 command=self.apply_x)
            tooltips.AddDescription(button, x_tooltips[i - 1])
            button.pack(side=LEFT, padx=3)
            button = make_button(framey,
                                 image=y_pixmaps[i - 1],
                                 value=i,
                                 variable=self.var_y,
                                 command=self.apply_y)
            tooltips.AddDescription(button, y_tooltips[i - 1])
            button.pack(side=LEFT, padx=3)

        #---------------------------------------------------------
        # Auto Apply Check
        self.var_auto_apply = IntVar(top)
        self.var_auto_apply.set(0)

        self.auto_apply_check = TCheckbutton(top,
                                             text=_("Auto Apply"),
                                             variable=self.var_auto_apply,
                                             command=self.reset)
        self.auto_apply_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Button frame

        self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        self.button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button_apply = TButton(self.button_frame,
                                    text=_("Apply"),
                                    command=self.apply_distribute)

        self.apply_button_show(1)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)

    def init_from_doc(self):
        self.Update()

    def Update(self, *arg):
        reference = self.var_reference.get()
        if self.is_selection(reference):
            state = NORMAL
        else:
            state = DISABLED
        self.button_apply['state'] = state

    def apply_button_show(self, state):
        if not state:
            self.button_apply.pack_forget()
        else:
            self.button_apply.pack(side=BOTTOM, expand=1, fill=X, pady=3)

    def make_cs_list(self):
        cs = ()
        cs += (SELECT, PAGE, EDGE)
        return cs

    def set_cs(self):
        self.Update()

    def is_selection(self, reference=SELECT):
        if not self.var_auto_apply.get(
        ) and self.value_x == 0 and self.value_y == 0:
            return 0
        if reference == SELECT:
            return (len(self.document.selection) > 2)
        else:
            return (len(self.document.selection) > 1)

    def HDistributeSelection(self, x, reference=SELECT):
        if self.is_selection(reference) and x:
            self.document.begin_transaction(TRANSACTION)
            try:
                try:
                    add_undo = self.document.add_undo
                    objects = self.document.selection.GetObjects()
                    if reference == PAGE:
                        brleft, brbottom, brright, brtop = self.document.PageRect(
                        )
                    else:
                        brleft, brbottom, brright, brtop = self.document.selection.coord_rect

                    posh = []
                    total_width = 0
                    for obj in objects:
                        rect = obj.coord_rect
                        posh.append((rect.left, rect.right - rect.left, obj))
                        total_width += rect.right - rect.left
                    posh.sort()

                    first_obj_left, first_obj_width, first_obj = posh[0]
                    last_obj_left, last_obj_width, last_obj = posh[-1]

                    # how much influence of the width. 1-no, 0-full
                    part_obj_dict = [None, 1.0, 0.5, 1.0, 0]
                    # influence the width last object
                    first_obj_dict = [
                        None, 0, first_obj_width * 0.5, 0, first_obj_width
                    ]
                    # influence the width last object
                    last_obj_dict = [
                        None, last_obj_width, last_obj_width * 0.5, 0, 0
                    ]
                    # influence the width. 0-no , 1-yes
                    width_obj_dict = [None, 0, 0, 1, 0]

                    brleft += first_obj_dict[x]
                    brright -= last_obj_dict[x]
                    brwidth = (brright - brleft -
                               total_width * width_obj_dict[x])
                    if reference == EDGE:
                        step = config.preferences.handle_jump
                    else:
                        step = brwidth / (len(posh) - 1)
                    part = part_obj_dict[x]
                    next = 0
                    for left, width, obj in posh[0:]:
                        off = Point(
                            next - left + brleft - width + width * part, 0)
                        self.document.add_undo(obj.Translate(off))
                        next += step + width * width_obj_dict[x]
                    add_undo(self.document.queue_edited())
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def VDistributeSelection(self, y, reference=SELECT):
        if self.is_selection(reference) and y:
            self.document.begin_transaction(TRANSACTION)
            try:
                try:
                    add_undo = self.document.add_undo
                    objects = self.document.selection.GetObjects()
                    if reference == PAGE:
                        brleft, brbottom, brright, brtop = self.document.PageRect(
                        )
                    else:
                        brleft, brbottom, brright, brtop = self.document.selection.coord_rect

                    posv = []
                    total_height = 0
                    for obj in objects:
                        rect = obj.coord_rect
                        posv.append((rect.top, rect.bottom - rect.top, obj))
                        total_height += rect.bottom - rect.top
                    posv.sort()
                    posv.reverse()

                    first_obj_top, first_obj_height, first_obj = posv[0]
                    last_obj_top, last_obj_height, last_obj = posv[-1]

                    # how much influence of the height. 1-no, 0-full
                    part_obj_dict = [None, 1.0, 0.5, 1.0, 0]
                    # influence the height last object
                    first_obj_dict = [
                        None, 0, first_obj_height * 0.5, 0, first_obj_height
                    ]
                    # influence the height last object
                    last_obj_dict = [
                        None, last_obj_height, last_obj_height * 0.5, 0, 0
                    ]
                    # influence the height. 0-no , 1-yes
                    height_obj_dict = [None, 0, 0, 1, 0]

                    brtop += first_obj_dict[y]
                    brbottom -= last_obj_dict[y]
                    brwidth = (brbottom - brtop -
                               total_height * height_obj_dict[y])
                    if reference == EDGE:
                        step = -1 * config.preferences.handle_jump
                    else:
                        step = brwidth / (len(posv) - 1)
                    part = part_obj_dict[y]
                    next = 0
                    for top, height, obj in posv[0:]:
                        off = Point(
                            0, next - top + brtop - height + height * part)
                        self.document.add_undo(obj.Translate(off))
                        next += step + height * height_obj_dict[y]
                    add_undo(self.document.queue_edited())
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def apply_x(self):
        x = self.var_x.get()
        reference = self.var_reference.get()
        if self.var_auto_apply.get():
            self.reset()
            self.HDistributeSelection(x, reference=reference)
        else:
            if self.value_x == x:
                self.var_x.set(0)
                self.value_x = 0
            else:
                self.value_x = x
            self.Update()

    def apply_y(self):
        y = self.var_y.get()
        reference = self.var_reference.get()
        if self.var_auto_apply.get():
            self.reset()
            self.VDistributeSelection(y, reference=reference)
        else:
            if self.value_y == y:
                self.var_y.set(0)
                self.value_y = 0
            else:
                self.value_y = y
            self.Update()

    def apply_distribute(self):
        if self.var_auto_apply.get():
            return
        self.document.begin_transaction(TRANSACTION)
        try:
            try:
                reference = self.var_reference.get()
                x = self.value_x
                y = self.value_y
                self.HDistributeSelection(x, reference=reference)
                self.VDistributeSelection(y, reference=reference)
            except:
                self.document.abort_transaction()
        finally:
            self.document.end_transaction()

    def reset(self):
        self.var_x.set(0)
        self.value_x = 0
        self.var_y.set(0)
        self.value_y = 0
        ##		self.apply_button_show(not self.var_auto_apply.get())
        self.Update()
Example #10
0
class PagePanel(CtxSubPanel):

    name = 'PagePanel'

    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)

        self.USER_SPECIFIC = _("<Custom Size>")

        root = self.mw.root
        self.var_format_name = StringVar(root)
        self.var_format_name.set(config.preferences.default_paper_format)
        self.page_orientation = config.preferences.default_page_orientation

        label = TLabel(self.panel, text=_("Page:"))
        label.pack(side=LEFT, padx=2)
        self.page_formats = TCombobox(self.panel,
                                      state='readonly',
                                      postcommand=self.set_format,
                                      values=self.make_formats(),
                                      width=17,
                                      style='ComboNormal',
                                      textvariable=self.var_format_name)
        tooltips.AddDescription(self.page_formats, _("Page formats"))
        self.page_formats.pack(side=LEFT, padx=2)

        #--------------
        sep = FlatFrame(self.panel, width=5, height=2)
        sep.pack(side=LEFT)
        #--------------

        var_width_number = DoubleVar(root)
        var_height_number = DoubleVar(root)
        var_width_unit = StringVar(root)
        var_height_unit = StringVar(root)
        unit = config.preferences.default_unit
        self.var_width = LengthVar(10, unit, var_width_number, var_width_unit)
        self.var_height = LengthVar(10, unit, var_height_number,
                                    var_height_unit)
        jump = config.preferences.default_unit_jump

        label = TLabel(self.panel, text=_("H:"))
        label.pack(side=LEFT)
        self.widthentry = TSpinbox(self.panel,
                                   textvariable=var_width_number,
                                   command=self.applyResize,
                                   vartype=1,
                                   min=5,
                                   max=50000,
                                   step=jump,
                                   width=7)
        tooltips.AddDescription(self.widthentry, _("Page width"))
        self.widthentry.pack(side=LEFT, padx=2)

        #--------------
        sep = FlatFrame(self.panel, width=5, height=2)
        sep.pack(side=LEFT)
        #--------------

        label = TLabel(self.panel, text=_("V:"))
        label.pack(side=LEFT)
        self.heightentry = TSpinbox(self.panel,
                                    textvariable=var_height_number,
                                    command=self.applyResize,
                                    vartype=1,
                                    min=5,
                                    max=50000,
                                    step=jump,
                                    width=7)
        tooltips.AddDescription(self.heightentry, _("Page height"))
        self.heightentry.pack(side=LEFT, padx=2)

        self.portrait_val = StringVar(root)
        self.landscape_val = StringVar(root)

        self.portrait = TCheckbutton(self.panel,
                                     image='context_portrait',
                                     variable=self.portrait_val,
                                     command=self.set_portrait,
                                     style='ToolBarCheckButton')
        tooltips.AddDescription(self.portrait, _("Portrait"))
        self.portrait.pack(side=LEFT, padx=2)
        self.landscape = TCheckbutton(self.panel,
                                      image='context_landscape',
                                      variable=self.landscape_val,
                                      command=self.set_landscape,
                                      style='ToolBarCheckButton')
        tooltips.AddDescription(self.landscape, _("Landscape"))
        self.landscape.pack(side=LEFT)
        config.preferences.Subscribe(CHANGED, self.update_pref)
        self.doc.Subscribe(PAGE, self.update_pref)
        self.doc.Subscribe(UNDO, self.update_pref)

    def init_from_doc(self):
        self.page_orientation = self.doc.Layout().Orientation()

        formatname = self.doc.Layout().FormatName()
        if formatname == '':
            formatname = self.USER_SPECIFIC
            width, height = self.doc.PageSize()
            if width <= height:
                self.page_orientation = 0
            else:
                self.page_orientation = 1
            self.update_size(width, height)

        self.var_format_name.set(formatname)
        self.update()

    def ReSubscribe(self):
        self.init_from_doc()

    def make_formats(self):
        formats = ()
        for format in PapersizesList:
            formats += (format[0], )
        formats += (self.USER_SPECIFIC, )
        return formats

    def set_portrait(self):
        self.page_orientation = 0
        width = min(self.var_width.get(), self.var_height.get())
        height = max(self.var_width.get(), self.var_height.get())
        self.update_size(width, height)
        self.set_size()

    def set_landscape(self):
        self.page_orientation = 1
        width = max(self.var_width.get(), self.var_height.get())
        height = min(self.var_width.get(), self.var_height.get())
        self.update_size(width, height)
        self.set_size()

    def set_size(self):
        self.var_width.UpdateNumber()
        self.var_height.UpdateNumber()
        self.update()
        self.apply_settings()

    def set_format(self):
        if not self.var_format_name.get() == self.doc.page_layout.paperformat:
            self.set_size()

    def update_pref(self, *arg):
        self.var_width.unit = config.preferences.default_unit
        self.var_height.unit = config.preferences.default_unit
        width, height = self.doc.PageSize()
        self.var_format_name.set(self.doc.page_layout.paperformat)
        if self.doc.page_layout.paperformat == "":
            self.var_format_name.set(self.USER_SPECIFIC)
            self.set_entry_sensitivity()
        self.page_orientation = self.doc.page_layout.orientation
        self.update_size(width, height)
        self.update()

    def update(self):
        self.set_entry_sensitivity()
        self.update_size_from_name(self.var_format_name.get())
        if self.page_orientation:
            self.portrait_val.set('')
            self.landscape_val.set('1')
        else:
            self.portrait_val.set('1')
            self.landscape_val.set('')

    def set_entry_sensitivity(self):
        formatname = self.var_format_name.get()
        if formatname != self.USER_SPECIFIC:
            self.widthentry.set_state(DISABLED)
            self.heightentry.set_state(DISABLED)
        else:
            self.widthentry.set_state(NORMAL)
            self.heightentry.set_state(NORMAL)

    def update_size(self, width, height):
        self.var_width.set(width)
        self.var_height.set(height)

    def update_size_from_name(self, formatname):
        if formatname == "":
            formatname = self.USER_SPECIFIC
        if not formatname == self.USER_SPECIFIC:
            width, height = Papersize[formatname]
            if self.page_orientation:
                width, height = height, width
            self.update_size(width, height)

    def applyResize(self, event):
        try:
            width = self.var_width.get()
            height = self.var_height.get()
            if width <= height:
                self.set_portrait()
            else:
                self.set_landscape()
        except:
            return

    def apply_settings(self):
        formatname = self.var_format_name.get()
        if formatname == self.USER_SPECIFIC:
            layout = PageLayout(width=self.var_width.get(),
                                height=self.var_height.get(),
                                orientation=0)
        else:
            layout = PageLayout(formatname, orientation=self.page_orientation)
        self.mw.canvas.bitmap_buffer = None
        self.doc.SetLayout(layout)
        self.doc.pages[self.doc.active_page].page_layout = layout
class GradientFillPanel(PluginPanel):
    name = 'GradientFill'
    title = _("Gradient Fill")
    dashlist = []
    dash = ()
    ref_style = None
    color = None

    def init(self, master):
        PluginPanel.init(self, master)

        root = self.mw.root

        top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
        top.pack(side=TOP, fill=BOTH)

        ########### APPLY BUTTON ################################################
        button = UpdatedButton(top,
                               text=_("Apply"),
                               command=self.apply_properties,
                               sensitivecb=self.is_correct_selection)
        button.pack(side=BOTTOM, expand=1, fill=X)
        self.Subscribe(SELECTION, button.Update)

        ########### COLOR BUTTON ################################################

        color_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        color_frame.pack(side=TOP)

        label = TLabel(color_frame, style='FlatLabel', text=_('Color:'))
        label.pack(side=LEFT, padx=5)

        self.color_button = TColorButton(color_frame,
                                         command=self.show_outline_color)
        self.color_button.pack(side=LEFT, padx=5)
        self.color_button.set_color((255, 0, 0))

        ########### LINE WIDTH ##################################################

        self.var_width_number = DoubleVar(root)

        self.var_width_base = DoubleVar(root)

        var_width_unit = StringVar(root)

        unit = config.preferences.default_unit

        self.var_width = LengthVar(10, unit, self.var_width_number,
                                   var_width_unit)

        line_width_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        line_width_frame.pack(side=TOP, fill=BOTH)

        self.labelwunit = TLabel(line_width_frame,
                                 style='FlatLabel',
                                 text=self.var_width.unit)
        self.labelwunit.pack(side=RIGHT, padx=5)

        self.entry_width = TSpinbox(line_width_frame,
                                    var=0,
                                    vartype=1,
                                    textvariable=self.var_width_number,
                                    min=0,
                                    max=50000,
                                    step=.1,
                                    width=8,
                                    command=self.update_pattern)
        self.entry_width.pack(side=RIGHT)

        label = TLabel(line_width_frame,
                       style='FlatLabel',
                       text=_('Line width:'))
        label.pack(side=RIGHT, padx=5)
        ########### LINE STYLE #################################################
        style_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        style_frame.pack(side=TOP, fill=X)

        for item in range(1, 12):
            self.dashlist.append("dash%d" % (item))

        self.style_button = TOptionMenu(style_frame,
                                        self.dashlist,
                                        command=self.set_dash,
                                        entry_type='image',
                                        style='TComboSmall')
        self.style_button.pack(side=RIGHT, fill=X)

        label = TLabel(style_frame, style='FlatLabel', text=_('Style:'))
        label.pack(side=RIGHT, padx=5)

        ########################################################################
        selection_frame = TFrame(top, style='FlatFrame', borderwidth=1)
        selection_frame.pack(side=TOP)

        ########### CORNERS #####################################################

        label = TLabel(selection_frame,
                       text=" " + _("Corners:") + " ",
                       style="FlatLabel")
        label.pack()

        corners_frame = TLabelframe(selection_frame,
                                    labelwidget=label,
                                    style='Labelframe',
                                    borderwidth=8)

        corners_frame.pack(side=LEFT, fill=Y, pady=1, padx=1)

        self.var_corner = IntVar(root)
        radio = UpdatedRadiobutton(corners_frame,
                                   image="join_miter",
                                   variable=self.var_corner,
                                   value=const.JoinMiter,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)

        radio = UpdatedRadiobutton(corners_frame,
                                   image="join_round",
                                   variable=self.var_corner,
                                   value=const.JoinRound,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)

        radio = UpdatedRadiobutton(corners_frame,
                                   image="join_bevel",
                                   variable=self.var_corner,
                                   value=const.JoinBevel,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)

        ########### LINE CAPS ###################################################

        label = TLabel(selection_frame,
                       text=" " + _("Line caps:") + " ",
                       style="FlatLabel")
        label.pack()

        caps_frame = TLabelframe(selection_frame,
                                 labelwidget=label,
                                 style='Labelframe',
                                 borderwidth=8)

        caps_frame.pack(side=RIGHT, fill=Y, pady=1, padx=1)

        self.var_caps = IntVar(root)
        radio = UpdatedRadiobutton(caps_frame,
                                   image="cap_butt",
                                   variable=self.var_caps,
                                   value=const.CapButt,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)

        radio = UpdatedRadiobutton(caps_frame,
                                   image="cap_round",
                                   variable=self.var_caps,
                                   value=const.CapRound,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)

        radio = UpdatedRadiobutton(caps_frame,
                                   image="cap_projecting",
                                   variable=self.var_caps,
                                   value=const.CapProjecting,
                                   command=self.update_pattern)
        radio.pack(side=TOP, anchor=W, pady=2)
        self.var_caps.set(0)

        ############ BOTTOM BUTTONS #############################################

        button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
        button_frame.pack(side=BOTTOM, fill=X, pady=5)

        button = TButton(button_frame,
                         style='TSmallbutton',
                         text=' ',
                         image='small_colorpicker',
                         command=self.copy_from)
        button.pack(side=LEFT)
        tooltips.AddDescription(button, _("Copy From..."))

        button = TButton(button_frame,
                         style='TSmallbutton',
                         text=' ',
                         image='restore_color',
                         command=self.restore_properties)
        button.pack(side=LEFT, padx=5)
        tooltips.AddDescription(button, _("Restore properties"))

        self.var_autoupdate = IntVar(top)
        self.var_autoupdate.set(1)

        self.autoupdate_check = TCheckbutton(button_frame,
                                             text=_("Auto Update"),
                                             variable=self.var_autoupdate,
                                             command=self.init_from_doc)
        self.autoupdate_check.pack(side=RIGHT, anchor=W, padx=10)
        #######################################################################

        self.set_default_style()

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def is_correct_selection(self):
        return (len(self.document.selection) > 0)

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.init_from_doc)
        self.document.Subscribe(EDITED, self.init_from_doc)
        config.preferences.Subscribe(CHANGED, self.update_pref)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.init_from_doc)
        self.document.Unsubscribe(EDITED, self.init_from_doc)
        config.preferences.Unsubscribe(CHANGED, self.update_pref)

    def init_from_doc(self, *arg):
        self.issue(SELECTION)
        if self.var_autoupdate.get():
            if self.is_correct_selection():
                if len(self.document.selection) > 1:
                    info, obj = self.document.selection.GetInfo()[0]
                    self.update_from_object(obj)
                else:
                    self.init_from_style(self.document.CurrentProperties())
            else:
                self.ref_style = None
                self.set_default_style()

    def set_dash(self, value):
        if value in self.dashlist:
            dash_index = self.dashlist.index(value)
            self.dash = StandardDashes()[dash_index]

    def update_pattern(self, *args):
        pass

    def apply_properties(self):
        kw = {}
        if self.color is not None:
            kw["line_pattern"] = SolidPattern(self.color)
            kw["line_width"] = self.var_width.get()
            kw["line_join"] = self.var_corner.get()
            kw["line_cap"] = self.var_caps.get()
            kw["line_dashes"] = self.dash
        else:
            kw["line_pattern"] = EmptyPattern
        styledlg.set_properties(self.mw.root, self.document,
                                _("Set Outline Properties"), 'line', kw)

    def copy_from(self):
        self.mw.canvas.PickObject(self.update_from_object)

    def show_outline_color(self):
        self.mw.LoadPlugin('OutlineColor')

    def update_from_object(self, obj):
        if obj is not None:
            self.init_from_style(obj.Properties())

    def restore_properties(self):
        self.init_from_style(self.ref_style)

    def init_from_style(self, initial_style):
        if initial_style is None:
            self.set_default_style()
            return
        import copy
        self.ref_style = copy.copy(initial_style)
        style = self.ref_style
        if style.HasLine():
            self.var_corner.set(style.line_join)
            self.var_caps.set(style.line_cap)
            self.color = copy.copy(style.line_pattern.Color())
            r, g, b = style.line_pattern.Color().getRGB()
            self.color_button.set_color(
                (int(round(r * 255)), int(round(g * 255)),
                 int(round(b * 255))))
            self.var_width.set(style.line_width)
            self.dash = style.line_dashes
            if style.line_dashes in StandardDashes():
                dash_index = StandardDashes().index(self.dash)
                self.style_button.SetValue(self.dashlist[dash_index])
            else:
                dash_image = self.generate_dash_image(style.line_dashes)
                self.style_button.SetValue(dash_image)
        else:
            self.set_default_style()

    def set_default_style(self):
        self.var_corner.set(DEFAULT_CORNER)
        self.var_caps.set(DEFAULT_CAPS)
        self.color_button.set_color(None)
        self.color = None
        self.var_width.set(DEFAULT_WIDTH)
        self.style_button.SetValue(self.dashlist[0])

    def generate_dash_image(self, dashes):
        self.generated_image = Image.new("RGBA", DASH_SIZE, (0, 0, 0, 0))
        draw = ImageDraw.Draw(self.generated_image)
        point = 0
        fill = 1
        y = int(DASH_SIZE[1] / 2)
        while point < DASH_SIZE[0]:
            for item in dashes:
                if fill:
                    color = (0, 0, 0, 1)
                    fill = 0
                else:
                    color = (0, 0, 0, 0)
                    fill = 1
                draw.line([(point, y), (point + item * DASH_WIDTH, y)], color,
                          DASH_WIDTH)
                point += item * DASH_WIDTH
        self.generated_tk_image = ImageTk.PhotoImage(self.generated_image)
        return self.generated_tk_image

    def update_pref(self, *arg):
        self.labelwunit['text'] = config.preferences.default_unit
        self.var_width.UpdateUnit(config.preferences.default_unit)
        self.init_from_doc()
Example #12
0
class FindReplacePanel(PluginPanel):
	name='Text Find & Replace'
	title = _("Text Find & Replace")
	
	def init(self, master):
		PluginPanel.init(self, master)
		top = self.panel

		top = TFrame(top, borderwidth=2, style='FlatFrame')
		top.pack(side = TOP, expand = 1, fill = X)

		button_frame = TFrame(top, borderwidth=2, style='FlatFrame')
		button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1)
		
		button=TButton(button_frame,text=_('Apply'), command=self.replace)
		button.pack(side = TOP)
		
		#----------------------------------------------------------
		main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
		main_frame.pack(side = TOP, fill=X)

		self.find_var = StringVar(top);
		self.find_var.set('')
		findField = TEntryExt(main_frame, textvariable=self.find_var)
		findField.pack(side = RIGHT)
			   
		label = TLabel(main_frame, style='FlatLabel', text = _("Find:")+" ")
		label.pack(side = RIGHT, anchor = E)
		#---------------------------------------------------------
		main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
		main_frame.pack(side = TOP, fill=X)


		self.replace_var = StringVar(top);
		self.replace_var.set('')
		replaceField = TEntryExt(main_frame, textvariable=self.replace_var)
		replaceField.pack(side = RIGHT)
		
		label = TLabel(main_frame, style='FlatLabel', text = _("Replace to:")+" ")
		label.pack(side = RIGHT, anchor = E)
		
		main_frame = TFrame(top, style='FlatFrame', borderwidth=3)
		main_frame.pack(side = TOP)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Parameters")+" ", style="FlatLabel")
		label.pack()
		
		parametersFrameLabel=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)

		parametersFrameLabel.pack(side = TOP, fill=X, pady=4, padx=4)
		
		parametersFrame = TFrame(parametersFrameLabel, style='FlatFrame')  
		
		self.var_case_sensitive = BooleanVar(top)
		self.var_case_sensitive.set(False)
		self.case_sensitive_check = TCheckbutton(parametersFrame, text = _("Case sensitive"), variable = self.var_case_sensitive)
		self.case_sensitive_check.pack(side = TOP, anchor=W, padx=5)
	   
		self.var_whole_word = BooleanVar(top)
		self.var_whole_word.set(False)
		self.whole_word_check = TCheckbutton(parametersFrame, text = _("Whole word"), variable = self.var_whole_word)
		self.whole_word_check.pack(side = TOP, anchor=W, padx=5)
		
		self.var_regexp = BooleanVar(top)
		self.var_regexp.set(False)
		self.regexpCheck = TCheckbutton(parametersFrame, text = _("RegExp search"), variable = self.var_regexp, command=self.disable_enable_action)
		self.regexpCheck.pack(side = TOP, anchor=W, padx=5)
		
		parametersFrame.pack(side=TOP, fill=X, pady=2)
################################################################
	def replace_text(self,objects, toReplace, replaceTo):		
		for object in objects:
			if object.is_Text:
				
				if self.var_regexp.get():
					if self.var_case_sensitive.get():
						p=re.compile(toReplace)
					else:
						p=re.compile(toReplace, re.I)
					text=p.sub(replaceTo, object.text)
					app.mw.document.SelectObject(object)
					app.mw.document.CallObjectMethod(object.__class__,_('Text Replace'),'SetText',text)
					continue
				
				if self.var_whole_word.get():
					if not self.var_case_sensitive.get():
						if object.text.lower()==toReplace.lower():
							text=replaceTo
							app.mw.document.SelectObject(object)
							app.mw.document.CallObjectMethod(object.__class__,_('Text Replace'),'SetText',text)
					else:
						if object.text==toReplace:
							text=replaceTo
							app.mw.document.SelectObject(object)
							app.mw.document.CallObjectMethod(object.__class__,_('Text Replace'),'SetText',text)
							
				else:
					if object.text.lower().find(toReplace.lower(), 0, len(object.text)) != -1:
						if not self.var_case_sensitive.get():
							text=object.text.lower().replace(toReplace.lower(), replaceTo)
						else:
							text=object.text.replace(toReplace, replaceTo)
						app.mw.document.SelectObject(object)
						app.mw.document.CallObjectMethod(object.__class__,_('Text Replace'),'SetText',text)

			if object.is_Group:
				self.replace_text(object.objects)
################################################################
	def replace(self):
		textObjects=[]
		textToReplace=self.find_var.get().decode('utf-8')
		replaceTo=self.replace_var.get().decode('utf-8')

		for layer in app.mw.document.layers:
			self.replace_text(layer.objects, textToReplace, replaceTo)
		app.mw.canvas.ForceRedraw()
################################################################
	def disable_enable_action(self):
		if self.var_regexp.get():	
			self.whole_word_check['state'] = DISABLED
		else:
			self.whole_word_check['state'] = NORMAL
################################################################
	def whole_word_action(self):
		pass
Example #13
0
class FillPanel(PluginPanel):
	name = 'SolidFill'
	title = _("Solid Fill")
	initial_color = None
	current_color = None
	default_color = BLACK_COLOR
	sign = 'tools_color_fill'


	def init(self, master):
		PluginPanel.init(self, master)
		
		self.initial_color = self.default_color
		self.current_color = copy.copy(self.initial_color)

		top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
		top.pack(side=TOP, fill=BOTH)

		self.selector = ColorSpaceSelector(top, self.refresh_widgets, self.current_color, self.sign)
		self.selector.pack(side=TOP, expand=1, fill=X)
		
		self.picker = ColorChooserWidget(top, self.refresh_widgets, self.current_color)
		self.picker.pack(side=TOP, expand=1, fill=X)	
		
		self.digitizer = ColorDigitizer(top, self.refresh_widgets, self.current_color)
		self.digitizer.pack(side=TOP, expand=1, fill=X)


		button = UpdatedButton(top, text=_("Apply"),
								command=self.apply_pattern,
								sensitivecb=self.is_selection)
		button.pack(side=BOTTOM, expand=1, fill=X)
		self.Subscribe(SELECTION, button.Update)
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
		button_frame.pack(side=BOTTOM, fill=X, pady=5)
		
		button = TButton(button_frame, style='TSmallbutton', text=' ', image='small_colorpicker', command=self.copy_from)
		button.pack(side=LEFT)
		tooltips.AddDescription(button, _("Copy From..."))
		
		button = TButton(button_frame, style='TSmallbutton', text=' ', image='restore_color', command=self.restore_color)
		button.pack(side=LEFT, padx=5)
		tooltips.AddDescription(button, _("Restore color"))
		
		self.var_autoupdate = IntVar(top)
		self.var_autoupdate.set(1)
		
		self.autoupdate_check = TCheckbutton(button_frame, text=_("Auto Update"), variable=self.var_autoupdate,
											command=self.init_from_doc)
		self.autoupdate_check.pack(side=RIGHT, anchor=W, padx=10)

		self.init_from_doc()
		self.subscribe_receivers()

###############################################################################
	def is_selection(self):
		return (len(self.document.selection) > 0)
	
	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.init_from_doc)	
		self.document.Subscribe(EDITED, self.init_from_doc)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.init_from_doc)	
		self.document.Unsubscribe(EDITED, self.init_from_doc)

	def init_from_doc(self, *arg):
		if self.var_autoupdate.get():
			self.Update()
		self.issue(SELECTION)

	def Update(self):		
		self.initial_color = self.get_object_color()
		self.current_color = copy.copy(self.initial_color)		
		self.refresh_widgets(self.current_color)
	
	def refresh_widgets(self, color):
		self.current_color = color
		self.selector.set_color(self.current_color)
		self.picker.set_color(self.current_color)
		self.digitizer.set_color(self.current_color)


	def apply_pattern(self):
		if self.current_color is None:
			self.mw.no_pattern('fill')
		else:
			self.mw.canvas.FillSolid(self.current_color)
		self.Update()

	def copy_from(self):
		self.mw.canvas.PickObject(self.update_from_object)
		
	def update_from_object(self, obj):
		if obj is not None:
			self.refresh_widgets(self.init_from_properties(obj.Properties()))
	
	def restore_color(self):
		self.refresh_widgets(copy.copy(self.initial_color))
	
	def get_object_color(self):
		if self.document.HasSelection():
			if len(self.document.selection) > 1:
				info, obj = self.document.selection.GetInfo()[0]
				properties = obj.Properties()
			else:
				properties = self.document.CurrentProperties()
			return self.init_from_properties(properties)
		else:
			return self.default_color
		
	def init_from_properties(self, properties):
		if properties and properties.HasFill() and properties.fill_pattern.__class__ == SolidPattern:
			return properties.fill_pattern.Color()
		else:
			return None
Example #14
0
class MovePanel(PluginPanel):
    name = 'Move'
    title = _("Move")

    def init(self, master):
        PluginPanel.init(self, master)

        root = self.mw.root
        self.var_width_number = DoubleVar(root)
        self.var_height_number = DoubleVar(root)

        self.var_width_base = DoubleVar(root)
        self.var_height_base = DoubleVar(root)

        var_width_unit = StringVar(root)
        var_height_unit = StringVar(root)

        unit = config.preferences.default_unit
        self.var_width = LengthVar(10, unit, self.var_width_number,
                                   var_width_unit)
        self.var_height = LengthVar(10, unit, self.var_height_number,
                                    var_height_unit)

        jump = config.preferences.default_unit_jump
        self.var_width.set(0)
        self.var_height.set(0)

        self.var_width_base.set(0)
        self.var_height_base.set(0)

        self.var_position = StringVar(root)
        self.var_position.set(ABSOLUTE)

        self.var_basepoint = StringVar(root)
        self.var_basepoint.set('C')

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------
        # Horisontal size
        size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style='FlatLabel', image='move_h')
        label.pack(side=LEFT, padx=5)
        self.entry_width = TSpinbox(size_frameH,
                                    var=0,
                                    vartype=1,
                                    textvariable=self.var_width_number,
                                    min=-50000,
                                    max=50000,
                                    step=jump,
                                    width=10,
                                    command=self.apply_move)
        self.entry_width.pack(side=LEFT)

        self.labelwunit = TLabel(size_frameH,
                                 style='FlatLabel',
                                 text=self.var_width.unit)
        self.labelwunit.pack(side=LEFT, padx=5)
        #---------------------------------------------------------
        # Vertical

        size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameV.pack(side=TOP, fill=BOTH)
        label = TLabel(size_frameV, style='FlatLabel', image='move_v')
        label.pack(side=LEFT, padx=5)

        self.entry_height = TSpinbox(size_frameV,
                                     var=0,
                                     vartype=1,
                                     textvariable=self.var_height_number,
                                     min=-50000,
                                     max=50000,
                                     step=jump,
                                     width=10,
                                     command=self.apply_move)
        self.entry_height.pack(side=LEFT)

        self.labelhunit = TLabel(size_frameV,
                                 style='FlatLabel',
                                 text=self.var_height.unit)
        self.labelhunit.pack(side=LEFT, padx=5)

        #---------------------------------------------------------
        # position chek

        self.position_check = TCheckbutton(top,
                                           text=_("Absolute Coordinates"),
                                           variable=self.var_position,
                                           onvalue=ABSOLUTE,
                                           offvalue=RELATIVE,
                                           command=self.position)
        self.position_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Basepoint check

        label = TLabel(top, style='FlatLabel', text=_("Basepoint:"))
        label.pack(side=TOP, fill=BOTH, padx=5)
        basepoint_frame = TLabelframe(top,
                                      labelwidget=label,
                                      style='Labelframe',
                                      borderwidth=4)
        basepoint_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.Basepoint = BasePointSelector(basepoint_frame,
                                           anchor=self.var_basepoint,
                                           command=self.apply_basepoint)
        self.Basepoint.pack(side=LEFT, fill=BOTH, padx=5)

        label = TLabel(basepoint_frame,
                       style='FlatLabel',
                       image='coordinate_sys')
        label.pack(side=LEFT, fill=BOTH, padx=10)

        #---------------------------------------------------------
        # Button frame

        button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button = UpdatedButton(top,
                                    text=_("Apply"),
                                    command=self.apply_move)
        self.button.pack(in_=button_frame,
                         side=BOTTOM,
                         expand=1,
                         fill=X,
                         pady=3)

        self.button_copy = UpdatedButton(top,
                                         text=_("Apply to Copy"),
                                         command=self.apply_to_copy)
        self.button_copy.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)
        self.document.Subscribe(EDITED, self.update_var)
        config.preferences.Subscribe(CHANGED, self.update_pref)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)
        self.document.Unsubscribe(EDITED, self.update_var)
        config.preferences.Unsubscribe(CHANGED, self.update_pref)

    def init_from_doc(self, *arg):
        self.Update()

    def Update(self, *arg):
        if self.is_selection():
            self.entry_width.set_state(NORMAL)
            self.entry_height.set_state(NORMAL)
            self.position_check['state'] = NORMAL
            self.button['state'] = NORMAL
            self.button_copy['state'] = NORMAL
        else:
            self.entry_width.set_state(DISABLED)
            self.entry_height.set_state(DISABLED)
            self.position_check['state'] = DISABLED
            self.button['state'] = DISABLED
            self.button_copy['state'] = DISABLED

        self.update_pref()

    def apply_basepoint(self):
        self.Update()

    def position(self):
        if self.var_position.get() == ABSOLUTE and self.var_basepoint.get(
        ) == 'USER':
            self.var_basepoint.set('C')
        self.update_var()

    def apply_move(self, *arg):
        if self.button["state"] == DISABLED:
            return
        try:
            var_x = self.var_width.get()
            var_y = self.var_height.get()
        except:
            return

        x, y = self.coordinates(self.var_position.get())

        if self.var_position.get() == RELATIVE:
            if self.var_width_base != self.var_width.get(
            ) or self.var_height_base != self.var_height.get():
                self.var_basepoint.set('USER')
            x, y = var_x, var_y
        else:
            x, y = var_x - x, var_y - y

        if arg and arg[0] == 'Duplicate':
            self.document.MoveAndCopy(x, y, Point(0, 0))
        else:
            self.document.MoveSelected(x, y)

    def apply_to_copy(self):
        self.apply_move('Duplicate')

    def coordinates(self, position):
        br = self.document.selection.coord_rect
        hor_sel = br.right - br.left
        ver_sel = br.top - br.bottom

        if position == RELATIVE:
            left, bottom = -hor_sel / 2, -ver_sel / 2
        else:
            left, bottom = br.left, br.bottom

        cnt_x, cnt_y = self.Basepoint.get_basepoint(hor_sel, ver_sel, left,
                                                    bottom)

        if position == RELATIVE and cnt_x != None:
            return cnt_x * 2, cnt_y * 2
        else:
            return cnt_x, cnt_y

    def update_pref(self, *arg):
        self.labelwunit['text'] = config.preferences.default_unit
        self.labelhunit['text'] = config.preferences.default_unit
        self.entry_width.step = config.preferences.default_unit_jump
        self.entry_height.step = config.preferences.default_unit_jump
        self.update_var()

    def update_var(self, *arg):
        if len(self.document.selection.GetInfo()):
            if self.var_basepoint.get() == 'USER':
                x = self.var_width.get()
                y = self.var_height.get()
                self.var_width.unit = config.preferences.default_unit
                self.var_height.unit = config.preferences.default_unit
                self.var_width.set(x)
                self.var_height.set(y)

            else:
                self.var_width.unit = config.preferences.default_unit
                self.var_height.unit = config.preferences.default_unit
                x, y = self.coordinates(self.var_position.get())
                self.var_width.set(x)
                self.var_height.set(y)
                self.var_width_base = self.var_width.get()
                self.var_height_base = self.var_height.get()

    def is_selection(self):
        return (len(self.document.selection) > 0)
Example #15
0
class AlignPlugin(PluginPanel):
	
	name='Alignment'
	title = _("Alignment")
	
	def init(self, master):
		PluginPanel.init(self, master)
		root=self.mw.root
		self.var_reference = StringVar(root)
		self.var_reference.set(SELECT)
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		rel_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.reference = TCombobox(rel_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14,
									 textvariable=self.var_reference, postcommand = self.set_cs)
		self.reference.pack(side = TOP)
		#---------------------------------------------------------

		label=TLabel(top, text=" "+_("Alignment type")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		framec.pack(side = TOP, fill=X, padx=5, pady=2)
		
		framex = TFrame(framec, style='FlatFrame')
		framex.pack(side = TOP, expand = 0, padx = 5, pady = 5)
		
		framey = TFrame(framec, style='FlatFrame')
		framey.pack(side = TOP, expand = 0, padx = 5, pady = 5)


		x_pixmaps = ['aoleft', 'aocenterh', 'aoright']
		y_pixmaps = ['aotop', 'aocenterv', 'aobottom']
		x_tooltips = [_('Align left sides'),
						_('Center on vertical axis'),
						_('Align right sides')]

		y_tooltips = [_('Align tops'),
						_('Center on horizontal axis'),
						_('Align bottoms')]
						
		self.var_x = IntVar(top)
		self.var_x.set(0)
		self.value_x = 0
		self.var_y = IntVar(top)
		self.var_y.set(0)
		self.value_y = 0

		for i in range(1, 4):
			button = make_button(framex, image = x_pixmaps[i - 1], value = i, variable = self.var_x, command = self.apply_x)
			tooltips.AddDescription(button, x_tooltips[i - 1])
			button.pack(side = LEFT, padx = 3)
			button = make_button(framey, image = y_pixmaps[i - 1], value = i, variable = self.var_y, command = self.apply_y)
			tooltips.AddDescription(button, y_tooltips[i - 1])
			button.pack(side = LEFT, padx = 3)


		#---------------------------------------------------------
		# Auto Apply Check
		self.var_auto_apply = IntVar(top)
		self.var_auto_apply.set(0)
		
		self.auto_apply_check = TCheckbutton(top, text = _("Auto Apply"), variable = self.var_auto_apply, command = self.reset)
		self.auto_apply_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Button frame 
		
		self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		self.button_frame.pack(side = BOTTOM, fill = BOTH)
		
		self.update_buttons = []
		self.button_apply = TButton(self.button_frame, text = _("Apply"),
								command = self.apply)
		
		self.apply_button_show(1)

		self.init_from_doc()
		self.subscribe_receivers()


###############################################################################

	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.Update)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.Update)

	def init_from_doc(self):
		self.Update()
		self.issue(SELECTION)

	def Update(self, *arg):
		reference = self.var_reference.get()
		if self.is_selection(reference):
			state=NORMAL
		else:
			state=DISABLED
		self.button_apply['state']=state

	def apply_button_show(self, state):
		if not state:
			self.button_apply.pack_forget()
		else:
			self.button_apply.pack(side = BOTTOM, expand = 1, fill = X, pady=3)

	def make_cs_list(self):
		cs=()
		cs+=(SELECT,LOWERMOST,PAGE)
		return cs

	def set_cs(self):
		self.Update()

	def is_selection(self, reference = SELECT):
		if not self.var_auto_apply.get() and self.value_x==0 and self.value_y==0:
			return 0
		if reference == PAGE:
			return (len(self.document.selection) > 0)
		else:
			return (len(self.document.selection) > 1)

	def apply_x(self):
		x = self.var_x.get()
		if self.var_auto_apply.get():
			self.reset()
			self.apply(x=x)
		else:
			if self.value_x==x:
				self.var_x.set(0)
				self.value_x = 0
			else:
				self.value_x = x
			self.Update()

	def apply_y(self):
		y = self.var_y.get()
		if self.var_auto_apply.get():
			self.reset()
			self.apply(y=y)
		else:
			if self.value_y==y:
				self.var_y.set(0)
				self.value_y = 0
			else:
				self.value_y = y
			self.Update()

	def apply(self, x=None, y=None, reference = None):
		reference = self.var_reference.get()
		if not self.is_selection(reference):
			return
		
		if x is None:
			x = self.var_x.get()
			
		if y is None:
			y = self.var_y.get()
			
		if reference is None:
			reference = self.var_reference.get()
		
		reference = self.reference_command(reference)
		
		self.document.AlignSelection(x, y, reference = reference)

	def reference_command(self, reference):
		if reference == SELECT:
			return 'selection'
		if reference == LOWERMOST:
			return 'lowermost'
		if reference == PAGE:
			return 'page'

	def reset(self):
		self.var_x.set(0)
		self.value_x = 0
		self.var_y.set(0)
		self.value_y = 0
##		self.apply_button_show(not self.var_auto_apply.get())
		self.Update()
class ScalePanel(PluginPanel):
    name = 'ScaleAndMirror'
    title = _("Scale and Mirror")

    def init(self, master):
        PluginPanel.init(self, master)

        self.width_priority = 1

        root = self.mw.root
        self.var_width = DoubleVar(root)
        self.var_height = DoubleVar(root)

        unit = '%'
        jump = 5

        self.var_proportional = IntVar(root)
        self.var_proportional.set(0)

        self.var_basepoint = StringVar(root)
        self.var_basepoint.set('C')

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------
        # Horisontal size
        size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style='FlatLabel', image='size_h')
        label.pack(side=LEFT, padx=5)
        self.entry_width = TSpinbox(size_frameH,
                                    var=100,
                                    vartype=1,
                                    textvariable=self.var_width,
                                    min=-30000,
                                    max=30000,
                                    step=jump,
                                    width=6,
                                    command=self.apply_scale)
        self.entry_width.pack(side=LEFT)

        self.entry_width.down_button.bind('<ButtonRelease>',
                                          self.entry_width_chang)
        self.entry_width.down_button.bind('<KeyRelease>',
                                          self.entry_width_chang)
        self.entry_width.up_button.bind('<ButtonRelease>',
                                        self.entry_width_chang)
        self.entry_width.up_button.bind('<KeyRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<ButtonRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<KeyRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<FocusOut>', self.entry_width_chang)
        self.entry_width.entry.bind('<FocusIn>', self.entry_width_FocusIn)

        self.labelwunit = TLabel(size_frameH, style='FlatLabel', text=unit)
        self.labelwunit.pack(side=LEFT, padx=5)

        self.hflip = BooleanVar(root)
        self.hflip.set(0)
        button = TCheckbutton(size_frameH,
                              image="pstrip_hflip",
                              style='ToolBarCheckButton',
                              variable=self.hflip,
                              command=None)
        button.pack(side=LEFT)

        #---------------------------------------------------------
        # Vertical

        size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameV.pack(side=TOP, fill=BOTH)
        label = TLabel(size_frameV, style='FlatLabel', image='size_v')
        label.pack(side=LEFT, padx=5)

        self.entry_height = TSpinbox(size_frameV,
                                     var=100,
                                     vartype=1,
                                     textvariable=self.var_height,
                                     min=-30000,
                                     max=30000,
                                     step=jump,
                                     width=6,
                                     command=self.apply_scale)
        self.entry_height.pack(side=LEFT)

        self.entry_height.down_button.bind('<ButtonRelease>',
                                           self.entry_height_chang)
        self.entry_height.down_button.bind('<KeyRelease>',
                                           self.entry_height_chang)
        self.entry_height.up_button.bind('<ButtonRelease>',
                                         self.entry_height_chang)
        self.entry_height.up_button.bind('<KeyRelease>',
                                         self.entry_height_chang)
        self.entry_height.entry.bind('<ButtonRelease>',
                                     self.entry_height_chang)
        self.entry_height.entry.bind('<KeyRelease>', self.entry_height_chang)
        self.entry_height.entry.bind('<FocusOut>', self.entry_height_chang)
        self.entry_height.entry.bind('<FocusIn>', self.entry_height_FocusIn)

        self.labelhunit = TLabel(size_frameV, style='FlatLabel', text=unit)
        self.labelhunit.pack(side=LEFT, padx=5)

        self.vflip = BooleanVar(root)
        self.vflip.set(0)
        button = TCheckbutton(size_frameV,
                              image="pstrip_vflip",
                              style='ToolBarCheckButton',
                              variable=self.vflip,
                              command=None)
        button.pack(side=LEFT)

        #---------------------------------------------------------
        # Proportional chek

        self.proportional_check = TCheckbutton(top,
                                               text=_("Proportional"),
                                               variable=self.var_proportional,
                                               command=self.proportional)
        self.proportional_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Basepoint check
        label = TLabel(top, style='FlatLabel', text=_("Basepoint:"))
        label.pack(side=TOP, fill=BOTH, padx=5)
        basepoint_frame = TLabelframe(top,
                                      labelwidget=label,
                                      style='Labelframe',
                                      borderwidth=4)
        basepoint_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.Basepoint = BasePointSelector(basepoint_frame,
                                           anchor=self.var_basepoint)
        self.Basepoint.pack(side=LEFT, fill=BOTH, padx=5)

        label = TLabel(basepoint_frame,
                       style='FlatLabel',
                       image='coordinate_sys')
        label.pack(side=LEFT, fill=BOTH, padx=10)

        #---------------------------------------------------------
        # Button frame

        button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button = UpdatedButton(top,
                                    text=_("Apply"),
                                    command=self.apply_scale)
        self.button.pack(in_=button_frame,
                         side=BOTTOM,
                         expand=1,
                         fill=X,
                         pady=3)

        self.button_copy = UpdatedButton(top,
                                         text=_("Apply to Copy"),
                                         command=self.apply_to_copy)
        self.button_copy.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)

    def init_from_doc(self, *arg):
        self.Update()

    def Update(self, *arg):
        if self.is_selection():
            self.entry_width.set_state(NORMAL)
            self.entry_height.set_state(NORMAL)
            self.proportional_check['state'] = NORMAL
            self.button['state'] = NORMAL
            self.button_copy['state'] = NORMAL
        else:
            self.entry_width.set_state(DISABLED)
            self.entry_height.set_state(DISABLED)
            self.proportional_check['state'] = DISABLED
            self.button['state'] = DISABLED
            self.button_copy['state'] = DISABLED

    def entry_width_FocusIn(self, *arg):
        self.width_priority = 1

    def entry_height_FocusIn(self, *arg):
        self.width_priority = 0

    def ScaleSelected(self, h, v, cnt_x=None, cnt_y=None):
        text = _("Scale")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    br = self.document.selection.coord_rect
                    hor_sel = br.right - br.left
                    ver_sel = br.top - br.bottom
                    if cnt_x is None:
                        cnt_x = hor_sel / 2 + br.left
                    if cnt_y is None:
                        cnt_y = ver_sel / 2 + br.bottom
                    trafo = Trafo(h, 0, 0, v, cnt_x - cnt_x * h,
                                  cnt_y - cnt_y * v)
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def ScaleAndCopy(self, h, v, cnt_x=None, cnt_y=None):
        text = _("Scale&Copy")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    br = self.document.selection.coord_rect
                    hor_sel = br.right - br.left
                    ver_sel = br.top - br.bottom
                    if cnt_x is None:
                        cnt_x = hor_sel / 2 + br.left
                    if cnt_y is None:
                        cnt_y = ver_sel / 2 + br.bottom
                    trafo = Trafo(h, 0, 0, v, cnt_x - cnt_x * h,
                                  cnt_y - cnt_y * v)
                    self.document.ApplyToDuplicate()
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def entry_height_chang(self, *arg):
        if self.var_proportional.get():
            self.var_width.set(self.var_height.get())

    def entry_width_chang(self, *arg):
        if self.var_proportional.get():
            self.var_height.set(self.var_width.get())

    def proportional(self):
        if self.width_priority:
            self.entry_width_chang()
        else:
            self.entry_height_chang()

    def apply_scale(self, *arg):
        if self.button["state"] == DISABLED:
            return
        self.proportional()
        width = self.var_width.get()
        height = self.var_height.get()
        br = self.document.selection.coord_rect
        hor_sel = br.right - br.left
        ver_sel = br.top - br.bottom
        cnt_x, cnt_y = self.Basepoint.get_basepoint(hor_sel, ver_sel, br.left,
                                                    br.bottom)

        h = width / 100
        if h == 0:
            h = 1
        if self.hflip.get():
            h = -1 * h

        v = height / 100
        if v == 0:
            v = 1
        if self.vflip.get():
            v = -1 * v

        if arg and arg[0] == 'Duplicate':
            self.ScaleAndCopy(h, v, cnt_x, cnt_y)
        else:
            self.ScaleSelected(h, v, cnt_x, cnt_y)

    def apply_to_copy(self):
        self.apply_scale('Duplicate')

    def is_selection(self):
        return (len(self.document.selection) > 0)
    def init(self, master):
        PluginPanel.init(self, master)

        self.width_priority = 1

        root = self.mw.root
        self.var_width = DoubleVar(root)
        self.var_height = DoubleVar(root)

        unit = '%'
        jump = 5

        self.var_proportional = IntVar(root)
        self.var_proportional.set(0)

        self.var_basepoint = StringVar(root)
        self.var_basepoint.set('C')

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------
        # Horisontal size
        size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style='FlatLabel', image='size_h')
        label.pack(side=LEFT, padx=5)
        self.entry_width = TSpinbox(size_frameH,
                                    var=100,
                                    vartype=1,
                                    textvariable=self.var_width,
                                    min=-30000,
                                    max=30000,
                                    step=jump,
                                    width=6,
                                    command=self.apply_scale)
        self.entry_width.pack(side=LEFT)

        self.entry_width.down_button.bind('<ButtonRelease>',
                                          self.entry_width_chang)
        self.entry_width.down_button.bind('<KeyRelease>',
                                          self.entry_width_chang)
        self.entry_width.up_button.bind('<ButtonRelease>',
                                        self.entry_width_chang)
        self.entry_width.up_button.bind('<KeyRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<ButtonRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<KeyRelease>', self.entry_width_chang)
        self.entry_width.entry.bind('<FocusOut>', self.entry_width_chang)
        self.entry_width.entry.bind('<FocusIn>', self.entry_width_FocusIn)

        self.labelwunit = TLabel(size_frameH, style='FlatLabel', text=unit)
        self.labelwunit.pack(side=LEFT, padx=5)

        self.hflip = BooleanVar(root)
        self.hflip.set(0)
        button = TCheckbutton(size_frameH,
                              image="pstrip_hflip",
                              style='ToolBarCheckButton',
                              variable=self.hflip,
                              command=None)
        button.pack(side=LEFT)

        #---------------------------------------------------------
        # Vertical

        size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameV.pack(side=TOP, fill=BOTH)
        label = TLabel(size_frameV, style='FlatLabel', image='size_v')
        label.pack(side=LEFT, padx=5)

        self.entry_height = TSpinbox(size_frameV,
                                     var=100,
                                     vartype=1,
                                     textvariable=self.var_height,
                                     min=-30000,
                                     max=30000,
                                     step=jump,
                                     width=6,
                                     command=self.apply_scale)
        self.entry_height.pack(side=LEFT)

        self.entry_height.down_button.bind('<ButtonRelease>',
                                           self.entry_height_chang)
        self.entry_height.down_button.bind('<KeyRelease>',
                                           self.entry_height_chang)
        self.entry_height.up_button.bind('<ButtonRelease>',
                                         self.entry_height_chang)
        self.entry_height.up_button.bind('<KeyRelease>',
                                         self.entry_height_chang)
        self.entry_height.entry.bind('<ButtonRelease>',
                                     self.entry_height_chang)
        self.entry_height.entry.bind('<KeyRelease>', self.entry_height_chang)
        self.entry_height.entry.bind('<FocusOut>', self.entry_height_chang)
        self.entry_height.entry.bind('<FocusIn>', self.entry_height_FocusIn)

        self.labelhunit = TLabel(size_frameV, style='FlatLabel', text=unit)
        self.labelhunit.pack(side=LEFT, padx=5)

        self.vflip = BooleanVar(root)
        self.vflip.set(0)
        button = TCheckbutton(size_frameV,
                              image="pstrip_vflip",
                              style='ToolBarCheckButton',
                              variable=self.vflip,
                              command=None)
        button.pack(side=LEFT)

        #---------------------------------------------------------
        # Proportional chek

        self.proportional_check = TCheckbutton(top,
                                               text=_("Proportional"),
                                               variable=self.var_proportional,
                                               command=self.proportional)
        self.proportional_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Basepoint check
        label = TLabel(top, style='FlatLabel', text=_("Basepoint:"))
        label.pack(side=TOP, fill=BOTH, padx=5)
        basepoint_frame = TLabelframe(top,
                                      labelwidget=label,
                                      style='Labelframe',
                                      borderwidth=4)
        basepoint_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.Basepoint = BasePointSelector(basepoint_frame,
                                           anchor=self.var_basepoint)
        self.Basepoint.pack(side=LEFT, fill=BOTH, padx=5)

        label = TLabel(basepoint_frame,
                       style='FlatLabel',
                       image='coordinate_sys')
        label.pack(side=LEFT, fill=BOTH, padx=10)

        #---------------------------------------------------------
        # Button frame

        button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button = UpdatedButton(top,
                                    text=_("Apply"),
                                    command=self.apply_scale)
        self.button.pack(in_=button_frame,
                         side=BOTTOM,
                         expand=1,
                         fill=X,
                         pady=3)

        self.button_copy = UpdatedButton(top,
                                         text=_("Apply to Copy"),
                                         command=self.apply_to_copy)
        self.button_copy.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X)

        self.init_from_doc()
        self.subscribe_receivers()
Example #18
0
class GradientFillPanel(PluginPanel):
	name='GradientFill'
	title = _("Gradient Fill")
	dashlist=[]
	dash=()
	ref_style=None
	color=None

	def init(self, master):
		PluginPanel.init(self, master)
		
		root=self.mw.root
		
		top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
		top.pack(side = TOP, fill=BOTH)

		########### APPLY BUTTON ################################################
		button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_properties,
								sensitivecb = self.is_correct_selection)
		button.pack(side = BOTTOM, expand = 1, fill = X)
		self.Subscribe(SELECTION, button.Update)

		########### COLOR BUTTON ################################################		
		
		color_frame = TFrame(top, style='FlatFrame', borderwidth=3)
		color_frame.pack(side = TOP)
		
		label = TLabel(color_frame, style='FlatLabel', text=_('Color:'))
		label.pack(side = LEFT, padx=5)
		
		self.color_button = TColorButton(color_frame, command=self.show_outline_color)
		self.color_button.pack(side = LEFT, padx=5)
		self.color_button.set_color((255,0,0))
		
		########### LINE WIDTH ##################################################

		self.var_width_number=DoubleVar(root)
		
		self.var_width_base=DoubleVar(root)

		var_width_unit = StringVar(root)
		
		unit = config.preferences.default_unit
		
		self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit)
		
		line_width_frame = TFrame(top, style='FlatFrame', borderwidth=3)
		line_width_frame.pack(side = TOP, fill = BOTH)

		self.labelwunit = TLabel(line_width_frame, style='FlatLabel', text = self.var_width.unit)
		self.labelwunit.pack(side = RIGHT, padx=5)
		
		self.entry_width = TSpinbox(line_width_frame,  var=0, vartype=1, textvariable = self.var_width_number, 
									min = 0, max = 50000, step = .1, width = 8, command=self.update_pattern)
		self.entry_width.pack(side = RIGHT)
		
		label = TLabel(line_width_frame, style='FlatLabel', text=_('Line width:'))
		label.pack(side = RIGHT, padx=5)		
		########### LINE STYLE #################################################		
		style_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		style_frame.pack(side = TOP, fill=X)
		
		for item in range(1,12):
			self.dashlist.append("dash%d"%(item))
		
		self.style_button = TOptionMenu(style_frame, self.dashlist, command = self.set_dash, 
									entry_type = 'image', style='TComboSmall')
		self.style_button.pack(side = RIGHT, fill=X)
		
		label = TLabel(style_frame, style='FlatLabel', text=_('Style:'))
		label.pack(side = RIGHT, padx=5)

		########################################################################		
		selection_frame = TFrame(top, style='FlatFrame', borderwidth=1)
		selection_frame.pack(side = TOP)
			
		########### CORNERS #####################################################	
		
		label=TLabel(selection_frame, text=" "+_("Corners:")+" ", style="FlatLabel")
		label.pack()
		
		corners_frame=TLabelframe(selection_frame, labelwidget=label, style='Labelframe', borderwidth=8)

		corners_frame.pack(side = LEFT, fill=Y, pady=1, padx=1)
		
		self.var_corner = IntVar(root)
		radio = UpdatedRadiobutton(corners_frame, image = "join_miter",
									variable = self.var_corner,
									value = const.JoinMiter,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)
		
		radio = UpdatedRadiobutton(corners_frame, image = "join_round",
									variable = self.var_corner,
									value = const.JoinRound,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)
		
		radio = UpdatedRadiobutton(corners_frame, image = "join_bevel",
									variable = self.var_corner,
									value = const.JoinBevel,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)

		
		########### LINE CAPS ###################################################
		
		label=TLabel(selection_frame, text=" "+_("Line caps:")+" ", style="FlatLabel")
		label.pack()
		
		caps_frame=TLabelframe(selection_frame, labelwidget=label, style='Labelframe', borderwidth=8)

		caps_frame.pack(side = RIGHT, fill=Y, pady=1, padx=1)
		
		self.var_caps = IntVar(root)
		radio = UpdatedRadiobutton(caps_frame, image = "cap_butt",
									variable = self.var_caps,
									value = const.CapButt,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)
		
		radio = UpdatedRadiobutton(caps_frame, image = "cap_round",
									variable = self.var_caps,
									value = const.CapRound,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)
		
		radio = UpdatedRadiobutton(caps_frame, image = "cap_projecting",
									variable = self.var_caps,
									value = const.CapProjecting,
									command = self.update_pattern)
		radio.pack(side = TOP, anchor=W, pady=2)
		self.var_caps.set(0)
		
		############ BOTTOM BUTTONS #############################################
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
		button_frame.pack(side = BOTTOM, fill=X, pady=5)
		
		button = TButton(button_frame, style='TSmallbutton', text=' ', image='small_colorpicker', command = self.copy_from)
		button.pack(side = LEFT)
		tooltips.AddDescription(button, _("Copy From..."))
		
		button = TButton(button_frame, style='TSmallbutton', text=' ', image='restore_color', command = self.restore_properties)
		button.pack(side = LEFT, padx=5)
		tooltips.AddDescription(button, _("Restore properties"))
		
		self.var_autoupdate = IntVar(top)
		self.var_autoupdate.set(1)
		
		self.autoupdate_check = TCheckbutton(button_frame, text = _("Auto Update"), variable = self.var_autoupdate, 
											command=self.init_from_doc)
		self.autoupdate_check.pack(side = RIGHT, anchor=W, padx=10)
		#######################################################################
		
		
		self.set_default_style()

		self.init_from_doc()
		self.subscribe_receivers()

###############################################################################
	def is_correct_selection(self):
		return (len(self.document.selection) >0)
	
	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.init_from_doc)	
		self.document.Subscribe(EDITED, self.init_from_doc)
		config.preferences.Subscribe(CHANGED, self.update_pref)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.init_from_doc)	
		self.document.Unsubscribe(EDITED, self.init_from_doc)
		config.preferences.Unsubscribe(CHANGED, self.update_pref)

	def init_from_doc(self, *arg):
		self.issue(SELECTION)
		if self.var_autoupdate.get():
			if self.is_correct_selection():
				if len(self.document.selection) > 1:
					info,obj=self.document.selection.GetInfo()[0]
					self.update_from_object(obj)
				else:
					self.init_from_style(self.document.CurrentProperties())
			else:
				self.ref_style=None
				self.set_default_style()
		
	def set_dash(self, value):
		if value in self.dashlist:
			dash_index=self.dashlist.index(value)
			self.dash=StandardDashes()[dash_index]
		
	def update_pattern(self, *args):
		pass

	def apply_properties(self):
		kw = {}
		if self.color is not None:			
			kw["line_pattern"]  = SolidPattern(self.color)
			kw["line_width"] = self.var_width.get()
			kw["line_join"] = self.var_corner.get()
			kw["line_cap"] = self.var_caps.get()
			kw["line_dashes"] = self.dash
		else:
			kw["line_pattern"] = EmptyPattern
		styledlg.set_properties(self.mw.root, self.document, _("Set Outline Properties"), 'line', kw)
		
	def copy_from(self):
		self.mw.canvas.PickObject(self.update_from_object)
		
	def show_outline_color(self):
		self.mw.LoadPlugin('OutlineColor')
		
	def update_from_object(self, obj):
		if obj is not None:
			self.init_from_style(obj.Properties())
	
	def restore_properties(self):
		self.init_from_style(self.ref_style)
	
	def init_from_style(self, initial_style):
		if initial_style is None:
			self.set_default_style()
			return
		import copy
		self.ref_style=copy.copy(initial_style)
		style=self.ref_style
		if style.HasLine():
			self.var_corner.set(style.line_join)
			self.var_caps.set(style.line_cap)
			self.color=copy.copy(style.line_pattern.Color())
			r,g,b=style.line_pattern.Color().getRGB()
			self.color_button.set_color((int(round(r*255)),
										int(round(g*255)),
										int(round(b*255))))
			self.var_width.set(style.line_width)
			self.dash=style.line_dashes
			if style.line_dashes in StandardDashes(): 			
				dash_index=StandardDashes().index(self.dash)
				self.style_button.SetValue(self.dashlist[dash_index])
			else:
				dash_image=self.generate_dash_image(style.line_dashes)
				self.style_button.SetValue(dash_image)
		else:
			self.set_default_style()
			
	def set_default_style(self):
		self.var_corner.set(DEFAULT_CORNER)
		self.var_caps.set(DEFAULT_CAPS)
		self.color_button.set_color(None)
		self.color=None
		self.var_width.set(DEFAULT_WIDTH)
		self.style_button.SetValue(self.dashlist[0])
		
	def generate_dash_image(self, dashes):
		self.generated_image=Image.new("RGBA",DASH_SIZE,(0,0,0,0))
		draw = ImageDraw.Draw(self.generated_image)
		point=0
		fill=1
		y=int(DASH_SIZE[1]/2)
		while point<DASH_SIZE[0]:
			for item in dashes:
				if fill:
					color=(0,0,0,1)
					fill=0
				else:
					color=(0,0,0,0)
					fill=1
				draw.line([(point,y),(point+item*DASH_WIDTH,y)], color, DASH_WIDTH)
				point+=item*DASH_WIDTH
		self.generated_tk_image=ImageTk.PhotoImage(self.generated_image)
		return self.generated_tk_image
	
	def update_pref(self, *arg):
		self.labelwunit['text']=config.preferences.default_unit
		self.var_width.UpdateUnit(config.preferences.default_unit)
		self.init_from_doc()
Example #19
0
class TrimPanel(PluginPanel):
	name='Trim'
	title = _("Trim")

	def init(self, master):
		PluginPanel.init(self, master)

		top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
		top.pack(side = TOP, fill=BOTH)

		sign = TFrame(top, style='RoundedFrame', borderwidth=5)
		sign.pack(side = TOP)

		self.sign=TLabel(sign, image='shaping_trim')
		self.sign.pack(side=TOP)

		button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_action,
								sensitivecb = self.is_correct_selection)
		button.pack(side = BOTTOM, expand = 1, fill = X)
		self.Subscribe(SELECTION, button.Update)
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
		button_frame.pack(side = BOTTOM, fill=X, pady=5)
				
		self.var_originals = IntVar(top)
		self.var_originals.set(0)
		
		self.autoupdate_check = TCheckbutton(button_frame, text = _("Leave originals"), 
											variable = self.var_originals)
		self.autoupdate_check.pack(side = LEFT, anchor=W, padx=10)

		self.init_from_doc()
		self.subscribe_receivers()

###############################################################################
	def is_correct_selection(self):
		return (len(self.document.selection) > 1)
	
	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.init_from_doc)	
		self.document.Subscribe(EDITED, self.init_from_doc)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.init_from_doc)	
		self.document.Unsubscribe(EDITED, self.init_from_doc)

	def init_from_doc(self, *arg):
		self.issue(SELECTION)

	def apply_action(self):
		objects = base.get_selection(self.mw)
		if not objects:
			return
		for i in range(len(objects)-1):
			for j in range(i+1, len(objects)):
				objects[i] = self.minus([objects[i], objects[j]])
		if not self.var_originals.get():
			self.document.RemoveSelected()
		for i in range(len(objects)):
			self.document.Insert(objects[i])
		
	def minus(self, objects):
		assert len(objects) == 2
		new_paths, untouched_paths = base.intersect_objects(objects)
		buffer = []
		for i, paths in new_paths:
			if i == 0:
				container = objects[1]
				condition = 0
			else:
				container = objects[0]
				condition = 1
			for cp1, path, cp2 in paths:
				if base.contained(path, container) == condition:
					buffer.append((cp1, path, cp2))
		paths = base.join(buffer)
		for i, path in untouched_paths:
			if i == 0:
				container = objects[1]
				condition = 0
			else:
				container = objects[0]
				condition = 1
			if base.contained(path, container) == condition:
				paths.append(path)
		object = objects[0].Duplicate()
		object.SetPaths(paths)
		return object
Example #20
0
class RotatePanel(PluginPanel):
    name = 'Rotate'
    title = _("Rotate")

    def init(self, master):
        PluginPanel.init(self, master)

        root = self.mw.root

        self.var_angle = DoubleVar(root)
        self.var_angle.set(0)

        self.var_width_number = DoubleVar(root)
        self.var_height_number = DoubleVar(root)

        self.var_width_base = DoubleVar(root)
        self.var_height_base = DoubleVar(root)

        self.cnt_x_absolute = None
        self.cnt_y_absolute = None

        var_width_unit = StringVar(root)
        var_height_unit = StringVar(root)

        unit = config.preferences.default_unit
        self.var_width = LengthVar(10, unit, self.var_width_number,
                                   var_width_unit)
        self.var_height = LengthVar(10, unit, self.var_height_number,
                                    var_height_unit)

        jump = config.preferences.default_unit_jump
        self.var_width.set(0)
        self.var_height.set(0)

        self.var_width_base.set(0)
        self.var_height_base.set(0)

        self.var_position = StringVar(root)
        self.var_position.set(ABSOLUTE)

        self.var_basepoint = StringVar(root)
        self.var_basepoint.set('C')

        #---------------------------------------------------------
        top = TFrame(self.panel, style='FlatFrame')
        top.pack(side=TOP, fill=BOTH)
        #---------------------------------------------------------

        angle_frame = TFrame(top, style='FlatFrame', borderwidth=3)
        angle_frame.pack(side=TOP, fill=BOTH)
        label = TLabel(angle_frame,
                       style='FlatLabel',
                       text=" " + _("Angle:") + " ")
        label.pack(side=LEFT, padx=5)

        self.entry_angle = TSpinbox(angle_frame,
                                    var=0,
                                    vartype=1,
                                    textvariable=self.var_angle,
                                    min=-360,
                                    max=360,
                                    step=5,
                                    width=6,
                                    command=self.apply_rotate)
        self.entry_angle.pack(side=LEFT, anchor=E)
        label = TLabel(angle_frame, style='FlatLabel', text=_("deg"))
        label.pack(side=LEFT, padx=5)
        #---------------------------------------------------------
        label = TLabel(top, style='FlatLabel', text=_("Center:"))
        label.pack(side=TOP, fill=BOTH, padx=5)

        #---------------------------------------------------------
        # Horisontal
        size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style='FlatLabel', image='center_h')
        label.pack(side=LEFT, padx=5)
        self.entry_width = TSpinbox(size_frameH,
                                    var=0,
                                    vartype=1,
                                    textvariable=self.var_width_number,
                                    min=-50000,
                                    max=50000,
                                    step=jump,
                                    width=10,
                                    command=self.apply_rotate)
        self.entry_width.pack(side=LEFT)

        self.labelwunit = TLabel(size_frameH,
                                 style='FlatLabel',
                                 text=self.var_width.unit)
        self.labelwunit.pack(side=LEFT, padx=5)
        #---------------------------------------------------------
        # Vertical

        size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameV.pack(side=TOP, fill=BOTH)
        label = TLabel(size_frameV, style='FlatLabel', image='center_v')
        label.pack(side=LEFT, padx=5)

        self.entry_height = TSpinbox(size_frameV,
                                     var=0,
                                     vartype=1,
                                     textvariable=self.var_height_number,
                                     min=-50000,
                                     max=50000,
                                     step=jump,
                                     width=10,
                                     command=self.apply_rotate)
        self.entry_height.pack(side=LEFT)

        self.labelhunit = TLabel(size_frameV,
                                 style='FlatLabel',
                                 text=self.var_height.unit)
        self.labelhunit.pack(side=LEFT, padx=5)

        #---------------------------------------------------------
        # position chek

        self.position_check = TCheckbutton(top,
                                           text=_("Absolute Center"),
                                           variable=self.var_position,
                                           onvalue=ABSOLUTE,
                                           offvalue=RELATIVE,
                                           command=self.position)
        self.position_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Basepoint check

        label = TLabel(top, style='FlatLabel', text=_("Basepoint:"))
        label.pack(side=TOP, fill=BOTH, padx=5)
        basepoint_frame = TLabelframe(top,
                                      labelwidget=label,
                                      style='Labelframe',
                                      borderwidth=4)
        basepoint_frame.pack(side=TOP, fill=X, padx=5, pady=2)

        self.Basepoint = BasePointSelector(basepoint_frame,
                                           anchor=self.var_basepoint,
                                           command=self.apply_basepoint)
        self.Basepoint.pack(side=LEFT, fill=BOTH, padx=5)

        label = TLabel(basepoint_frame,
                       style='FlatLabel',
                       image='coordinate_deg')
        label.pack(side=LEFT, fill=BOTH, padx=10)

        self.position_check.pack(side=TOP, anchor=W, padx=5, pady=5)

        #---------------------------------------------------------
        # Button frame

        button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
        button_frame.pack(side=BOTTOM, fill=BOTH)

        self.update_buttons = []
        self.button = UpdatedButton(top,
                                    text=_("Apply"),
                                    command=self.apply_rotate)
        self.button.pack(in_=button_frame,
                         side=BOTTOM,
                         expand=1,
                         fill=X,
                         pady=3)

        self.button_copy = UpdatedButton(top,
                                         text=_("Apply to Copy"),
                                         command=self.apply_to_copy)
        self.button_copy.pack(in_=button_frame, side=BOTTOM, expand=1, fill=X)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.Update)
        self.document.Subscribe(EDITED, self.update_var)
        config.preferences.Subscribe(CHANGED, self.update_pref)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.Update)
        self.document.Unsubscribe(EDITED, self.update_var)
        config.preferences.Unsubscribe(CHANGED, self.update_pref)

    def init_from_doc(self, *arg):
        self.Update()

    def Update(self, *arg):
        if self.is_selection():
            self.entry_angle.set_state(NORMAL)
            self.entry_width.set_state(NORMAL)
            self.entry_height.set_state(NORMAL)
            self.position_check['state'] = NORMAL
            self.button['state'] = NORMAL
            self.button_copy['state'] = NORMAL
            self.TestBasepoint()
        else:
            self.entry_angle.set_state(DISABLED)
            self.entry_width.set_state(DISABLED)
            self.entry_height.set_state(DISABLED)
            self.position_check['state'] = DISABLED
            self.button['state'] = DISABLED
            self.button_copy['state'] = DISABLED

        self.update_pref()

    def apply_basepoint(self):
        self.update_var()

    def position(self):
        self.update_var()

    def RotateSelected(self, angle, cnt=None):
        text = _("Rotation")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    if cnt is None:
                        cnt = self.document.selection.coord_rect.center()
                    angle = angle * degrees
                    trafo = Rotation(angle, cnt)
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def RotateAndCopy(self, angle, cnt=None):
        text = _("Rotation&Copy")
        if self.document.selection:
            self.document.begin_transaction(text)
            try:
                try:
                    if cnt is None:
                        cnt = self.document.selection.coord_rect.center()
                    angle = angle * degrees
                    trafo = Rotation(angle, cnt)
                    self.document.ApplyToDuplicate()
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def apply_rotate(self, *arg):
        if self.button["state"] == DISABLED:
            return

        try:
            var_x = self.var_width.get()
            var_y = self.var_height.get()
            var_a = self.var_angle.get()
        except:
            return

        if var_a < 0:
            if var_a < -360:
                var_a += int(var_a / 360) * 360
            var_a += 360

        if self.var_basepoint.get() != 'USER':
            self.cnt_x_absolute, self.cnt_y_absolute = self.coordinates(
                ABSOLUTE)
            self.var_basepoint.set('USER')

        if self.var_width_base != var_x or self.var_height_base != var_y:

            if self.var_position.get() == ABSOLUTE:
                self.cnt_x_absolute = var_x
                self.cnt_y_absolute = var_y
            else:
                x, y = self.coordinates(ABSOLUTE, 'C')
                self.cnt_x_absolute = var_x + x
                self.cnt_y_absolute = var_y + y

            self.var_basepoint.set('USER')

        if arg and arg[0] == 'Duplicate':
            self.RotateAndCopy(var_a,
                               Point(self.cnt_x_absolute, self.cnt_y_absolute))
        else:
            self.RotateSelected(
                var_a, Point(self.cnt_x_absolute, self.cnt_y_absolute))

    def apply_to_copy(self):
        self.apply_rotate('Duplicate')

    def coordinates(self, position, anchor=None):
        br = self.document.selection.coord_rect
        hor_sel = br.right - br.left
        ver_sel = br.top - br.bottom

        if position == RELATIVE:
            left, bottom = -hor_sel / 2.0, -ver_sel / 2.0
        else:
            left, bottom = br.left, br.bottom

        cnt_x, cnt_y = self.Basepoint.get_basepoint(hor_sel, ver_sel, left,
                                                    bottom, anchor)
        return cnt_x, cnt_y

    def TestBasepoint(self):
        if self.cnt_x_absolute is None:
            return
        base = ['C', 'NW', 'N', 'NE', 'W', 'E', 'SW', 'S', 'SE']
        for b in xrange(len(base)):
            cnt_x, cnt_y = self.coordinates(ABSOLUTE, base[b])
            if round(cnt_x,2) == round(self.cnt_x_absolute,2) and \
                 round(cnt_y,2) == round(self.cnt_y_absolute,2):
                self.var_basepoint.set(base[b])
                return
        self.var_basepoint.set('USER')

    def update_pref(self, *arg):
        self.labelwunit['text'] = config.preferences.default_unit
        self.labelhunit['text'] = config.preferences.default_unit
        self.entry_width.step = config.preferences.default_unit_jump
        self.entry_height.step = config.preferences.default_unit_jump
        self.update_var()

    def update_var(self, *arg):
        if len(self.document.selection.GetInfo()):

            self.var_width.unit = config.preferences.default_unit
            self.var_height.unit = config.preferences.default_unit

            if self.var_basepoint.get() == 'USER':

                if self.var_position.get() == ABSOLUTE:
                    self.var_width.set(self.cnt_x_absolute)
                    self.var_height.set(self.cnt_y_absolute)
                else:
                    x, y = self.coordinates(ABSOLUTE, 'C')
                    self.var_width.set(self.cnt_x_absolute - x)
                    self.var_height.set(self.cnt_y_absolute - y)

            else:
                x, y = self.coordinates(self.var_position.get())
                self.var_width.set(x)
                self.var_height.set(y)
                self.var_width_base = self.var_width.get()
                self.var_height_base = self.var_height.get()

    def is_selection(self):
        return (len(self.document.selection) > 0)
Example #21
0
class DistributePlugin(PluginPanel):
	
	name='Distribute'
	title = _("Distribution")
	
	def init(self, master):
		PluginPanel.init(self, master)
		root=self.mw.root
		self.var_reference = StringVar(root)
		self.var_reference.set(SELECT)
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		rel_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		button_frame=TFrame(rel_frame, style='FlatFrame')
		button_frame.pack(side = TOP, fill = BOTH, padx=5)
		
		self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14,
									 textvariable=self.var_reference, postcommand = self.set_cs)
		self.reference.pack(side = TOP)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Distribute type")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		framec.pack(side = TOP, fill=X, padx=5, pady=2)
		
		
		framex = TFrame(framec, style='FlatFrame')
		framex.pack(side = TOP, expand = 0, padx = 5, pady = 5)
		
		framey = TFrame(framec, style='FlatFrame')
		framey.pack(side = TOP, expand = 0, padx = 5, pady = 5)


		x_pixmaps = ['doleft', 'docenterh', 'dospacingh', 'doright']
		y_pixmaps = ['dotop', 'docenterv', 'dospacingv', 'dobottom']
		x_tooltips = [_('Distribute left sides equidistantly'),
						_('Distribute centers equidistantly horizontally'),
						_('Make horizontal gaps between objects equal'),
						_('Distribute right sides equidistantly')]

		y_tooltips = [_('Distribute tops sides equidistantly'),
						_('Distribute centers equidistantly vertically'),
						_('Make vertical gaps between objects equal'),
						_('Distribute bottoms sides equidistantly')]

		self.var_x = IntVar(top)
		self.var_x.set(0)
		self.value_x = 0
		self.var_y = IntVar(top)
		self.var_y.set(0)
		self.value_y = 0
		
		for i in range(1, 5):
			button = make_button(framex, image = x_pixmaps[i - 1], value = i, variable = self.var_x, command = self.apply_x)
			tooltips.AddDescription(button, x_tooltips[i - 1])
			button.pack(side = LEFT, padx = 3)
			button = make_button(framey, image = y_pixmaps[i - 1], value = i, variable = self.var_y, command = self.apply_y)
			tooltips.AddDescription(button, y_tooltips[i - 1])
			button.pack(side = LEFT, padx = 3)
		
		#---------------------------------------------------------
		# Auto Apply Check
		self.var_auto_apply = IntVar(top)
		self.var_auto_apply.set(0)
		
		self.auto_apply_check = TCheckbutton(top, text = _("Auto Apply"), variable = self.var_auto_apply, command = self.reset)
		self.auto_apply_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Button frame 
		
		self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		self.button_frame.pack(side = BOTTOM, fill = BOTH)
		
		self.update_buttons = []
		self.button_apply = TButton(self.button_frame, text = _("Apply"),
								command = self.apply_distribute)
		
		self.apply_button_show(1)

		self.init_from_doc()
		self.subscribe_receivers()


###############################################################################

	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.Update)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.Update)

	def init_from_doc(self):
		self.Update()

	def Update(self, *arg):
		reference = self.var_reference.get()
		if self.is_selection(reference):
			state=NORMAL
		else:
			state=DISABLED
		self.button_apply['state']=state

	def apply_button_show(self, state):
		if not state:
			self.button_apply.pack_forget()
		else:
			self.button_apply.pack(side = BOTTOM, expand = 1, fill = X, pady=3)

	def make_cs_list(self):
		cs=()
		cs+=(SELECT,PAGE,EDGE)
		return cs

	def set_cs(self):
		self.Update()

	def is_selection(self, reference = SELECT):
		if not self.var_auto_apply.get() and self.value_x==0 and self.value_y==0:
			return 0
		if reference == SELECT:
			return (len(self.document.selection) > 2)
		else:
			return (len(self.document.selection) > 1)

	def HDistributeSelection(self, x, reference = SELECT):
		if self.is_selection(reference) and x:
			self.document.begin_transaction(TRANSACTION)
			try:
				try:
					add_undo = self.document.add_undo
					objects = self.document.selection.GetObjects()
					if reference == PAGE:
						brleft, brbottom, brright, brtop = self.document.PageRect()
					else:
						brleft,  brbottom, brright, brtop = self.document.selection.coord_rect
					
					posh = []
					total_width=0
					for obj in objects:
						rect = obj.coord_rect
						posh.append((rect.left, rect.right - rect.left, obj))
						total_width += rect.right - rect.left
					posh.sort()
					
					first_obj_left, first_obj_width, first_obj = posh[0]
					last_obj_left, last_obj_width, last_obj = posh[-1]
					
					# how much influence of the width. 1-no, 0-full
					part_obj_dict=[None, 1.0, 0.5, 1.0, 0]
					# influence the width last object
					first_obj_dict = [None, 0, first_obj_width*0.5, 0, first_obj_width]
					# influence the width last object
					last_obj_dict  = [None, last_obj_width, last_obj_width*0.5, 0, 0]
					# influence the width. 0-no , 1-yes
					width_obj_dict = [None, 0,0,1,0]
					
					brleft  += first_obj_dict[x]
					brright -= last_obj_dict[x]
					brwidth = (brright-brleft - total_width*width_obj_dict[x])
					if reference == EDGE:
						step = config.preferences.handle_jump
					else:
						step = brwidth / (len(posh)-1)
					part=part_obj_dict[x]
					next = 0
					for left, width, obj in posh[0:]:
						off = Point(next - left +brleft - width + width*part, 0)
						self.document.add_undo(obj.Translate(off))
						next += step+width*width_obj_dict[x]
					add_undo(self.document.queue_edited())
				except:
					self.document.abort_transaction()
			finally:
				self.document.end_transaction()



	def VDistributeSelection(self, y, reference = SELECT):
		if self.is_selection(reference) and y:
			self.document.begin_transaction(TRANSACTION)
			try:
				try:
					add_undo = self.document.add_undo
					objects = self.document.selection.GetObjects()
					if reference == PAGE:
						brleft, brbottom, brright, brtop = self.document.PageRect()
					else:
						brleft,  brbottom, brright, brtop = self.document.selection.coord_rect
					
					posv = []
					total_height=0
					for obj in objects:
						rect = obj.coord_rect
						posv.append((rect.top, rect.bottom - rect.top, obj))
						total_height += rect.bottom - rect.top
					posv.sort()
					posv.reverse()
					
					first_obj_top, first_obj_height, first_obj = posv[0]
					last_obj_top, last_obj_height, last_obj = posv[-1]
					
					# how much influence of the height. 1-no, 0-full
					part_obj_dict=[None, 1.0, 0.5, 1.0, 0]
					# influence the height last object
					first_obj_dict = [None, 0, first_obj_height*0.5, 0, first_obj_height]
					# influence the height last object
					last_obj_dict  = [None, last_obj_height, last_obj_height*0.5, 0, 0]
					# influence the height. 0-no , 1-yes
					height_obj_dict = [None, 0,0,1,0]
					
					brtop  += first_obj_dict[y]
					brbottom -= last_obj_dict[y]
					brwidth = (brbottom-brtop - total_height*height_obj_dict[y])
					if reference == EDGE:
						step = -1*config.preferences.handle_jump
					else:
						step = brwidth / (len(posv)-1)
					part=part_obj_dict[y]
					next = 0
					for top, height, obj in posv[0:]:
						off = Point(0, next - top +brtop - height + height*part)
						self.document.add_undo(obj.Translate(off))
						next += step+height*height_obj_dict[y]
					add_undo(self.document.queue_edited())
				except:
					self.document.abort_transaction()
			finally:
					self.document.end_transaction()

	def apply_x(self):
		x = self.var_x.get()
		reference = self.var_reference.get()
		if self.var_auto_apply.get():
			self.reset()
			self.HDistributeSelection(x, reference = reference)
		else:
			if self.value_x==x:
				self.var_x.set(0)
				self.value_x = 0
			else:
				self.value_x = x
			self.Update()

	def apply_y(self):
		y = self.var_y.get()
		reference = self.var_reference.get()
		if self.var_auto_apply.get():
			self.reset()
			self.VDistributeSelection(y, reference = reference)
		else:
			if self.value_y==y:
				self.var_y.set(0)
				self.value_y = 0
			else:
				self.value_y = y
			self.Update()

	def apply_distribute(self):
		if self.var_auto_apply.get():
			return
		self.document.begin_transaction(TRANSACTION)
		try:
			try:
				reference = self.var_reference.get()
				x = self.value_x
				y = self.value_y
				self.HDistributeSelection(x, reference = reference)
				self.VDistributeSelection(y, reference = reference)
			except:
				self.document.abort_transaction()
		finally:
					self.document.end_transaction()

	def reset(self):
		self.var_x.set(0)
		self.value_x = 0
		self.var_y.set(0)
		self.value_y = 0
##		self.apply_button_show(not self.var_auto_apply.get())
		self.Update()
Example #22
0
class DividePanel(PluginPanel):
    name = 'Divide'
    title = _("Divide")

    def init(self, master):
        PluginPanel.init(self, master)

        top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
        top.pack(side=TOP, fill=BOTH)

        sign = TFrame(top, style='RoundedFrame', borderwidth=5)
        sign.pack(side=TOP)

        self.sign = TLabel(sign, image='shaping_divide')
        self.sign.pack(side=TOP)

        button = UpdatedButton(top,
                               text=_("Apply"),
                               command=self.apply_action,
                               sensitivecb=self.is_correct_selection)
        button.pack(side=BOTTOM, expand=1, fill=X)
        self.Subscribe(SELECTION, button.Update)

        button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
        button_frame.pack(side=BOTTOM, fill=X, pady=5)

        self.var_originals = IntVar(top)
        self.var_originals.set(1)

        self.autoupdate_check = TCheckbutton(button_frame,
                                             text=_("Leave originals"),
                                             variable=self.var_originals)
        self.autoupdate_check.pack(side=LEFT, anchor=W, padx=10)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def is_correct_selection(self):
        return (len(self.document.selection) == 2)

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.init_from_doc)
        self.document.Subscribe(EDITED, self.init_from_doc)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.init_from_doc)
        self.document.Unsubscribe(EDITED, self.init_from_doc)

    def init_from_doc(self, *arg):
        self.issue(SELECTION)

    def apply_action(self):
        objects = base.get_selection(self.mw)
        if not objects:
            return
        objects[0:2] = self.divide(objects[0], objects[1])
        if not self.var_originals.get():
            self.document.RemoveSelected()
        for object in objects:
            self.document.Insert(object)

    def divide(self, object1, object2):
        buffer = []
        new_paths, untouched_paths = base.intersect_objects([object1, object2])
        if new_paths:
            common = []
            parts = ([], [])
            for i, paths in new_paths:
                if i == 0:
                    container = object2
                    parts2, parts1 = parts
                else:
                    container = object1
                    parts1, parts2 = parts
                for cp1, path, cp2 in paths:
                    if base.contained(path, container):
                        common.append((cp1, path, cp2))
                        parts2.append((cp1, path, cp2))
                    else:
                        parts1.append((cp1, path, cp2))
            for path in base.join(parts1):
                object = object1.Duplicate()
                object.SetPaths([path])
                buffer.append(object)
            for path in base.join(parts2):
                object = object2.Duplicate()
                object.SetPaths([path])
                buffer.append(object)
            for path in base.join(common):
                object = object2.Duplicate()
                object.SetPaths([path])
                buffer.append(object)
            for i, path in untouched_paths:
                if i == 0:
                    object = object1.Duplicate()
                else:
                    object = object2.Duplicate()
                object.SetPaths([path])
                buffer.append(object)
        else:
            buffer.append(object1.Duplicate())
            buffer.append(object2.Duplicate())
        return buffer
Example #23
0
class DividePanel(PluginPanel):
	name='Divide'
	title = _("Divide")

	def init(self, master):
		PluginPanel.init(self, master)

		top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
		top.pack(side = TOP, fill=BOTH)
		
		sign = TFrame(top, style='RoundedFrame', borderwidth=5)
		sign.pack(side = TOP)

		self.sign=TLabel(sign, image='shaping_divide')
		self.sign.pack(side=TOP)

		button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_action,
								sensitivecb = self.is_correct_selection)
		button.pack(side = BOTTOM, expand = 1, fill = X)
		self.Subscribe(SELECTION, button.Update)
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
		button_frame.pack(side = BOTTOM, fill=X, pady=5)
				
		self.var_originals = IntVar(top)
		self.var_originals.set(1)
		
		self.autoupdate_check = TCheckbutton(button_frame, text = _("Leave originals"), 
											variable = self.var_originals)
		self.autoupdate_check.pack(side = LEFT, anchor=W, padx=10)

		self.init_from_doc()
		self.subscribe_receivers()

###############################################################################
	def is_correct_selection(self):
		return (len(self.document.selection) == 2)
	
	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.init_from_doc)	
		self.document.Subscribe(EDITED, self.init_from_doc)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.init_from_doc)	
		self.document.Unsubscribe(EDITED, self.init_from_doc)

	def init_from_doc(self, *arg):
		self.issue(SELECTION)

	def apply_action(self):
		objects = base.get_selection(self.mw)
		if not objects:
			return
		objects[0:2] = self.divide(objects[0], objects[1])
		if not self.var_originals.get():
			self.document.RemoveSelected()
		for object in objects:
			self.document.Insert(object)
		
	def divide(self, object1, object2):
		buffer = []
		new_paths, untouched_paths = base.intersect_objects([object1, object2])
		if new_paths:
			common = []
			parts = ([], [])
			for i, paths in new_paths:
				if i == 0:
					container = object2
					parts2, parts1 = parts
				else:
					container = object1
					parts1, parts2 = parts
				for cp1, path, cp2 in paths:
					if base.contained(path, container):
						common.append((cp1, path, cp2))
						parts2.append((cp1, path, cp2))
					else:						 
						parts1.append((cp1, path, cp2))
			for path in base.join(parts1):
				object = object1.Duplicate()
				object.SetPaths([path])
				buffer.append(object)
			for path in base.join(parts2):
				object = object2.Duplicate()
				object.SetPaths([path])
				buffer.append(object)
			for path in base.join(common):
				object = object2.Duplicate()
				object.SetPaths([path])
				buffer.append(object)
			for i, path in untouched_paths:
				if i == 0:
					object = object1.Duplicate()
				else:
					object = object2.Duplicate()
				object.SetPaths([path])
				buffer.append(object)
		else:
			buffer.append(object1.Duplicate())
			buffer.append(object2.Duplicate())
		return buffer
Example #24
0
class FillPanel(PluginPanel):
    name = 'SolidFill'
    title = _("Solid Fill")
    initial_color = None
    current_color = None
    default_color = BLACK_COLOR
    sign = 'tools_color_fill'

    def init(self, master):
        PluginPanel.init(self, master)

        self.initial_color = self.default_color
        self.current_color = copy.copy(self.initial_color)

        top = TFrame(self.panel, style='FlatFrame', borderwidth=5)
        top.pack(side=TOP, fill=BOTH)

        self.selector = ColorSpaceSelector(top, self.refresh_widgets,
                                           self.current_color, self.sign)
        self.selector.pack(side=TOP, expand=1, fill=X)

        self.picker = ColorChooserWidget(top, self.refresh_widgets,
                                         self.current_color)
        self.picker.pack(side=TOP, expand=1, fill=X)

        self.digitizer = ColorDigitizer(top, self.refresh_widgets,
                                        self.current_color)
        self.digitizer.pack(side=TOP, expand=1, fill=X)

        button = UpdatedButton(top,
                               text=_("Apply"),
                               command=self.apply_pattern,
                               sensitivecb=self.is_selection)
        button.pack(side=BOTTOM, expand=1, fill=X)
        self.Subscribe(SELECTION, button.Update)

        button_frame = TFrame(top, style='FlatFrame', borderwidth=1)
        button_frame.pack(side=BOTTOM, fill=X, pady=5)

        button = TButton(button_frame,
                         style='TSmallbutton',
                         text=' ',
                         image='small_colorpicker',
                         command=self.copy_from)
        button.pack(side=LEFT)
        tooltips.AddDescription(button, _("Copy From..."))

        button = TButton(button_frame,
                         style='TSmallbutton',
                         text=' ',
                         image='restore_color',
                         command=self.restore_color)
        button.pack(side=LEFT, padx=5)
        tooltips.AddDescription(button, _("Restore color"))

        self.var_autoupdate = IntVar(top)
        self.var_autoupdate.set(1)

        self.autoupdate_check = TCheckbutton(button_frame,
                                             text=_("Auto Update"),
                                             variable=self.var_autoupdate,
                                             command=self.init_from_doc)
        self.autoupdate_check.pack(side=RIGHT, anchor=W, padx=10)

        self.init_from_doc()
        self.subscribe_receivers()


###############################################################################

    def is_selection(self):
        return (len(self.document.selection) > 0)

    def subscribe_receivers(self):
        self.document.Subscribe(SELECTION, self.init_from_doc)
        self.document.Subscribe(EDITED, self.init_from_doc)

    def unsubscribe_receivers(self):
        self.document.Unsubscribe(SELECTION, self.init_from_doc)
        self.document.Unsubscribe(EDITED, self.init_from_doc)

    def init_from_doc(self, *arg):
        if self.var_autoupdate.get():
            self.Update()
        self.issue(SELECTION)

    def Update(self):
        self.initial_color = self.get_object_color()
        self.current_color = copy.copy(self.initial_color)
        self.refresh_widgets(self.current_color)

    def refresh_widgets(self, color):
        self.current_color = color
        self.selector.set_color(self.current_color)
        self.picker.set_color(self.current_color)
        self.digitizer.set_color(self.current_color)

    def apply_pattern(self):
        if self.current_color is None:
            self.mw.no_pattern('fill')
        else:
            self.mw.canvas.FillSolid(self.current_color)
        self.Update()

    def copy_from(self):
        self.mw.canvas.PickObject(self.update_from_object)

    def update_from_object(self, obj):
        if obj is not None:
            self.refresh_widgets(self.init_from_properties(obj.Properties()))

    def restore_color(self):
        self.refresh_widgets(copy.copy(self.initial_color))

    def get_object_color(self):
        if self.document.HasSelection():
            if len(self.document.selection) > 1:
                info, obj = self.document.selection.GetInfo()[0]
                properties = obj.Properties()
            else:
                properties = self.document.CurrentProperties()
            return self.init_from_properties(properties)
        else:
            return self.default_color

    def init_from_properties(self, properties):
        if properties and properties.HasFill(
        ) and properties.fill_pattern.__class__ == SolidPattern:
            return properties.fill_pattern.Color()
        else:
            return None
Example #25
0
class ResizePanel(PluginPanel):
	name='Resize'
	title = _("Resize")


	def init(self, master):
		PluginPanel.init(self, master)

		self.width_priority=1
		
		root=self.mw.root
		self.var_width_number=DoubleVar(root)
		self.var_height_number=DoubleVar(root)

		var_width_unit = StringVar(root)
		var_height_unit = StringVar(root)
		
		unit = config.preferences.default_unit
		self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit)
		self.var_height = LengthVar(10, unit,self.var_height_number,var_height_unit)
		
		jump=config.preferences.default_unit_jump
		self.var_width.set(0)
		self.var_height.set(0)
		
		self.var_proportional = IntVar(root)
		self.var_proportional.set(0)
		
		self.var_basepoint = StringVar(root)
		self.var_basepoint.set('C')
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		# Horisontal size
		size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameH.pack(side = TOP, fill = BOTH)
		
		label = TLabel(size_frameH, style='FlatLabel', image='size_h')
		label.pack(side = LEFT, padx=5)
		self.entry_width = TSpinbox(size_frameH,  var=0, vartype=1, textvariable = self.var_width_number, 
									min = 0, max = 50000, step = jump, width = 10, command=self.apply_resize)
		self.entry_width.pack(side = LEFT)

		self.entry_width.down_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.down_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusOut>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusIn>', self.entry_width_FocusIn)
		
		self.labelwunit = TLabel(size_frameH, style='FlatLabel', text = self.var_width.unit)
		self.labelwunit.pack(side = LEFT, padx=5)
		#---------------------------------------------------------
		# Vertical 
		
		size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameV.pack(side = TOP, fill = BOTH)
		label = TLabel(size_frameV, style='FlatLabel', image='size_v')
		label.pack(side = LEFT, padx=5)
		
		self.entry_height = TSpinbox(size_frameV, var=0, vartype=1, textvariable = self.var_height_number, 
									min = 0, max = 50000, step = jump, width = 10, command=self.apply_resize)
		self.entry_height.pack(side = LEFT)
		
		self.entry_height.down_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.down_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusOut>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusIn>', self.entry_height_FocusIn)
		
		self.labelhunit = TLabel(size_frameV, style='FlatLabel', text = self.var_height.unit)
		self.labelhunit.pack(side = LEFT, padx=5)
		
		#---------------------------------------------------------
		# Proportional chek
		
		self.proportional_check = TCheckbutton(top, text = _("Proportional"), variable = self.var_proportional, command = self.proportional)
		self.proportional_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Basepoint check
		label = TLabel(top, style='FlatLabel', text = _("Basepoint:"))
		label.pack(side = TOP, fill = BOTH, padx=5)
		basepoint_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		basepoint_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.Basepoint = BasePointSelector(basepoint_frame, anchor=self.var_basepoint)
		self.Basepoint.pack(side = LEFT, fill = BOTH, padx=5)
		
		label = TLabel(basepoint_frame, style='FlatLabel', image = 'coordinate_sys')
		label.pack(side = LEFT, fill = BOTH, padx=10)
			
		#---------------------------------------------------------
		# Button frame 
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		button_frame.pack(side = BOTTOM, fill = BOTH)

		self.update_buttons = []
		self.button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_resize)
		self.button.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X, pady=3)

		self.button_copy = UpdatedButton(top, text = _("Apply to Copy"),
								command = self.apply_to_copy)
		self.button_copy.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X)
		
		self.subscribe_receivers()
		self.Update()


###############################################################################

	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.Update)	
		self.document.Subscribe(EDITED, self.update_var)
		config.preferences.Subscribe(CHANGED, self.update_pref)

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.Update)	
		self.document.Unsubscribe(EDITED, self.update_var)
		config.preferences.Unsubscribe(CHANGED, self.update_pref)

	def init_from_doc(self, *arg):
			self.Update()

	def Update(self, *arg):
		if self.is_selection():
			self.entry_width.set_state(NORMAL)
			self.entry_height.set_state(NORMAL)
			self.proportional_check['state']=NORMAL
			self.button['state']=NORMAL
			self.button_copy['state']=NORMAL
		else:
			self.entry_width.set_state(DISABLED)
			self.entry_height.set_state(DISABLED)
			self.proportional_check['state']=DISABLED
			self.button['state']=DISABLED
			self.button_copy['state']=DISABLED
			self.var_width.set(0)
			self.var_height.set(0)
			
		self.update_pref()

	def entry_width_FocusIn(self, *arg):
		self.width_priority=1

	def entry_height_FocusIn(self, *arg):
		self.width_priority=0

	def ResizeSelected(self, h, v, cnt_x=None, cnt_y=None):
		text = _("Resize")
		if self.document.selection:
			self.document.begin_transaction(text)
			try:
				try:
					br=self.document.selection.coord_rect
					hor_sel=br.right - br.left
					ver_sel=br.top - br.bottom
					if cnt_x is None:
						cnt_x=hor_sel/2+br.left
					if cnt_y is None:
						cnt_y=ver_sel/2+br.bottom
					trafo = Trafo(h, 0, 0, v, cnt_x-cnt_x*h, cnt_y-cnt_y*v)
					self.document.TransformSelected(trafo, text)
				except:
					self.document.abort_transaction()
			finally:
				self.document.end_transaction()

	def ResizeAndCopy(self, h, v, cnt_x=None, cnt_y=None):
		text = _("Resize&Copy")
		if self.document.selection:
			self.document.begin_transaction(text)
			try:
				try:
					br=self.document.selection.coord_rect
					hor_sel=br.right - br.left
					ver_sel=br.top - br.bottom
					if cnt_x is None:
						cnt_x=hor_sel/2+br.left
					if cnt_y is None:
						cnt_y=ver_sel/2+br.bottom
					trafo = Trafo(h, 0, 0, v, cnt_x-cnt_x*h, cnt_y-cnt_y*v)
					self.document.ApplyToDuplicate()
					self.document.TransformSelected(trafo, text)
				except:
					self.document.abort_transaction()
			finally:
				self.document.end_transaction()

	def entry_height_chang(self, *arg):
		if self.var_proportional.get():
			try:
				height=self.var_height.get()
				br=self.document.selection.coord_rect
				hor_sel=br.right - br.left
				ver_sel=br.top - br.bottom
				self.var_width.set(hor_sel * height/ver_sel)
			except ZeroDivisionError:
				return

	def entry_width_chang(self, *arg):
		if self.var_proportional.get():
			try:
				width=self.var_width.get()
				br=self.document.selection.coord_rect
				hor_sel=br.right - br.left
				ver_sel=br.top - br.bottom
				self.var_height.set(ver_sel * width/hor_sel)
			except ZeroDivisionError:
				return

	def proportional(self):
		if self.width_priority:
			self.entry_width_chang()
		else:
			self.entry_height_chang()

	def apply_resize(self, *arg):
		if self.button["state"]==DISABLED:
			return
		self.proportional()
		width=self.var_width.get()
		height=self.var_height.get()
		br=self.document.selection.coord_rect
		hor_sel=br.right - br.left
		ver_sel=br.top - br.bottom
		cnt_x,cnt_y=self.Basepoint.get_basepoint(hor_sel,ver_sel,br.left,br.bottom)
		
		try:
			h=width/hor_sel
		except ZeroDivisionError:
			h=0
		
		try:
			v=height/ver_sel
		except ZeroDivisionError:
			v=0
		
		if arg and arg[0] == 'Duplicate':
			self.ResizeAndCopy(h, v, cnt_x, cnt_y)
		else:
			self.ResizeSelected(h, v, cnt_x, cnt_y)
		
		self.update_var()

	def apply_to_copy(self):
		self.apply_resize('Duplicate')

	def update_pref(self, *arg):
		self.labelwunit['text']=config.preferences.default_unit
		self.labelhunit['text']=config.preferences.default_unit
		self.var_width.unit=config.preferences.default_unit
		self.var_height.unit=config.preferences.default_unit
		self.entry_width.step=config.preferences.default_unit_jump
		self.entry_height.step=config.preferences.default_unit_jump
		self.update_var()
		
	def update_var(self, *arg):
		if len(self.document.selection.GetInfo()):
			br=self.document.selection.coord_rect
			width=br.right - br.left
			height=br.top - br.bottom
			self.var_width.set(width)
			self.var_height.set(height)

	def is_selection(self):
		return (len(self.document.selection) > 0)
Example #26
0
class ScalePanel(PluginPanel):
	name='ScaleAndMirror'
	title = _("Scale and Mirror")


	def init(self, master):
		PluginPanel.init(self, master)

		self.width_priority=1
		
		root=self.mw.root
		self.var_width=DoubleVar(root)
		self.var_height=DoubleVar(root)
		
		unit='%'
		jump=5
		
		self.var_proportional = IntVar(root)
		self.var_proportional.set(0)
		
		self.var_basepoint = StringVar(root)
		self.var_basepoint.set('C')
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		# Horisontal size
		size_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameH.pack(side = TOP, fill = BOTH)
		
		label = TLabel(size_frameH, style='FlatLabel', image='size_h')
		label.pack(side = LEFT, padx=5)
		self.entry_width = TSpinbox(size_frameH,  var=100, vartype=1, textvariable = self.var_width, 
									min = -30000, max = 30000, step = jump, width = 6, command=self.apply_scale)
		self.entry_width.pack(side = LEFT)

		self.entry_width.down_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.down_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.up_button.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<ButtonRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<KeyRelease>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusOut>', self.entry_width_chang)
		self.entry_width.entry.bind('<FocusIn>', self.entry_width_FocusIn)
		
		self.labelwunit = TLabel(size_frameH, style='FlatLabel', text = unit)
		self.labelwunit.pack(side = LEFT, padx=5)
		
		self.hflip=BooleanVar(root)
		self.hflip.set(0)
		button = TCheckbutton(size_frameH, image = "pstrip_hflip", style='ToolBarCheckButton', variable = self.hflip, command = None)
		button.pack(side = LEFT)
		
		#---------------------------------------------------------
		# Vertical 
		
		size_frameV = TFrame(top, style='FlatFrame', borderwidth=3)
		size_frameV.pack(side = TOP, fill = BOTH)
		label = TLabel(size_frameV, style='FlatLabel', image='size_v')
		label.pack(side = LEFT, padx=5)
		
		self.entry_height = TSpinbox(size_frameV, var=100, vartype=1, textvariable = self.var_height, 
									min = -30000, max = 30000, step = jump, width = 6, command=self.apply_scale)
		self.entry_height.pack(side = LEFT)
		
		self.entry_height.down_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.down_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.up_button.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<ButtonRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<KeyRelease>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusOut>', self.entry_height_chang)
		self.entry_height.entry.bind('<FocusIn>', self.entry_height_FocusIn)
		
		self.labelhunit = TLabel(size_frameV, style='FlatLabel', text = unit)
		self.labelhunit.pack(side = LEFT, padx=5)
		
		self.vflip=BooleanVar(root)
		self.vflip.set(0)
		button = TCheckbutton(size_frameV, image = "pstrip_vflip", style='ToolBarCheckButton', variable = self.vflip, command = None)
		button.pack(side = LEFT)
		
		#---------------------------------------------------------
		# Proportional chek
		
		self.proportional_check = TCheckbutton(top, text = _("Proportional"), variable = self.var_proportional, command = self.proportional)
		self.proportional_check.pack(side = TOP, anchor=W, padx=5,pady=5)
		
		#---------------------------------------------------------
		# Basepoint check
		label = TLabel(top, style='FlatLabel', text = _("Basepoint:"))
		label.pack(side = TOP, fill = BOTH, padx=5)
		basepoint_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		basepoint_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.Basepoint = BasePointSelector(basepoint_frame, anchor=self.var_basepoint)
		self.Basepoint.pack(side = LEFT, fill = BOTH, padx=5)
		
		label = TLabel(basepoint_frame, style='FlatLabel', image = 'coordinate_sys')
		label.pack(side = LEFT, fill = BOTH, padx=10)
		
		#---------------------------------------------------------
		# Button frame 
		
		button_frame = TFrame(top, style='FlatFrame', borderwidth=5)
		button_frame.pack(side = BOTTOM, fill = BOTH)

		self.update_buttons = []
		self.button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_scale)
		self.button.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X, pady=3)

		self.button_copy = UpdatedButton(top, text = _("Apply to Copy"),
								command = self.apply_to_copy)
		self.button_copy.pack(in_ = button_frame, side = BOTTOM, expand = 1, fill = X)
		
		self.init_from_doc()
		self.subscribe_receivers()


###############################################################################

	def subscribe_receivers(self):
		self.document.Subscribe(SELECTION, self.Update)	

	def unsubscribe_receivers(self):
		self.document.Unsubscribe(SELECTION, self.Update)	

	def init_from_doc(self, *arg):
			self.Update()

	def Update(self, *arg):
		if self.is_selection():
			self.entry_width.set_state(NORMAL)
			self.entry_height.set_state(NORMAL)
			self.proportional_check['state']=NORMAL
			self.button['state']=NORMAL
			self.button_copy['state']=NORMAL
		else:
			self.entry_width.set_state(DISABLED)
			self.entry_height.set_state(DISABLED)
			self.proportional_check['state']=DISABLED
			self.button['state']=DISABLED
			self.button_copy['state']=DISABLED

	def entry_width_FocusIn(self, *arg):
		self.width_priority=1

	def entry_height_FocusIn(self, *arg):
		self.width_priority=0

	def ScaleSelected(self, h, v, cnt_x=None, cnt_y=None):
		text = _("Scale")
		if self.document.selection:
			self.document.begin_transaction(text)
			try:
				try:
					br=self.document.selection.coord_rect
					hor_sel=br.right - br.left
					ver_sel=br.top - br.bottom
					if cnt_x is None:
						cnt_x=hor_sel/2+br.left
					if cnt_y is None:
						cnt_y=ver_sel/2+br.bottom
					trafo = Trafo(h, 0, 0, v, cnt_x-cnt_x*h, cnt_y-cnt_y*v)
					self.document.TransformSelected(trafo, text)
				except:
					self.document.abort_transaction()
			finally:
				self.document.end_transaction()

	def ScaleAndCopy(self, h, v, cnt_x=None, cnt_y=None):
		text = _("Scale&Copy")
		if self.document.selection:
			self.document.begin_transaction(text)
			try:
				try:
					br=self.document.selection.coord_rect
					hor_sel=br.right - br.left
					ver_sel=br.top - br.bottom
					if cnt_x is None:
						cnt_x=hor_sel/2+br.left
					if cnt_y is None:
						cnt_y=ver_sel/2+br.bottom
					trafo = Trafo(h, 0, 0, v, cnt_x-cnt_x*h, cnt_y-cnt_y*v)
					self.document.ApplyToDuplicate()
					self.document.TransformSelected(trafo, text)
				except:
					self.document.abort_transaction()
			finally:
				self.document.end_transaction()

	def entry_height_chang(self, *arg):
		if self.var_proportional.get():
			self.var_width.set(self.var_height.get())

	def entry_width_chang(self, *arg):
		if self.var_proportional.get():
			self.var_height.set(self.var_width.get())

	def proportional(self):
		if self.width_priority:
			self.entry_width_chang()
		else:
			self.entry_height_chang()

	def apply_scale(self, *arg):
		if self.button["state"]==DISABLED:
			return
		self.proportional()
		width=self.var_width.get()
		height=self.var_height.get()
		br=self.document.selection.coord_rect
		hor_sel=br.right - br.left
		ver_sel=br.top - br.bottom
		cnt_x,cnt_y=self.Basepoint.get_basepoint(hor_sel,ver_sel,br.left,br.bottom)
		
		h=width/100
		if h==0:
			h=1
		if self.hflip.get():
			h=-1*h
		
		v=height/100
		if v==0:
			v=1
		if self.vflip.get():
			v=-1*v
		
		if arg and arg[0] == 'Duplicate':
			self.ScaleAndCopy(h, v, cnt_x, cnt_y)
		else:
			self.ScaleSelected(h, v, cnt_x, cnt_y)

	def apply_to_copy(self):
		self.apply_scale('Duplicate')

	def is_selection(self):
		return (len(self.document.selection) > 0)