コード例 #1
0
ファイル: unit_panel.py プロジェクト: kindlychung/sk1
class UnitPanel(CtxSubPanel):
	
	name='UnitPanel'	
	
	def __init__(self, parent):
		CtxSubPanel.__init__(self, parent)
		self.my_changes=0
		
		self.var_unit = StringVar(self.mw.root)
		self.var_unit.set(config.preferences.default_unit)
		
		label = TLabel(self.panel, text=_("Units:"))
		label.pack(side = LEFT, padx=2)
		self.entry_width = TCombobox(self.panel, state='readonly', postcommand = self.applyUnits, 
									 values=self.make_units(), width=4, style='ComboNormal', textvariable=self.var_unit)
		self.entry_width.pack(side = LEFT, padx=2)
		
		config.preferences.Subscribe(CHANGED, self.update)
		
	def applyUnits(self):
		self.my_changes=1
		config.preferences.default_unit=self.var_unit.get()
	
	def update(self,event, event2):	
		if self.my_changes:
			self.my_changes=0
		else:
			self.var_unit.set(config.preferences.default_unit)
	
	def make_units(self):
		units_tuple=()
		for unit in unit_names:
			units_tuple+=(unit,)		
		return units_tuple
			
コード例 #2
0
	def init(self, master):
		PluginPanel.init(self, master)
		top = TFrame(self.panel, style='FlatFrame', borderwidth=7)
		top.pack(side = TOP, fill=BOTH)
		
		sign = TFrame(top, style='RoundedFrame', borderwidth=5)
		sign.pack(side=TOP)

		self.sign = TLabel(sign, image='color_converter')
		self.sign.pack(side=TOP)
		
		self.cs_name = StringVar(top)
		self.cs_name.set(RGB)
		
		label = TLabel(top, text=_("Colorspace:")+" ")
		label.pack(side = TOP, anchor=W)
		
		self.colorspaces = TCombobox(top, state='readonly', postcommand = self.set_cs, 
									 values=self.make_cs_list(), width=14, style='ComboNormal',
									 textvariable=self.cs_name)
		self.colorspaces.pack(side = TOP, fill=X, pady=3)
		
		button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_colorspace,
								sensitivecb = self.is_selection)
		button.pack(side = BOTTOM, expand = 1, fill = X, pady=3)
		self.Subscribe(SELECTION, button.Update)
		


		self.init_from_doc()
		self.subscribe_receivers()
コード例 #3
0
ファイル: general.py プロジェクト: sanyaade-multimedia/sk1-tk
    def build(self):
        text = _(
            'sK1 generates PDF file as a printing output. So as a printing target you can use any application \
which accepts PDF file on input: evince, kprinter, acroread etc. \
Printing command should contain %f symbols replaced by \
temporal PDF file name during printing.')
        label = Text(self, height=5, wrap=WORD)
        label.pack(side=TOP, anchor='nw')
        label.insert(END, text)

        frame = FlatFrame(self)
        frame.pack(side=TOP, fill=X, expand=1, pady=10)

        frame.columnconfigure(1, weight=1)

        label = Label(frame, text=_('Printing command:'), justify=LEFT)
        label.grid(column=0, row=0, sticky='w')

        combo = TCombobox(frame,
                          state='normal',
                          values=self.prn_commandrs,
                          style='ComboNormal',
                          textvariable=self.var_print_command)  #, width=30)
        combo.grid(column=1, row=0, sticky='we', pady=5, padx=10)

        label = Label(frame, text=_('Output PDF level:'), justify=LEFT)
        label.grid(column=0, row=1, sticky='w')

        combo = TCombobox(frame,
                          state='readonly',
                          values=self.levels,
                          style='ComboNormal',
                          width=10,
                          textvariable=self.var_pdf_level)
        combo.grid(column=1, row=1, sticky='w', pady=5, padx=10)
コード例 #4
0
    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)
        self.my_changes = 0

        self.var_unit = StringVar(self.mw.root)
        self.var_unit.set(config.preferences.default_unit)

        label = TLabel(self.panel, text=_("Units:"))
        label.pack(side=LEFT, padx=2)
        self.entry_width = TCombobox(self.panel,
                                     state='readonly',
                                     postcommand=self.applyUnits,
                                     values=self.make_units(),
                                     width=4,
                                     style='ComboNormal',
                                     textvariable=self.var_unit)
        self.entry_width.pack(side=LEFT, padx=2)

        config.preferences.Subscribe(CHANGED, self.update)
コード例 #5
0
    def __init__(self, parent, callback, color, sign, allow_emtpy=1, **kw):
        self.color = color
        self.callback = callback
        TFrame.__init__(self, parent, style='FlatFrame', **kw)
        self.cs_name = StringVar(self)
        self.set_cs_name(self.color)

        self.colorspaces = TCombobox(self,
                                     state='readonly',
                                     postcommand=self.set_cs,
                                     values=self.make_cs_list(allow_emtpy),
                                     width=17,
                                     style='ComboNormal',
                                     textvariable=self.cs_name)
        self.colorspaces.pack(side=BOTTOM, fill=X, pady=3)

        label = TLabel(self, text=_("Colorspace:") + " ")
        label.pack(side=LEFT, anchor='sw')

        label = TLabel(self, image=sign)
        label.pack(side=RIGHT)
コード例 #6
0
ファイル: general.py プロジェクト: kindlychung/sk1
	def build(self):
		text = _('sK1 generates PDF file as a printing output. So as a printing target you can use any application \
which accepts PDF file on input: evince, kprinter, acroread etc. \
Printing command should contain %f symbols replaced by \
temporal PDF file name during printing.')
		label = Text(self, height=5, wrap=WORD)
		label.pack(side=TOP, anchor='nw')
		label.insert(END, text)

		frame = FlatFrame(self)
		frame.pack(side=TOP, fill=X, expand=1, pady=10)

		frame.columnconfigure(1, weight=1)

		label = Label(frame, text=_('Printing command:'), justify=LEFT)
		label.grid(column=0, row=0, sticky='w')


		combo = TCombobox(frame, state='normal', values=self.prn_commandrs, style='ComboNormal',
									 textvariable=self.var_print_command)#, width=30)
		combo.grid(column=1, row=0, sticky='we', pady=5, padx=10)

		label = Label(frame, text=_('Output PDF level:'), justify=LEFT)
		label.grid(column=0, row=1, sticky='w')


		combo = TCombobox(frame, state='readonly', values=self.levels, style='ComboNormal',
									 width=10, textvariable=self.var_pdf_level)
		combo.grid(column=1, row=1, sticky='w', pady=5, padx=10)
コード例 #7
0
class UnitPanel(CtxSubPanel):

    name = 'UnitPanel'

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

        self.var_unit = StringVar(self.mw.root)
        self.var_unit.set(config.preferences.default_unit)

        label = TLabel(self.panel, text=_("Units:"))
        label.pack(side=LEFT, padx=2)
        self.entry_width = TCombobox(self.panel,
                                     state='readonly',
                                     postcommand=self.applyUnits,
                                     values=self.make_units(),
                                     width=4,
                                     style='ComboNormal',
                                     textvariable=self.var_unit)
        self.entry_width.pack(side=LEFT, padx=2)

        config.preferences.Subscribe(CHANGED, self.update)

    def applyUnits(self):
        self.my_changes = 1
        config.preferences.default_unit = self.var_unit.get()

    def update(self, event, event2):
        if self.my_changes:
            self.my_changes = 0
        else:
            self.var_unit.set(config.preferences.default_unit)

    def make_units(self):
        units_tuple = ()
        for unit in unit_names:
            units_tuple += (unit, )
        return units_tuple
コード例 #8
0
ファイル: unit_panel.py プロジェクト: kindlychung/sk1
	def __init__(self, parent):
		CtxSubPanel.__init__(self, parent)
		self.my_changes=0
		
		self.var_unit = StringVar(self.mw.root)
		self.var_unit.set(config.preferences.default_unit)
		
		label = TLabel(self.panel, text=_("Units:"))
		label.pack(side = LEFT, padx=2)
		self.entry_width = TCombobox(self.panel, state='readonly', postcommand = self.applyUnits, 
									 values=self.make_units(), width=4, style='ComboNormal', textvariable=self.var_unit)
		self.entry_width.pack(side = LEFT, padx=2)
		
		config.preferences.Subscribe(CHANGED, self.update)
コード例 #9
0
ファイル: colorspacesel.py プロジェクト: kindlychung/sk1
	def __init__(self, parent, callback, color, sign, allow_emtpy=1, **kw):
		self.color=color
		self.callback=callback
		TFrame.__init__(self, parent, style='FlatFrame', **kw)
		self.cs_name = StringVar(self)
		self.set_cs_name(self.color)
		
		self.colorspaces = TCombobox(self, state='readonly', postcommand = self.set_cs, 
									 values=self.make_cs_list(allow_emtpy), width=17, style='ComboNormal',
									 textvariable=self.cs_name)
		self.colorspaces.pack(side = BOTTOM, fill=X, pady=3)
		
		label = TLabel(self, text=_("Colorspace:")+" ")
		label.pack(side = LEFT, anchor='sw')
		
		label = TLabel(self, image=sign)
		label.pack(side = RIGHT)
コード例 #10
0
ファイル: page_panel.py プロジェクト: kindlychung/sk1
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
コード例 #11
0
ファイル: font_panel.py プロジェクト: sk1project/sk1-tk
    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)

        self.var_font_name = StringVar(self.mw.root, " ")
        self.var_style_name = StringVar(self.mw.root, " ")
        self.var_font_size = StringVar(self.mw.root, " ")

        label = TLabel(self.panel, image="context_font_name")
        label.pack(side=LEFT, padx=2)
        tooltips.AddDescription(label, _("Font name"))
        self.font_name = TCombobox(
            self.panel,
            state="readonly",
            postcommand=self.name_changed,
            values=self.make_families(),
            width=25,
            style="PseudoActive",
            textvariable=self.var_font_name,
        )
        self.font_name.pack(side=LEFT, padx=2)

        label = TLabel(self.panel, text=" ")
        label.pack(side=LEFT)

        label = TLabel(self.panel, image="context_font_style")
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _("Font style"))
        self.style_name = TCombobox(
            self.panel,
            state="readonly",
            postcommand=self.style_changed,
            values=(),
            width=18,
            style="PseudoActive",
            textvariable=self.var_style_name,
        )
        self.style_name.pack(side=LEFT, padx=2)

        label = TLabel(self.panel, text=" ")
        label.pack(side=LEFT)

        label = TLabel(self.panel, image="context_font_size")
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _("Font size"))
        self.font_size = TCombobox(
            self.panel,
            state="normal",
            postcommand=self.apply_changes,
            values=self.make_sizes(),
            width=5,
            style="ComboNormal",
            textvariable=self.var_font_size,
        )
        self.font_size.pack(side=LEFT, padx=2)

        ######################################
        self.var_bold = StringVar(self.mw.root, "")
        self.var_italic = StringVar(self.mw.root, "")
        self.var_underline = StringVar(self.mw.root, "")

        self.bold_check = UpdatedRadiobutton(
            self.panel,
            value="bold",
            image="context_text_bold",
            command=self.bold_action,
            variable=self.var_bold,
            style="ToolbarRadiobutton",
        )
        self.bold_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.bold_check, _("Bold"))

        self.italic_check = UpdatedRadiobutton(
            self.panel,
            value="italic",
            image="context_text_italic",
            command=self.italic_action,
            variable=self.var_italic,
            style="ToolbarRadiobutton",
        )
        self.italic_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.italic_check, _("Italic"))

        # 		self.underline_check = UpdatedRadiobutton(self.panel, value = 'under', image='context_text_under_disabled', state='disabled',
        # 								command=self.action, variable = self.var_underline, style='ToolbarRadiobutton')
        # 		self.underline_check.pack(side=LEFT, padx=2)
        # 		tooltips.AddDescription(self.underline_check, _('Underline'))

        self.ReSubscribe()
コード例 #12
0
ファイル: distribute_plugin.py プロジェクト: kindlychung/sk1
	def init(self, master):
		PluginPanel.init(self, master)
		root=self.mw.root
		self.var_reference = StringVar(root)
		self.var_reference.set(SELECT)
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		rel_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		button_frame=TFrame(rel_frame, style='FlatFrame')
		button_frame.pack(side = TOP, fill = BOTH, padx=5)
		
		self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14,
									 textvariable=self.var_reference, postcommand = self.set_cs)
		self.reference.pack(side = TOP)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Distribute type")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		framec.pack(side = TOP, fill=X, padx=5, pady=2)
		
		
		framex = TFrame(framec, style='FlatFrame')
		framex.pack(side = TOP, expand = 0, padx = 5, pady = 5)
		
		framey = TFrame(framec, style='FlatFrame')
		framey.pack(side = TOP, expand = 0, padx = 5, pady = 5)


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

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

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

		self.init_from_doc()
		self.subscribe_receivers()
コード例 #13
0
class AlignPlugin(PluginPanel):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.apply_button_show(1)

        self.init_from_doc()
        self.subscribe_receivers()


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

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

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

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

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

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

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

    def set_cs(self):
        self.Update()

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

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

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

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

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

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

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

        reference = self.reference_command(reference)

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

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

    def reset(self):
        self.var_x.set(0)
        self.value_x = 0
        self.var_y.set(0)
        self.value_y = 0
        ##		self.apply_button_show(not self.var_auto_apply.get())
        self.Update()
コード例 #14
0
ファイル: colorspacesel.py プロジェクト: kindlychung/sk1
class ColorSpaceSelector(TFrame):
	
	current_cs=''
	
	def __init__(self, parent, callback, color, sign, allow_emtpy=1, **kw):
		self.color=color
		self.callback=callback
		TFrame.__init__(self, parent, style='FlatFrame', **kw)
		self.cs_name = StringVar(self)
		self.set_cs_name(self.color)
		
		self.colorspaces = TCombobox(self, state='readonly', postcommand = self.set_cs, 
									 values=self.make_cs_list(allow_emtpy), width=17, style='ComboNormal',
									 textvariable=self.cs_name)
		self.colorspaces.pack(side = BOTTOM, fill=X, pady=3)
		
		label = TLabel(self, text=_("Colorspace:")+" ")
		label.pack(side = LEFT, anchor='sw')
		
		label = TLabel(self, image=sign)
		label.pack(side = RIGHT)
		
	def make_cs_list(self,allow_emtpy):
		cs=()
		if allow_emtpy:
			cs+=(EMPTY,)
		cs+=(RGB,CMYK,SPOT,REGISTRATION)
		return cs
	
	def set_cs(self):
		if self.check_changes():
			if self.cs_name.get()==RGB:
				if self.current_cs==EMPTY:
					self.callback(CreateRGBColor(0,0,0))
				else:
					r,g,b=self.color.getRGB()
					self.callback(CreateRGBAColor(r,g,b, self.color.alpha))
			elif self.cs_name.get()==CMYK:
				if self.current_cs==EMPTY:
					self.callback(CreateCMYKColor(0,0,0,1))
				else:
					c,m,y,k=self.color.getCMYK()
					self.callback(CreateCMYKAColor(c,m,y,k, self.color.alpha))
			elif self.cs_name.get()==REGISTRATION:
				self.callback(Registration_Black())
			elif self.cs_name.get()==SPOT:
				self.cs_name.set(self.current_cs)
			else:
				self.callback(None)
	
	def set_cs_name(self,color):
		if color is None:
			self.cs_name.set(EMPTY)
		elif color.model=='RGB':
			self.cs_name.set(RGB)
		elif color.model=='CMYK':
			self.cs_name.set(CMYK)
		elif color.model=='SPOT':
			if color.name=='All':
				self.cs_name.set(REGISTRATION)
			else:
				self.cs_name.set(SPOT)
		self.current_cs=self.cs_name.get()
				
				
	def set_color(self,color):
		self.color=color
		self.set_cs_name(self.color)
		
	def get_colorspace_name(self,value):
		if value==RGB:
			return 'RGB'
		elif value==CMYK:
			return 'CMYK'
		elif value==SPOT:
			return 'SPORT'
		elif value==REGISTRATION:
			return 'Registration color'
		else:
			return None
		
	def check_changes(self):
		if self.current_cs==self.cs_name.get():
			return False
		else:
			return True
コード例 #15
0
class DistributePlugin(PluginPanel):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.apply_button_show(1)

        self.init_from_doc()
        self.subscribe_receivers()


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

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

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

    def init_from_doc(self):
        self.Update()

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

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

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

    def set_cs(self):
        self.Update()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def reset(self):
        self.var_x.set(0)
        self.value_x = 0
        self.var_y.set(0)
        self.value_y = 0
        ##		self.apply_button_show(not self.var_auto_apply.get())
        self.Update()
コード例 #16
0
    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)
コード例 #17
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
コード例 #18
0
ファイル: page_panel.py プロジェクト: kindlychung/sk1
	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)
コード例 #19
0
ファイル: distribute_plugin.py プロジェクト: kindlychung/sk1
class DistributePlugin(PluginPanel):
	
	name='Distribute'
	title = _("Distribution")
	
	def init(self, master):
		PluginPanel.init(self, master)
		root=self.mw.root
		self.var_reference = StringVar(root)
		self.var_reference.set(SELECT)
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4)
		rel_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		button_frame=TFrame(rel_frame, style='FlatFrame')
		button_frame.pack(side = TOP, fill = BOTH, padx=5)
		
		self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14,
									 textvariable=self.var_reference, postcommand = self.set_cs)
		self.reference.pack(side = TOP)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Distribute type")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		framec.pack(side = TOP, fill=X, padx=5, pady=2)
		
		
		framex = TFrame(framec, style='FlatFrame')
		framex.pack(side = TOP, expand = 0, padx = 5, pady = 5)
		
		framey = TFrame(framec, style='FlatFrame')
		framey.pack(side = TOP, expand = 0, padx = 5, pady = 5)


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

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

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

		self.init_from_doc()
		self.subscribe_receivers()


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

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

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

	def init_from_doc(self):
		self.Update()

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

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

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

	def set_cs(self):
		self.Update()

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

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



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

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

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

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

	def reset(self):
		self.var_x.set(0)
		self.value_x = 0
		self.var_y.set(0)
		self.value_y = 0
##		self.apply_button_show(not self.var_auto_apply.get())
		self.Update()
コード例 #20
0
    def init(self, master):
        PluginPanel.init(self, master)
        root = self.mw.root
        self.var_reference = StringVar(root)
        self.var_reference.set(SELECT)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.apply_button_show(1)

        self.init_from_doc()
        self.subscribe_receivers()
コード例 #21
0
ファイル: font_panel.py プロジェクト: sk1project/sk1-tk
class FontPanel(CtxSubPanel):

    name = "FontPanel"
    family_to_fonts = {}
    families = []
    styles = []
    bold = 0
    italic = 0

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

        self.var_font_name = StringVar(self.mw.root, " ")
        self.var_style_name = StringVar(self.mw.root, " ")
        self.var_font_size = StringVar(self.mw.root, " ")

        label = TLabel(self.panel, image="context_font_name")
        label.pack(side=LEFT, padx=2)
        tooltips.AddDescription(label, _("Font name"))
        self.font_name = TCombobox(
            self.panel,
            state="readonly",
            postcommand=self.name_changed,
            values=self.make_families(),
            width=25,
            style="PseudoActive",
            textvariable=self.var_font_name,
        )
        self.font_name.pack(side=LEFT, padx=2)

        label = TLabel(self.panel, text=" ")
        label.pack(side=LEFT)

        label = TLabel(self.panel, image="context_font_style")
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _("Font style"))
        self.style_name = TCombobox(
            self.panel,
            state="readonly",
            postcommand=self.style_changed,
            values=(),
            width=18,
            style="PseudoActive",
            textvariable=self.var_style_name,
        )
        self.style_name.pack(side=LEFT, padx=2)

        label = TLabel(self.panel, text=" ")
        label.pack(side=LEFT)

        label = TLabel(self.panel, image="context_font_size")
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _("Font size"))
        self.font_size = TCombobox(
            self.panel,
            state="normal",
            postcommand=self.apply_changes,
            values=self.make_sizes(),
            width=5,
            style="ComboNormal",
            textvariable=self.var_font_size,
        )
        self.font_size.pack(side=LEFT, padx=2)

        ######################################
        self.var_bold = StringVar(self.mw.root, "")
        self.var_italic = StringVar(self.mw.root, "")
        self.var_underline = StringVar(self.mw.root, "")

        self.bold_check = UpdatedRadiobutton(
            self.panel,
            value="bold",
            image="context_text_bold",
            command=self.bold_action,
            variable=self.var_bold,
            style="ToolbarRadiobutton",
        )
        self.bold_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.bold_check, _("Bold"))

        self.italic_check = UpdatedRadiobutton(
            self.panel,
            value="italic",
            image="context_text_italic",
            command=self.italic_action,
            variable=self.var_italic,
            style="ToolbarRadiobutton",
        )
        self.italic_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.italic_check, _("Italic"))

        # 		self.underline_check = UpdatedRadiobutton(self.panel, value = 'under', image='context_text_under_disabled', state='disabled',
        # 								command=self.action, variable = self.var_underline, style='ToolbarRadiobutton')
        # 		self.underline_check.pack(side=LEFT, padx=2)
        # 		tooltips.AddDescription(self.underline_check, _('Underline'))

        self.ReSubscribe()

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

    def Update(self, *arg):
        object = self.mw.document.CurrentObject()
        if object is not None and object.is_Text:
            _font = object.Font()
            self.var_font_name.set(_font.familyname)
            self.var_style_name.set(_font.facename)
            self.style_name["values"] = self.make_styles()
            self.var_font_size.set(object.FontSize())
        # 		else:
        # 			try:
        # 				default = ft2engine.GetFont(config.preferences.default_font)
        # 			except:
        # 				name = self.family_to_fonts.keys()[0]#[0]
        # 				fonts = self.family_to_fonts[name]
        # 				default = ft2engine.GetFont(fonts[1])
        # 			self.var_font_name.set(default.family)
        # 			self.var_style_name.set(default.font_attrs)
        # 			self.style_name['values'] = self.make_styles()
        # 			self.var_font_size.set(properties.default_text_style.font_size)
        self.checkBI()

    def make_families(self):
        result = ()
        self.families = libpango.FAMILIES_LIST
        for item in self.families:
            result += (item,)
        return result

    def make_styles(self):
        faces = libpango.FAMILIES_DICT[self.var_font_name.get()]
        attrs = ()
        self.styles = []
        for name in faces:
            self.styles.append(name)
            attrs += (name,)
        return attrs

    def make_sizes(self):
        sizes = ()
        for size in [5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 48, 56, 64, 72]:
            sizes += (size,)
        return sizes

    def name_changed(self):
        self.style_name["values"] = self.make_styles()
        if not self.var_style_name.get() in self.styles:
            self.setRegular()
        self.checkBI()
        self.apply_changes()

    def style_changed(self):
        self.checkBI()
        self.apply_changes()

    def apply_changes(self):
        familyname = self.var_font_name.get()
        facename = self.var_style_name.get()
        self.mw.document.CallObjectMethod(
            text.CommonText,
            _("Set Font Properties"),
            "SetFont",
            libpango.get_fontface(familyname, facename),
            atof(self.var_font_size.get()),
        )
        self.mw.canvas.ForceRedraw()

    def bold_action(self):
        if self.bold:
            self.bold = 0
            self.var_bold.set("")
        else:
            self.bold = 1
            self.var_bold.set("bold")

        if self.bold and self.italic:
            if "Bold Italic" in self.styles:
                self.var_style_name.set("Bold Italic")
            elif "Bold Oblique" in self.styles:
                self.var_style_name.set("Bold Oblique")
            else:
                self.bold = 0
                self.var_bold.set("")
        elif self.bold:
            self.var_style_name.set("Bold")
        elif self.italic:
            if "Italic" in self.styles:
                self.var_style_name.set("Italic")
            if "Oblique" in self.styles:
                self.var_style_name.set("Oblique")
        else:
            self.setRegular()
        self.style_changed()

    def italic_action(self):
        if self.italic:
            self.italic = 0
            self.var_italic.set("")
        else:
            self.italic = 1
            self.var_italic.set("italic")

        if self.bold and self.italic:
            if "Bold Italic" in self.styles:
                self.var_style_name.set("Bold Italic")
            elif "Bold Oblique" in self.styles:
                self.var_style_name.set("Bold Oblique")
            else:
                self.italic = 0
                self.var_italic.set("")
        elif self.italic:
            if "Italic" in self.styles:
                self.var_style_name.set("Italic")
            if "Oblique" in self.styles:
                self.var_style_name.set("Oblique")
        elif self.bold:
            self.var_style_name.set("Bold")
        else:
            self.setRegular()
        self.style_changed()

    def setRegular(self):
        normal = None
        for item in ["Roman", "Book", "Normal", "Regular"]:
            if item in self.styles:
                normal = item
        if normal:
            self.var_style_name.set(normal)
        else:
            self.var_style_name.set(self.styles[0])

    def checkBI(self):
        if "Bold" in self.styles:
            self.bold_check["state"] = "normal"
        else:
            self.bold_check["state"] = "disabled"
            self.bold = 0
            self.var_bold.set("")
        if "Italic" in self.styles or "Oblique" in self.styles:
            self.italic_check["state"] = "normal"
        else:
            self.italic = 0
            self.italic_check["state"] = "disabled"
            self.var_italic.set("")

        if self.var_style_name.get() == "Bold":
            self.bold = 1
            self.italic = 0
            self.var_bold.set("bold")
            self.var_italic.set("")
        elif self.var_style_name.get() in ["Italic", "Oblique"]:
            self.bold = 0
            self.italic = 1
            self.var_italic.set("italic")
            self.var_bold.set("")
        elif self.var_style_name.get() in ["Bold Italic", "Bold Oblique"]:
            self.bold = 1
            self.italic = 1
            self.var_bold.set("bold")
            self.var_italic.set("italic")
        else:
            self.bold = 0
            self.italic = 0
            self.var_bold.set("")
            self.var_italic.set("")

    def action(self):
        pass
コード例 #22
0
class ColorSpaceConverter(PluginPanel):
	name='ColorSpaceConverter'
	title = _("Color Space Converter")


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

		self.sign = TLabel(sign, image='color_converter')
		self.sign.pack(side=TOP)
		
		self.cs_name = StringVar(top)
		self.cs_name.set(RGB)
		
		label = TLabel(top, text=_("Colorspace:")+" ")
		label.pack(side = TOP, anchor=W)
		
		self.colorspaces = TCombobox(top, state='readonly', postcommand = self.set_cs, 
									 values=self.make_cs_list(), width=14, style='ComboNormal',
									 textvariable=self.cs_name)
		self.colorspaces.pack(side = TOP, fill=X, pady=3)
		
		button = UpdatedButton(top, text = _("Apply"),
								command = self.apply_colorspace,
								sensitivecb = self.is_selection)
		button.pack(side = BOTTOM, expand = 1, fill = X, pady=3)
		self.Subscribe(SELECTION, button.Update)
		


		self.init_from_doc()
		self.subscribe_receivers()

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

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

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

	def Update(self):
		pass

	def make_cs_list(self):
		cs=()
		cs+=(RGB,CMYK)
		return cs

	def set_cs(self):
		pass

	def apply_colorspace(self):
		objects = self.document.selection.GetObjects()
		name = self.cs_name.get()
		if name==RGB:
			cs_name= 'RGB'
		elif name==CMYK:
			cs_name= 'CMYK'
		
		self.document.begin_transaction(name)
		try:
			try:
				add_undo = self.document.add_undo
				self.apply_cs(objects, cs_name)
				add_undo(self.document.queue_edited())
			except:
				self.document.abort_transaction()
		finally:
			self.document.end_transaction()
		app.mw.canvas.ForceRedraw()

	def apply_cs(self, objects, cs_name):
		for object in objects:
			if object.is_Compound:
				self.apply_cs(object.GetObjects(),cs_name)
			
			elif object.is_Text or object.is_Bezier or object.is_Rectangle or object.is_Ellipse:
				self.document.add_undo(self.FillStyle(object,cs_name))
				self.document.add_undo(self.OutlineStyle(object,cs_name))
			
			elif object.is_Image:
				if not cs_name==object.data.image_mode:
					self.document.add_undo(object.Convert(cs_name))


	def FillStyle(self, object, cs_name):
		undo_info = None
		try:
			fill_pattern = object.properties.fill_pattern
			
			if fill_pattern is EmptyPattern:
				pass
			
			elif fill_pattern.is_Solid:
				color=fill_pattern.Color()
				undo_info = self.setSolidPatternFill(object, color, cs_name)
			
			elif fill_pattern.is_Hatching:
				pass
			
			elif fill_pattern.is_Tiled:
				pass
			
			elif fill_pattern.is_Gradient:
				pass
			
			elif fill_pattern.is_Image:
				pass
		finally:
			if undo_info is not None:
				return undo_info
			return NullUndo

	def setSolidPatternFill(self, object, color, cs_name):
		if color.model == cs_name:
			return
		color=self.convert_color(color, cs_name)
		undo=(object.SetProperties(fill_pattern=SolidPattern(color)))
		return undo



	def OutlineStyle(self, object, cs_name):
		undo_info = None
		try:
			line_pattern=object.properties.line_pattern
			if line_pattern is EmptyPattern:
					pass
			elif line_pattern.is_Solid:
					color=line_pattern.Color()
					undo_info = self.setSolidPatternOutline(object, color, cs_name)
		finally:
			if undo_info is not None:
				return undo_info
			return NullUndo

	def setSolidPatternOutline(self, object, color, cs_name):
		if color.model == cs_name:
			return
		color=self.convert_color(color, cs_name)
		undo=(object.SetProperties(line_pattern=SolidPattern(color)))
		return undo




	def convert_color(self, color, cs_name):
		if cs_name is None:
			return color
		
		elif cs_name == 'CMYK':
			c, m, y, k = color.getCMYK()
			return CreateCMYKAColor(c, m, y, k, color.alpha)
		
		elif cs_name == 'RGB':
			r, g, b = color.getRGB()
			return CreateRGBAColor(r, g, b, color.alpha)
コード例 #23
0
class FontPanel(CtxSubPanel):

    name = 'FontPanel'
    family_to_fonts = {}
    families = []
    styles = []
    bold = 0
    italic = 0

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

        self.var_font_name = StringVar(self.mw.root, ' ')
        self.var_style_name = StringVar(self.mw.root, ' ')
        self.var_font_size = StringVar(self.mw.root, ' ')

        label = TLabel(self.panel, image='context_font_name')
        label.pack(side=LEFT, padx=2)
        tooltips.AddDescription(label, _('Font name'))
        self.font_name = TCombobox(self.panel,
                                   state='readonly',
                                   postcommand=self.name_changed,
                                   values=self.make_families(),
                                   width=25,
                                   style='PseudoActive',
                                   textvariable=self.var_font_name)
        self.font_name.pack(side=LEFT, padx=2)

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

        label = TLabel(self.panel, image='context_font_style')
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _('Font style'))
        self.style_name = TCombobox(self.panel,
                                    state='readonly',
                                    postcommand=self.style_changed,
                                    values=(),
                                    width=18,
                                    style='PseudoActive',
                                    textvariable=self.var_style_name)
        self.style_name.pack(side=LEFT, padx=2)

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

        label = TLabel(self.panel, image='context_font_size')
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _('Font size'))
        self.font_size = TCombobox(self.panel,
                                   state='normal',
                                   postcommand=self.apply_changes,
                                   values=self.make_sizes(),
                                   width=5,
                                   style='ComboNormal',
                                   textvariable=self.var_font_size)
        self.font_size.pack(side=LEFT, padx=2)

        ######################################
        self.var_bold = StringVar(self.mw.root, '')
        self.var_italic = StringVar(self.mw.root, '')
        self.var_underline = StringVar(self.mw.root, '')

        self.bold_check = UpdatedRadiobutton(self.panel,
                                             value='bold',
                                             image='context_text_bold',
                                             command=self.bold_action,
                                             variable=self.var_bold,
                                             style='ToolbarRadiobutton')
        self.bold_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.bold_check, _('Bold'))

        self.italic_check = UpdatedRadiobutton(self.panel,
                                               value='italic',
                                               image='context_text_italic',
                                               command=self.italic_action,
                                               variable=self.var_italic,
                                               style='ToolbarRadiobutton')
        self.italic_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.italic_check, _('Italic'))

        #		self.underline_check = UpdatedRadiobutton(self.panel, value = 'under', image='context_text_under_disabled', state='disabled',
        #								command=self.action, variable = self.var_underline, style='ToolbarRadiobutton')
        #		self.underline_check.pack(side=LEFT, padx=2)
        #		tooltips.AddDescription(self.underline_check, _('Underline'))

        self.ReSubscribe()

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

    def Update(self, *arg):
        object = self.mw.document.CurrentObject()
        if object is not None and object.is_Text:
            _font = object.Font()
            self.var_font_name.set(_font.familyname)
            self.var_style_name.set(_font.facename)
            self.style_name['values'] = self.make_styles()
            self.var_font_size.set(object.FontSize())
#		else:
#			try:
#				default = ft2engine.GetFont(config.preferences.default_font)
#			except:
#				name = self.family_to_fonts.keys()[0]#[0]
#				fonts = self.family_to_fonts[name]
#				default = ft2engine.GetFont(fonts[1])
#			self.var_font_name.set(default.family)
#			self.var_style_name.set(default.font_attrs)
#			self.style_name['values'] = self.make_styles()
#			self.var_font_size.set(properties.default_text_style.font_size)
        self.checkBI()

    def make_families(self):
        result = ()
        self.families = libpango.FAMILIES_LIST
        for item in self.families:
            result += (item, )
        return result

    def make_styles(self):
        faces = libpango.FAMILIES_DICT[self.var_font_name.get()]
        attrs = ()
        self.styles = []
        for name in faces:
            self.styles.append(name)
            attrs += (name, )
        return attrs

    def make_sizes(self):
        sizes = ()
        for size in [
                5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40,
                48, 56, 64, 72
        ]:
            sizes += (size, )
        return sizes

    def name_changed(self):
        self.style_name['values'] = self.make_styles()
        if not self.var_style_name.get() in self.styles:
            self.setRegular()
        self.checkBI()
        self.apply_changes()

    def style_changed(self):
        self.checkBI()
        self.apply_changes()

    def apply_changes(self):
        familyname = self.var_font_name.get()
        facename = self.var_style_name.get()
        self.mw.document.CallObjectMethod(
            text.CommonText, _("Set Font Properties"), 'SetFont',
            libpango.get_fontface(familyname, facename),
            atof(self.var_font_size.get()))
        self.mw.canvas.ForceRedraw()

    def bold_action(self):
        if self.bold:
            self.bold = 0
            self.var_bold.set('')
        else:
            self.bold = 1
            self.var_bold.set('bold')

        if self.bold and self.italic:
            if 'Bold Italic' in self.styles:
                self.var_style_name.set('Bold Italic')
            elif 'Bold Oblique' in self.styles:
                self.var_style_name.set('Bold Oblique')
            else:
                self.bold = 0
                self.var_bold.set('')
        elif self.bold:
            self.var_style_name.set('Bold')
        elif self.italic:
            if 'Italic' in self.styles:
                self.var_style_name.set('Italic')
            if 'Oblique' in self.styles:
                self.var_style_name.set('Oblique')
        else:
            self.setRegular()
        self.style_changed()

    def italic_action(self):
        if self.italic:
            self.italic = 0
            self.var_italic.set('')
        else:
            self.italic = 1
            self.var_italic.set('italic')

        if self.bold and self.italic:
            if 'Bold Italic' in self.styles:
                self.var_style_name.set('Bold Italic')
            elif 'Bold Oblique' in self.styles:
                self.var_style_name.set('Bold Oblique')
            else:
                self.italic = 0
                self.var_italic.set('')
        elif self.italic:
            if 'Italic' in self.styles:
                self.var_style_name.set('Italic')
            if 'Oblique' in self.styles:
                self.var_style_name.set('Oblique')
        elif self.bold:
            self.var_style_name.set('Bold')
        else:
            self.setRegular()
        self.style_changed()

    def setRegular(self):
        normal = None
        for item in ['Roman', 'Book', 'Normal', 'Regular']:
            if item in self.styles:
                normal = item
        if normal:
            self.var_style_name.set(normal)
        else:
            self.var_style_name.set(self.styles[0])

    def checkBI(self):
        if 'Bold' in self.styles:
            self.bold_check['state'] = 'normal'
        else:
            self.bold_check['state'] = 'disabled'
            self.bold = 0
            self.var_bold.set('')
        if 'Italic' in self.styles or 'Oblique' in self.styles:
            self.italic_check['state'] = 'normal'
        else:
            self.italic = 0
            self.italic_check['state'] = 'disabled'
            self.var_italic.set('')

        if self.var_style_name.get() == 'Bold':
            self.bold = 1
            self.italic = 0
            self.var_bold.set('bold')
            self.var_italic.set('')
        elif self.var_style_name.get() in ['Italic', 'Oblique']:
            self.bold = 0
            self.italic = 1
            self.var_italic.set('italic')
            self.var_bold.set('')
        elif self.var_style_name.get() in ['Bold Italic', 'Bold Oblique']:
            self.bold = 1
            self.italic = 1
            self.var_bold.set('bold')
            self.var_italic.set('italic')
        else:
            self.bold = 0
            self.italic = 0
            self.var_bold.set('')
            self.var_italic.set('')

    def action(self):
        pass
コード例 #24
0
class ColorSpaceSelector(TFrame):

    current_cs = ''

    def __init__(self, parent, callback, color, sign, allow_emtpy=1, **kw):
        self.color = color
        self.callback = callback
        TFrame.__init__(self, parent, style='FlatFrame', **kw)
        self.cs_name = StringVar(self)
        self.set_cs_name(self.color)

        self.colorspaces = TCombobox(self,
                                     state='readonly',
                                     postcommand=self.set_cs,
                                     values=self.make_cs_list(allow_emtpy),
                                     width=17,
                                     style='ComboNormal',
                                     textvariable=self.cs_name)
        self.colorspaces.pack(side=BOTTOM, fill=X, pady=3)

        label = TLabel(self, text=_("Colorspace:") + " ")
        label.pack(side=LEFT, anchor='sw')

        label = TLabel(self, image=sign)
        label.pack(side=RIGHT)

    def make_cs_list(self, allow_emtpy):
        cs = ()
        if allow_emtpy:
            cs += (EMPTY, )
        cs += (RGB, CMYK, SPOT, REGISTRATION)
        return cs

    def set_cs(self):
        if self.check_changes():
            if self.cs_name.get() == RGB:
                if self.current_cs == EMPTY:
                    self.callback(CreateRGBColor(0, 0, 0))
                else:
                    r, g, b = self.color.getRGB()
                    self.callback(CreateRGBAColor(r, g, b, self.color.alpha))
            elif self.cs_name.get() == CMYK:
                if self.current_cs == EMPTY:
                    self.callback(CreateCMYKColor(0, 0, 0, 1))
                else:
                    c, m, y, k = self.color.getCMYK()
                    self.callback(
                        CreateCMYKAColor(c, m, y, k, self.color.alpha))
            elif self.cs_name.get() == REGISTRATION:
                self.callback(Registration_Black())
            elif self.cs_name.get() == SPOT:
                self.cs_name.set(self.current_cs)
            else:
                self.callback(None)

    def set_cs_name(self, color):
        if color is None:
            self.cs_name.set(EMPTY)
        elif color.model == 'RGB':
            self.cs_name.set(RGB)
        elif color.model == 'CMYK':
            self.cs_name.set(CMYK)
        elif color.model == 'SPOT':
            if color.name == 'All':
                self.cs_name.set(REGISTRATION)
            else:
                self.cs_name.set(SPOT)
        self.current_cs = self.cs_name.get()

    def set_color(self, color):
        self.color = color
        self.set_cs_name(self.color)

    def get_colorspace_name(self, value):
        if value == RGB:
            return 'RGB'
        elif value == CMYK:
            return 'CMYK'
        elif value == SPOT:
            return 'SPORT'
        elif value == REGISTRATION:
            return 'Registration color'
        else:
            return None

    def check_changes(self):
        if self.current_cs == self.cs_name.get():
            return False
        else:
            return True
コード例 #25
0
    def __init__(self, parent):
        CtxSubPanel.__init__(self, parent)

        self.var_font_name = StringVar(self.mw.root, ' ')
        self.var_style_name = StringVar(self.mw.root, ' ')
        self.var_font_size = StringVar(self.mw.root, ' ')

        label = TLabel(self.panel, image='context_font_name')
        label.pack(side=LEFT, padx=2)
        tooltips.AddDescription(label, _('Font name'))
        self.font_name = TCombobox(self.panel,
                                   state='readonly',
                                   postcommand=self.name_changed,
                                   values=self.make_families(),
                                   width=25,
                                   style='PseudoActive',
                                   textvariable=self.var_font_name)
        self.font_name.pack(side=LEFT, padx=2)

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

        label = TLabel(self.panel, image='context_font_style')
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _('Font style'))
        self.style_name = TCombobox(self.panel,
                                    state='readonly',
                                    postcommand=self.style_changed,
                                    values=(),
                                    width=18,
                                    style='PseudoActive',
                                    textvariable=self.var_style_name)
        self.style_name.pack(side=LEFT, padx=2)

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

        label = TLabel(self.panel, image='context_font_size')
        label.pack(side=LEFT)
        tooltips.AddDescription(label, _('Font size'))
        self.font_size = TCombobox(self.panel,
                                   state='normal',
                                   postcommand=self.apply_changes,
                                   values=self.make_sizes(),
                                   width=5,
                                   style='ComboNormal',
                                   textvariable=self.var_font_size)
        self.font_size.pack(side=LEFT, padx=2)

        ######################################
        self.var_bold = StringVar(self.mw.root, '')
        self.var_italic = StringVar(self.mw.root, '')
        self.var_underline = StringVar(self.mw.root, '')

        self.bold_check = UpdatedRadiobutton(self.panel,
                                             value='bold',
                                             image='context_text_bold',
                                             command=self.bold_action,
                                             variable=self.var_bold,
                                             style='ToolbarRadiobutton')
        self.bold_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.bold_check, _('Bold'))

        self.italic_check = UpdatedRadiobutton(self.panel,
                                               value='italic',
                                               image='context_text_italic',
                                               command=self.italic_action,
                                               variable=self.var_italic,
                                               style='ToolbarRadiobutton')
        self.italic_check.pack(side=LEFT, padx=2)
        tooltips.AddDescription(self.italic_check, _('Italic'))

        #		self.underline_check = UpdatedRadiobutton(self.panel, value = 'under', image='context_text_under_disabled', state='disabled',
        #								command=self.action, variable = self.var_underline, style='ToolbarRadiobutton')
        #		self.underline_check.pack(side=LEFT, padx=2)
        #		tooltips.AddDescription(self.underline_check, _('Underline'))

        self.ReSubscribe()
コード例 #26
0
ファイル: align_plugin.py プロジェクト: kindlychung/sk1
class AlignPlugin(PluginPanel):
	
	name='Alignment'
	title = _("Alignment")
	
	def init(self, master):
		PluginPanel.init(self, master)
		root=self.mw.root
		self.var_reference = StringVar(root)
		self.var_reference.set(SELECT)
		
		#---------------------------------------------------------
		top = TFrame(self.panel, style='FlatFrame')
		top.pack(side = TOP, fill=BOTH)
		#---------------------------------------------------------
		label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel")
		label.pack(side = TOP, fill = BOTH, padx=5)
		rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3)
		rel_frame.pack(side = TOP, fill=X, padx=5, pady=2)
		
		self.reference = TCombobox(rel_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14,
									 textvariable=self.var_reference, postcommand = self.set_cs)
		self.reference.pack(side = TOP)
		#---------------------------------------------------------

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


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

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

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


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

		self.init_from_doc()
		self.subscribe_receivers()


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

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

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

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

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

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

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

	def set_cs(self):
		self.Update()

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

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

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

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

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

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