Beispiel #1
0
class JumpPanel(CtxSubPanel):

    name = 'JumpPanel'

    def __init__(self, parent):
        self.my_changes = 0

        CtxSubPanel.__init__(self, parent)
        self.var_jump_number = DoubleVar(self.mw.root)

        unit = config.preferences.default_unit
        var_jump_unit = StringVar(self.mw.root)
        self.var_jump = LengthVar(10, unit, self.var_jump_number,
                                  var_jump_unit)

        label = TLabel(self.panel, text=_("Jump:"))
        label.pack(side=LEFT, padx=2)
        self.entry_jump = TSpinbox(self.panel,
                                   var=0,
                                   vartype=1,
                                   textvariable=self.var_jump_number,
                                   min=0,
                                   max=1000,
                                   step=.1,
                                   width=6,
                                   command=self.applyJump)
        self.entry_jump.pack(side=LEFT, padx=2)
        config.preferences.Subscribe(CHANGED, self.update)
        self.var_jump.set(config.preferences.handle_jump)
        self.update(0, 0)

    def update(self, *arg):
        if self.my_changes:
            self.my_changes = 0
        else:
            self.var_jump.unit = config.preferences.default_unit
            self.var_jump.set(config.preferences.handle_jump)

    def applyJump(self, *arg):
        self.my_changes = 1
        self.var_jump.unit = config.preferences.default_unit
        config.preferences.handle_jump = self.var_jump.get()
        self.var_jump.set(config.preferences.handle_jump)
Beispiel #2
0
class JumpPanel(CtxSubPanel):
	
	name='JumpPanel'	
	
	def __init__(self, parent):
		self.my_changes=0
		
		CtxSubPanel.__init__(self, parent)
		self.var_jump_number=DoubleVar(self.mw.root)
		
		unit = config.preferences.default_unit
		var_jump_unit = StringVar(self.mw.root)
		self.var_jump = LengthVar(10, unit, self.var_jump_number, var_jump_unit)
		
		label = TLabel(self.panel, text=_("Jump:"))
		label.pack(side = LEFT, padx=2)
		self.entry_jump = TSpinbox(self.panel,  var=0, 
						vartype=1, textvariable = self.var_jump_number,
						min = 0, max = 1000, step = .1, width = 6, command = self.applyJump)
		self.entry_jump.pack(side = LEFT, padx=2)
		config.preferences.Subscribe(CHANGED, self.update)		
		self.var_jump.set(config.preferences.handle_jump)
		self.update(0, 0)	

	def update(self,*arg):
		if self.my_changes:
			self.my_changes=0
		else:
			self.var_jump.unit=config.preferences.default_unit
			self.var_jump.set(config.preferences.handle_jump)

		
	def applyJump(self,*arg):
		self.my_changes=1
		self.var_jump.unit=config.preferences.default_unit
		config.preferences.handle_jump=self.var_jump.get()
		self.var_jump.set(config.preferences.handle_jump)
Beispiel #3
0
class GuidesPanel(CtxSubPanel):

    name = 'GuidesPanel'

    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)
        b = TButton(self.panel,
                    command=self.makePageFrame,
                    style='Toolbutton',
                    image='context_add_page_frame')
        tooltips.AddDescription(b, _('Add page frame'))
        b.pack(side=LEFT)
        b = TButton(self.panel,
                    command=self.addCenteredGuides,
                    style='Toolbutton',
                    image='context_add_centered_guides')
        tooltips.AddDescription(b, _('Add guides for page center'))
        b.pack(side=LEFT)

        #############
        b = TLabel(self.panel, image="toolbar_sep")
        b.pack(side=LEFT)
        b = TButton(self.panel,
                    command=self.addGuidesFrame,
                    style='Toolbutton',
                    image='context_add_guides_frame')
        tooltips.AddDescription(b, _('Add guides across page border'))
        b.pack(side=LEFT)

        self.var_jump_number = DoubleVar(self.mw.root)

        unit = config.preferences.default_unit
        var_jump_unit = StringVar(self.mw.root)
        self.var_jump = LengthVar(10, unit, self.var_jump_number,
                                  var_jump_unit)

        self.entry_jump = TSpinbox(self.panel,
                                   var=0,
                                   vartype=1,
                                   textvariable=self.var_jump_number,
                                   min=-1000,
                                   max=1000,
                                   step=5,
                                   width=6,
                                   command=self.addGuidesFrame)
        self.entry_jump.pack(side=LEFT, padx=2)
        config.preferences.Subscribe(CHANGED, self.update)
        self.var_jump.set(0)
        self.update(0, 0)

        b = TLabel(self.panel, image="toolbar_sep")
        b.pack(side=LEFT)
        ##############

        b = TButton(self.panel,
                    command=self.removeAllGuides,
                    style='Toolbutton',
                    image='context_remove_all_guides')
        tooltips.AddDescription(b, _('Remove all guides'))
        b.pack(side=LEFT)

    def update(self, *arg):
        self.var_jump.unit = config.preferences.default_unit

    def makePageFrame(self):
        doc = self.doc
        layout = doc.Layout()
        hor_p = layout.Width()
        ver_p = layout.Height()
        path = CreatePath()
        path.AppendLine(Point(0, 0))
        path.AppendLine(Point(hor_p, 0))
        path.AppendLine(Point(hor_p, ver_p))
        path.AppendLine(Point(0, ver_p))
        path.AppendLine(Point(0, 0))
        path.AppendLine(path.Node(0))
        path.ClosePath()
        bezier = PolyBezier((path, ))
        doc.Insert(bezier)

    def addGuidesFrame(self, *arg):
        border = self.var_jump.get()
        doc = self.doc
        layout = doc.Layout()
        hor_p = layout.Width()
        ver_p = layout.Height()
        doc.AddGuideLine(Point(0, 0 + border), 1)
        doc.AddGuideLine(Point(0 + border, 0), 0)
        doc.AddGuideLine(Point(0, ver_p - border), 1)
        doc.AddGuideLine(Point(hor_p - border, 0), 0)

    def addCenteredGuides(self):
        doc = self.doc
        layout = doc.Layout()
        hor_p = layout.Width()
        ver_p = layout.Height()
        doc.AddGuideLine(Point(0, ver_p / 2), 1)
        doc.AddGuideLine(Point(hor_p / 2, 0), 0)

    def removeAllGuides(self):
        doc = self.doc
        guide_lines = doc.GuideLines()
        for line in guide_lines:
            doc.RemoveGuideLine(line)
Beispiel #4
0
class PagePanel(CtxSubPanel):

	name = 'PagePanel'

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

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

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

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

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

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

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

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

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

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

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


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

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

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

	def ReSubscribe(self):
		self.init_from_doc()

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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


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

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

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

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

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

	def apply_basepoint(self):
		self.Update()

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

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

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


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

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

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

	def is_selection(self):
		return (len(self.document.selection) > 0)
class PagePlugin(PluginPanel):
	
	name='Page'
	title = _("Page")
	
	def init(self, master):
		PluginPanel.init(self, master)
		self.top = self.panel
		root = self.top
		
		self.USER_SPECIFIC = _("<Custom Size>")
		
		top_root = TFrame(root, borderwidth=2, style='FlatFrame')
		top_root.pack(side = TOP, expand = 1, fill = X)
		
		top=TLabelframe(top_root, text='Page format')
		top.pack(side = TOP, fill=X, pady=2)

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


# ===========================================================
		format_frame = TFrame(top, borderwidth=0, style='FlatFrame')
		format_frame.pack(side = TOP, expand = 1, fill = X, pady = 4)

		format_names = map(lambda t: t[0], PapersizesList)
		format_names.append(self.USER_SPECIFIC)
		self.var_format_name = StringVar(root)
		
		format_menu =TComboSmall(format_frame, format_names, command = self.choose_format,
								 variable = self.var_format_name, width=17)
		format_menu.configure(width = max(map(len, format_names)))
		format_menu.pack(side = RIGHT, expand = 1, fill = X)

# =====================		
		size_frame = TFrame(top, borderwidth=0, style='FlatFrame')
		size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4)		
		label = TLabel(size_frame, text ="H: ", style='FlatLabel')
		
		self.widthentry = TSpinbox(size_frame, textvariable = var_width_number, command = self.var_width.UpdateNumber,
								vartype=1, min = 5, max = 50000, step = 1, width = 7)
		self.widthentry.pack(side = RIGHT, anchor = E, padx = 5)
		label.pack(side = RIGHT, anchor = E)
		
		size_frame = TFrame(top, borderwidth=0, style='FlatFrame')
		size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4)
		label = TLabel(size_frame, text = "V: ", style='FlatLabel')
			
		self.heightentry = TSpinbox(size_frame, textvariable =var_height_number, command = self.var_height.UpdateNumber,
		 						vartype=1, min = 5, max = 50000, step = 1, width = 7)
		self.heightentry.pack(side = RIGHT, anchor = E, padx = 5)
		label.pack(side = RIGHT, anchor = E)
		
		size_frame = TFrame(top, borderwidth=0, style='FlatFrame')
		size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4)

		def CallBoth(arg, x = self.var_width, y = self.var_height):
			x.UpdateUnit(arg)
			y.UpdateUnit(arg)

		optmenu = create_unit_menu(size_frame, CallBoth, variable = var_width_unit, width = 3)
		optmenu.pack(side = RIGHT, padx = 5)

		label = TLabel(size_frame, text = "Units: ", style='FlatLabel')
		label.pack(side = RIGHT)
#---------------------------------------------------------------------------------------------------------------------
		middle=TLabelframe(top_root, text='Page orientation')
		middle.pack(side = TOP, fill=X, pady=2)
		
		self.label = TLabel(middle, image = 'portrait', style='FlatLabel')
		self.label.pack(side = LEFT, padx=4)

		orientation_frame = TFrame(middle, borderwidth=0, style='FlatFrame')
		orientation_frame.pack(side = LEFT, expand = 1, fill = X)
		
		self.var_orientation = IntVar(root)
		radio = UpdatedRadiobutton(orientation_frame, text = _("Portrait"),
									variable = self.var_orientation,
									value = Portrait,
									command = self.choose_orientation)
		radio.pack(side = TOP, anchor=W)
		
		radio = UpdatedRadiobutton(orientation_frame, text = _("Landscape"),
									variable = self.var_orientation,
									value = Landscape,
									command = self.choose_orientation)
		radio.pack(side = TOP, anchor=W)

#---------------------------------------------------------------------------------------------------------------------
		button_frame = TFrame(top_root, borderwidth=1, style='FlatFrame')
		button_frame.pack(side = BOTTOM, fill = BOTH, pady=2)
		button = UpdatedButton(button_frame, text = _("Apply"), command = self.apply_settings, width=15)
		button.pack(side = BOTTOM)
		
		app.mw.docmanager.activedoc.Subscribe(LAYOUT, self.init_from_doc)
		app.mw.Subscribe(DOCUMENT, self.init_from_doc)
		

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

	def update_size_from_name(self, formatname):
		width, height = Papersize[formatname]
		if self.var_orientation.get() == Landscape:
			width, height = height, width
		self.update_size(width, height)

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

	def Update(self):
		layout = self.document.Layout()
		formatname = layout.FormatName()
		self.var_orientation.set(layout.Orientation())
		if self.var_orientation.get() == Landscape:
			self.label["image"] = 'landscape'
		else:
			self.label["image"] = 'portrait'
		if formatname and formatname != self.USER_SPECIFIC:
			self.update_size_from_name(formatname)
		else:
			formatname = self.USER_SPECIFIC
			self.update_size(layout.Width(), layout.Height())
		self.var_format_name.set(formatname)
		self.set_entry_sensitivity()

	def set_entry_sensitivity(self):
		formatname = self.var_format_name.get()
		if formatname != self.USER_SPECIFIC:
			self.widthentry.set_state("disabled")
			self.heightentry.set_state("disabled")
		else:
			self.widthentry.set_state("enabled")
			self.heightentry.set_state("enabled")

	def choose_format(self, formatname):
		self.var_format_name.set(formatname)
		if formatname != self.USER_SPECIFIC:
			self.update_size_from_name(formatname)
		self.set_entry_sensitivity()

	def choose_orientation(self):
		name = self.var_format_name.get()
		if name != self.USER_SPECIFIC:
			self.update_size_from_name(name)
		if self.var_orientation.get() == Landscape:
			self.label["image"] = 'landscape'
		else:
			self.label["image"] = 'portrait'	

	def apply_settings(self):
		formatname = self.var_format_name.get()
		if formatname == self.USER_SPECIFIC:
			layout = PageLayout(width = self.var_width.get(),
								height = self.var_height.get(),
								orientation = self.var_orientation.get())
		else:
			layout = PageLayout(formatname,
								orientation = self.var_orientation.get())
		self.document.SetLayout(layout)
Beispiel #7
0
class ResizePanel(CtxSubPanel):

    name = 'ResizePanel'

    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)
        self.my_changes = 0
        self.var_width_number = DoubleVar(self.mw.root)
        self.var_height_number = DoubleVar(self.mw.root)

        var_width_unit = StringVar(self.mw.root)
        var_height_unit = StringVar(self.mw.root)

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

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

        label = TLabel(self.panel, image='size_h')
        label.pack(side=LEFT)

        self.entry_width = TSpinbox(self.panel,
                                    var=0,
                                    vartype=1,
                                    textvariable=self.var_width_number,
                                    min=0,
                                    max=50000,
                                    step=jump,
                                    width=6,
                                    command=self.applyResize)
        tooltips.AddDescription(self.entry_width, _("Width of selection"))
        self.entry_width.pack(side=LEFT, padx=5)

        label = TLabel(self.panel, image='size_v')
        label.pack(side=LEFT)

        self.entry_height = TSpinbox(self.panel,
                                     var=0,
                                     vartype=1,
                                     textvariable=self.var_height_number,
                                     min=0,
                                     max=50000,
                                     step=jump,
                                     width=6,
                                     command=self.applyResize)
        tooltips.AddDescription(self.entry_height, _("Height of selection"))
        self.entry_height.pack(side=LEFT, padx=5)

        self.ReSubscribe()
        config.preferences.Subscribe(CHANGED, self.update_pref)

    def ReSubscribe(self):
        self.doc.Subscribe(SELECTION, self.Update)
        self.doc.Subscribe(EDITED, self.update)
        self.Update()

    def applyResize(self, event):
        try:
            x = self.var_width.get()
            y = self.var_height.get()
            br = self.doc.selection.coord_rect
            hor_sel = br.right - br.left
            ver_sel = br.top - br.bottom
        except:
            return

        if hor_sel:
            xx = x / hor_sel
        else:
            xx = 1

        if ver_sel:
            yy = y / ver_sel
        else:
            yy = 1

        self.doc.ScaleSelected(xx, yy)
        self.update_size()

    def update(self, issue):
        self.Update()

    def Update(self):
        if len(self.doc.selection.GetInfo()):
            self.update_size()

    def update_size(self):
        self.var_width.unit = config.preferences.default_unit
        self.var_height.unit = config.preferences.default_unit
        br = self.doc.selection.coord_rect
        width = br.right - br.left
        height = br.top - br.bottom
        self.var_width.set(width)
        self.var_height.set(height)
        self.entry_width.step = config.preferences.default_unit_jump
        self.entry_height.step = config.preferences.default_unit_jump

    def update_pref(self, arg1, arg2):
        if self.my_changes:
            self.my_changes = 0
        else:
            if len(self.doc.selection.GetInfo()):
                self.update_size()
Beispiel #8
0
class RotatePanel(PluginPanel):
    name = 'Rotate'
    title = _("Rotate")

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

        root = self.mw.root

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

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

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

        self.cnt_x_absolute = None
        self.cnt_y_absolute = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.init_from_doc()
        self.subscribe_receivers()


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

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

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

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

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

        self.update_pref()

    def apply_basepoint(self):
        self.update_var()

    def position(self):
        self.update_var()

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

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

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

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

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

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

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

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

            self.var_basepoint.set('USER')

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

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

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

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

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

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

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

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

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

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

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

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

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

    name = 'PagePanel'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def ReSubscribe(self):
        self.init_from_doc()

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

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

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

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

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

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

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

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

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

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

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

    def apply_settings(self):
        formatname = self.var_format_name.get()
        if formatname == self.USER_SPECIFIC:
            layout = PageLayout(width=self.var_width.get(),
                                height=self.var_height.get(),
                                orientation=0)
        else:
            layout = PageLayout(formatname, orientation=self.page_orientation)
        self.mw.canvas.bitmap_buffer = None
        self.doc.SetLayout(layout)
        self.doc.pages[self.doc.active_page].page_layout = layout
Beispiel #10
0
class ResizePanel(CtxSubPanel):
	
	name='ResizePanel'
	
	def __init__(self, parent):
		CtxSubPanel.__init__(self, parent)
		self.my_changes=0
		self.var_width_number=DoubleVar(self.mw.root)
		self.var_height_number=DoubleVar(self.mw.root)

		var_width_unit = StringVar(self.mw.root)
		var_height_unit = StringVar(self.mw.root)
		
		unit = config.preferences.default_unit
		self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit)
		self.var_height = LengthVar(10, unit,self.var_height_number,var_height_unit)
		
		jump=config.preferences.default_unit_jump
		self.var_width.set(0)
		self.var_height.set(0)
		
		label = TLabel(self.panel, image='size_h')
		label.pack(side = LEFT)
		
		self.entry_width = TSpinbox(self.panel,  var=0, vartype=1, textvariable = self.var_width_number,
						min = 0, max = 50000, step = jump, width = 6, command = self.applyResize)
		tooltips.AddDescription(self.entry_width, _("Width of selection"))
		self.entry_width.pack(side = LEFT, padx=5)


		label = TLabel(self.panel, image='size_v')
		label.pack(side = LEFT)
		
		self.entry_height = TSpinbox(self.panel,  var=0, vartype=1, textvariable = self.var_height_number,
						min = 0, max = 50000, step = jump, width = 6, command = self.applyResize)
		tooltips.AddDescription(self.entry_height, _("Height of selection"))
		self.entry_height.pack(side = LEFT, padx=5)
		
		self.ReSubscribe()
		config.preferences.Subscribe(CHANGED, self.update_pref)

	def ReSubscribe(self):
		self.doc.Subscribe(SELECTION, self.Update)	
		self.doc.Subscribe(EDITED, self.update)
		self.Update()
						
	def applyResize(self, event):
		try:
			x=self.var_width.get()
			y=self.var_height.get()
			br=self.doc.selection.coord_rect
			hor_sel=br.right - br.left
			ver_sel=br.top - br.bottom
		except:
			return
		
		if hor_sel:
			xx=x / hor_sel
		else:
			xx = 1
		
		if ver_sel:
			yy = y / ver_sel
		else:
			yy = 1
		
		self.doc.ScaleSelected(xx, yy)
		self.update_size()
		
	def update(self, issue):
		self.Update()
		
	def Update(self):
		if len(self.doc.selection.GetInfo()):
			self.update_size()
			
	def update_size(self):	
		self.var_width.unit=config.preferences.default_unit
		self.var_height.unit=config.preferences.default_unit
		br=self.doc.selection.coord_rect
		width=br.right - br.left
		height=br.top - br.bottom
		self.var_width.set(width)
		self.var_height.set(height)
		self.entry_width.step=config.preferences.default_unit_jump
		self.entry_height.step=config.preferences.default_unit_jump
		
	def update_pref(self, arg1, arg2):
		if self.my_changes:
			self.my_changes=0
		else:
			if len(self.doc.selection.GetInfo()):
				self.update_size()
class GradientFillPanel(PluginPanel):
    name = 'GradientFill'
    title = _("Gradient Fill")
    dashlist = []
    dash = ()
    ref_style = None
    color = None

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

        root = self.mw.root

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

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

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

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

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

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

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

        self.var_width_number = DoubleVar(root)

        self.var_width_base = DoubleVar(root)

        var_width_unit = StringVar(root)

        unit = config.preferences.default_unit

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.set_default_style()

        self.init_from_doc()
        self.subscribe_receivers()


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

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

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

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

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

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

    def update_pattern(self, *args):
        pass

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

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

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

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

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

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

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

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

    def update_pref(self, *arg):
        self.labelwunit['text'] = config.preferences.default_unit
        self.var_width.UpdateUnit(config.preferences.default_unit)
        self.init_from_doc()
Beispiel #12
0
class GuidelinesPanel(PluginPanel):
	name = 'Guidelines'
	title = _("Guides")


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

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

		var_number = DoubleVar(top)
		var_unit = StringVar(top)
		self.var_pos = LengthVar(1.0, config.preferences.default_unit, var_number, var_unit, command=self.set_pos)

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

		list_frame = TFrame(top1, style="RoundedFrame", borderwidth=5)
		list_frame.pack(side=TOP, expand=1, fill=BOTH)

		sb_vert = TScrollbar(list_frame)
		sb_vert.pack(side=RIGHT, fill=Y)
		guides = UpdatedListbox(list_frame, bg='white', borderwidth=0, selectborderwidth=0, width=20, height=8)
		guides.pack(expand=1, fill=BOTH)
		guides.Subscribe(SELECTION, self.select_guide)
		sb_vert['command'] = (guides, 'yview')
		guides['yscrollcommand'] = (sb_vert, 'set')
		self.guides = guides
		self.selected = None

		pos_frame = TFrame(top1, style='FlatFrame')
		pos_frame.pack(side=TOP, expand=0)

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

		self.var_label = StringVar(top)
		self.var_label.set('X: ')

		labelunit = UnitLabel(pos_frame)
		labelunit.pack(side=RIGHT, expand=0, anchor=W)

		label = TLabel(pos_frame, image='space_6', style='FlatLabel')
		label.pack(side=RIGHT)

		self.entry = TSpinbox(pos_frame, var=0, vartype=1,
						min=-50000, max=50000, step=.1, width=6, command=self.pos_changed)
		self.entry.pack(side=RIGHT, expand=0, anchor=E)

		label = TLabel(pos_frame, textvariable=self.var_label, style='FlatLabel')
		label.pack(side=RIGHT, expand=0, anchor=E)

		frame = TFrame(top1, style='FlatFrame')
		frame.pack(side=TOP, fill=X)
		top2 = TFrame(frame, height=15, width=120, style='FlatFrame')
		top2.pack(side=TOP)

		button = UpdatedButton(frame, text=_("Add Horizontal Guide"), command=self.add_guide, args=1)
		button.pack(side=TOP)

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

		button = UpdatedButton(frame, text=_("Add Vertical Guide"), command=self.add_guide, args=0)
		button.pack(side=TOP)

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

		button = UpdatedButton(frame, text=_("Delete Guide"), command=self.del_guide)
		button.pack(side=TOP)

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

		app.mw.docmanager.activedoc.Subscribe(GUIDE_LINES, self.init_from_doc)
		app.mw.Subscribe(DOCUMENT, self.init_from_doc)
		self.init_from_doc()

	def set_unit(self, *rest):
		apply(self.var_pos.UpdateUnit, rest)
		self.update_list()

	def init_from_doc(self, *rest):
		self.guide_lines = self.document.GuideLines()
		self.guide_lines.reverse()
		self.update_list()

	def update_list(self):
		strings = []
		factor = self.var_pos.Factor()
		unit = self.var_pos.UnitName()
		if unit in ('in', 'cm'):
			prec = 2
		else:
			prec = 1
		for line in self.guide_lines:
			pos, horizontal = line.Coordinates()
			if horizontal:
				format = _("% 6.*f %s    horizontal")
			else:
				format = _("% 6.*f %s    vertical")
			strings.append(format % (prec, pos / factor, unit))
		self.guides.SetList(strings)
		self.select_index(self.selected)

	def select_index(self, index):
		if index is not None and index < len(self.guide_lines):
			self.guides.Select(index)
			self.select_guide()
		else:
			self.selected = None

	def set_pos(self, *rest):
		if self.selected is not None:
			self.document.MoveGuideLine(self.guide_lines[self.selected],
										self.var_pos.get())

	def select_guide(self, *rest):
		sel = self.guides.curselection()
		if sel:
			self.selected = atoi(sel[0])
			pos, horizontal = self.guide_lines[self.selected].Coordinates()
			self.var_pos.set(pos)
			self.entry.set_value(round(pos * 100 / self.var_pos.Factor()) / 100)
			if horizontal:
				self.var_label.set("Y: ")
			else:
				self.var_label.set("X: ")
		else:
			self.selected = None

	def del_guide(self, *rest):
		if self.selected is not None:
			line = self.guide_lines[self.selected]
			self.document.RemoveGuideLine(line)

	def add_guide(self, horizontal):
		length = len(self.guide_lines)
		self.document.AddGuideLine(Point(0, 0), horizontal)
		self.select_index(length)

	def pos_changed(self, *rest):
		self.var_pos.set(self.entry.get_value() * self.var_pos.Factor())
		self.set_pos()
		self.update_list()
Beispiel #13
0
class GuidelinesPanel(PluginPanel):
    name = 'Guidelines'
    title = _("Guides")

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

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

        var_number = DoubleVar(top)
        var_unit = StringVar(top)
        self.var_pos = LengthVar(1.0,
                                 config.preferences.default_unit,
                                 var_number,
                                 var_unit,
                                 command=self.set_pos)

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

        list_frame = TFrame(top1, style="RoundedFrame", borderwidth=5)
        list_frame.pack(side=TOP, expand=1, fill=BOTH)

        sb_vert = TScrollbar(list_frame)
        sb_vert.pack(side=RIGHT, fill=Y)
        guides = UpdatedListbox(list_frame,
                                bg='white',
                                borderwidth=0,
                                selectborderwidth=0,
                                width=20,
                                height=8)
        guides.pack(expand=1, fill=BOTH)
        guides.Subscribe(SELECTION, self.select_guide)
        sb_vert['command'] = (guides, 'yview')
        guides['yscrollcommand'] = (sb_vert, 'set')
        self.guides = guides
        self.selected = None

        pos_frame = TFrame(top1, style='FlatFrame')
        pos_frame.pack(side=TOP, expand=0)

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

        self.var_label = StringVar(top)
        self.var_label.set('X: ')

        labelunit = UnitLabel(pos_frame)
        labelunit.pack(side=RIGHT, expand=0, anchor=W)

        label = TLabel(pos_frame, image='space_6', style='FlatLabel')
        label.pack(side=RIGHT)

        self.entry = TSpinbox(pos_frame,
                              var=0,
                              vartype=1,
                              min=-50000,
                              max=50000,
                              step=.1,
                              width=6,
                              command=self.pos_changed)
        self.entry.pack(side=RIGHT, expand=0, anchor=E)

        label = TLabel(pos_frame,
                       textvariable=self.var_label,
                       style='FlatLabel')
        label.pack(side=RIGHT, expand=0, anchor=E)

        frame = TFrame(top1, style='FlatFrame')
        frame.pack(side=TOP, fill=X)
        top2 = TFrame(frame, height=15, width=120, style='FlatFrame')
        top2.pack(side=TOP)

        button = UpdatedButton(frame,
                               text=_("Add Horizontal Guide"),
                               command=self.add_guide,
                               args=1)
        button.pack(side=TOP)

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

        button = UpdatedButton(frame,
                               text=_("Add Vertical Guide"),
                               command=self.add_guide,
                               args=0)
        button.pack(side=TOP)

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

        button = UpdatedButton(frame,
                               text=_("Delete Guide"),
                               command=self.del_guide)
        button.pack(side=TOP)

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

        app.mw.docmanager.activedoc.Subscribe(GUIDE_LINES, self.init_from_doc)
        app.mw.Subscribe(DOCUMENT, self.init_from_doc)
        self.init_from_doc()

    def set_unit(self, *rest):
        apply(self.var_pos.UpdateUnit, rest)
        self.update_list()

    def init_from_doc(self, *rest):
        self.guide_lines = self.document.GuideLines()
        self.guide_lines.reverse()
        self.update_list()

    def update_list(self):
        strings = []
        factor = self.var_pos.Factor()
        unit = self.var_pos.UnitName()
        if unit in ('in', 'cm'):
            prec = 2
        else:
            prec = 1
        for line in self.guide_lines:
            pos, horizontal = line.Coordinates()
            if horizontal:
                format = _("% 6.*f %s    horizontal")
            else:
                format = _("% 6.*f %s    vertical")
            strings.append(format % (prec, pos / factor, unit))
        self.guides.SetList(strings)
        self.select_index(self.selected)

    def select_index(self, index):
        if index is not None and index < len(self.guide_lines):
            self.guides.Select(index)
            self.select_guide()
        else:
            self.selected = None

    def set_pos(self, *rest):
        if self.selected is not None:
            self.document.MoveGuideLine(self.guide_lines[self.selected],
                                        self.var_pos.get())

    def select_guide(self, *rest):
        sel = self.guides.curselection()
        if sel:
            self.selected = atoi(sel[0])
            pos, horizontal = self.guide_lines[self.selected].Coordinates()
            self.var_pos.set(pos)
            self.entry.set_value(
                round(pos * 100 / self.var_pos.Factor()) / 100)
            if horizontal:
                self.var_label.set("Y: ")
            else:
                self.var_label.set("X: ")
        else:
            self.selected = None

    def del_guide(self, *rest):
        if self.selected is not None:
            line = self.guide_lines[self.selected]
            self.document.RemoveGuideLine(line)

    def add_guide(self, horizontal):
        length = len(self.guide_lines)
        self.document.AddGuideLine(Point(0, 0), horizontal)
        self.select_index(length)

    def pos_changed(self, *rest):
        self.var_pos.set(self.entry.get_value() * self.var_pos.Factor())
        self.set_pos()
        self.update_list()
Beispiel #14
0
class RotatePanel(PluginPanel):
    name = "Rotate"
    title = _("Rotate")

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

        root = self.mw.root

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

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

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

        self.cnt_x_absolute = None
        self.cnt_y_absolute = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.init_from_doc()
        self.subscribe_receivers()

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

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

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

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

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

        self.update_pref()

    def apply_basepoint(self):
        self.update_var()

    def position(self):
        self.update_var()

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

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

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

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

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

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

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

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

            self.var_basepoint.set("USER")

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

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

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

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

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

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

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

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

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

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

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

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

    def is_selection(self):
        return len(self.document.selection) > 0
Beispiel #15
0
class GradientFillPanel(PluginPanel):
	name='GradientFill'
	title = _("Gradient Fill")
	dashlist=[]
	dash=()
	ref_style=None
	color=None

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

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

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

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

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

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

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

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

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

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

		self.init_from_doc()
		self.subscribe_receivers()

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	def is_selection(self):
		return (len(self.document.selection) > 0)
Beispiel #17
0
class MovePanel(PluginPanel):
    name = 'Move'
    title = _("Move")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.init_from_doc()
        self.subscribe_receivers()


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

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

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

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

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

        self.update_pref()

    def apply_basepoint(self):
        self.Update()

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

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

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

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

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

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

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

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

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

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

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

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

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

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