Exemple #1
0
class GetNameDlg(SKModal):

    title = _("Name")

    def __init__(self, master, name, **kw):
	self.name = name
	apply(SKModal.__init__, (self, master), kw)

    def build_dlg(self):
	top = self.top

	frame = Frame(top)
	frame.pack(side = BOTTOM, fill = BOTH, expand = 1)
	button = Button(frame, text = _("OK"), command = self.ok)
	button.pack(side = LEFT, expand = 1)
	button = Button(frame, text = _("Cancel"), command = self.cancel)
	button.pack(side = RIGHT, expand = 1)

	self.label = Label(top, text = _("Name"))
	self.label.pack(side = LEFT)

	self.entry = MyEntry(top, command = self.ok)
	self.entry.pack(side = RIGHT, expand = 1, fill = X)
	self.entry.SetText(self.name)

    def ok(self, *args):
	self.close_dlg(self.entry.get())
Exemple #2
0
class GetNameDlg(SKModal):

    title = _("Name")

    def __init__(self, master, name, **kw):
        self.name = name
        apply(SKModal.__init__, (self, master), kw)

    def build_dlg(self):
        top = self.top

        frame = Frame(top)
        frame.pack(side=BOTTOM, fill=BOTH, expand=1)
        button = Button(frame, text=_("OK"), command=self.ok)
        button.pack(side=LEFT, expand=1)
        button = Button(frame, text=_("Cancel"), command=self.cancel)
        button.pack(side=RIGHT, expand=1)

        self.label = Label(top, text=_("Name"))
        self.label.pack(side=LEFT)

        self.entry = MyEntry(top, command=self.ok)
        self.entry.pack(side=RIGHT, expand=1, fill=X)
        self.entry.SetText(self.name)

    def ok(self, *args):
        self.close_dlg(self.entry.get())
Exemple #3
0
def create_mini_entry(top, master, command, vartype = IntVar,
						min = 0, max = None, step = 1, scroll_pad = 2):
	var_number = vartype(top)
	entry = MyEntry(master, textvariable = var_number, justify = RIGHT,
					width = 6, command = command)
	entry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
	scroll = MiniScroller(master, variable = var_number, min = min, max = max,
							step = step)
	scroll.pack(side = LEFT, fill = Y, pady = scroll_pad)
	scroll.Subscribe(COMMAND, command)
	return var_number
Exemple #4
0
    def build_dlg(self):
	top = self.top

	var_number = DoubleVar(top)
	var_unit = StringVar(top)
	self.var_pos = LengthVar(1.0, config.preferences.default_unit,
                                 var_number, var_unit, command = self.set_pos)
	pos_frame = Frame(top)
	pos_frame.pack(side = TOP, fill = X, expand = 0)
	self.var_label = StringVar(top)
	self.var_label.set('X:')
	label = Label(pos_frame, textvariable = self.var_label)
	label.pack(side = LEFT, expand = 1, anchor = E)
	entry = MyEntry(pos_frame, textvariable = var_number,
			justify = RIGHT, width = 4,
			command = self.var_pos.UpdateNumber)
	entry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
	scroll = MiniScroller(pos_frame, variable = var_number,
			      min = 0, max = None, step = 1)
	scroll.pack(side = LEFT, fill = Y)
	optmenu = create_unit_menu(pos_frame, self.set_unit,
				   variable = var_unit,
				   indicatoron = 0, width = 3)
	optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W)

	list_frame = Frame(top)
	list_frame.pack(side = TOP, expand = 1, fill = BOTH)

	sb_vert = Scrollbar(list_frame, takefocus = 0)
	sb_vert.pack(side = RIGHT, fill = Y)
	guides = UpdatedListbox(list_frame, name = 'list')
	guides.pack(expand = 1, fill = BOTH)
	guides.Subscribe(SELECTION, self.select_guide)
	sb_vert['command'] = (guides, 'yview')
	guides['yscrollcommand'] = (sb_vert, 'set')
	self.guides = guides
	self.selected = None

	frame = Frame(top)
	frame.pack(side = BOTTOM, fill = X)
	button = UpdatedButton(frame, text = _("Add H"),
			       command = self.add_guide, args = 1)
	button.pack(side = LEFT)
	button = UpdatedButton(frame, text = _("Add V"),
			       command = self.add_guide, args = 0)
	button.pack(side = LEFT)
	button = UpdatedButton(frame, text = _("Delete"),
			       command = self.del_guide)
	button.pack(side = LEFT)
	button = UpdatedButton(frame, text = _("Close"),
			       command = self.close_dlg)
	button.pack(side = RIGHT)
Exemple #5
0
    def __init__(self, master=None, **kw):
	apply(PatternFrame.__init__, (self, master), kw)

	gradient = CreateSimpleGradient(StandardColors.white,
					StandardColors.black)
	frame = Frame(self)
	frame.pack(side = TOP, fill = X)
	self.var_gradient_type = IntVar(self)
	for value, bitmap in [(0, 'linear'), (1, 'conical'), (2, 'radial')]:
	    bitmap = getattr(pixmaps, 'gradient_' + bitmap)
	    button = make_button(frame, bitmap = bitmap, value = value,
				 variable = self.var_gradient_type,
				 command = self.choose_type)
	    button.pack(side = LEFT, fill = X, expand = 1)

	frame = Frame(self)
	frame.pack(side = TOP, expand = 1, fill = X)
	self.colors = [None, None]
	self.colors[0] = ColorButton(frame, height = 1,
				     color = gradient.StartColor(),
				     command = self.set_color, args = 0)
	self.colors[0].pack(side = LEFT, fill = X, expand = 1)
	self.colors[1] =  ColorButton(frame, height = 1,
				      color = gradient.EndColor(),
				      command = self.set_color, args = 1)
	self.colors[1].pack(side = LEFT, fill = X, expand = 1)

	self.var_border = DoubleVar(self)
	self.var_border.set(0.0)
	frame = Frame(self)
	frame.pack(side = TOP, fill = X, expand = 1)
	label = Label(frame, text = _("Border"))
	label.pack(side = LEFT, expand = 1, anchor = E)
	entry = MyEntry(frame, textvariable = self.var_border, width = 4,
			justify = RIGHT, command = self.set_border)
	entry.pack(side = LEFT, expand = 1, fill = X)
	scroll = MiniScroller(frame, variable = self.var_border,
			      min = 0.0, max = 100.0, step = 1.0,
			      command = self.set_border)
	scroll.pack(side = LEFT, fill = Y)

	button = UpdatedButton(self, text = _("Edit Gradient"),
			       command = self.edit_gradient)
	button.pack(side = TOP, fill = X)

	pattern = LinearGradient(gradient)
	self.SetPattern(pattern)
Exemple #6
0
    def __init__(self, master=None, **kw):
        apply(PatternFrame.__init__, (self, master), kw)

        gradient = CreateSimpleGradient(StandardColors.white,
                                        StandardColors.black)
        frame = Frame(self)
        frame.pack(side = TOP, fill = X)
        self.var_gradient_type = IntVar(self)
        for value, bitmap in [(0, 'linear'), (1, 'conical'), (2, 'radial')]:
            bitmap = getattr(pixmaps, 'gradient_' + bitmap)
            button = make_button(frame, bitmap = bitmap, value = value,
                                 variable = self.var_gradient_type,
                                 command = self.choose_type)
            button.pack(side = LEFT, fill = X, expand = 1)

        frame = Frame(self)
        frame.pack(side = TOP, expand = 1, fill = X)
        self.colors = [None, None]
        self.colors[0] = ColorButton(frame, height = 1,
                                     color = gradient.StartColor(),
                                     command = self.set_color, args = 0)
        self.colors[0].pack(side = LEFT, fill = X, expand = 1)
        self.colors[1] =  ColorButton(frame, height = 1,
                                      color = gradient.EndColor(),
                                      command = self.set_color, args = 1)
        self.colors[1].pack(side = LEFT, fill = X, expand = 1)

        self.var_border = DoubleVar(self)
        self.var_border.set(0.0)
        frame = Frame(self)
        frame.pack(side = TOP, fill = X, expand = 1)
        label = Label(frame, text = _("Border"))
        label.pack(side = LEFT, expand = 1, anchor = E)
        entry = MyEntry(frame, textvariable = self.var_border, width = 4,
                        justify = RIGHT, command = self.set_border)
        entry.pack(side = LEFT, expand = 1, fill = X)
        scroll = MiniScroller(frame, variable = self.var_border,
                              min = 0.0, max = 100.0, step = 1.0,
                              command = self.set_border)
        scroll.pack(side = LEFT, fill = Y)

        button = UpdatedButton(self, text = _("Edit Gradient"),
                               command = self.edit_gradient)
        button.pack(side = TOP, fill = X)

        pattern = LinearGradient(gradient)
        self.SetPattern(pattern)
Exemple #7
0
    def build_dlg(self):
	top = self.top

	self.var_style_name = StringVar(top)
	entry_name = MyEntry(top, textvariable = self.var_style_name,
					command = self.ok, width = 15)
	entry_name.pack(side = TOP, fill = X)

	properties = self.object.Properties()
	self.flags = {}
	for prop in property_names:
	    type = property_types[prop]
	    if type == FillProperty:
		state = self.object.has_fill and NORMAL or DISABLED
	    elif type == LineProperty:
		state = self.object.has_line and NORMAL or DISABLED
	    elif type == FontProperty:
		state = self.object.has_font and NORMAL or DISABLED
	    else:
		# unknown property type!
		continue
	    long, short = property_titles[prop]
	    self.flags[prop] = var = IntVar(top)
	    var.set(state == NORMAL)
	    radio = Checkbutton(top, text = long, state = state,
				variable = var)
	    radio.pack(side = TOP, anchor = W)

	but_frame = Frame(top)
	but_frame.pack(side = TOP, fill = BOTH, expand = 1)

	button = Button(but_frame, text = _("OK"), command = self.ok)
	button.pack(side = LEFT, expand = 1)
	button = Button(but_frame, text = _("Cancel"), command = self.cancel)
	button.pack(side = RIGHT, expand = 1)

	entry_name.focus()
Exemple #8
0
    def __init__(self, master=None, **kw):
	apply(PatternFrame.__init__, (self, master), kw)

	frame = Frame(self)
	frame.pack(side = TOP, fill = X, expand = 1)
	self.colors = [None, None]
	self.colors[0] = ColorButton(frame, height = 1,
				     command = self.set_color, args = 0)
	self.colors[0].pack(side = LEFT, fill = X, expand = 1)
	self.colors[1] = ColorButton(frame, height = 1,
				     command = self.set_color, args = 1)
	self.colors[1].pack(side = LEFT, fill = X, expand = 1)

	var_spacing_number = DoubleVar(self)
	var_unit = StringVar(self)
	self.var_spacing = LengthVar(1.0, config.preferences.default_unit,
                                     var_spacing_number, var_unit,
                                     command = self.set_spacing)
	width_frame = Frame(self)
	width_frame.pack(side = TOP, fill = X, expand = 1)
	#label = Label(width_frame, text = 'Spacing')
	#label.pack(side = LEFT, expand = 1, anchor = E)
	entry = MyEntry(width_frame, textvariable = var_spacing_number,
			justify = RIGHT, width = 6,
			command = self.var_spacing.UpdateNumber)
	entry.pack(side = LEFT, expand = 1, fill = X)
	scroll = MiniScroller(width_frame, variable = var_spacing_number,
			      min = 0.0, max = None, step = 1.0,
			      command = self.var_spacing.UpdateNumber)
	scroll.pack(side = LEFT, fill = Y)
	optmenu = create_unit_menu(width_frame, self.var_spacing.UpdateUnit,
				   variable = var_unit,
				   indicatoron = 0, width = 3)
	optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W)

	self.SetPattern(HatchingPattern(StandardColors.red))
Exemple #9
0
    def __init__(self, master=None, **kw):
        apply(PatternFrame.__init__, (self, master), kw)

        frame = Frame(self)
        frame.pack(side = TOP, fill = X, expand = 1)
        self.colors = [None, None]
        self.colors[0] = ColorButton(frame, height = 1,
                                     command = self.set_color, args = 0)
        self.colors[0].pack(side = LEFT, fill = X, expand = 1)
        self.colors[1] = ColorButton(frame, height = 1,
                                     command = self.set_color, args = 1)
        self.colors[1].pack(side = LEFT, fill = X, expand = 1)

        var_spacing_number = DoubleVar(self)
        var_unit = StringVar(self)
        self.var_spacing = LengthVar(1.0, config.preferences.default_unit,
                                     var_spacing_number, var_unit,
                                     command = self.set_spacing)
        width_frame = Frame(self)
        width_frame.pack(side = TOP, fill = X, expand = 1)
        #label = Label(width_frame, text = 'Spacing')
        #label.pack(side = LEFT, expand = 1, anchor = E)
        entry = MyEntry(width_frame, textvariable = var_spacing_number,
                        justify = RIGHT, width = 6,
                        command = self.var_spacing.UpdateNumber)
        entry.pack(side = LEFT, expand = 1, fill = X)
        scroll = MiniScroller(width_frame, variable = var_spacing_number,
                              min = 0.0, max = None, step = 1.0,
                              command = self.var_spacing.UpdateNumber)
        scroll.pack(side = LEFT, fill = Y)
        optmenu = create_unit_menu(width_frame, self.var_spacing.UpdateUnit,
                                   variable = var_unit,
                                   indicatoron = 0, width = 3)
        optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W)

        self.SetPattern(HatchingPattern(StandardColors.red))
Exemple #10
0
    def build_dlg(self):
        top = self.top

        self.view = SketchView(top,
                               self.document,
                               width=200,
                               height=200,
                               background='white')
        self.view.pack(side=LEFT, fill=BOTH, expand=1)

        self.opt_format = MyOptionMenu2(top, bitmap_types)
        self.opt_format.pack(side=TOP)

        frame = Frame(top)
        frame.pack(side=TOP, expand=1, fill=X)
        label = Label(frame, text='Resolution')
        label.pack(side=LEFT)
        entry = MyEntry(frame, width=4)
        entry.pack(side=LEFT)
        label = Label(frame, text='dpi')
        label.pack(side=LEFT)

        frame = Frame(top)
        frame.pack(side=TOP, expand=1, fill=X)
        label = Label(frame, text='Size')
        label.pack(side=LEFT)
        entry = MyEntry(frame, width=4)
        entry.pack(side=LEFT)
        label = Label(frame, text='x')
        label.pack(side=LEFT)
        entry = MyEntry(frame, width=4)
        entry.pack(side=LEFT)
        label = Label(frame, text='pixel')
        label.pack(side=LEFT)

        check = UpdatedCheckbutton(top, text='antialiasing')
        check.pack(side=TOP)

        frame = Frame(top)
        frame.pack(side=TOP)
        button = UpdatedButton(frame, text='Export')
        button.pack(side=LEFT)
        button = UpdatedButton(frame, text='Close', command=self.close_dlg)
        button.pack(side=LEFT)
Exemple #11
0
    def build_dlg(self):
	top = self.top

	self.view = SketchView(top, self.document, width = 200, height = 200,
			       background = 'white')
	self.view.pack(side = LEFT, fill = BOTH, expand = 1)

	self.opt_format = MyOptionMenu2(top, bitmap_types)
	self.opt_format.pack(side = TOP)

	frame = Frame(top)
	frame.pack(side = TOP, expand = 1, fill = X)
	label = Label(frame, text = 'Resolution')
	label.pack(side = LEFT)
	entry = MyEntry(frame, width = 4)
	entry.pack(side = LEFT)
	label = Label(frame, text = 'dpi')
	label.pack(side = LEFT)

	frame = Frame(top)
	frame.pack(side = TOP, expand = 1, fill = X)
	label = Label(frame, text = 'Size')
	label.pack(side = LEFT)
	entry = MyEntry(frame, width = 4)
	entry.pack(side = LEFT)
	label = Label(frame, text = 'x')
	label.pack(side = LEFT)
	entry = MyEntry(frame, width = 4)
	entry.pack(side = LEFT)
	label = Label(frame, text = 'pixel')
	label.pack(side = LEFT)

	check = UpdatedCheckbutton(top, text = 'antialiasing')
	check.pack(side = TOP)

	frame = Frame(top)
	frame.pack(side =TOP)
	button = UpdatedButton(frame, text = 'Export')
	button.pack(side = LEFT)
	button = UpdatedButton(frame, text = 'Close', command = self.close_dlg)
	button.pack(side = LEFT)
Exemple #12
0
class BlendPanel(PropertyPanel):

    title = _("Blend")
    def __init__(self, master, main_window, doc):
        PropertyPanel.__init__(self, master, main_window, doc,
                               name = 'blenddlg')

    def build_dlg(self):
        top = self.top

        button_frame = Frame(top)
        button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1)

        self.update_buttons = []
        button = UpdatedButton(top, text = _("Apply"),
                               command = self.apply_blend,
                               sensitivecb = self.doc_can_blend)
        button.pack(in_ = button_frame, side = LEFT, expand = 1, fill = X)
        self.Subscribe(SELECTION, button.Update)

        button = UpdatedButton(top, text = _("Close"),
                               command = self.close_dlg)
        button.pack(in_ = button_frame, side = RIGHT, expand = 1, fill = X)

        steps_frame = Frame(top, relief = GROOVE, bd = 2)
        steps_frame.pack(side = TOP, fill = X, expand = 1)
        label = Label(steps_frame, text = _("Steps"))
        label.pack(side = LEFT, anchor = E)
        self.var_steps = IntVar(top)
        self.var_steps.set(config.preferences.blend_panel_default_steps)
        self.entry = MyEntry(steps_frame, name = 'steps',
                             textvariable = self.var_steps,
                             command = self.apply_blend)
        self.entry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
        scroll = MiniScroller(steps_frame, variable = self.var_steps,
                              min = 2, max = None, step = 1)
        scroll.pack(side = LEFT, fill = Y)

        button = UpdatedButton(top, text = _("Select Start"),
                               sensitivecb = self.can_select,
                               command = self.select_control,
                               args = SelectStart)
        button.pack(side = BOTTOM, fill = X, expand = 1)
        self.Subscribe(SELECTION, button.Update)

        button = UpdatedButton(top, text = _("Select End"),
                               sensitivecb = self.can_select,
                               command = self.select_control,
                               args = SelectEnd)
        button.pack(side = BOTTOM, fill = X, expand = 1)
        self.Subscribe(SELECTION, button.Update)

    def doc_can_blend(self):
        return ((self.document.CanBlend() or self.current_obj_is_blend())
                and self.var_steps.get() >= 2)

    def current_obj_is_blend(self):
        object = self.document.CurrentObject()
        return (object is not None
                and (object.is_BlendInterpolation
                     or (object.is_Blend and object.NumObjects() == 3)))

    def current_object(self):
        # assume current_obj_is_blend() yields true
        object = self.document.CurrentObject()
        if object.is_Blend:
            # XXX reaching into object.objects is ugly
            object = object.objects[1]
        return object

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

    def Update(self):
        if self.current_obj_is_blend():
            steps = self.current_object().Steps()
            self.var_steps.set(steps)
            if self.doc_can_blend():
                self.entry['state'] = NORMAL
            else:
                self.entry['state'] = DISABLED

    def apply_blend(self, *args):
        steps = self.var_steps.get()
        if self.current_obj_is_blend() and steps >= 2:
            doc = self.document
            doc.BeginTransaction(_("Set %d Blend Steps") % steps)
            try:
                try:
                    doc.AddUndo(self.current_object().SetParameters(steps))
                except:
                    doc.AbortTransaction()
            finally:
                doc.EndTransaction()
        else:
            self.document.Blend(steps)

    def can_select(self):
        object = self.document.CurrentObject()
        return (object is not None
                and (object.parent.is_Blend or object.is_Blend))

    def select_control(self, which):
        object = self.document.CurrentObject()
        if object is not None:
            if object.is_Blend:
                # XXX reaching into object.objects is ugly
                if which == SelectStart:
                    child = object.objects[0]
                else:
                    child = object.objects[-1]
                self.document.SelectObject(child)
            elif object.parent.is_Blend:
                object.parent.SelectControl(object, which)
Exemple #13
0
class BlendPanel(PropertyPanel):

    title = _("Blend")
    def __init__(self, master, main_window, doc):
	PropertyPanel.__init__(self, master, main_window, doc,
			       name = 'blenddlg')

    def build_dlg(self):
	top = self.top

	button_frame = Frame(top)
	button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1)

	self.update_buttons = []
	button = UpdatedButton(top, text = _("Apply"),
			       command = self.apply_blend,
			       sensitivecb = self.doc_can_blend)
	button.pack(in_ = button_frame, side = LEFT, expand = 1, fill = X)
	self.Subscribe(SELECTION, button.Update)

	button = UpdatedButton(top, text = _("Close"),
			       command = self.close_dlg)
	button.pack(in_ = button_frame, side = RIGHT, expand = 1, fill = X)

	steps_frame = Frame(top, relief = GROOVE, bd = 2)
	steps_frame.pack(side = TOP, fill = X, expand = 1)
	label = Label(steps_frame, text = _("Steps"))
	label.pack(side = LEFT, anchor = E)
	self.var_steps = IntVar(top)
	self.var_steps.set(config.preferences.blend_panel_default_steps)
	self.entry = MyEntry(steps_frame, name = 'steps',
                             textvariable = self.var_steps,
			     command = self.apply_blend)
	self.entry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
	scroll = MiniScroller(steps_frame, variable = self.var_steps,
			      min = 2, max = None, step = 1)
	scroll.pack(side = LEFT, fill = Y)

	button = UpdatedButton(top, text = _("Select Start"),
			       sensitivecb = self.can_select,
			       command = self.select_control,
			       args = SelectStart)
	button.pack(side = BOTTOM, fill = X, expand = 1)
	self.Subscribe(SELECTION, button.Update)

	button = UpdatedButton(top, text = _("Select End"),
			       sensitivecb = self.can_select,
			       command = self.select_control,
			       args = SelectEnd)
	button.pack(side = BOTTOM, fill = X, expand = 1)
	self.Subscribe(SELECTION, button.Update)

    def doc_can_blend(self):
	return ((self.document.CanBlend() or self.current_obj_is_blend())
		and self.var_steps.get() >= 2)

    def current_obj_is_blend(self):
	object = self.document.CurrentObject()
	return (object is not None
                and (object.is_BlendInterpolation
                     or (object.is_Blend and object.NumObjects() == 3)))

    def current_object(self):
	# assume current_obj_is_blend() yields true
	object = self.document.CurrentObject()
        if object.is_Blend:
            # XXX reaching into object.objects is ugly
            object = object.objects[1]
        return object

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

    def Update(self):
	if self.current_obj_is_blend():
            steps = self.current_object().Steps()
	    self.var_steps.set(steps)
	    if self.doc_can_blend():
		self.entry['state'] = NORMAL
	    else:
		self.entry['state'] = DISABLED

    def apply_blend(self, *args):
	steps = self.var_steps.get()
	if self.current_obj_is_blend() and steps >= 2:
	    doc = self.document
	    doc.BeginTransaction(_("Set %d Blend Steps") % steps)
	    try:
		try:
		    doc.AddUndo(self.current_object().SetParameters(steps))
		except:
		    doc.AbortTransaction()
	    finally:
		doc.EndTransaction()
	else:
	    self.document.Blend(steps)

    def can_select(self):
	object = self.document.CurrentObject()
	return (object is not None
                and (object.parent.is_Blend or object.is_Blend))

    def select_control(self, which):
	object = self.document.CurrentObject()
	if object is not None:
            if object.is_Blend:
                # XXX reaching into object.objects is ugly
                if which == SelectStart:
                    child = object.objects[0]
                else:
                    child = object.objects[-1]
                self.document.SelectObject(child)
            elif object.parent.is_Blend:
                object.parent.SelectControl(object, which)
Exemple #14
0
class FontPanel(StylePropertyPanel):

    title = _("Fonts")

    def __init__(self, master, main_window, doc):
        self.family_to_fonts = font.make_family_to_fonts()
        self.families = self.family_to_fonts.keys()
        self.families.sort()
        StylePropertyPanel.__init__(self,
                                    master,
                                    main_window,
                                    doc,
                                    name='fontdlg')
        self.family_list.SetList(self.families)
        index = self.families.index(self.font_family)
        self.family_list.select_set(index)
        self.family_list.yview(index)

    def build_dlg(self):
        top = self.top

        buttons = self.create_std_buttons(top)
        buttons.grid(row=3, column=4, columnspan=2, sticky="news")

        self.sample = FontPreview(top)
        self.sample.grid(column=0, row=3, columnspan=4, sticky="news")
        # XXX: the background color of the sample text should be
        # configurable

        label = Label(top, text=_("Font Family:"), anchor=W)
        label.grid(column=0, row=0, columnspan=2, sticky="ew")
        sb_vert = Scrollbar(top, takefocus=0)
        sb_vert.grid(column=1, row=1, rowspan=2, sticky="news")
        family_list = UpdatedListbox(top, name='families', height=8)
        family_list.grid(column=0, row=1, rowspan=2, sticky="news")
        family_list.Subscribe(SELECTION, self.family_selected)
        sb_vert['command'] = (family_list, 'yview')
        family_list['yscrollcommand'] = (sb_vert, 'set')
        self.family_list = family_list

        label = Label(top, text=_("Font Style:"), anchor=W)
        label.grid(column=2, row=0, sticky="ew")
        sb_vert = Scrollbar(top, takefocus=0)
        sb_vert.grid(column=3, row=1, rowspan=2, sticky="news")
        self.font_attr_list = UpdatedListbox(top,
                                             name='weights',
                                             height=4,
                                             width=15)
        self.font_attr_list.grid(column=2, row=1, rowspan=2, sticky="news")
        self.font_attr_list.Subscribe(SELECTION, self.attr_selected)
        sb_vert['command'] = (self.font_attr_list, 'yview')
        self.font_attr_list['yscrollcommand'] = (sb_vert, 'set')

        label = Label(top, text=_("Size:"), anchor=W)
        label.grid(column=4, row=0, columnspan=2, sticky="ew")

        frame = Frame(top)
        frame.grid(column=4, row=1, columnspan=2, sticky='ew')
        self.var_size = DoubleVar(top)
        scroll = MiniScroller(frame,
                              variable=self.var_size,
                              min=0.0,
                              max=None,
                              step=1)
        scroll.pack(side=RIGHT, fill=Y)
        self.size_entry = MyEntry(frame,
                                  textvariable=self.var_size,
                                  width=4,
                                  command=self.apply_size,
                                  justify=RIGHT)
        self.size_entry.pack(side=LEFT, expand=1, fill=BOTH)

        sb_vert = Scrollbar(top, takefocus=0)
        sb_vert.grid(column=5, row=2, sticky="news")
        self.size_list = UpdatedListbox(top, name='sizes', width=4, height=5)
        self.size_list.grid(column=4, row=2, sticky="news")
        self.size_list.Subscribe(SELECTION, self.size_selected)
        self.size_list.SetList(std_sizes)
        sb_vert['command'] = (self.size_list, 'yview')
        self.size_list['yscrollcommand'] = (sb_vert, 'set')

        top.columnconfigure(0, weight=1000)
        top.columnconfigure(4, weight=1)
        top.rowconfigure(2, weight=1)

    def init_from_doc(self):
        object = self.document.CurrentObject()
        if object is not None and object.is_Text:
            self.update_from_object_cb(object)
        else:
            default = font.GetFont(config.preferences.default_font)
            self.font_family = default.family
            self.font_attr = default.font_attrs
            self.update_from_family()
            self.update_size(properties.default_text_style.font_size)

    def Update(self):
        self.update_from_object_cb(self.document.CurrentObject())

    def update_from_object_cb(self, obj):
        if obj is not None and obj.is_Text:
            font = obj.Font()
            self.font_family = font.family
            self.font_attr = font.font_attrs
            self.update_size(obj.FontSize())
            self.update_from_family()

    def do_apply(self):
        name = self.current_font_ps()
        if not name:
            if __debug__:
                pdebug(None, 'FontPanel.do_apply: no ps name!')
            return
        kw = {
            'font': font.GetFont(name),
            'font_size': self.var_size.get(),
            # set if_type_present to one to make sure that font
            # properties are only set on objects that can have font
            # properties. This is not ideal, but it works and needed
            # only simple changes to base.py
            'if_type_present': 1
        }
        self.set_properties(_("Set Font `%s'") % name, 'font', kw)

    def update_from_family(self, set_view=1):
        index = self.families.index(self.font_family)
        self.family_list.Select(index, set_view)
        fonts = self.family_to_fonts[self.font_family]
        attrs = []
        for name in fonts:
            attrs.append(font.fontmap[name][1])

        attrs.sort()
        self.set_font_attrs(attrs)
        self.update_sample()

    def update_size(self, size):
        self.var_size.set(size)
        if size in std_sizes:
            self.size_list.Select(list(std_sizes).index(size), 1)
        else:
            self.size_list.SelectNone()

    def update_sample(self):
        self.sample.SetFont(self.current_font_ps())

    def set_font_attrs(self, attrs):
        self.font_attrs = attrs
        self.font_attr_list.SetList(attrs)
        self.font_attr = get_from_list(self.font_attr, attrs)
        self.font_attr_list.Select(attrs.index(self.font_attr), 1)

    def current_font_xlfd(self):
        fonts = self.family_to_fonts[self.font_family]
        for name in fonts:
            family, attrs, xlfd_start, encoding = font.fontmap[name]
            if attrs == self.font_attr:
                return font.xlfd_template % (xlfd_start, 24, encoding)
        return ''

    def current_font_ps(self):
        fonts = self.family_to_fonts[self.font_family]
        for name in fonts:
            family, attrs, xlfd_start, encoding = font.fontmap[name]
            if attrs == self.font_attr:
                return name
        return ''

    def family_selected(self):
        sel = self.family_list.curselection()
        if sel:
            index = sel[0]
            self.font_family = self.families[index]
            self.update_from_family(set_view=0)

    def attr_selected(self):
        sel = self.font_attr_list.curselection()
        if sel:
            index = sel[0]
            self.font_attr = self.font_attrs[index]
            self.update_sample()

    def size_selected(self):
        sel = self.size_list.curselection()
        if sel:
            self.var_size.set(self.size_list.get(sel[0]))

    def apply_size(self, *args):
        if self.can_apply():
            size = self.var_size.get()
            self.document.CallObjectMethod(text.CommonText,
                                           _("Set Font Size %.1f") % size,
                                           'SetFontSize', size)

    def save_prefs(self):
        StylePropertyPanel.save_prefs(self)
        config.preferences.sample_text = self.sample.Text()
Exemple #15
0
class LayoutPanel(SketchPanel):

    title = _("Layout")
    class_name = 'SKLayout'
    receivers = SketchPanel.receivers[:]

    def __init__(self, master, main_window, doc):
        SketchPanel.__init__(self, master, main_window, doc,
                             name = 'layoutdlg')

    def build_dlg(self):
        top = self.top

        format_frame = Frame(top)
        format_frame.pack(side = TOP, expand = 1, fill = X,
                          padx = 4, pady = 4)
        format_label = Label(format_frame, text = _("Paper format:"))
        format_label.pack(side = LEFT, expand = 1, fill = X)

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

        orientation_frame = Frame(top)
        orientation_frame.pack(side = TOP, expand = 1, fill = X)
        self.var_orientation = IntVar(top)
        radio = UpdatedRadiobutton(orientation_frame, text = _("Portrait"),
                                   variable = self.var_orientation,
                                   value = Portrait,
                                   command = self.choose_orientation)
        radio.pack(side = LEFT, expand = 1, fill = X)
        radio = UpdatedRadiobutton(orientation_frame, text = _("Landscape"),
                                   variable = self.var_orientation,
                                   value = Landscape,
                                   command = self.choose_orientation)
        radio.pack(side = RIGHT, expand = 1, fill = X)

        size_frame = Frame(top)
        size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4)
        var_width_number = DoubleVar(top)
        var_height_number = DoubleVar(top)
        var_width_unit = StringVar(top)
        var_height_unit = StringVar(top)
        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)
        label = Label(size_frame, text = _("Page size:"))
        label.pack(side = TOP, anchor = W)
        label = Label(size_frame, text = _("Width"))
        label.pack(side = LEFT, anchor = E)
        self.widthentry = MyEntry(size_frame, textvariable = var_width_number,
                                  command = self.var_width.UpdateNumber,
                                  width = 6)
        self.widthentry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
        label = Label(size_frame, text = _("Height"))
        label.pack(side = LEFT, anchor = E)
        self.heightentry = MyEntry(size_frame, textvariable =var_height_number,
                                   command = self.var_height.UpdateNumber,
                                   width = 6)
        self.heightentry.pack(side = LEFT, expand = 1, fill = X, anchor = E)

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

        optmenu = create_unit_menu(size_frame, CallBoth,
                                   variable = var_width_unit,
                                   indicatoron = 0, width = 3)
        optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W)



        button_frame = Frame(top)
        button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1,
                          padx = 4, pady = 4)
        button = UpdatedButton(button_frame, text = _("Apply"),
                               command = self.apply_settings)
        button.pack(side = LEFT, expand = 1)
        button = UpdatedButton(button_frame, text = _("Close"),
                               command = self.close_dlg)
        button.pack(side = RIGHT, expand = 1)


    def init_from_doc(self):
        self.Update()

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

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

    receivers.append((LAYOUT, 'Update'))
    def Update(self):
        layout = self.document.Layout()
        formatname = layout.FormatName()
        self.var_orientation.set(layout.Orientation())
        if formatname and formatname != USER_SPECIFIC:
            self.update_size_from_name(formatname)
        else:
            formatname = USER_SPECIFIC
            self.update_size(layout.Width(), layout.Height())
        self.var_format_name.set(formatname)
        self.set_entry_sensitivity()

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

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

    def choose_orientation(self):
        name = self.var_format_name.get()
        if name != USER_SPECIFIC:
            self.update_size_from_name(name)

    def apply_settings(self):
        formatname = self.var_format_name.get()
        if formatname == USER_SPECIFIC:
            layout = PageLayout(width = self.var_width.get(),
                                height = self.var_height.get(),
                                orientation = self.var_orientation.get())
        else:
            layout = PageLayout(formatname,
                                orientation = self.var_orientation.get())
        self.document.SetLayout(layout)
Exemple #16
0
    def build_dlg(self):
        top = self.top

        var_number = DoubleVar(top)
        var_unit = StringVar(top)
        self.var_pos = LengthVar(1.0,
                                 config.preferences.default_unit,
                                 var_number,
                                 var_unit,
                                 command=self.set_pos)
        pos_frame = Frame(top)
        pos_frame.pack(side=TOP, fill=X, expand=0)
        self.var_label = StringVar(top)
        self.var_label.set('X:')
        label = Label(pos_frame, textvariable=self.var_label)
        label.pack(side=LEFT, expand=1, anchor=E)
        entry = MyEntry(pos_frame,
                        textvariable=var_number,
                        justify=RIGHT,
                        width=4,
                        command=self.var_pos.UpdateNumber)
        entry.pack(side=LEFT, expand=1, fill=X, anchor=E)
        scroll = MiniScroller(pos_frame,
                              variable=var_number,
                              min=0,
                              max=None,
                              step=1)
        scroll.pack(side=LEFT, fill=Y)
        optmenu = create_unit_menu(pos_frame,
                                   self.set_unit,
                                   variable=var_unit,
                                   indicatoron=0,
                                   width=3)
        optmenu.pack(side=LEFT, expand=1, fill=X, anchor=W)

        list_frame = Frame(top)
        list_frame.pack(side=TOP, expand=1, fill=BOTH)

        sb_vert = Scrollbar(list_frame, takefocus=0)
        sb_vert.pack(side=RIGHT, fill=Y)
        guides = UpdatedListbox(list_frame, name='list')
        guides.pack(expand=1, fill=BOTH)
        guides.Subscribe(SELECTION, self.select_guide)
        sb_vert['command'] = (guides, 'yview')
        guides['yscrollcommand'] = (sb_vert, 'set')
        self.guides = guides
        self.selected = None

        frame = Frame(top)
        frame.pack(side=BOTTOM, fill=X)
        button = UpdatedButton(frame,
                               text=_("Add H"),
                               command=self.add_guide,
                               args=1)
        button.pack(side=LEFT)
        button = UpdatedButton(frame,
                               text=_("Add V"),
                               command=self.add_guide,
                               args=0)
        button.pack(side=LEFT)
        button = UpdatedButton(frame, text=_("Delete"), command=self.del_guide)
        button.pack(side=LEFT)
        button = UpdatedButton(frame, text=_("Close"), command=self.close_dlg)
        button.pack(side=RIGHT)
Exemple #17
0
    def build_dlg(self):
	top = self.top

	#
	#	Undo
	#

	undo_frame = self.make_frame()
	label = Label(undo_frame, text = _("# Undo Levels:"), anchor = E)
	label.pack(side = LEFT, expand = 1, fill = X)

	self.var_undo = IntVar(top)
	self.undo_entry = Entry(undo_frame, textvariable = self.var_undo,
				width = 4)
	self.undo_entry.pack(side = LEFT)
	self.var_unlimited = IntVar(top)
	check = UpdatedCheckbutton(undo_frame,
				   text = _("unlimited"),
				   variable = self.var_unlimited,
				   command = self.unlimited_undo)
	check.pack(side = RIGHT, expand = 1, anchor = W)
	limit = preferences.undo_limit
	if limit == None:
	    self.var_undo.set(10)
	    self.var_unlimited.set(1)
	else:
	    if limit < 0:
		limit = 0
	    self.var_undo.set(limit)
	    self.var_unlimited.set(0)


	#
	#	Duplication
	#

	off_frame = self.make_frame()
	var_off_x_number = DoubleVar(top)
	var_off_y_number = DoubleVar(top)
	var_off_x_unit = StringVar(top)
	var_off_y_unit = StringVar(top)
	x, y = preferences.duplicate_offset
        unit = config.preferences.default_unit
	self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit)
	self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit)
	label = Label(off_frame, text = _("Duplication Offset"))
	label.pack(side = TOP, anchor = W)
	label = Label(off_frame, text = _("Hor."))
	label.pack(side = LEFT, expand = 1, anchor = E)
	entry = MyEntry(off_frame, textvariable = var_off_x_number,
			width = 6, command = self.var_off_x.UpdateNumber)
	entry.pack(side = LEFT, fill = X, anchor = E)
	label = Label(off_frame, text = _("Vert."))
	label.pack(side = LEFT, anchor = E)
	entry = MyEntry(off_frame, textvariable = var_off_y_number,
			width = 6, command = self.var_off_y.UpdateNumber)
	entry.pack(side = LEFT, fill = X, anchor = E)

	def CallBoth(arg, x = self.var_off_x, y = self.var_off_y):
	    x.UpdateUnit(arg)
	    y.UpdateUnit(arg)

	optmenu = create_unit_menu(off_frame, CallBoth,
				   variable = var_off_x_unit,
				   indicatoron = 0, width = 3)
	optmenu.pack(side = LEFT, expand = 1, anchor = W)

        #
        #       Default Unit
        #

        self.default_unit = config.preferences.default_unit
        frame = self.make_frame()
        label = Label(frame, text = _("Default Unit"))
        label.pack(side = LEFT, expand = 1)
        menu = create_unit_menu(frame, self.set_unit, indicatoron = 0,
                                width = 3, text = self.default_unit)
        menu.pack(side = RIGHT, expand = 1)


	#
	#	Gradient Patterns
	#

	#self.var_steps = IntVar(top)
	#self.var_steps.set(preferences.gradient_steps)
	#frame = self.make_frame()
	#label = Label(frame, text = 'Gradient Steps')


	#
	#	Standard Buttons (OK, Cancel)
	#

	but_frame = Frame(top)
	but_frame.pack(side = BOTTOM, fill = BOTH, expand = 1,
		       padx = 4, pady = 4)
	button = UpdatedButton(but_frame, text = _("OK"), command = self.ok)
	button.pack(side = LEFT, expand = 1)
	button = UpdatedButton(but_frame, text = _("Cancel"),
			       command = self.close_dlg)
	button.pack(side = RIGHT, expand = 1)
Exemple #18
0
class LayoutPanel(SketchPanel):

    title = _("Layout")
    class_name = 'SKLayout'
    receivers = SketchPanel.receivers[:]

    def __init__(self, master, main_window, doc):
	SketchPanel.__init__(self, master, main_window, doc,
			     name = 'layoutdlg')

    def build_dlg(self):
	top = self.top

	format_frame = Frame(top)
	format_frame.pack(side = TOP, expand = 1, fill = X,
			  padx = 4, pady = 4)
	format_label = Label(format_frame, text = _("Paper format:"))
	format_label.pack(side = LEFT, expand = 1, fill = X)

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

	orientation_frame = Frame(top)
	orientation_frame.pack(side = TOP, expand = 1, fill = X)
	self.var_orientation = IntVar(top)
	radio = UpdatedRadiobutton(orientation_frame, text = _("Portrait"),
				   variable = self.var_orientation,
				   value = Portrait,
				   command = self.choose_orientation)
	radio.pack(side = LEFT, expand = 1, fill = X)
	radio = UpdatedRadiobutton(orientation_frame, text = _("Landscape"),
				   variable = self.var_orientation,
				   value = Landscape,
				   command = self.choose_orientation)
	radio.pack(side = RIGHT, expand = 1, fill = X)

	size_frame = Frame(top)
	size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4)
	var_width_number = DoubleVar(top)
	var_height_number = DoubleVar(top)
	var_width_unit = StringVar(top)
	var_height_unit = StringVar(top)
        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)
	label = Label(size_frame, text = _("Page size:"))
	label.pack(side = TOP, anchor = W)
	label = Label(size_frame, text = _("Width"))
	label.pack(side = LEFT, anchor = E)
	self.widthentry = MyEntry(size_frame, textvariable = var_width_number,
				  command = self.var_width.UpdateNumber,
				  width = 6)
	self.widthentry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
	label = Label(size_frame, text = _("Height"))
	label.pack(side = LEFT, anchor = E)
	self.heightentry = MyEntry(size_frame, textvariable =var_height_number,
				   command = self.var_height.UpdateNumber,
				   width = 6)
	self.heightentry.pack(side = LEFT, expand = 1, fill = X, anchor = E)

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

	optmenu = create_unit_menu(size_frame, CallBoth,
				   variable = var_width_unit,
				   indicatoron = 0, width = 3)
	optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W)



	button_frame = Frame(top)
	button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1,
			  padx = 4, pady = 4)
	button = UpdatedButton(button_frame, text = _("Apply"),
			       command = self.apply_settings)
	button.pack(side = LEFT, expand = 1)
	button = UpdatedButton(button_frame, text = _("Close"),
			       command = self.close_dlg)
	button.pack(side = RIGHT, expand = 1)


    def init_from_doc(self):
	self.Update()

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

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

    receivers.append((LAYOUT, 'Update'))
    def Update(self):
	layout = self.document.Layout()
	formatname = layout.FormatName()
	self.var_orientation.set(layout.Orientation())
	if formatname and formatname != USER_SPECIFIC:
	    self.update_size_from_name(formatname)
	else:
	    formatname = USER_SPECIFIC
	    self.update_size(layout.Width(), layout.Height())
	self.var_format_name.set(formatname)
	self.set_entry_sensitivity()

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

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

    def choose_orientation(self):
	name = self.var_format_name.get()
	if name != USER_SPECIFIC:
	    self.update_size_from_name(name)

    def apply_settings(self):
	formatname = self.var_format_name.get()
	if formatname == USER_SPECIFIC:
	    layout = PageLayout(width = self.var_width.get(),
				height = self.var_height.get(),
				orientation = self.var_orientation.get())
	else:
	    layout = PageLayout(formatname,
				orientation = self.var_orientation.get())
	self.document.SetLayout(layout)
Exemple #19
0
    def build_dlg(self):
        top = self.top

        #
        #	Undo
        #

        undo_frame = self.make_frame()
        label = Label(undo_frame, text=_("# Undo Levels:"), anchor=E)
        label.pack(side=LEFT, expand=1, fill=X)

        self.var_undo = IntVar(top)
        self.undo_entry = Entry(undo_frame,
                                textvariable=self.var_undo,
                                width=4)
        self.undo_entry.pack(side=LEFT)
        self.var_unlimited = IntVar(top)
        check = UpdatedCheckbutton(undo_frame,
                                   text=_("unlimited"),
                                   variable=self.var_unlimited,
                                   command=self.unlimited_undo)
        check.pack(side=RIGHT, expand=1, anchor=W)
        limit = preferences.undo_limit
        if limit == None:
            self.var_undo.set(10)
            self.var_unlimited.set(1)
        else:
            if limit < 0:
                limit = 0
            self.var_undo.set(limit)
            self.var_unlimited.set(0)

        #
        #	Duplication
        #

        off_frame = self.make_frame()
        var_off_x_number = DoubleVar(top)
        var_off_y_number = DoubleVar(top)
        var_off_x_unit = StringVar(top)
        var_off_y_unit = StringVar(top)
        x, y = preferences.duplicate_offset
        unit = config.preferences.default_unit
        self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit)
        self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit)
        label = Label(off_frame, text=_("Duplication Offset"))
        label.pack(side=TOP, anchor=W)
        label = Label(off_frame, text=_("Hor."))
        label.pack(side=LEFT, expand=1, anchor=E)
        entry = MyEntry(off_frame,
                        textvariable=var_off_x_number,
                        width=6,
                        command=self.var_off_x.UpdateNumber)
        entry.pack(side=LEFT, fill=X, anchor=E)
        label = Label(off_frame, text=_("Vert."))
        label.pack(side=LEFT, anchor=E)
        entry = MyEntry(off_frame,
                        textvariable=var_off_y_number,
                        width=6,
                        command=self.var_off_y.UpdateNumber)
        entry.pack(side=LEFT, fill=X, anchor=E)

        def CallBoth(arg, x=self.var_off_x, y=self.var_off_y):
            x.UpdateUnit(arg)
            y.UpdateUnit(arg)

        optmenu = create_unit_menu(off_frame,
                                   CallBoth,
                                   variable=var_off_x_unit,
                                   indicatoron=0,
                                   width=3)
        optmenu.pack(side=LEFT, expand=1, anchor=W)

        #
        #       Default Unit
        #

        self.default_unit = config.preferences.default_unit
        frame = self.make_frame()
        label = Label(frame, text=_("Default Unit"))
        label.pack(side=LEFT, expand=1)
        menu = create_unit_menu(frame,
                                self.set_unit,
                                indicatoron=0,
                                width=3,
                                text=self.default_unit)
        menu.pack(side=RIGHT, expand=1)

        #
        #	Gradient Patterns
        #

        #self.var_steps = IntVar(top)
        #self.var_steps.set(preferences.gradient_steps)
        #frame = self.make_frame()
        #label = Label(frame, text = 'Gradient Steps')

        #
        #	Standard Buttons (OK, Cancel)
        #

        but_frame = Frame(top)
        but_frame.pack(side=BOTTOM, fill=BOTH, expand=1, padx=4, pady=4)
        button = UpdatedButton(but_frame, text=_("OK"), command=self.ok)
        button.pack(side=LEFT, expand=1)
        button = UpdatedButton(but_frame,
                               text=_("Cancel"),
                               command=self.close_dlg)
        button.pack(side=RIGHT, expand=1)
Exemple #20
0
class FontPanel(StylePropertyPanel):

    title = _("Fonts")

    def __init__(self, master, main_window, doc):
	self.family_to_fonts = font.make_family_to_fonts()
	self.families = self.family_to_fonts.keys()
	self.families.sort()
	StylePropertyPanel.__init__(self, master, main_window, doc,
                                    name = 'fontdlg')
	self.family_list.SetList(self.families)
	index = self.families.index(self.font_family)
	self.family_list.select_set(index)
	self.family_list.yview(index)

    def build_dlg(self):
	top = self.top

	buttons = self.create_std_buttons(top)
	buttons.grid(row = 3, column = 4, columnspan = 2, sticky = "news")

	self.sample_text = StringVar(top)
	self.sample_text.set(config.preferences.sample_text)
	self.sample = Entry(top, textvariable = self.sample_text,
			    relief = FLAT, bg = top['bg'],
			    width = len(config.preferences.sample_text))
	self.sample.grid(column = 0, row = 3, columnspan = 4, sticky = "news")
	# XXX: the background color of the sample text should be
	# configurable

	label = Label(top, text = _("Font Family:"), anchor = W)
	label.grid(column = 0, row = 0, columnspan = 2, sticky = "ew")
	sb_vert = Scrollbar(top, takefocus = 0)
	sb_vert.grid(column = 1, row = 1, rowspan = 2, sticky = "news")
	family_list = UpdatedListbox(top, name = 'families', height = 8)
	family_list.grid(column = 0, row = 1, rowspan = 2, sticky = "news")
	family_list.Subscribe(SELECTION, self.family_selected)
	sb_vert['command'] = (family_list, 'yview')
	family_list['yscrollcommand'] = (sb_vert, 'set')
	self.family_list = family_list

	label = Label(top, text = _("Font Style:"), anchor = W)
	label.grid(column = 2, row = 0, sticky = "ew")
	sb_vert = Scrollbar(top, takefocus = 0)
	sb_vert.grid(column = 3, row = 1, rowspan = 2, sticky = "news")
	self.font_attr_list = UpdatedListbox(top, name = 'weights', height = 4,
					     width = 15)
	self.font_attr_list.grid(column = 2, row = 1, rowspan = 2,
				 sticky = "news")
	self.font_attr_list.Subscribe(SELECTION, self.attr_selected)
	sb_vert['command'] = (self.font_attr_list, 'yview')
	self.font_attr_list['yscrollcommand'] = (sb_vert, 'set')

	label = Label(top, text = _("Size:"), anchor = W)
	label.grid(column = 4, row = 0, columnspan = 2, sticky = "ew")

	frame = Frame(top)
	frame.grid(column = 4, row = 1, columnspan = 2, sticky = 'ew')
	self.var_size = DoubleVar(top)
	scroll = MiniScroller(frame, variable = self.var_size,
			      min = 0.0, max = None, step = 1)
	scroll.pack(side = RIGHT, fill = Y)
	self.size_entry = MyEntry(frame, textvariable = self.var_size,
				  width = 4, command = self.apply_size,
				  justify = RIGHT)
	self.size_entry.pack(side = LEFT, expand = 1, fill = BOTH)

	sb_vert = Scrollbar(top, takefocus = 0)
	sb_vert.grid(column = 5, row = 2, sticky = "news")
	self.size_list = UpdatedListbox(top, name = 'sizes', width = 4,
					height = 5)
	self.size_list.grid(column = 4, row = 2, sticky = "news")
	self.size_list.Subscribe(SELECTION, self.size_selected)
	self.size_list.SetList(std_sizes)
	sb_vert['command'] = (self.size_list, 'yview')
	self.size_list['yscrollcommand'] = (sb_vert, 'set')

	top.columnconfigure(0, weight = 1000)
	top.columnconfigure(4, weight = 1)
	top.rowconfigure(2, weight = 1)

    def init_from_doc(self):
        object = self.document.CurrentObject()
        if object is not None and object.is_Text:
            self.update_from_object_cb(object)
        else:
            default = font.GetFont(config.preferences.default_font)
            self.font_family = default.family
            self.font_attr = default.font_attrs
            self.update_from_family()
            self.update_size(properties.default_text_style.font_size)
        
    def Update(self):
        self.update_from_object_cb(self.document.CurrentObject())

    def update_from_object_cb(self, obj):
	if obj is not None and obj.is_Text:
	    font = obj.Font()
            self.font_family = font.family
	    self.font_attr = font.font_attrs
            self.update_size(obj.FontSize())
	    self.update_from_family()

    def do_apply(self):
        name = self.current_font_ps()
        if not name:
            if __debug__:
                pdebug(None, 'FontPanel.do_apply: no ps name!')
            return
        kw = {'font': font.GetFont(name),
              'font_size': self.var_size.get(),
              # set if_type_present to one to make sure that font
              # properties are only set on objects that can have font
              # properties. This is not ideal, but it works and needed
              # only simple changes to base.py
              'if_type_present': 1}
        self.set_properties(_("Set Font `%s'") % name, 'font', kw)

    def update_from_family(self, set_view = 1):
	index = self.families.index(self.font_family)
	self.family_list.Select(index, set_view)
	fonts = self.family_to_fonts[self.font_family]
	attrs = []
	for name in fonts:
	    attrs.append(font.fontmap[name][1])

	attrs.sort()
	self.set_font_attrs(attrs)
	self.update_sample()

    def update_size(self, size):
        self.var_size.set(size)
        if size in std_sizes:
            self.size_list.Select(list(std_sizes).index(size), 1)
        else:
            self.size_list.SelectNone()

    def update_sample(self):
	xlfd = self.current_font_xlfd()
	if not xlfd:
	    xlfd = 'fixed'
	self.sample['font'] = xlfd

    def set_font_attrs(self, attrs):
	self.font_attrs = attrs
	self.font_attr_list.SetList(attrs)
	self.font_attr = get_from_list(self.font_attr, attrs)
	self.font_attr_list.Select(attrs.index(self.font_attr), 1)

    def current_font_xlfd(self):
	fonts = self.family_to_fonts[self.font_family]
	for name in fonts:
	    family, attrs, xlfd_start, encoding = font.fontmap[name]
	    if attrs == self.font_attr:
		return font.xlfd_template % (xlfd_start, 24, encoding)
	return ''

    def current_font_ps(self):
	fonts = self.family_to_fonts[self.font_family]
	for name in fonts:
	    family, attrs, xlfd_start, encoding = font.fontmap[name]
	    if attrs == self.font_attr:
		return name
	return ''

    def family_selected(self):
	sel = self.family_list.curselection()
	if sel:
	    index = string.atoi(sel[0])
	    self.font_family = self.families[index]
	    self.update_from_family(set_view = 0)

    def attr_selected(self):
	sel = self.font_attr_list.curselection()
	if sel:
	    index = string.atoi(sel[0])
	    self.font_attr = self.font_attrs[index]
	    self.update_sample()

    def size_selected(self):
	sel = self.size_list.curselection()
	if sel:
	    self.var_size.set(self.size_list.get(sel[0]))

    def apply_size(self, *args):
	if self.can_apply():
	    size = self.var_size.get()
	    self.document.CallObjectMethod(text.CommonText,
					   _("Set Font Size %.1f") % size,
					   'SetFontSize', size)

    def save_prefs(self):
	StylePropertyPanel.save_prefs(self)
	config.preferences.sample_text = self.sample_text.get()