Ejemplo n.º 1
0
	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()
Ejemplo n.º 2
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_OBJECT_JUMP, _('Default object jump'))
        self.add(bmp, 0, LEFT | CENTER, 2)

        self.jump_spin = UnitSpin(self.app, self, onenter=self.user_changes)
        self.jump_spin.set_point_value(config.obj_jump)
        self.add(self.jump_spin, 0, LEFT | CENTER, 2)
Ejemplo n.º 3
0
    def build(self):
        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,
                               onchange=self.on_reset)
        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,
                               onchange=self.on_reset)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding=5)
        self.abs_pos = wal.Checkbox(self,
                                    _('Absolute position'),
                                    onclick=self.update)
        self.pack(self.abs_pos, align_center=False, padding=5)

        self.active_widgets = [self.h_spin, self.v_spin, self.abs_pos]
Ejemplo n.º 4
0
    def build(self):
        btn = ActionButton(self, self.actions[pdids.ID_PAGE_FRAME])
        self.add(btn, 0, LEFT | CENTER, 2)

        # =====
        self.add(VLine(self), 0, ALL | EXPAND, 2)

        self.page_border = UnitSpin(self.app,
                                    self,
                                    onchange=self.user_changes,
                                    can_be_negative=True)
        self.page_border.set_point_value(config.page_border)
        self.add(self.page_border, 0, LEFT | CENTER, 2)

        btn = ActionButton(self, self.actions[pdids.ID_PAGE_GUIDE_FRAME])
        self.add(btn, 0, LEFT | CENTER, 2)

        self.add(VLine(self), 0, ALL | EXPAND, 2)
        # =====

        btn = ActionButton(self, self.actions[pdids.ID_GUIDES_AT_CENTER])
        self.add(btn, 0, LEFT | CENTER, 2)

        btn = ActionButton(self, self.actions[pdids.ID_REMOVE_ALL_GUIDES])
        self.add(btn, 0, LEFT | CENTER, 2)
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_OBJECT_JUMP, _('Default object jump'))
        self.pack(bmp, padding=2)

        self.jump_spin = UnitSpin(self.app,
                                  self,
                                  onenter=self.user_changes,
                                  onchange=self.user_changes)
        self.jump_spin.set_point_value(config.obj_jump)
        self.pack(self.jump_spin, padding=2)
Ejemplo n.º 7
0
    def build(self):
        self.pack(wal.Label(self, 'x:'), padding=2)
        self.x_spin = UnitSpin(self.app,
                               self,
                               can_be_negative=True,
                               onchange=self.user_changes)
        self.pack(self.x_spin, padding=2)

        self.pack(wal.Label(self, 'y:'), padding=2)
        self.y_spin = UnitSpin(self.app,
                               self,
                               can_be_negative=True,
                               onchange=self.user_changes)
        self.pack(self.y_spin, padding=2)
Ejemplo n.º 8
0
Archivo: jump.py Proyecto: Scrik/sk1-wx
	def build(self):
		bmp = get_bmp(self, icons.CTX_OBJECT_JUMP, _('Default object jump'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.jump_spin = UnitSpin(self.app, self, onenter=self.user_changes)
		self.jump_spin.set_point_value(config.obj_jump)
		self.add(self.jump_spin, 0, LEFT | CENTER, 2)
Ejemplo n.º 9
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_OBJECT_RESIZE, _('Selection size'))
        self.pack(bmp, padding=2)
        self.pack((2, 2))

        self.width_spin = UnitSpin(self.app, self, onchange=self.w_changes)
        self.pack(self.width_spin, padding=2)

        self.pack(get_bmp(self, icons.CTX_W_ON_H), padding=1)

        self.height_spin = UnitSpin(self.app, self, onchange=self.h_changes)
        self.pack(self.height_spin, padding=2)

        self.pack((2, 2))

        self.keep_ratio = RatioToggle(self)
        self.pack(self.keep_ratio, padding=2)
Ejemplo n.º 10
0
	def build(self):
		grid = wal.GridPanel(self, 2, 3, 2, 2)

		grid.pack(get_bmp(grid, make_artid('h-sign')))
		self.h_spin = UnitSpin(self.app, grid, onchange=self.on_reset)
		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, onchange=self.height_changed)
		grid.pack(self.v_spin)
		grid.pack(UnitLabel(self.app, grid))

		self.pack(grid, align_center=False, padding=5)
		self.proportion = wal.Checkbox(self, _('Keep ratio'), True)
		self.pack(self.proportion, align_center=False, padding=5)

		self.active_widgets = [self.h_spin, self.v_spin, self.proportion]
Ejemplo n.º 11
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_OBJECT_RESIZE, _('Selection size'))
        self.add(bmp, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.width_spin = UnitSpin(self.app, self, onchange=self.w_changes)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app, self, onchange=self.h_changes)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.keep_ratio = RatioToggle(self)
        self.add(self.keep_ratio, 0, LEFT | CENTER, 2)
Ejemplo n.º 12
0
    def build(self):
        grid = wal.GridPanel(self, 2, 3, 2, 2)

        grid.pack(get_bmp(grid, make_artid('h-sign')))
        self.h_spin = UnitSpin(self.app, grid, onchange=self.on_reset)
        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, onchange=self.height_changed)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding=5)
        self.proportion = wal.Checkbox(self, _('Keep ratio'), True)
        self.pack(self.proportion, align_center=False, padding=5)

        self.active_widgets = [self.h_spin, self.v_spin, self.proportion]
Ejemplo n.º 13
0
	def __init__(self, parent, dlg, new_stroke):
		self.dlg = dlg
		self.app = dlg.app
		self.stroke = new_stroke
		wal.VPanel.__init__(self, parent)

		self.pack((30, 30))

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Stroke width:')), padding=5)
		self.width_spin = UnitSpin(self.app, p, self.stroke[1], step=0.1)
		p.pack(self.width_spin)
		p.pack(StaticUnitLabel(self.app, p), padding=5)
		self.pack(p)

		self.pack((20, 20))

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Dashes:')), padding=5)
		self.dashes = DashChoice(p, self.stroke[3])
		p.pack(self.dashes)
		txt = _('Edit dash pattern')
		p.pack(wal.ImageButton(p, icons.PD_EDIT, art_size=wal.SIZE_16,
							tooltip=txt, flat=False,
							onclick=self.edit_dash), padding=5)
		self.pack(p)

		grid = wal.GridPanel(self, vgap=15, hgap=15)

		caps_p = wal.LabeledPanel(grid, _('Caps:'))
		self.caps = CapChoice(caps_p, self.stroke[4])
		caps_p.pack(self.caps, align_center=False, padding_all=10)
		grid.pack(caps_p)

		join_p = wal.LabeledPanel(grid, _('Join:'))
		self.join = JoinChoice(join_p, self.stroke[5])
		join_p.pack(self.join, align_center=False, padding_all=10)
		grid.pack(join_p)

		self.pack(grid, padding_all=10)

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Miter limit:')), padding=5)
		self.miter_limit = wal.FloatSpin(p, self.stroke[6],
									range_val=(0.0, 1000.0), digits=5)
		p.pack(self.miter_limit)
		self.pack(p)

		p = wal.HPanel(self)
		self.behind = wal.NumCheckbox(p, _('Behind fill'), self.stroke[7])
		p.pack(self.behind)
		p.pack((30, 10))
		self.scalable = wal.NumCheckbox(p, _('Scalable stroke'), self.stroke[8])
		p.pack(self.scalable)
		self.pack(p, padding=10)
		self.layout()
Ejemplo n.º 14
0
	def build(self):
		bmp = get_bmp(self, icons.CTX_OBJECT_RESIZE, _('Selection size'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		self.width_spin = UnitSpin(self.app, self,
							onchange=self.w_changes)
		self.add(self.width_spin, 0, LEFT | CENTER, 2)

		self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

		self.height_spin = UnitSpin(self.app, self,
							onchange=self.h_changes)
		self.add(self.height_spin, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		self.keep_ratio = RatioToggle(self)
		self.add(self.keep_ratio, 0, LEFT | CENTER, 2)
Ejemplo n.º 15
0
class PageBorderPlugin(CtxPlugin):
    name = 'PageBorderPlugin'
    page_border = None

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

    def build(self):
        btn = ActionButton(self, self.actions[pdids.ID_PAGE_FRAME])
        self.add(btn, 0, LEFT | CENTER, 2)

        # =====
        self.add(VLine(self), 0, ALL | EXPAND, 2)

        self.page_border = UnitSpin(self.app,
                                    self,
                                    onchange=self.user_changes,
                                    can_be_negative=True)
        self.page_border.set_tooltip(_('Guide frame margin'))
        self.page_border.set_point_value(config.page_border)
        self.add(self.page_border, 0, LEFT | CENTER, 2)

        btn = ActionButton(self, self.actions[pdids.ID_PAGE_GUIDE_FRAME])
        self.add(btn, 0, LEFT | CENTER, 2)

        self.add(VLine(self), 0, ALL | EXPAND, 2)
        # =====

        btn = ActionButton(self, self.actions[pdids.ID_GUIDES_AT_CENTER])
        self.add(btn, 0, LEFT | CENTER, 2)

        btn = ActionButton(self, self.actions[pdids.ID_REMOVE_ALL_GUIDES])
        self.add(btn, 0, LEFT | CENTER, 2)

        btn = ActionToggle(self, self.actions[pdids.ID_LOCK_GUIDES])
        self.add(btn, 0, LEFT | CENTER, 2)

    def user_changes(self, *_args):
        val = self.page_border.get_point_value()
        if not config.page_border == val:
            config.page_border = val
Ejemplo n.º 16
0
	def build(self):
		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,
							onchange=self.on_reset)
		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,
							onchange=self.on_reset)
		grid.pack(self.v_spin)
		grid.pack(UnitLabel(self.app, grid))

		self.pack(grid, align_center=False, padding=5)
		self.abs_pos = wal.Checkbox(self, _('Absolute position'),
								onclick=self.update)
		self.pack(self.abs_pos, align_center=False, padding=5)

		self.active_widgets = [self.h_spin, self.v_spin, self.abs_pos]
Ejemplo n.º 17
0
class JumpPlugin(CtxPlugin):
    name = 'JumpPlugin'
    jump_spin = None

    def __init__(self, app, parent):
        CtxPlugin.__init__(self, app, parent)
        events.connect(events.CONFIG_MODIFIED, self.config_changed)

    def build(self):
        bmp = get_bmp(self, icons.CTX_OBJECT_JUMP, _('Default object jump'))
        self.pack(bmp, padding=2)

        self.jump_spin = UnitSpin(self.app,
                                  self,
                                  onenter=self.user_changes,
                                  onchange=self.user_changes)
        self.jump_spin.set_point_value(config.obj_jump)
        self.pack(self.jump_spin, padding=2)

    def user_changes(self, *_args):
        val = self.jump_spin.get_point_value()
        if not config.obj_jump == val:
            config.obj_jump = val

    def config_changed(self, *args):
        if args[0] == 'obj_jump':
            val = self.jump_spin.get_point_value()
            if not config.obj_jump == val:
                self.jump_spin.set_point_value(config.obj_jump)
Ejemplo n.º 18
0
    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.add(self.combo, 0, LEFT | CENTER, 2)
        self.add((3, 3))

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.add(self.portrait, 0, LEFT | CENTER, 2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.add(self.landscape, 0, LEFT | CENTER, 2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)
Ejemplo n.º 19
0
Archivo: jump.py Proyecto: Scrik/sk1-wx
class JumpPlugin(CtxPlugin):

	name = 'JumpPlugin'

	def __init__(self, app, parent):
		CtxPlugin.__init__(self, app, parent)
		events.connect(events.CONFIG_MODIFIED, self.config_changed)

	def build(self):
		bmp = get_bmp(self, icons.CTX_OBJECT_JUMP, _('Default object jump'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.jump_spin = UnitSpin(self.app, self, onenter=self.user_changes)
		self.jump_spin.set_point_value(config.obj_jump)
		self.add(self.jump_spin, 0, LEFT | CENTER, 2)

	def user_changes(self, *args):
		val = self.jump_spin.get_point_value()
		if not config.obj_jump == val:
			config.obj_jump = val

	def config_changed(self, *args):
		if args[0][0] == 'obj_jump':
			val = self.jump_spin.get_point_value()
			if not config.obj_jump == val:
				self.jump_spin.set_point_value(config.obj_jump)
Ejemplo n.º 20
0
class PositionPlugin(CtxPlugin):
    name = 'PositionPlugin'
    update_flag = False
    x_spin = None
    y_spin = 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)
        events.connect(events.DOC_MODIFIED, self.update)

    def build(self):
        self.pack(wal.Label(self, 'x:'), padding=2)
        self.x_spin = UnitSpin(self.app,
                               self,
                               can_be_negative=True,
                               onchange=self.user_changes)
        self.pack(self.x_spin, padding=2)

        self.pack(wal.Label(self, 'y:'), padding=2)
        self.y_spin = UnitSpin(self.app,
                               self,
                               can_be_negative=True,
                               onchange=self.user_changes)
        self.pack(self.y_spin, padding=2)

    def get_coords(self):
        pw, ph = self.app.current_doc.get_page_size()
        bbox = self.app.current_doc.selection.bbox
        doc_origin = self.app.current_doc.methods.get_doc_origin()
        page_factor = 0.0 if doc_origin == sk2const.DOC_ORIGIN_CENTER else 1.0
        y_factor = -1.0 if doc_origin == sk2const.DOC_ORIGIN_LU else 1.0
        return (page_factor * pw + bbox[2] + bbox[0]) / 2.0, \
               (page_factor * ph + y_factor * (bbox[3] + bbox[1])) / 2.0

    def update(self, *_args):
        if self.insp.is_selection():
            x, y = self.get_coords()
            self.update_flag = True
            self.x_spin.set_point_value(x)
            self.y_spin.set_point_value(y)
            self.update_flag = False

    def user_changes(self, *_args):
        if not self.update_flag and self.insp.is_selection():
            x, y = self.get_coords()
            dx = self.x_spin.get_point_value() - x
            dy = self.y_spin.get_point_value() - y
            if any([dx, dy]):
                doc_origin = self.app.current_doc.methods.get_doc_origin()
                dy *= -1.0 if doc_origin == sk2const.DOC_ORIGIN_LU else 1.0
                trafo = [1.0, 0.0, 0.0, 1.0, dx, dy]
                self.app.current_doc.api.transform_selected(trafo)
Ejemplo n.º 21
0
class PositionTransform(AbstractTransform):

    name = _('Position')
    dx = 0.0
    dy = 0.0

    def build(self):
        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,
                               onchange=self.on_reset)
        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,
                               onchange=self.on_reset)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding=5)
        self.abs_pos = wal.Checkbox(self,
                                    _('Absolute position'),
                                    onclick=self.update)
        self.pack(self.abs_pos, align_center=False, padding=5)

        self.active_widgets = [self.h_spin, self.v_spin, self.abs_pos]

    def update(self):
        if not self.app.insp.is_selection(): return
        if self.user_changes: return
        bbox = self.get_selection_bbox()
        w = bbox[2] - bbox[0]
        h = bbox[3] - bbox[1]
        dx = self.orientation[0] * w
        dy = self.orientation[1] * h
        if self.is_lu_coords() and dy: dy *= -1.0
        if self.abs_pos.get_value():
            new_x = bbox[0] + dx
            new_y = bbox[1] + dy
            new_x, new_y = self.doc_to_coords([new_x, new_y])
            self.h_spin.set_point_value(new_x)
            self.v_spin.set_point_value(new_y)
        else:
            self.h_spin.set_point_value(dx)
            self.v_spin.set_point_value(dy)

    def get_trafo(self):
        trafo = [] + sk2_const.NORMAL_TRAFO
        if self.abs_pos.get_value():
            bbox = self.get_selection_bbox()
            new_x = self.h_spin.get_point_value()
            new_y = self.v_spin.get_point_value()
            new_x, new_y = self.coords_to_doc([new_x, new_y])
            trafo[4] = new_x - bbox[0]
            trafo[5] = new_y - bbox[1]
        else:
            trafo[4] = self.h_spin.get_point_value()
            trafo[5] = self.v_spin.get_point_value()
            if self.is_lu_coords() and trafo[5]: trafo[5] *= -1.0
        return trafo
Ejemplo n.º 22
0
class PositionTransform(AbstractTransform):
    name = _('Position')
    dx = 0.0
    dy = 0.0
    h_spin = None
    v_spin = None
    abs_pos = None

    def build(self):
        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,
                               onchange=self.on_reset)
        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,
                               onchange=self.on_reset)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding=5)
        self.abs_pos = wal.Checkbox(self,
                                    _('Absolute position'),
                                    onclick=self.update)
        self.pack(self.abs_pos, align_center=False, padding=5)

        self.active_widgets = [self.h_spin, self.v_spin, self.abs_pos]

    def on_reset(self):
        self.user_changes = True
        if not self.abs_pos.get_value():
            AbstractTransform.on_reset(self)

    def update(self):
        if self.app.insp.is_selection() and not self.user_changes:
            bbox = self.get_selection_bbox()
            w, h = self.get_selection_size()
            if self.abs_pos.get_value():
                new_x = bbox[2] + bbox[0] + self.orientation[0] * w
                new_y = bbox[3] + bbox[1] + self.orientation[1] * h
                dx, dy = self.doc_to_coords([new_x / 2.0, new_y / 2.0])
            else:
                dx = self.orientation[0] * w
                dy = self.orientation[1] * h
                dy *= -1.0 if self.is_lu_coords() else 1.0
            self.h_spin.set_point_value(dx)
            self.v_spin.set_point_value(dy)

    def get_trafo(self):
        trafo = [] + sk2const.NORMAL_TRAFO
        if self.abs_pos.get_value():
            bbox = self.get_selection_bbox()
            w, h = self.get_selection_size()
            new_x = self.h_spin.get_point_value()
            new_y = self.v_spin.get_point_value()
            new_x, new_y = self.coords_to_doc([new_x, new_y])
            old_x = (bbox[2] + bbox[0] + self.orientation[0] * w) / 2.0
            old_y = (bbox[3] + bbox[1] + self.orientation[1] * h) / 2.0
            trafo[4] = new_x - old_x
            trafo[5] = new_y - old_y
        else:
            trafo[4] = self.h_spin.get_point_value()
            trafo[5] = self.v_spin.get_point_value()
            trafo[5] *= -1.0 if self.is_lu_coords() else 1.0
        return trafo
Ejemplo n.º 23
0
	def build(self):
		self.pack((5, 5))

		self.geom = self.doc.methods.get_grid_values()
		hpanel = wal.HPanel(self)

		txt = _('Grid origin')
		origin_panel = wal.LabeledPanel(hpanel, text=txt)
		grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

		grid.pack(wal.Label(grid, 'X:'))
		self.x_val = UnitSpin(self.app, grid, self.geom[0])
		grid.pack(self.x_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		grid.pack(wal.Label(grid, 'Y:'))
		self.y_val = UnitSpin(self.app, grid, self.geom[1])
		grid.pack(self.y_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		origin_panel.pack(grid, padding_all=5)
		hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True)

		txt = _('Grid frequency')
		freq_panel = wal.LabeledPanel(hpanel, text=txt)
		grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

		grid.pack(wal.Label(grid, 'dX:'))
		self.dx_val = UnitSpin(self.app, grid, self.geom[2])
		grid.pack(self.dx_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		grid.pack(wal.Label(grid, 'dY:'))
		self.dy_val = UnitSpin(self.app, grid, self.geom[3])
		grid.pack(self.dy_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		freq_panel.pack(grid, padding_all=5)
		hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True)

		self.pack(hpanel, fill=True)

		self.pack((5, 5))

		color_panel = wal.HPanel(self)

		color_panel.pack((10, 10))

		vpanel = wal.VPanel(color_panel)

		hpanel = wal.HPanel(vpanel)
		hpanel.pack(wal.Label(hpanel, _('Grid color:')))
		hpanel.pack((10, 5))
		self.color = self.doc.methods.get_grid_rgba_color()
		self.grid_color_btn = wal.ColorButton(hpanel, self.color[:3],
										onchange=self.on_change)
		hpanel.pack(self.grid_color_btn)
		vpanel.pack(hpanel, fill=True)

		hpanel = wal.HPanel(vpanel)
		hpanel.pack(wal.Label(hpanel, _('Grid opacity:')))
		hpanel.pack((10, 5))
		self.alpha_spin = wal.FloatSpin(hpanel, self.color[3] * 100.0,
								range_val=(0.0, 100.0), width=5,
								onchange=self.on_spin_change,
								onenter=self.on_spin_change)
		hpanel.pack(self.alpha_spin)
		hpanel.pack(wal.Label(hpanel, '%'), padding=3)

		vpanel.pack(hpanel, fill=True, padding=5)

		self.alpha_slider = wal.Slider(vpanel, int(self.color[3] * 100.0),
							range_val=(0, 100), onchange=self.on_slider_change)
		vpanel.pack(self.alpha_slider, fill=True, padding=5)

		val = self.doc.methods.is_grid_visible()
		self.show_grid_check = wal.Checkbox(vpanel,
										_('Show grid on canvas'), val)
		vpanel.pack(self.show_grid_check, fill=True, padding=5)

		color_panel.pack(vpanel)

		color_panel.pack((10, 10))

		preview_panel = wal.VPanel(color_panel)
		preview_panel.pack(wal.Label(hpanel, _('Grid preview:')))
		preview_panel.pack((5, 5))
		self.grid_preview = GridPreview(preview_panel, self.color)
		preview_panel.pack(self.grid_preview, fill=True, expand=True)
		color_panel.pack(preview_panel, fill=True, expand=True)

		color_panel.pack((10, 10))

		self.pack(color_panel, fill=True)
Ejemplo n.º 24
0
class ResizePlugin(CtxPlugin):

	name = 'ResizePlugin'
	update_flag = False

	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):
		bmp = get_bmp(self, icons.CTX_OBJECT_RESIZE, _('Selection size'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		self.width_spin = UnitSpin(self.app, self,
							onchange=self.w_changes)
		self.add(self.width_spin, 0, LEFT | CENTER, 2)

		self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

		self.height_spin = UnitSpin(self.app, self,
							onchange=self.h_changes)
		self.add(self.height_spin, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		self.keep_ratio = RatioToggle(self)
		self.add(self.keep_ratio, 0, LEFT | CENTER, 2)

	def update(self, *args):
		if self.insp.is_selection():
			bbox = self.app.current_doc.selection.bbox
			w = bbox[2] - bbox[0]
			h = bbox[3] - bbox[1]
			self.update_flag = True
			self.width_spin.set_point_value(w)
			self.height_spin.set_point_value(h)
			self.update_flag = False

	def w_changes(self, *args):
		if self.update_flag: return
		self.user_changes(True)

	def h_changes(self, *args):
		if self.update_flag: return
		self.user_changes(False)

	def user_changes(self, hr=True):
		if self.update_flag: return
		if self.insp.is_selection():
			doc = self.app.current_doc
			bbox = doc.selection.bbox
			w = bbox[2] - bbox[0]
			h = bbox[3] - bbox[1]
			center_x = bbox[0] + w / 2.0
			center_y = bbox[1] + h / 2.0

			new_w = self.width_spin.get_point_value()
			new_h = self.height_spin.get_point_value()

			if not w == new_w or not h == new_h:
				if not new_w: self.width_spin.set_point_value(w);return
				if not new_h: self.height_spin.set_point_value(h);return

				m11 = new_w / w
				m22 = new_h / h

				if m11 == m22 == 1.0:return

				trafo = []

				if self.keep_ratio.get_active():
					if hr:
						dx = center_x * (1 - m11)
						dy = center_y * (1 - m11)
						trafo = [m11, 0.0, 0.0, m11, dx, dy]
					else:
						dx = center_x * (1 - m22)
						dy = center_y * (1 - m22)
						trafo = [m22, 0.0, 0.0, m22, dx, dy]
				else:
					dx = center_x * (1 - m11)
					dy = center_y * (1 - m22)
					trafo = [m11, 0.0, 0.0, m22, dx, dy]

				if trafo: doc.api.transform_selected(trafo)
Ejemplo n.º 25
0
    def build(self):
        self.page_format = self.doc.methods.get_default_page_format()

        self.formats = [
            _('Custom'),
        ] + uc2const.PAGE_FORMAT_NAMES
        self.pack((5, 10))

        # ---
        hpanel = wal.HPanel(self)
        hpanel.pack((5, 5))
        label = wal.Label(hpanel, _('Default page:'))
        hpanel.pack(label)
        hpanel.pack((5, 5))
        self.page_combo = wal.Combolist(self,
                                        items=self.formats,
                                        onchange=self.page_combo_changed)

        hpanel.pack(self.page_combo)

        hpanel.pack((15, 5))

        self.orient_keeper = wal.HToggleKeeper(self,
                                               ORIENTS,
                                               ORIENTS_ICONS,
                                               ORIENTS_NAMES,
                                               on_change=self.orient_changed)
        hpanel.pack(self.orient_keeper)

        hpanel.pack((5, 5))

        self.as_current = wal.Button(hpanel,
                                     ' %s ' % _('As current page'),
                                     onclick=self.set_as_current)
        hpanel.pack(self.as_current)

        self.pack(hpanel, fill=True)

        self.pack((5, 5))

        # ---
        hpanel = wal.HPanel(self)
        dx = label.get_size()[0] + 10
        hpanel.pack((dx, 5))

        self.page_width = UnitSpin(self.app,
                                   hpanel,
                                   0,
                                   onchange=self.page_spin_changed)
        hpanel.pack(self.page_width)
        hpanel.pack(get_bmp(self, icons.CTX_W_ON_H), padding=5)
        self.page_height = UnitSpin(self.app,
                                    hpanel,
                                    0,
                                    onchange=self.page_spin_changed)
        hpanel.pack(self.page_height)
        hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5)

        self.pack(hpanel, fill=True)
        self.pack(wal.HLine(self), padding_all=5, fill=True)

        self.set_page_format(self.page_format)

        # --- COLORS
        hpanel = wal.HPanel(self)
        hpanel.pack((5, 5))

        grid = wal.GridPanel(hpanel, 3, 3, 5, 5)
        grid.add_growable_col(2)

        grid.pack(wal.Label(grid, _('Desktop:')))
        self.desktop_bg = self.doc.methods.get_desktop_bg()
        self.desktop_color_btn = wal.ColorButton(grid, self.desktop_bg)
        grid.pack(self.desktop_color_btn)
        grid.pack(CBMiniPalette(grid,
                                onclick=self.desktop_color_btn.set_value))

        self.page_fill = self.doc.methods.get_page_fill()
        if self.page_fill[0] == FILL_SOLID:
            color1 = self.page_fill[1]
            color2 = [1.0, 1.0, 1.0]
        else:
            color1 = self.page_fill[1][0]
            color2 = self.page_fill[1][1]

        grid.pack(wal.Label(grid, _('Page:')))
        self.page_color1_btn = wal.ColorButton(grid, color1)
        grid.pack(self.page_color1_btn)
        grid.pack(CBMiniPalette(grid, onclick=self.page_color1_btn.set_value))

        grid.pack((5, 5))
        self.page_color2_btn = wal.ColorButton(grid, color2)
        grid.pack(self.page_color2_btn)
        self.colors2 = CBMiniPalette(grid,
                                     onclick=self.page_color2_btn.set_value)
        grid.pack(self.colors2)
        if not self.page_fill[0] == FILL_PATTERN:
            self.page_color2_btn.set_enable(False)
            self.colors2.set_enable(False)

        hpanel.pack(grid, fill=True)
        hpanel.pack((5, 5))
        self.pack(hpanel, fill=True)

        # ---
        vpanel = wal.VPanel(self)
        if wal.IS_MSW:
            vpanel.pack((5, 5))

        self.pattern_check = wal.Checkbox(vpanel,
                                          _('Use pattern for page fill'),
                                          self.page_fill[0] == FILL_PATTERN,
                                          onclick=self.pattern_check_changed)
        vpanel.pack(self.pattern_check, align_center=False)

        if wal.IS_MSW:
            vpanel.pack((5, 5))

        self.border_flag = self.doc.methods.get_page_border()
        self.border_check = wal.Checkbox(vpanel, _('Show page border'),
                                         self.border_flag)
        vpanel.pack(self.border_check, align_center=False)
        self.pack(vpanel, fill=True, padding_all=5)
Ejemplo n.º 26
0
    def build(self):
        self.pack((5, 5))

        self.geom = self.doc.methods.get_grid_values()
        hpanel = wal.HPanel(self)

        txt = _('Grid origin')
        origin_panel = wal.LabeledPanel(hpanel, text=txt)
        grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

        grid.pack(wal.Label(grid, 'X:'))
        self.x_val = UnitSpin(self.app, grid, self.geom[0])
        grid.pack(self.x_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        grid.pack(wal.Label(grid, 'Y:'))
        self.y_val = UnitSpin(self.app, grid, self.geom[1])
        grid.pack(self.y_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        origin_panel.pack(grid, padding_all=5)
        hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True)

        txt = _('Grid frequency')
        freq_panel = wal.LabeledPanel(hpanel, text=txt)
        grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

        grid.pack(wal.Label(grid, 'dX:'))
        self.dx_val = UnitSpin(self.app, grid, self.geom[2])
        grid.pack(self.dx_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        grid.pack(wal.Label(grid, 'dY:'))
        self.dy_val = UnitSpin(self.app, grid, self.geom[3])
        grid.pack(self.dy_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        freq_panel.pack(grid, padding_all=5)
        hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True)

        self.pack(hpanel, fill=True)

        self.pack((5, 5))

        color_panel = wal.HPanel(self)

        color_panel.pack((10, 10))

        vpanel = wal.VPanel(color_panel)

        hpanel = wal.HPanel(vpanel)
        hpanel.pack(wal.Label(hpanel, _('Grid color:')))
        hpanel.pack((10, 5))
        self.color = self.doc.methods.get_grid_rgba_color()
        self.grid_color_btn = wal.ColorButton(hpanel,
                                              self.color[:3],
                                              onchange=self.on_change)
        hpanel.pack(self.grid_color_btn)
        vpanel.pack(hpanel, fill=True)

        hpanel = wal.HPanel(vpanel)
        hpanel.pack(wal.Label(hpanel, _('Grid opacity:')))
        hpanel.pack((10, 5))
        self.alpha_spin = wal.FloatSpin(hpanel,
                                        self.color[3] * 100.0,
                                        range_val=(0.0, 100.0),
                                        onchange=self.on_spin_change,
                                        onenter=self.on_spin_change)
        hpanel.pack(self.alpha_spin)
        hpanel.pack(wal.Label(hpanel, '%'), padding=3)

        vpanel.pack(hpanel, fill=True, padding=5)

        self.alpha_slider = wal.Slider(vpanel,
                                       int(self.color[3] * 100.0),
                                       range_val=(0, 100),
                                       onchange=self.on_slider_change)
        vpanel.pack(self.alpha_slider, fill=True, padding=5)

        val = self.doc.methods.is_grid_visible()
        self.show_grid_check = wal.Checkbox(vpanel, _('Show grid on canvas'),
                                            val)
        vpanel.pack(self.show_grid_check, fill=True, padding=5)

        color_panel.pack(vpanel)

        color_panel.pack((10, 10))

        preview_panel = wal.VPanel(color_panel)
        preview_panel.pack(wal.Label(hpanel, _('Grid preview:')))
        preview_panel.pack((5, 5))
        self.grid_preview = GridPreview(preview_panel, self.color)
        preview_panel.pack(self.grid_preview, fill=True, expand=True)
        color_panel.pack(preview_panel, fill=True, expand=True)

        color_panel.pack((10, 10))

        self.pack(color_panel, fill=True)
Ejemplo n.º 27
0
class ResizeTransform(AbstractTransform):

	name = _('Resizing')

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

		grid.pack(get_bmp(grid, make_artid('h-sign')))
		self.h_spin = UnitSpin(self.app, grid, onchange=self.on_reset)
		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, onchange=self.height_changed)
		grid.pack(self.v_spin)
		grid.pack(UnitLabel(self.app, grid))

		self.pack(grid, align_center=False, padding=5)
		self.proportion = wal.Checkbox(self, _('Keep ratio'), True)
		self.pack(self.proportion, align_center=False, padding=5)

		self.active_widgets = [self.h_spin, self.v_spin, self.proportion]

	def height_changed(self): self.on_reset(True)

	def on_reset(self, height_changed=False):
		self.user_changes = True
		if not self.h_spin.get_point_value():
			self.h_spin.set_point_value(1.0)
		if not self.v_spin.get_point_value():
			self.v_spin.set_point_value(1.0)
		if self.proportion.get_value():
			w, h = self.get_selection_size()
			if height_changed:
				new_h = self.v_spin.get_point_value()
				self.h_spin.set_point_value(w * new_h / h)
			else:
				new_w = self.h_spin.get_point_value()
				self.v_spin.set_point_value(h * new_w / w)

	def set_enable(self, state):
		self.user_changes = False
		AbstractTransform.set_enable(self, state)

	def set_orientation(self, orientation=(0.0, 0.0)):
		self.orientation = orientation
		self.update()

	def update(self):
		if not self.app.insp.is_selection():return
		if self.user_changes: return
		w, h = self.get_selection_size()
		self.h_spin.set_point_value(w)
		self.v_spin.set_point_value(h)

	def get_trafo(self):
		trafo = [] + sk2_const.NORMAL_TRAFO
		bbox = self.get_selection_bbox()
		w, h = self.get_selection_size()
		new_w = self.h_spin.get_point_value()
		new_h = self.v_spin.get_point_value()
		trafo[0] = new_w / w
		trafo[3] = new_h / h

		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
Ejemplo n.º 28
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]
Ejemplo n.º 29
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]
Ejemplo n.º 30
0
class ResizePlugin(CtxPlugin):
    name = 'ResizePlugin'
    update_flag = False
    width_spin = None
    height_spin = None
    keep_ratio = 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):
        bmp = get_bmp(self, icons.CTX_OBJECT_RESIZE, _('Selection size'))
        self.add(bmp, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.width_spin = UnitSpin(self.app, self, onchange=self.w_changes)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app, self, onchange=self.h_changes)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.keep_ratio = RatioToggle(self)
        self.add(self.keep_ratio, 0, LEFT | CENTER, 2)

    def update(self, *args):
        if self.insp.is_selection():
            bbox = self.app.current_doc.selection.bbox
            w = bbox[2] - bbox[0]
            h = bbox[3] - bbox[1]
            self.update_flag = True
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False

    def w_changes(self, *args):
        if self.update_flag:
            return
        self.user_changes(True)

    def h_changes(self, *args):
        if self.update_flag:
            return
        self.user_changes(False)

    def user_changes(self, hr=True):
        if self.update_flag:
            return
        if self.insp.is_selection():
            doc = self.app.current_doc
            bbox = doc.selection.bbox
            w = bbox[2] - bbox[0]
            h = bbox[3] - bbox[1]
            center_x = bbox[0] + w / 2.0
            center_y = bbox[1] + h / 2.0

            new_w = self.width_spin.get_point_value()
            new_h = self.height_spin.get_point_value()

            if not w == new_w or not h == new_h:
                if not new_w:
                    self.width_spin.set_point_value(w)
                    return
                if not new_h:
                    self.height_spin.set_point_value(h)
                    return

                m11 = new_w / w
                m22 = new_h / h

                if m11 == m22 == 1.0:
                    return

                if self.keep_ratio.get_active():
                    if hr:
                        dx = center_x * (1 - m11)
                        dy = center_y * (1 - m11)
                        trafo = [m11, 0.0, 0.0, m11, dx, dy]
                    else:
                        dx = center_x * (1 - m22)
                        dy = center_y * (1 - m22)
                        trafo = [m22, 0.0, 0.0, m22, dx, dy]
                else:
                    dx = center_x * (1 - m11)
                    dy = center_y * (1 - m22)
                    trafo = [m11, 0.0, 0.0, m22, dx, dy]

                if trafo:
                    doc.api.transform_selected(trafo)
Ejemplo n.º 31
0
    def __init__(self, parent, dlg, new_stroke):
        self.dlg = dlg
        self.app = dlg.app
        self.stroke = new_stroke
        wal.VPanel.__init__(self, parent)

        self.pack((30, 30))

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Stroke width:')), padding=5)
        self.width_spin = UnitSpin(self.app, p, self.stroke[1], step=0.1)
        p.pack(self.width_spin)
        p.pack(StaticUnitLabel(self.app, p), padding=5)
        self.pack(p)

        self.pack((20, 20))

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Dashes:')), padding=5)
        self.dashes = DashChoice(p, self.stroke[3])
        p.pack(self.dashes)
        txt = _('Edit dash pattern')
        p.pack(wal.ImageButton(p,
                               icons.PD_EDIT,
                               tooltip=txt,
                               flat=False,
                               onclick=self.edit_dash),
               padding=5)
        self.pack(p)

        grid = wal.GridPanel(self, vgap=15, hgap=15)

        caps_p = wal.LabeledPanel(grid, _('Caps:'))
        self.caps = CapChoice(caps_p, self.stroke[4])
        caps_p.pack(self.caps, align_center=False, padding_all=10)
        grid.pack(caps_p)

        join_p = wal.LabeledPanel(grid, _('Join:'))
        self.join = JoinChoice(join_p, self.stroke[5])
        join_p.pack(self.join, align_center=False, padding_all=10)
        grid.pack(join_p)

        self.pack(grid, padding_all=10)

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Miter limit:')), padding=5)
        self.miter_limit = wal.FloatSpin(p,
                                         self.stroke[6],
                                         range_val=(0.0, 1000.0),
                                         digits=5)
        p.pack(self.miter_limit)
        self.pack(p)

        p = wal.HPanel(self)
        self.behind = wal.NumCheckbox(p, _('Behind fill'), self.stroke[7])
        p.pack(self.behind)
        p.pack((30, 10))
        self.scalable = wal.NumCheckbox(p, _('Scalable stroke'),
                                        self.stroke[8])
        p.pack(self.scalable)
        self.pack(p, padding=10)
Ejemplo n.º 32
0
    def __init__(self, parent, dlg, new_stroke):
        self.dlg = dlg
        self.app = dlg.app
        self.stroke = new_stroke
        wal.VPanel.__init__(self, parent)

        hp = wal.HPanel(self)

        width_p = wal.LabeledPanel(hp, _('Width:'))
        p = wal.HPanel(width_p)
        self.width_spin = UnitSpin(self.app, p, self.stroke[1], step=0.1)
        p.pack(self.width_spin)
        p.pack((5, 5))
        p.pack(StaticUnitLabel(self.app, p))
        width_p.pack(p, padding_all=5)
        hp.pack(width_p, fill=True)

        hp.pack((5, 5))
        arrow_p = wal.LabeledPanel(hp, _('Markers:'))

        p = wal.HPanel(arrow_p)

        end, start = [], []
        if self.stroke[9]:
            end, start = self.stroke[9]

        self.end_arrow = ArrowChoice(p, arrow=end, end=True)
        self.end_arrow.set_arrow(end)
        p.pack(self.end_arrow)
        p.pack((5, 5))
        self.start_arrow = ArrowChoice(p, arrow=start)
        self.start_arrow.set_arrow(start)
        p.pack(self.start_arrow)

        arrow_p.pack(p)

        hp.pack(arrow_p, expand=True, fill=True)
        self.pack(hp, fill=True, padding_all=10)

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Dashes:')), padding=5)
        self.dashes = DashChoice(p, self.stroke[3])
        p.pack(self.dashes)
        txt = _('Edit dash pattern')
        p.pack(wal.ImageButton(p,
                               icons.PD_EDIT,
                               art_size=wal.SIZE_16,
                               tooltip=txt,
                               flat=False,
                               onclick=self.edit_dash),
               padding=5)
        self.pack(p)

        grid = wal.GridPanel(self, rows=1, cols=3, vgap=15, hgap=15)
        grid.add_growable_col(2)

        caps_p = wal.LabeledPanel(grid, _('Caps:'))
        self.caps = CapChoice(caps_p, self.stroke[4])
        caps_p.pack(self.caps, align_center=False, padding_all=10)
        grid.pack(caps_p)

        join_p = wal.LabeledPanel(grid, _('Join:'))
        self.join = JoinChoice(join_p, self.stroke[5])
        join_p.pack(self.join, align_center=False, padding_all=10)
        grid.pack(join_p)

        opt_p = wal.LabeledPanel(grid, _('Options:'))

        p = wal.HPanel(opt_p)
        p.pack(wal.Label(p, _('Miter limit:')), padding=5)
        self.miter_limit = wal.FloatSpin(p,
                                         self.stroke[6],
                                         range_val=(0.0, 1000.0),
                                         digits=5)
        p.pack(self.miter_limit)
        opt_p.pack(p, align_center=False, padding_all=10)

        p = wal.VPanel(opt_p)
        self.behind = wal.NumCheckbox(p, _('Behind fill'), self.stroke[7])
        p.pack(self.behind, align_center=False)

        self.scalable = wal.NumCheckbox(p, _('Scalable stroke'),
                                        self.stroke[8])
        p.pack(self.scalable, align_center=False, padding=10)
        opt_p.pack(p, align_center=False, padding_all=10)

        grid.pack(opt_p, fill=True)

        self.pack(grid, padding_all=10, fill=True)
        self.layout()
Ejemplo n.º 33
0
class PagePlugin(CtxPlugin):
    name = 'PagePlugin'
    update_flag = False
    format = None
    formats = None
    combo = None
    width_spin = None
    height_spin = None
    portrait = None
    landscape = None

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

    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.pack(self.combo, padding_all=3)

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.pack(self.width_spin)
        self.pack((3, 3))

        self.pack(get_bmp(self, icons.CTX_W_ON_H))

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.pack(self.height_spin, padding_all=3)

        self.pack((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.pack(self.portrait, padding=2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.pack(self.landscape, padding=2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)

    def update(self, *args):
        if self.insp.is_doc():
            self.update_flag = True
            page_format = self.app.current_doc.active_page.page_format
            self.format = page_format
            width, height = page_format[1]
            if page_format[0] in PAGE_FORMAT_NAMES:
                self.combo.set_active(self.formats.index(page_format[0]))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(False)
                self.height_spin.set_enable(False)
            else:
                self.combo.set_active(self.formats.index(_('Custom')))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(True)
                self.height_spin.set_enable(True)
            self.update_flag = False

    def combo_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[0] == self.formats[self.combo.get_active()]:
            self.update_flag = True
            if self.formats[self.combo.get_active()] in PAGE_FORMAT_NAMES:
                w, h = PAGE_FORMATS[self.formats[self.combo.get_active()]]
                if self.portrait.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                elif self.landscape.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                elif self.portrait.get_active() and w < h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                else:
                    self.width_spin.set_point_value(h)
                    self.height_spin.set_point_value(w)
            self.update_flag = False
            self.changes()

    def width_spin_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[1][0] == self.width_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def height_spin_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[1][1] == self.height_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def portrait_toggled(self, *_args):
        if self.update_flag:
            return
        if self.portrait.get_active():
            self.update_flag = True
            self.landscape.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.portrait.set_active(True)
            self.update_flag = False

    def landscape_toggled(self, *_args):
        if self.update_flag:
            return
        if self.landscape.get_active():
            self.update_flag = True
            self.portrait.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.landscape.set_active(True)
            self.update_flag = False

    def changes(self):
        doc = self.app.current_doc
        new_format = [
            self.formats[self.combo.get_active()],
        ]
        new_format += [(self.width_spin.get_point_value(),
                        self.height_spin.get_point_value())]
        if self.portrait.get_active():
            new_format += [
                PORTRAIT,
            ]
        else:
            new_format += [
                LANDSCAPE,
            ]
        current_page_format = deepcopy(doc.active_page.page_format)
        doc.api.set_page_format(new_format)

        pdict = PAGE_FORMATS_MORE
        if new_format[0] in pdict and current_page_format[0] in pdids and \
                pdict[current_page_format[0]] != pdict[new_format[0]]:
            units, jump = pdict[new_format[0]]
            doc.api.set_doc_units(units)
            geom = doc.methods.get_grid_values()[:2] + [jump, jump]
            doc.api.set_grid_values(geom)
            config.obj_jump = jump

        doc.canvas.zoom_fit_to_page()
Ejemplo n.º 34
0
class ResizeTransform(AbstractTransform):

    name = _('Resizing')

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

        grid.pack(get_bmp(grid, make_artid('h-sign')))
        self.h_spin = UnitSpin(self.app, grid, onchange=self.on_reset)
        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, onchange=self.height_changed)
        grid.pack(self.v_spin)
        grid.pack(UnitLabel(self.app, grid))

        self.pack(grid, align_center=False, padding=5)
        self.proportion = wal.Checkbox(self, _('Keep ratio'), True)
        self.pack(self.proportion, align_center=False, padding=5)

        self.active_widgets = [self.h_spin, self.v_spin, self.proportion]

    def height_changed(self):
        self.on_reset(True)

    def on_reset(self, height_changed=False):
        self.user_changes = True
        if not self.h_spin.get_point_value():
            self.h_spin.set_point_value(1.0)
        if not self.v_spin.get_point_value():
            self.v_spin.set_point_value(1.0)
        if self.proportion.get_value():
            w, h = self.get_selection_size()
            if height_changed:
                new_h = self.v_spin.get_point_value()
                self.h_spin.set_point_value(w * new_h / h)
            else:
                new_w = self.h_spin.get_point_value()
                self.v_spin.set_point_value(h * new_w / w)

    def set_enable(self, state):
        self.user_changes = False
        AbstractTransform.set_enable(self, state)

    def set_orientation(self, orientation=(0.0, 0.0)):
        self.orientation = orientation
        self.update()

    def update(self):
        if not self.app.insp.is_selection(): return
        if self.user_changes: return
        w, h = self.get_selection_size()
        self.h_spin.set_point_value(w)
        self.v_spin.set_point_value(h)

    def get_trafo(self):
        trafo = [] + sk2_const.NORMAL_TRAFO
        bbox = self.get_selection_bbox()
        w, h = self.get_selection_size()
        new_w = self.h_spin.get_point_value()
        new_h = self.v_spin.get_point_value()
        trafo[0] = new_w / w
        trafo[3] = new_h / h

        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
Ejemplo n.º 35
0
class GridProps(DP_Panel):

	name = _('Grid')
	geom = []
	color = []

	def build(self):
		self.pack((5, 5))

		self.geom = self.doc.methods.get_grid_values()
		hpanel = wal.HPanel(self)

		txt = _('Grid origin')
		origin_panel = wal.LabeledPanel(hpanel, text=txt)
		grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

		grid.pack(wal.Label(grid, 'X:'))
		self.x_val = UnitSpin(self.app, grid, self.geom[0])
		grid.pack(self.x_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		grid.pack(wal.Label(grid, 'Y:'))
		self.y_val = UnitSpin(self.app, grid, self.geom[1])
		grid.pack(self.y_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		origin_panel.pack(grid, padding_all=5)
		hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True)

		txt = _('Grid frequency')
		freq_panel = wal.LabeledPanel(hpanel, text=txt)
		grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

		grid.pack(wal.Label(grid, 'dX:'))
		self.dx_val = UnitSpin(self.app, grid, self.geom[2])
		grid.pack(self.dx_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		grid.pack(wal.Label(grid, 'dY:'))
		self.dy_val = UnitSpin(self.app, grid, self.geom[3])
		grid.pack(self.dy_val)
		grid.pack(StaticUnitLabel(self.app, grid))

		freq_panel.pack(grid, padding_all=5)
		hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True)

		self.pack(hpanel, fill=True)

		self.pack((5, 5))

		color_panel = wal.HPanel(self)

		color_panel.pack((10, 10))

		vpanel = wal.VPanel(color_panel)

		hpanel = wal.HPanel(vpanel)
		hpanel.pack(wal.Label(hpanel, _('Grid color:')))
		hpanel.pack((10, 5))
		self.color = self.doc.methods.get_grid_rgba_color()
		self.grid_color_btn = wal.ColorButton(hpanel, self.color[:3],
										onchange=self.on_change)
		hpanel.pack(self.grid_color_btn)
		vpanel.pack(hpanel, fill=True)

		hpanel = wal.HPanel(vpanel)
		hpanel.pack(wal.Label(hpanel, _('Grid opacity:')))
		hpanel.pack((10, 5))
		self.alpha_spin = wal.FloatSpin(hpanel, self.color[3] * 100.0,
								range_val=(0.0, 100.0), width=5,
								onchange=self.on_spin_change,
								onenter=self.on_spin_change)
		hpanel.pack(self.alpha_spin)
		hpanel.pack(wal.Label(hpanel, '%'), padding=3)

		vpanel.pack(hpanel, fill=True, padding=5)

		self.alpha_slider = wal.Slider(vpanel, int(self.color[3] * 100.0),
							range_val=(0, 100), onchange=self.on_slider_change)
		vpanel.pack(self.alpha_slider, fill=True, padding=5)

		val = self.doc.methods.is_grid_visible()
		self.show_grid_check = wal.Checkbox(vpanel,
										_('Show grid on canvas'), val)
		vpanel.pack(self.show_grid_check, fill=True, padding=5)

		color_panel.pack(vpanel)

		color_panel.pack((10, 10))

		preview_panel = wal.VPanel(color_panel)
		preview_panel.pack(wal.Label(hpanel, _('Grid preview:')))
		preview_panel.pack((5, 5))
		self.grid_preview = GridPreview(preview_panel, self.color)
		preview_panel.pack(self.grid_preview, fill=True, expand=True)
		color_panel.pack(preview_panel, fill=True, expand=True)

		color_panel.pack((10, 10))

		self.pack(color_panel, fill=True)

	def on_slider_change(self):
		self.alpha_spin.set_value(float(self.alpha_slider.get_value()))
		self.on_change()

	def on_spin_change(self):
		self.alpha_slider.set_value(int(self.alpha_spin.get_value()))
		self.on_change()

	def on_change(self):
		color = list(self.grid_color_btn.get_value())
		color.append(self.alpha_spin.get_value() / 100.0)
		self.grid_preview.set_color(color)

	def save(self):
		geom = [self.x_val.get_point_value(), self.y_val.get_point_value(),
			self.dx_val.get_point_value(), self.dy_val.get_point_value()]
		if not self.geom == geom:
			self.api.set_grid_values(geom)
		color = list(self.grid_color_btn.get_value())
		color.append(self.alpha_spin.get_value() / 100.0)
		if not self.color == color:
			self.api.set_grid_color(color)
		visibility = self.doc.methods.is_grid_visible()
		if not visibility == self.show_grid_check.get_value():
			grid = self.doc.methods.get_grid_layer()
			props = self.doc.methods.get_grid_properties()
			props[0] = 0
			if self.show_grid_check.get_value():props[0] = 1
			self.api.set_layer_properties(grid, props)
Ejemplo n.º 36
0
class StrokeStyle(wal.VPanel):
    def __init__(self, parent, dlg, new_stroke):
        self.dlg = dlg
        self.app = dlg.app
        self.stroke = new_stroke
        wal.VPanel.__init__(self, parent)

        self.pack((30, 30))

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Stroke width:')), padding=5)
        self.width_spin = UnitSpin(self.app, p, self.stroke[1], step=0.1)
        p.pack(self.width_spin)
        p.pack(StaticUnitLabel(self.app, p), padding=5)
        self.pack(p)

        self.pack((20, 20))

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Dashes:')), padding=5)
        self.dashes = DashChoice(p, self.stroke[3])
        p.pack(self.dashes)
        txt = _('Edit dash pattern')
        p.pack(wal.ImageButton(p,
                               icons.PD_EDIT,
                               art_size=wal.SIZE_16,
                               tooltip=txt,
                               flat=False,
                               onclick=self.edit_dash),
               padding=5)
        self.pack(p)

        grid = wal.GridPanel(self, vgap=15, hgap=15)

        caps_p = wal.LabeledPanel(grid, _('Caps:'))
        self.caps = CapChoice(caps_p, self.stroke[4])
        caps_p.pack(self.caps, align_center=False, padding_all=10)
        grid.pack(caps_p)

        join_p = wal.LabeledPanel(grid, _('Join:'))
        self.join = JoinChoice(join_p, self.stroke[5])
        join_p.pack(self.join, align_center=False, padding_all=10)
        grid.pack(join_p)

        self.pack(grid, padding_all=10)

        p = wal.HPanel(self)
        p.pack(wal.Label(p, _('Miter limit:')), padding=5)
        self.miter_limit = wal.FloatSpin(p,
                                         self.stroke[6],
                                         range_val=(0.0, 1000.0),
                                         digits=5)
        p.pack(self.miter_limit)
        self.pack(p)

        p = wal.HPanel(self)
        self.behind = wal.NumCheckbox(p, _('Behind fill'), self.stroke[7])
        p.pack(self.behind)
        p.pack((30, 10))
        self.scalable = wal.NumCheckbox(p, _('Scalable stroke'),
                                        self.stroke[8])
        p.pack(self.scalable)
        self.pack(p, padding=10)
        self.layout()

    def edit_dash(self):
        ret = dash_editor_dlg(self.dlg, self.dashes.get_dash())
        if ret is not None:
            self.dashes.set_dash(ret)

    def get_stroke(self):
        self.stroke[1] = self.width_spin.get_point_value()
        self.stroke[3] = self.dashes.get_dash()
        self.stroke[4] = self.caps.get_cap()
        self.stroke[5] = self.join.get_join()
        self.stroke[6] = self.miter_limit.get_value()
        self.stroke[7] = self.behind.get_value()
        self.stroke[8] = self.scalable.get_value()
        return self.stroke
Ejemplo n.º 37
0
class StrokeStyle(wal.VPanel):

	def __init__(self, parent, dlg, new_stroke):
		self.dlg = dlg
		self.app = dlg.app
		self.stroke = new_stroke
		wal.VPanel.__init__(self, parent)

		self.pack((30, 30))

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Stroke width:')), padding=5)
		self.width_spin = UnitSpin(self.app, p, self.stroke[1], step=0.1)
		p.pack(self.width_spin)
		p.pack(StaticUnitLabel(self.app, p), padding=5)
		self.pack(p)

		self.pack((20, 20))

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Dashes:')), padding=5)
		self.dashes = DashChoice(p, self.stroke[3])
		p.pack(self.dashes)
		txt = _('Edit dash pattern')
		p.pack(wal.ImageButton(p, icons.PD_EDIT, tooltip=txt, flat=False,
							onclick=self.edit_dash), padding=5)
		self.pack(p)

		grid = wal.GridPanel(self, vgap=15, hgap=15)

		caps_p = wal.LabeledPanel(grid, _('Caps:'))
		self.caps = CapChoice(caps_p, self.stroke[4])
		caps_p.pack(self.caps, align_center=False, padding_all=10)
		grid.pack(caps_p)

		join_p = wal.LabeledPanel(grid, _('Join:'))
		self.join = JoinChoice(join_p, self.stroke[5])
		join_p.pack(self.join, align_center=False, padding_all=10)
		grid.pack(join_p)

		self.pack(grid, padding_all=10)

		p = wal.HPanel(self)
		p.pack(wal.Label(p, _('Miter limit:')), padding=5)
		self.miter_limit = wal.FloatSpin(p, self.stroke[6],
									range_val=(0.0, 1000.0), digits=5)
		p.pack(self.miter_limit)
		self.pack(p)

		p = wal.HPanel(self)
		self.behind = wal.NumCheckbox(p, _('Behind fill'), self.stroke[7])
		p.pack(self.behind)
		p.pack((30, 10))
		self.scalable = wal.NumCheckbox(p, _('Scalable stroke'), self.stroke[8])
		p.pack(self.scalable)
		self.pack(p, padding=10)

	def edit_dash(self):
		ret = dash_editor_dlg(self.dlg, self.dashes.get_dash())
		if not ret is None:
			self.dashes.set_dash(ret)

	def get_stroke(self):
		self.stroke[1] = self.width_spin.get_point_value()
		self.stroke[3] = self.dashes.get_dash()
		self.stroke[4] = self.caps.get_cap()
		self.stroke[5] = self.join.get_join()
		self.stroke[6] = self.miter_limit.get_value()
		self.stroke[7] = self.behind.get_value()
		self.stroke[8] = self.scalable.get_value()
		return self.stroke
Ejemplo n.º 38
0
class PageProps(DP_Panel):

	name = _('Page')
	page_format = None
	desktop_bg = None
	page_fill = None
	border_flag = False

	def build(self):
		self.page_format = self.doc.methods.get_default_page_format()
		self.formats = [_('Custom'), ] + uc2const.PAGE_FORMAT_NAMES
		self.pack((5, 10))

		#---
		hpanel = wal.HPanel(self)
		hpanel.pack((5, 5))
		label = wal.Label(hpanel, _('Default page:'))
		hpanel.pack(label)
		hpanel.pack((5, 5))
		self.page_combo = wal.Combolist(self, items=self.formats,
							onchange=self.page_combo_changed)
		index = 0
		state = True
		if self.page_format[0] in uc2const.PAGE_FORMAT_NAMES:
			index = self.formats.index(self.page_format[0])
			state = False
		self.page_combo.set_active(index)

		hpanel.pack(self.page_combo)

		hpanel.pack((15, 5))

		self.orient_keeper = wal.HToggleKeeper(self, ORIENTS, ORIENTS_ICONS,
								ORIENTS_NAMES, on_change=self.orient_changed)
		self.orient_keeper.set_mode(self.page_format[2])
		hpanel.pack(self.orient_keeper)

		self.pack(hpanel, fill=True)

		self.pack((5, 5))

		#---
		w, h = self.page_format[1]
		hpanel = wal.HPanel(self)
		dx = label.get_size()[0] + 10
		hpanel.pack((dx, 5))

		self.page_width = UnitSpin(self.app, hpanel, w,
								onchange=self.page_spin_changed)
		hpanel.pack(self.page_width)
		hpanel.pack(get_bmp(self, icons.CTX_W_ON_H), padding=5)
		self.page_height = UnitSpin(self.app, hpanel, h,
								onchange=self.page_spin_changed)
		hpanel.pack(self.page_height)
		hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5)
		self.page_width.set_enable(state)
		self.page_height.set_enable(state)

		self.pack(hpanel, fill=True)
		self.pack(wal.HLine(self), padding_all=5, fill=True)

		#---
		hpanel = wal.HPanel(self)
		hpanel.pack((5, 5))
		self.desktop_bg = self.doc.methods.get_desktop_bg()

		grid = wal.GridPanel(hpanel, 3, 3, 5, 5)
		grid.add_growable_col(2)

		grid.pack(wal.Label(hpanel, _('Desktop:')))
		self.desktop_color_btn = wal.ColorButton(hpanel, self.desktop_bg)
		grid.pack(self.desktop_color_btn)
		grid.pack(CBMiniPalette(grid, onclick=self.desktop_color_btn.set_value))

		self.page_fill = self.doc.methods.get_page_fill()
		if self.page_fill[0] == FILL_SOLID:
			color1 = self.page_fill[1]
			color2 = [1.0, 1.0, 1.0]
		else:
			color1 = self.page_fill[1][0]
			color2 = self.page_fill[1][1]

		grid.pack(wal.Label(hpanel, _('Page:')))
		self.page_color1_btn = wal.ColorButton(hpanel, color1)
		grid.pack(self.page_color1_btn)
		grid.pack(CBMiniPalette(grid, onclick=self.page_color1_btn.set_value))

		grid.pack((5, 5))
		self.page_color2_btn = wal.ColorButton(hpanel, color2)
		grid.pack(self.page_color2_btn)
		self.colors2 = CBMiniPalette(grid, onclick=self.page_color2_btn.set_value)
		grid.pack(self.colors2)
		if not self.page_fill[0] == FILL_PATTERN:
			self.page_color2_btn.set_enable(False)
			self.colors2.set_enable(False)

		hpanel.pack(grid, fill=True)
		hpanel.pack((5, 5))
		self.pack(hpanel, fill=True)

		#---
		vpanel = wal.VPanel(self)
		self.pattern_check = wal.Checkbox(vpanel,
							_('Use pattern for page fill'),
							self.page_fill[0] == FILL_PATTERN,
							onclick=self.pattern_check_changed)
		vpanel.pack(self.pattern_check, align_center=False)

		self.border_flag = self.doc.methods.get_page_border()
		self.border_check = wal.Checkbox(vpanel,
							_('Show page border'), self.border_flag)
		vpanel.pack(self.border_check, align_center=False)
		self.pack(vpanel, fill=True, padding_all=5)

	def page_combo_changed(self):
		state = False
		if not self.page_combo.get_active():
			state = True
		else:
			w, h = uc2const.PAGE_FORMATS[self.page_combo.get_active_value()]
			self.page_width.set_point_value(w)
			self.page_height.set_point_value(h)
			self.orient_keeper.set_mode(uc2const.PORTRAIT)
		self.page_width.set_enable(state)
		self.page_height.set_enable(state)

	def page_spin_changed(self):
		w = self.page_width.get_point_value()
		h = self.page_height.get_point_value()
		if w < h: mode = uc2const.PORTRAIT
		else: mode = uc2const.LANDSCAPE
		self.orient_keeper.set_mode(mode)

	def orient_changed(self, mode):
		w = self.page_width.get_point_value()
		h = self.page_height.get_point_value()
		w, h = h, w
		self.page_width.set_point_value(w)
		self.page_height.set_point_value(h)

	def pattern_check_changed(self):
		state = self.pattern_check.get_value()
		self.page_color2_btn.set_enable(state)
		self.colors2.set_enable(state)

	def save(self):
		page_format = [self.page_combo.get_active_value(),
				[self.page_width.get_point_value(),
				self.page_height.get_point_value(), ],
				self.orient_keeper.get_mode()]
		if not self.page_format == page_format:
			self.api.set_default_page_format(page_format)
		desktop_bg = self.desktop_color_btn.get_value()
		if not self.desktop_bg == desktop_bg:
			self.api.set_desktop_bg(desktop_bg)

		color1 = self.page_color1_btn.get_value()
		if self.pattern_check.get_value():
			color2 = self.page_color2_btn.get_value()
			page_fill = [FILL_PATTERN, [color1, color2]]
		else:
			page_fill = [FILL_SOLID, color1]
		if not self.page_fill == page_fill:
			self.api.set_page_fill(page_fill)

		border_flag = self.border_check.get_value()
		if not self.border_flag == border_flag:
			self.api.set_page_border(border_flag)
Ejemplo n.º 39
0
class PositionTransform(AbstractTransform):

	name = _('Position')
	dx = 0.0
	dy = 0.0

	def build(self):
		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,
							onchange=self.on_reset)
		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,
							onchange=self.on_reset)
		grid.pack(self.v_spin)
		grid.pack(UnitLabel(self.app, grid))

		self.pack(grid, align_center=False, padding=5)
		self.abs_pos = wal.Checkbox(self, _('Absolute position'),
								onclick=self.update)
		self.pack(self.abs_pos, align_center=False, padding=5)

		self.active_widgets = [self.h_spin, self.v_spin, self.abs_pos]

	def update(self):
		if not self.app.insp.is_selection():return
		if self.user_changes: return
		bbox = self.get_selection_bbox()
		w = bbox[2] - bbox[0]
		h = bbox[3] - bbox[1]
		dx = self.orientation[0] * w
		dy = self.orientation[1] * h
		if self.is_lu_coords() and dy: dy *= -1.0
		if self.abs_pos.get_value():
			new_x = bbox[0] + dx
			new_y = bbox[1] + dy
			new_x, new_y = self.doc_to_coords([new_x, new_y])
			self.h_spin.set_point_value(new_x)
			self.v_spin.set_point_value(new_y)
		else:
			self.h_spin.set_point_value(dx)
			self.v_spin.set_point_value(dy)

	def get_trafo(self):
		trafo = [] + sk2_const.NORMAL_TRAFO
		if self.abs_pos.get_value():
			bbox = self.get_selection_bbox()
			new_x = self.h_spin.get_point_value()
			new_y = self.v_spin.get_point_value()
			new_x, new_y = self.coords_to_doc([new_x, new_y])
			trafo[4] = new_x - bbox[0]
			trafo[5] = new_y - bbox[1]
		else:
			trafo[4] = self.h_spin.get_point_value()
			trafo[5] = self.v_spin.get_point_value()
			if self.is_lu_coords() and trafo[5]: trafo[5] *= -1.0
		return trafo
Ejemplo n.º 40
0
class GridProps(DP_Panel):
    name = _('Grid')
    geom = []
    color = []

    def build(self):
        self.pack((5, 5))

        self.geom = self.doc.methods.get_grid_values()
        hpanel = wal.HPanel(self)

        txt = _('Grid origin')
        origin_panel = wal.LabeledPanel(hpanel, text=txt)
        grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

        grid.pack(wal.Label(grid, 'X:'))
        self.x_val = UnitSpin(self.app, grid, self.geom[0])
        grid.pack(self.x_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        grid.pack(wal.Label(grid, 'Y:'))
        self.y_val = UnitSpin(self.app, grid, self.geom[1])
        grid.pack(self.y_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        origin_panel.pack(grid, padding_all=5)
        hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True)

        txt = _('Grid frequency')
        freq_panel = wal.LabeledPanel(hpanel, text=txt)
        grid = wal.GridPanel(origin_panel, 2, 3, 5, 5)

        grid.pack(wal.Label(grid, 'dX:'))
        self.dx_val = UnitSpin(self.app, grid, self.geom[2])
        grid.pack(self.dx_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        grid.pack(wal.Label(grid, 'dY:'))
        self.dy_val = UnitSpin(self.app, grid, self.geom[3])
        grid.pack(self.dy_val)
        grid.pack(StaticUnitLabel(self.app, grid))

        freq_panel.pack(grid, padding_all=5)
        hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True)

        self.pack(hpanel, fill=True)

        self.pack((5, 5))

        color_panel = wal.HPanel(self)

        color_panel.pack((10, 10))

        vpanel = wal.VPanel(color_panel)

        hpanel = wal.HPanel(vpanel)
        hpanel.pack(wal.Label(hpanel, _('Grid color:')))
        hpanel.pack((10, 5))
        self.color = self.doc.methods.get_grid_rgba_color()
        self.grid_color_btn = wal.ColorButton(hpanel,
                                              self.color[:3],
                                              onchange=self.on_change)
        hpanel.pack(self.grid_color_btn)
        vpanel.pack(hpanel, fill=True)

        hpanel = wal.HPanel(vpanel)
        hpanel.pack(wal.Label(hpanel, _('Grid opacity:')))
        hpanel.pack((10, 5))
        self.alpha_spin = wal.FloatSpin(hpanel,
                                        self.color[3] * 100.0,
                                        range_val=(0.0, 100.0),
                                        onchange=self.on_spin_change,
                                        onenter=self.on_spin_change)
        hpanel.pack(self.alpha_spin)
        hpanel.pack(wal.Label(hpanel, '%'), padding=3)

        vpanel.pack(hpanel, fill=True, padding=5)

        self.alpha_slider = wal.Slider(vpanel,
                                       int(self.color[3] * 100.0),
                                       range_val=(0, 100),
                                       onchange=self.on_slider_change)
        vpanel.pack(self.alpha_slider, fill=True, padding=5)

        val = self.doc.methods.is_grid_visible()
        self.show_grid_check = wal.Checkbox(vpanel, _('Show grid on canvas'),
                                            val)
        vpanel.pack(self.show_grid_check, fill=True, padding=5)

        color_panel.pack(vpanel)

        color_panel.pack((10, 10))

        preview_panel = wal.VPanel(color_panel)
        preview_panel.pack(wal.Label(hpanel, _('Grid preview:')))
        preview_panel.pack((5, 5))
        self.grid_preview = GridPreview(preview_panel, self.color)
        preview_panel.pack(self.grid_preview, fill=True, expand=True)
        color_panel.pack(preview_panel, fill=True, expand=True)

        color_panel.pack((10, 10))

        self.pack(color_panel, fill=True)

    def on_slider_change(self):
        self.alpha_spin.set_value(float(self.alpha_slider.get_value()))
        self.on_change()

    def on_spin_change(self):
        self.alpha_slider.set_value(int(self.alpha_spin.get_value()))
        self.on_change()

    def on_change(self):
        color = list(self.grid_color_btn.get_value())
        color.append(self.alpha_spin.get_value() / 100.0)
        self.grid_preview.set_color(color)

    def save(self):
        geom = [
            self.x_val.get_point_value(),
            self.y_val.get_point_value(),
            self.dx_val.get_point_value(),
            self.dy_val.get_point_value()
        ]
        if not self.geom == geom:
            self.api.set_grid_values(geom)
        color = list(self.grid_color_btn.get_value())
        color.append(self.alpha_spin.get_value() / 100.0)
        if not self.color == color:
            self.api.set_grid_color(color)
        visibility = self.doc.methods.is_grid_visible()
        if not visibility == self.show_grid_check.get_value():
            grid = self.doc.methods.get_grid_layer()
            props = self.doc.methods.get_grid_properties()
            props[0] = 0
            if self.show_grid_check.get_value(): props[0] = 1
            self.api.set_layer_properties(grid, props)
Ejemplo n.º 41
0
class PagePlugin(CtxPlugin):
    name = 'PagePlugin'
    update_flag = False
    format = []
    formats = None
    combo = None
    width_spin = None
    height_spin = None
    portrait = None
    landscape = None

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

    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.add(self.combo, 0, LEFT | CENTER, 2)
        self.add((3, 3))

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.add(self.portrait, 0, LEFT | CENTER, 2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.add(self.landscape, 0, LEFT | CENTER, 2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)

    def update(self, *args):
        if self.insp.is_doc():
            self.update_flag = True
            page_format = self.app.current_doc.active_page.page_format
            self.format = page_format
            width, height = page_format[1]
            if page_format[0] in PAGE_FORMAT_NAMES:
                self.combo.set_active(self.formats.index(page_format[0]))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(False)
                self.height_spin.set_enable(False)
            else:
                self.combo.set_active(self.formats.index(_('Custom')))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(True)
                self.height_spin.set_enable(True)
            self.update_flag = False

    def combo_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[0] == self.formats[self.combo.get_active()]:
            self.update_flag = True
            if self.formats[self.combo.get_active()] in PAGE_FORMAT_NAMES:
                w, h = PAGE_FORMATS[self.formats[self.combo.get_active()]]
                if self.portrait.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                elif self.landscape.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                elif self.portrait.get_active() and w < h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                else:
                    self.width_spin.set_point_value(h)
                    self.height_spin.set_point_value(w)
            self.update_flag = False
            self.changes()

    def width_spin_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[1][0] == self.width_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def height_spin_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[1][1] == self.height_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def portrait_toggled(self, *args):
        if self.update_flag:
            return
        if self.portrait.get_active():
            self.update_flag = True
            self.landscape.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.portrait.set_active(True)
            self.update_flag = False

    def landscape_toggled(self, *args):
        if self.update_flag:
            return
        if self.landscape.get_active():
            self.update_flag = True
            self.portrait.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.landscape.set_active(True)
            self.update_flag = False

    def changes(self):
        new_format = [
            self.formats[self.combo.get_active()],
        ]
        new_format += [(self.width_spin.get_point_value(),
                        self.height_spin.get_point_value())]
        if self.portrait.get_active():
            new_format += [
                PORTRAIT,
            ]
        else:
            new_format += [
                LANDSCAPE,
            ]
        self.app.current_doc.api.set_page_format(new_format)
Ejemplo n.º 42
0
class PageProps(DP_Panel):
    name = _('Page')
    page_format = None
    desktop_bg = None
    page_fill = None
    border_flag = False

    def build(self):
        self.page_format = self.doc.methods.get_default_page_format()
        self.formats = [
            _('Custom'),
        ] + uc2const.PAGE_FORMAT_NAMES
        self.pack((5, 10))

        # ---
        hpanel = wal.HPanel(self)
        hpanel.pack((5, 5))
        label = wal.Label(hpanel, _('Default page:'))
        hpanel.pack(label)
        hpanel.pack((5, 5))
        self.page_combo = wal.Combolist(self,
                                        items=self.formats,
                                        onchange=self.page_combo_changed)
        index = 0
        state = True
        if self.page_format[0] in uc2const.PAGE_FORMAT_NAMES:
            index = self.formats.index(self.page_format[0])
            state = False
        self.page_combo.set_active(index)

        hpanel.pack(self.page_combo)

        hpanel.pack((15, 5))

        self.orient_keeper = wal.HToggleKeeper(self,
                                               ORIENTS,
                                               ORIENTS_ICONS,
                                               ORIENTS_NAMES,
                                               on_change=self.orient_changed)
        self.orient_keeper.set_mode(self.page_format[2])
        hpanel.pack(self.orient_keeper)

        self.pack(hpanel, fill=True)

        self.pack((5, 5))

        # ---
        w, h = self.page_format[1]
        hpanel = wal.HPanel(self)
        dx = label.get_size()[0] + 10
        hpanel.pack((dx, 5))

        self.page_width = UnitSpin(self.app,
                                   hpanel,
                                   w,
                                   onchange=self.page_spin_changed)
        hpanel.pack(self.page_width)
        hpanel.pack(get_bmp(self, icons.CTX_W_ON_H), padding=5)
        self.page_height = UnitSpin(self.app,
                                    hpanel,
                                    h,
                                    onchange=self.page_spin_changed)
        hpanel.pack(self.page_height)
        hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5)
        self.page_width.set_enable(state)
        self.page_height.set_enable(state)

        self.pack(hpanel, fill=True)
        self.pack(wal.HLine(self), padding_all=5, fill=True)

        # ---
        hpanel = wal.HPanel(self)
        hpanel.pack((5, 5))
        self.desktop_bg = self.doc.methods.get_desktop_bg()

        grid = wal.GridPanel(hpanel, 3, 3, 5, 5)
        grid.add_growable_col(2)

        grid.pack(wal.Label(hpanel, _('Desktop:')))
        self.desktop_color_btn = wal.ColorButton(hpanel, self.desktop_bg)
        grid.pack(self.desktop_color_btn)
        grid.pack(CBMiniPalette(grid,
                                onclick=self.desktop_color_btn.set_value))

        self.page_fill = self.doc.methods.get_page_fill()
        if self.page_fill[0] == FILL_SOLID:
            color1 = self.page_fill[1]
            color2 = [1.0, 1.0, 1.0]
        else:
            color1 = self.page_fill[1][0]
            color2 = self.page_fill[1][1]

        grid.pack(wal.Label(hpanel, _('Page:')))
        self.page_color1_btn = wal.ColorButton(hpanel, color1)
        grid.pack(self.page_color1_btn)
        grid.pack(CBMiniPalette(grid, onclick=self.page_color1_btn.set_value))

        grid.pack((5, 5))
        self.page_color2_btn = wal.ColorButton(hpanel, color2)
        grid.pack(self.page_color2_btn)
        self.colors2 = CBMiniPalette(grid,
                                     onclick=self.page_color2_btn.set_value)
        grid.pack(self.colors2)
        if not self.page_fill[0] == FILL_PATTERN:
            self.page_color2_btn.set_enable(False)
            self.colors2.set_enable(False)

        hpanel.pack(grid, fill=True)
        hpanel.pack((5, 5))
        self.pack(hpanel, fill=True)

        # ---
        vpanel = wal.VPanel(self)
        if wal.IS_MSW: vpanel.pack((5, 5))

        self.pattern_check = wal.Checkbox(vpanel,
                                          _('Use pattern for page fill'),
                                          self.page_fill[0] == FILL_PATTERN,
                                          onclick=self.pattern_check_changed)
        vpanel.pack(self.pattern_check, align_center=False)

        if wal.IS_MSW: vpanel.pack((5, 5))

        self.border_flag = self.doc.methods.get_page_border()
        self.border_check = wal.Checkbox(vpanel, _('Show page border'),
                                         self.border_flag)
        vpanel.pack(self.border_check, align_center=False)
        self.pack(vpanel, fill=True, padding_all=5)

    def page_combo_changed(self):
        state = False
        if not self.page_combo.get_active():
            state = True
        else:
            w, h = uc2const.PAGE_FORMATS[self.page_combo.get_active_value()]
            self.page_width.set_point_value(w)
            self.page_height.set_point_value(h)
            self.orient_keeper.set_mode(uc2const.PORTRAIT)
        self.page_width.set_enable(state)
        self.page_height.set_enable(state)

    def page_spin_changed(self):
        w = self.page_width.get_point_value()
        h = self.page_height.get_point_value()
        if w < h:
            mode = uc2const.PORTRAIT
        else:
            mode = uc2const.LANDSCAPE
        self.orient_keeper.set_mode(mode)

    def orient_changed(self, mode):
        w = self.page_width.get_point_value()
        h = self.page_height.get_point_value()
        w, h = h, w
        self.page_width.set_point_value(w)
        self.page_height.set_point_value(h)

    def pattern_check_changed(self):
        state = self.pattern_check.get_value()
        self.page_color2_btn.set_enable(state)
        self.colors2.set_enable(state)

    def save(self):
        page_format = [
            self.page_combo.get_active_value(),
            [
                self.page_width.get_point_value(),
                self.page_height.get_point_value(),
            ],
            self.orient_keeper.get_mode()
        ]
        if not self.page_format == page_format:
            self.api.set_default_page_format(page_format)
        desktop_bg = self.desktop_color_btn.get_value()
        if not self.desktop_bg == desktop_bg:
            self.api.set_desktop_bg(desktop_bg)

        color1 = self.page_color1_btn.get_value()
        if self.pattern_check.get_value():
            color2 = self.page_color2_btn.get_value()
            page_fill = [FILL_PATTERN, [color1, color2]]
        else:
            page_fill = [FILL_SOLID, color1]
        if not self.page_fill == page_fill:
            self.api.set_page_fill(page_fill)

        border_flag = self.border_check.get_value()
        if not self.border_flag == border_flag:
            self.api.set_page_border(border_flag)
Ejemplo n.º 43
0
	def build(self):
		self.page_format = self.doc.methods.get_default_page_format()
		self.formats = [_('Custom'), ] + uc2const.PAGE_FORMAT_NAMES
		self.pack((5, 10))

		#---
		hpanel = wal.HPanel(self)
		hpanel.pack((5, 5))
		label = wal.Label(hpanel, _('Default page:'))
		hpanel.pack(label)
		hpanel.pack((5, 5))
		self.page_combo = wal.Combolist(self, items=self.formats,
							onchange=self.page_combo_changed)
		index = 0
		state = True
		if self.page_format[0] in uc2const.PAGE_FORMAT_NAMES:
			index = self.formats.index(self.page_format[0])
			state = False
		self.page_combo.set_active(index)

		hpanel.pack(self.page_combo)

		hpanel.pack((15, 5))

		self.orient_keeper = wal.HToggleKeeper(self, ORIENTS, ORIENTS_ICONS,
								ORIENTS_NAMES, on_change=self.orient_changed)
		self.orient_keeper.set_mode(self.page_format[2])
		hpanel.pack(self.orient_keeper)

		self.pack(hpanel, fill=True)

		self.pack((5, 5))

		#---
		w, h = self.page_format[1]
		hpanel = wal.HPanel(self)
		dx = label.get_size()[0] + 10
		hpanel.pack((dx, 5))

		self.page_width = UnitSpin(self.app, hpanel, w,
								onchange=self.page_spin_changed)
		hpanel.pack(self.page_width)
		hpanel.pack(get_bmp(self, icons.CTX_W_ON_H), padding=5)
		self.page_height = UnitSpin(self.app, hpanel, h,
								onchange=self.page_spin_changed)
		hpanel.pack(self.page_height)
		hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5)
		self.page_width.set_enable(state)
		self.page_height.set_enable(state)

		self.pack(hpanel, fill=True)
		self.pack(wal.HLine(self), padding_all=5, fill=True)

		#---
		hpanel = wal.HPanel(self)
		hpanel.pack((5, 5))
		self.desktop_bg = self.doc.methods.get_desktop_bg()

		grid = wal.GridPanel(hpanel, 3, 3, 5, 5)
		grid.add_growable_col(2)

		grid.pack(wal.Label(hpanel, _('Desktop:')))
		self.desktop_color_btn = wal.ColorButton(hpanel, self.desktop_bg)
		grid.pack(self.desktop_color_btn)
		grid.pack(CBMiniPalette(grid, onclick=self.desktop_color_btn.set_value))

		self.page_fill = self.doc.methods.get_page_fill()
		if self.page_fill[0] == FILL_SOLID:
			color1 = self.page_fill[1]
			color2 = [1.0, 1.0, 1.0]
		else:
			color1 = self.page_fill[1][0]
			color2 = self.page_fill[1][1]

		grid.pack(wal.Label(hpanel, _('Page:')))
		self.page_color1_btn = wal.ColorButton(hpanel, color1)
		grid.pack(self.page_color1_btn)
		grid.pack(CBMiniPalette(grid, onclick=self.page_color1_btn.set_value))

		grid.pack((5, 5))
		self.page_color2_btn = wal.ColorButton(hpanel, color2)
		grid.pack(self.page_color2_btn)
		self.colors2 = CBMiniPalette(grid, onclick=self.page_color2_btn.set_value)
		grid.pack(self.colors2)
		if not self.page_fill[0] == FILL_PATTERN:
			self.page_color2_btn.set_enable(False)
			self.colors2.set_enable(False)

		hpanel.pack(grid, fill=True)
		hpanel.pack((5, 5))
		self.pack(hpanel, fill=True)

		#---
		vpanel = wal.VPanel(self)
		if wal.is_msw(): vpanel.pack((5, 5))

		self.pattern_check = wal.Checkbox(vpanel,
							_('Use pattern for page fill'),
							self.page_fill[0] == FILL_PATTERN,
							onclick=self.pattern_check_changed)
		vpanel.pack(self.pattern_check, align_center=False)

		if wal.is_msw(): vpanel.pack((5, 5))

		self.border_flag = self.doc.methods.get_page_border()
		self.border_check = wal.Checkbox(vpanel,
							_('Show page border'), self.border_flag)
		vpanel.pack(self.border_check, align_center=False)
		self.pack(vpanel, fill=True, padding_all=5)