Beispiel #1
0
class RotatePlugin(CtxPlugin):
    name = 'RotatePlugin'
    angle_spin = None

    def __init__(self, app, parent):
        CtxPlugin.__init__(self, app, parent)

    def build(self):
        bmp = get_bmp(self, icons.CTX_ROTATE, _('Rotate selection'))
        self.pack(bmp, padding=2)

        self.angle_spin = AngleSpin(self, onenter=self.apply_changes)
        self.pack(self.angle_spin, padding=2)

        self.pack((2, 2))

        rot_left = ActionButton(self, self.actions[pdids.ID_ROTATE_LEFT])
        self.pack(rot_left)

        rot_right = ActionButton(self, self.actions[pdids.ID_ROTATE_RIGHT])
        self.pack(rot_right)

    def apply_changes(self, *_args):
        val = self.angle_spin.get_angle_value()
        if val != 0.0:
            self.app.current_doc.api.rotate_selected(val)
Beispiel #2
0
class RotatePlugin(CtxPlugin):

	name = 'RotatePlugin'

	def __init__(self, app, parent):
		CtxPlugin.__init__(self, app, parent)

	def build(self):
		bmp = get_bmp(self, icons.CTX_ROTATE, _('Rotate selection'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.angle_spin = AngleSpin(self, onenter=self.apply_changes)
		self.add(self.angle_spin, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		rot_left = ActionButton(self, self.actions[pdids.ID_ROTATE_LEFT])
		self.add(rot_left, 0, LEFT | CENTER)

		rot_right = ActionButton(self, self.actions[pdids.ID_ROTATE_RIGHT])
		self.add(rot_right, 0, LEFT | CENTER)

	def apply_changes(self, *args):
		val = self.angle_spin.get_angle_value()
		if val <> 0.0: self.app.current_doc.api.rotate_selected(val)
class ShearTransform(AbstractTransform):
    name = _('Shearing')
    h_shear = None
    v_shear = None

    def build(self):
        grid = wal.GridPanel(self, 3, 3, 2, 2)

        grid.pack(get_bmp(grid, make_artid('h-sign')))
        self.h_shear = AngleSpin(grid,
                                 val_range=(-89.0, 89.0),
                                 check_focus=True)
        grid.pack(self.h_shear)
        grid.pack(wal.Label(grid, _('degrees')))

        grid.pack(get_bmp(grid, make_artid('v-sign')))
        self.v_shear = AngleSpin(grid,
                                 val_range=(-89.0, 89.0),
                                 check_focus=True)
        grid.pack(self.v_shear)
        grid.pack(wal.Label(grid, _('degrees')))

        self.pack(grid, align_center=False, padding=5)

        self.active_widgets = [self.h_shear, self.v_shear]

    def get_trafo(self):
        angle1 = self.h_shear.get_angle_value()
        angle2 = self.v_shear.get_angle_value()

        m12 = math.tan(angle1)
        m21 = math.tan(angle2)
        m11 = 1.0
        m22 = 1.0 - (m12 * m21)
        trafo = [m11, m21, -m12, m22, 0, 0]

        bbox = self.get_selection_bbox()
        w, h = self.get_selection_size()
        bp = [
            bbox[0] + w * (1.0 + self.orientation[0]) / 2.0,
            bbox[1] + h * (1.0 + self.orientation[1]) / 2.0
        ]

        new_bp = libgeom.apply_trafo_to_point(bp, trafo)
        trafo[4] = bp[0] - new_bp[0]
        trafo[5] = bp[1] - new_bp[1]
        return trafo
Beispiel #4
0
class ShearTransform(AbstractTransform):

	name = _('Shearing')

	def build(self):
		grid = wal.GridPanel(self, 3, 3, 2, 2)

		grid.pack(get_bmp(grid, make_artid('h-sign')))
		self.h_shear = AngleSpin(grid, val_range=(-89.0, 89.0),
							check_focus=True)
		grid.pack(self.h_shear)
		grid.pack(wal.Label(grid, _('degrees')))

		grid.pack(get_bmp(grid, make_artid('v-sign')))
		self.v_shear = AngleSpin(grid, val_range=(-89.0, 89.0),
							check_focus=True)
		grid.pack(self.v_shear)
		grid.pack(wal.Label(grid, _('degrees')))

		self.pack(grid, align_center=False, padding=5)

		self.active_widgets = [self.h_shear, self.v_shear]

	def get_trafo(self):
		angle1 = self.h_shear.get_angle_value()
		angle2 = self.v_shear.get_angle_value()

		m12 = math.tan(angle1)
		m21 = math.tan(angle2)
		m11 = 1.0
		m22 = 1.0 - (m12 * m21)
		trafo = [m11, m21, -m12, m22, 0, 0]

		bbox = self.get_selection_bbox()
		w, h = self.get_selection_size()
		bp = [bbox[0] + w * (1.0 + self.orientation[0]) / 2.0,
			bbox[1] + h * (1.0 + self.orientation[1]) / 2.0]

		new_bp = libgeom.apply_trafo_to_point(bp, trafo)
		trafo[4] = bp[0] - new_bp[0]
		trafo[5] = bp[1] - new_bp[1]
		return trafo
Beispiel #5
0
class RotateTransform(AbstractTransform):

    name = _('Rotation')

    def build(self):
        grid = wal.GridPanel(self, 1, 3, 2, 2)

        grid.pack(wal.Label(grid, _('Angle:')))
        self.angle = AngleSpin(grid,
                               val_range=(-360.0, 360.0),
                               check_focus=True)
        grid.pack(self.angle)
        grid.pack(wal.Label(grid, u'°'))

        self.pack(grid, align_center=False, padding=5)
        self.pack(wal.Label(grid, _('Center:')), align_center=False, padding=5)

        grid = wal.GridPanel(self, 2, 3, 2, 2)

        grid.pack(get_bmp(grid, make_artid('h-sign')))
        self.h_spin = UnitSpin(self.app, grid, can_be_negative=True)
        grid.pack(self.h_spin)
        grid.pack(UnitLabel(self.app, grid))

        grid.pack(get_bmp(grid, make_artid('v-sign')))
        self.v_spin = UnitSpin(self.app, grid, can_be_negative=True)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding_all=5)
        self.center = wal.Checkbox(self,
                                   _('Relative center'),
                                   onclick=self.on_click)
        self.pack(self.center, align_center=False, padding=5)

        self.active_widgets = [self.angle, self.center]
        self.on_click()

    def on_click(self):
        state = False
        if self.center.get_value():
            state = True
            self.user_changes = True
            if self.callback: self.callback()
        self.v_spin.set_enable(state)
        self.h_spin.set_enable(state)

    def set_enable(self, state):
        if self.center.get_value():
            self.v_spin.set_enable(state)
            self.h_spin.set_enable(state)
        else:
            self.user_changes = False
        AbstractTransform.set_enable(self, state)

    def update(self):
        if not self.app.insp.is_selection(): return
        if self.user_changes: return
        bbox = self.get_selection_bbox()
        w, h = self.get_selection_size()
        bp = self.doc_to_coords([
            bbox[0] + w * (1.0 + self.orientation[0]) / 2.0,
            bbox[1] + h * (1.0 + self.orientation[1]) / 2.0
        ])
        self.h_spin.set_point_value(bp[0])
        self.v_spin.set_point_value(bp[1])

    def get_trafo(self):
        angle = self.angle.get_angle_value()
        center_x = self.h_spin.get_point_value()
        center_y = self.v_spin.get_point_value()
        center_x, center_y = self.coords_to_doc([center_x, center_y])
        m21 = math.sin(angle)
        m11 = m22 = math.cos(angle)
        m12 = -m21
        dx = center_x - m11 * center_x + m21 * center_y
        dy = center_y - m21 * center_x - m11 * center_y
        return [m11, m21, m12, m22, dx, dy]
Beispiel #6
0
class CirclePlugin(CtxPlugin):
    name = 'CirclePlugin'
    update_flag = False
    circle_type = ARC_CHORD
    start = 0
    end = 0
    toggles = {}

    target = None
    orig_type = ARC_CHORD
    orig_start = 0
    orig_end = 0

    slider = None
    angle_spin = None
    switch = None

    def __init__(self, app, parent):
        CtxPlugin.__init__(self, app, parent)
        events.connect(events.DOC_CHANGED, self.update)
        events.connect(events.SELECTION_CHANGED, self.update)

    def build(self):

        self.toggles[ARC_ARC] = wal.ImageToggleButton(self,
                                                      False,
                                                      icons.CTX_CIRCLE_ARC,
                                                      onchange=self.toggled,
                                                      tooltip=_('Arc'))
        self.pack(self.toggles[ARC_ARC])

        self.toggles[ARC_CHORD] = wal.ImageToggleButton(self,
                                                        False,
                                                        icons.CTX_CIRCLE_CHORD,
                                                        onchange=self.toggled,
                                                        tooltip=_('Chord'))
        self.pack(self.toggles[ARC_CHORD])

        idx = ARC_PIE_SLICE
        self.toggles[idx] = wal.ImageToggleButton(self,
                                                  False,
                                                  icons.CTX_CIRCLE_PIE_SLICE,
                                                  onchange=self.toggled,
                                                  tooltip=_('Pie slice'))
        self.pack(self.toggles[ARC_PIE_SLICE])

        self.slider = wal.Slider(self,
                                 0, (0, 360),
                                 onchange=self.slider_changes,
                                 on_final_change=self.slider_final_changes)
        self.pack(self.slider, padding=2)

        self.angle_spin = AngleSpin(self, onchange=self.angle_changes)
        self.pack(self.angle_spin, padding=2)

        txt1 = _('Start angle')
        txt2 = _('End angle')
        icons_dict = {
            True: [
                icons.CTX_CIRCLE_START_ANGLE,
                txt1,
            ],
            False: [
                icons.CTX_CIRCLE_END_ANGLE,
                txt2,
            ],
        }
        self.switch = BitmapToggle(self, True, icons_dict, self.switched)
        self.pack(self.switch, padding=2)

    def update(self, *args):
        if self.insp.is_selection():
            sel = self.app.current_doc.selection
            if len(sel.objs) == 1 and self.insp.is_obj_circle(sel.objs[0]):
                obj = sel.objs[0]
                self.circle_type = obj.circle_type
                self.start = obj.angle1
                self.end = obj.angle2
                self.update_flag = True
                for item in CIRCLE_TYPES:
                    self.toggles[item].set_active(item == self.circle_type)
                self.update_flag = False
                self.switched()
                if not obj == self.target:
                    self.target = obj
                    self.store_props()

    def store_props(self):
        self.orig_type = self.target.circle_type
        self.orig_start = self.target.angle1
        self.orig_end = self.target.angle2

    def toggled(self, *args):
        if self.update_flag:
            return
        self.update_flag = True
        val = -1
        for item in CIRCLE_TYPES:
            if self.toggles[item].get_active() and item != self.circle_type:
                val = item
            elif self.toggles[item].get_active() and item == self.circle_type:
                self.toggles[item].set_active(False)
        if val < 0:
            self.toggles[self.circle_type].set_active(True)
        else:
            self.circle_type = val
        self.update_flag = False
        self.apply_changes(True)

    def switched(self, *args):
        self.update_flag = True
        if self.switch.get_active():
            self.slider.set_value(int(self.start * 180.0 / math.pi))
            self.angle_spin.set_angle_value(self.start)
        else:
            self.slider.set_value(int(self.end * 180.0 / math.pi))
            self.angle_spin.set_angle_value(self.end)
        self.update_flag = False

    def angle_changes(self, *args):
        if self.update_flag:
            return
        if self.switch.get_active():
            self.start = self.angle_spin.get_angle_value()
        else:
            self.end = self.angle_spin.get_angle_value()
        self.apply_changes(True)

    def slider_changes(self, *args):
        if self.update_flag:
            return
        val = self.slider.get_value() * math.pi / 180.0
        if self.switch.get_active():
            self.start = val
        else:
            self.end = val
        self.apply_changes()

    def slider_final_changes(self, *args):
        if self.update_flag:
            return
        val = self.slider.get_value() * math.pi / 180.0
        if self.switch.get_active():
            self.start = val
        else:
            self.end = val
        self.apply_changes(True)

    def apply_changes(self, final=False):
        if self.insp.is_selection():
            sel = self.app.current_doc.selection
            if len(sel.objs) == 1 and self.insp.is_obj_circle(sel.objs[0]):
                obj = sel.objs[0]
                api = self.app.current_doc.api
                if final:
                    api.set_circle_properties_final(self.circle_type,
                                                    self.start, self.end,
                                                    self.orig_type,
                                                    self.orig_start,
                                                    self.orig_end)
                    self.store_props()
                elif not self.start == obj.angle1 or \
                        not self.end == obj.angle2:
                    api.set_circle_properties(self.circle_type, self.start,
                                              self.end)
Beispiel #7
0
class RotateTransform(AbstractTransform):

	name = _('Rotation')

	def build(self):
		grid = wal.GridPanel(self, 1, 3, 2, 2)

		grid.pack(wal.Label(grid, _('Angle:')))
		self.angle = AngleSpin(grid, val_range=(-360.0, 360.0),
							check_focus=True)
		grid.pack(self.angle)
		grid.pack(wal.Label(grid, _('degrees')))

		self.pack(grid, align_center=False, padding=5)
		self.pack(wal.Label(grid, _('Center:')), align_center=False, padding=5)

		grid = wal.GridPanel(self, 2, 3, 2, 2)

		grid.pack(get_bmp(grid, make_artid('h-sign')))
		self.h_spin = UnitSpin(self.app, grid, can_be_negative=True)
		grid.pack(self.h_spin)
		grid.pack(UnitLabel(self.app, grid))

		grid.pack(get_bmp(grid, make_artid('v-sign')))
		self.v_spin = UnitSpin(self.app, grid, can_be_negative=True)
		grid.pack(self.v_spin)
		grid.pack(UnitLabel(self.app, grid))

		self.pack(grid, align_center=False, padding_all=5)
		self.center = wal.Checkbox(self, _('Relative center'),
								onclick=self.on_click)
		self.pack(self.center, align_center=False, padding=5)

		self.active_widgets = [self.angle, self.center]
		self.on_click()

	def on_click(self):
		state = False
		if self.center.get_value():
			state = True
			self.user_changes = True
			if self.callback: self.callback()
		self.v_spin.set_enable(state)
		self.h_spin.set_enable(state)

	def set_enable(self, state):
		if self.center.get_value():
			self.v_spin.set_enable(state)
			self.h_spin.set_enable(state)
		else:
			self.user_changes = False
		AbstractTransform.set_enable(self, state)

	def update(self):
		if not self.app.insp.is_selection():return
		if self.user_changes: return
		bbox = self.get_selection_bbox()
		w, h = self.get_selection_size()
		bp = self.doc_to_coords([bbox[0] + w * (1.0 + self.orientation[0]) / 2.0,
			bbox[1] + h * (1.0 + self.orientation[1]) / 2.0])
		self.h_spin.set_point_value(bp[0])
		self.v_spin.set_point_value(bp[1])

	def get_trafo(self):
		angle = self.angle.get_angle_value()
		center_x = self.h_spin.get_point_value()
		center_y = self.v_spin.get_point_value()
		center_x, center_y = self.coords_to_doc([center_x, center_y])
		m21 = math.sin(angle)
		m11 = m22 = math.cos(angle)
		m12 = -m21
		dx = center_x - m11 * center_x + m21 * center_y;
		dy = center_y - m21 * center_x - m11 * center_y;
		return [m11, m21, m12, m22, dx, dy]
Beispiel #8
0
class CirclePlugin(CtxPlugin):

	name = 'CirclePlugin'
	update_flag = False
	circle_type = ARC_CHORD
	start = 0
	end = 0
	toggles = {}

	target = None
	orig_type = ARC_CHORD
	orig_start = 0
	orig_end = 0

	def __init__(self, app, parent):
		CtxPlugin.__init__(self, app, parent)
		events.connect(events.DOC_CHANGED, self.update)
		events.connect(events.SELECTION_CHANGED, self.update)

	def build(self):

		self.toggles[ARC_ARC] = wal.ImageToggleButton(self, False,
								icons.CTX_CIRCLE_ARC,
								onchange=self.toggled,
								tooltip=_('Arc'))
		self.add(self.toggles[ARC_ARC], 0, wal.LEFT | wal.CENTER)

		self.toggles[ARC_CHORD] = wal.ImageToggleButton(self, False,
								icons.CTX_CIRCLE_CHORD,
								onchange=self.toggled,
								tooltip=_('Chord'))
		self.add(self.toggles[ARC_CHORD], 0, wal.LEFT | wal.CENTER)

		self.toggles[ARC_PIE_SLICE] = wal.ImageToggleButton(self, False,
								icons.CTX_CIRCLE_PIE_SLICE,
								onchange=self.toggled,
								tooltip=_('Pie slice'))
		self.add(self.toggles[ARC_PIE_SLICE], 0, wal.LEFT | wal.CENTER)

		self.slider = wal.Slider(self, 0, (0, 360), onchange=self.slider_changes,
								on_final_change=self.slider_final_changes)
		self.add(self.slider, 0, wal.LEFT | wal.CENTER, 2)

		self.angle_spin = AngleSpin(self, onchange=self.angle_changes)
		self.add(self.angle_spin, 0, wal.LEFT | wal.CENTER, 2)

		txt1 = _('Start angle')
		txt2 = _('End angle')
		icons_dict = {True:[icons.CTX_CIRCLE_START_ANGLE, txt1, ],
				False:[icons.CTX_CIRCLE_END_ANGLE, txt2, ], }
		self.switch = BitmapToggle(self, True, icons_dict, self.switched)
		self.add(self.switch, 0, wal.LEFT | wal.CENTER, 2)

	def update(self, *args):
		if self.insp.is_selection():
			sel = self.app.current_doc.selection
			if len(sel.objs) == 1 and self.insp.is_obj_circle(sel.objs[0]):
				obj = sel.objs[0]
				self.circle_type = obj.circle_type
				self.start = obj.angle1
				self.end = obj.angle2
				self.update_flag = True
				for item in CIRCLE_TYPES:
					self.toggles[item].set_active(item == self.circle_type)
				self.update_flag = False
				self.switched()
				if not obj == self.target:
					self.target = obj
					self.store_props()

	def store_props(self):
		self.orig_type = self.target.circle_type
		self.orig_start = self.target.angle1
		self.orig_end = self.target.angle2

	def toggled(self, *args):
		if self.update_flag: return
		self.update_flag = True
		val = -1
		for item in CIRCLE_TYPES:
			if self.toggles[item].get_active() and not item == self.circle_type:
				val = item
			elif self.toggles[item].get_active() and item == self.circle_type:
				self.toggles[item].set_active(False)
		if val < 0: self.toggles[self.circle_type].set_active(True)
		else: self.circle_type = val
		self.update_flag = False
		self.apply_changes(True)

	def switched(self, *args):
		self.update_flag = True
		if self.switch.get_active():
			self.slider.set_value(int(self.start * 180.0 / math.pi))
			self.angle_spin.set_angle_value(self.start)
		else:
			self.slider.set_value(int(self.end * 180.0 / math.pi))
			self.angle_spin.set_angle_value(self.end)
		self.update_flag = False

	def angle_changes(self, *args):
		if self.update_flag: return
		if self.switch.get_active():
			self.start = self.angle_spin.get_angle_value()
		else:
			self.end = self.angle_spin.get_angle_value()
		self.apply_changes(True)

	def slider_changes(self, *args):
		if self.update_flag: return
		val = self.slider.get_value() * math.pi / 180.0
		if self.switch.get_active(): self.start = val
		else: self.end = val
		self.apply_changes()

	def slider_final_changes(self, *args):
		if self.update_flag: return
		val = self.slider.get_value() * math.pi / 180.0
		if self.switch.get_active(): self.start = val
		else: self.end = val
		self.apply_changes(True)

	def apply_changes(self, final=False):
		if self.insp.is_selection():
			sel = self.app.current_doc.selection
			if len(sel.objs) == 1 and self.insp.is_obj_circle(sel.objs[0]):
				obj = sel.objs[0]
				api = self.app.current_doc.api
				if final:
					api.set_circle_properties_final(self.circle_type,
								self.start, self.end, self.orig_type,
								self.orig_start, self.orig_end)
					self.store_props()
				elif not self.start == obj.angle1 or \
					not self.end == obj.angle2:
					api.set_circle_properties(self.circle_type,
											self.start, self.end)