Exemplo n.º 1
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
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
class SkewPanel(PluginPanel):
    name = 'Skew'
    title = _("Skew")

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

        self.width_priority = 1

        root = self.mw.root

        self.var_angleX = DoubleVar(root)
        self.var_angleY = DoubleVar(root)

        jump = 5
        self.var_angleX.set(0)
        self.var_angleY.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_frameH = TFrame(top, style='FlatFrame', borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style='FlatLabel', image='skew_h')
        label.pack(side=LEFT, padx=5)
        self.entry_angleX = TSpinbox(size_frameH,
                                     var=0,
                                     vartype=1,
                                     textvariable=self.var_angleX,
                                     min=-75,
                                     max=75,
                                     step=jump,
                                     width=10,
                                     command=self.apply_skew)
        self.entry_angleX.pack(side=LEFT)

        self.labelwunit = TLabel(size_frameH, style='FlatLabel', text=_("deg"))
        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='skew_v')
        label.pack(side=LEFT, padx=5)

        self.entry_angleY = TSpinbox(size_frameV,
                                     var=0,
                                     vartype=1,
                                     textvariable=self.var_angleY,
                                     min=-75,
                                     max=75,
                                     step=jump,
                                     width=10,
                                     command=self.apply_skew)
        self.entry_angleY.pack(side=LEFT)

        self.labelhunit = TLabel(size_frameV, style='FlatLabel', text=_("deg"))
        self.labelhunit.pack(side=LEFT, padx=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_deg')
        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_skew)
        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):
        self.Update()

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

    def SkewSelected(self, axisX=0, axisY=0):
        if self.document.selection:
            self.document.begin_transaction()
            try:
                try:
                    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)

                    text = _("Skew")
                    ax, ay = tan(axisX), tan(axisY)
                    sx = 1.0
                    sy = 1.0 - (ax * ay)
                    tx = cnt_x * ax
                    ty = cnt_y * ax * ay - cnt_y * ay
                    # Move the selection in the coordinates x0 y0
                    trafo = Trafo(1, 0, 0, 1, -cnt_x, -cnt_y)
                    # Skew and Scaling
                    trafo = Trafo(sx, ay, -ax, sy, 0, 0)(trafo)
                    # Move the selection in the coordinates basepoint
                    trafo = Trafo(1, 0, 0, 1, cnt_x, cnt_y)(trafo)
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def apply_skew(self, *arg):
        if self.button["state"] == DISABLED:
            return
        try:
            angleX = self.var_angleX.get() * degrees
            angleY = self.var_angleY.get() * degrees
            self.SkewSelected(angleX, angleY)
        except:
            return

    def apply_to_copy(self):
        if self.button["state"] == DISABLED:
            return
        self.document.begin_transaction(_("Skew&Copy"))
        try:
            try:
                self.document.ApplyToDuplicate()
                self.apply_skew()
            except:
                self.document.abort_transaction()
        finally:
            self.document.end_transaction()

    def is_selection(self):
        return (len(self.document.selection) > 0)
Exemplo n.º 6
0
class SkewPanel(PluginPanel):
    name = "Skew"
    title = _("Skew")

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

        self.width_priority = 1

        root = self.mw.root

        self.var_angleX = DoubleVar(root)
        self.var_angleY = DoubleVar(root)

        jump = 5
        self.var_angleX.set(0)
        self.var_angleY.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_frameH = TFrame(top, style="FlatFrame", borderwidth=3)
        size_frameH.pack(side=TOP, fill=BOTH)

        label = TLabel(size_frameH, style="FlatLabel", image="skew_h")
        label.pack(side=LEFT, padx=5)
        self.entry_angleX = TSpinbox(
            size_frameH,
            var=0,
            vartype=1,
            textvariable=self.var_angleX,
            min=-75,
            max=75,
            step=jump,
            width=10,
            command=self.apply_skew,
        )
        self.entry_angleX.pack(side=LEFT)

        self.labelwunit = TLabel(size_frameH, style="FlatLabel", text=_("deg"))
        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="skew_v")
        label.pack(side=LEFT, padx=5)

        self.entry_angleY = TSpinbox(
            size_frameV,
            var=0,
            vartype=1,
            textvariable=self.var_angleY,
            min=-75,
            max=75,
            step=jump,
            width=10,
            command=self.apply_skew,
        )
        self.entry_angleY.pack(side=LEFT)

        self.labelhunit = TLabel(size_frameV, style="FlatLabel", text=_("deg"))
        self.labelhunit.pack(side=LEFT, padx=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_deg")
        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_skew)
        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):
        self.Update()

    def Update(self, *arg):
        if self.is_selection():
            self.entry_angleX.set_state(NORMAL)
            self.entry_angleY.set_state(NORMAL)
            self.button["state"] = NORMAL
            self.button_copy["state"] = NORMAL
        else:
            self.entry_angleX.set_state(DISABLED)
            self.entry_angleY.set_state(DISABLED)
            self.button["state"] = DISABLED
            self.button_copy["state"] = DISABLED

    def SkewSelected(self, axisX=0, axisY=0):
        if self.document.selection:
            self.document.begin_transaction()
            try:
                try:
                    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)

                    text = _("Skew")
                    ax, ay = tan(axisX), tan(axisY)
                    sx = 1.0
                    sy = 1.0 - (ax * ay)
                    tx = cnt_x * ax
                    ty = cnt_y * ax * ay - cnt_y * ay
                    # Move the selection in the coordinates x0 y0
                    trafo = Trafo(1, 0, 0, 1, -cnt_x, -cnt_y)
                    # Skew and Scaling
                    trafo = Trafo(sx, ay, -ax, sy, 0, 0)(trafo)
                    # Move the selection in the coordinates basepoint
                    trafo = Trafo(1, 0, 0, 1, cnt_x, cnt_y)(trafo)
                    self.document.TransformSelected(trafo, text)
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()

    def apply_skew(self, *arg):
        if self.button["state"] == DISABLED:
            return
        try:
            angleX = self.var_angleX.get() * degrees
            angleY = self.var_angleY.get() * degrees
            self.SkewSelected(angleX, angleY)
        except:
            return

    def apply_to_copy(self):
        if self.button["state"] == DISABLED:
            return
        self.document.begin_transaction(_("Skew&Copy"))
        try:
            try:
                self.document.ApplyToDuplicate()
                self.apply_skew()
            except:
                self.document.abort_transaction()
        finally:
            self.document.end_transaction()

    def is_selection(self):
        return len(self.document.selection) > 0
Exemplo n.º 7
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)
Exemplo n.º 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)
Exemplo n.º 9
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)