Exemplo n.º 1
0
    def build_dlg(self):
	top = self.top

        label = Label(top, name = 'label',
                      text = _("Please select the object categories whose "
                               "default properties you want to change"))
        label.pack(side = TOP, anchor = W)
        frame = Frame(top)
        frame.pack(side = TOP)
        self.var_graphics = IntVar(top)
        if self.category != 'font':
            self.var_graphics.set(1)
        button = Checkbutton(frame, text = _("Graphics Objects"),
                             state = (self.category == 'font'
                                      and DISABLED or NORMAL),
                             variable = self.var_graphics)
        button.pack(side = TOP, anchor = W)
        self.var_text = IntVar(top)
        if self.category == 'font':
            self.var_text.set(1)
        button = Checkbutton(frame, text = _("Text Objects"),
                             state = (self.category == 'line'
                                      and DISABLED or NORMAL),
                             variable = self.var_text)
        button.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)
Exemplo n.º 2
0
    def build_dlg(self):
        self.var_corners = IntVar(self.top)
        self.var_corners.set(10)
        label = Label(self.top, text=_("Corners"))
        label.grid(column=0, row=0, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_corners)
        entry.grid(column=1, row=0)

        self.var_outer_radius = StringVar(self.top)
        self.var_outer_radius.set("100pt")
        label = Label(self.top, text=_("Outer Radius"))
        label.grid(column=0, row=1, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_outer_radius)
        entry.grid(column=1, row=1)

        self.var_inner_radius = StringVar(self.top)
        self.var_inner_radius.set("75pt")
        label = Label(self.top, text=_("Inner Radius"))
        label.grid(column=0, row=2, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_inner_radius)
        entry.grid(column=1, row=2)

        button = Button(self.top, text=_("OK"), command=self.ok)
        button.grid(column=0, row=3, sticky=W)
        button = Button(self.top, text=_("Cancel"), command=self.cancel)
        button.grid(column=1, row=3, sticky=E)
Exemplo n.º 3
0
def openfiletypes():
    types = [(_("Skencil/Sketch Document"), '.sk')]
    for info in plugins.import_plugins:
	types.append(info.tk_file_type)
    types.append((_("All Files"), '*'))
    types = tuple(types)
    return types
Exemplo n.º 4
0
    def InfoText(self):
	# Return a string describing the selected object(s)
        result = _("No Selection")
	if self.objects:
	    sel_info = self.objects
	    document = sel_info[0][1].document
	    if len(sel_info) == 1:
                path, obj = sel_info[0]
                dict = {'layer': document[path[0]].Name()}
		info = obj.Info()
                if type(info) == TupleType:
                    dict.update(info[1])
                    # the %% is correct here. The result has to be a
                    # %-template itself.
                    text = _("%s on `%%(layer)s'") % info[0]
                else:
                    dict['object'] = info
                    text = _("%(object)s on `%(layer)s'")
                result = text, dict
	    else:
		layer = sel_info[0][0][0]
		if layer == sel_info[-1][0][0]:
		    # a single layer
		    layer_name = document.layers[layer].Name()
		    result = _("%(number)d objects on `%(layer)s'") \
                             % {'number':len(sel_info), 'layer':layer_name}
		else:
		    result = _("%d objects on several layers") % len(sel_info)

        return result
Exemplo n.º 5
0
    def build_dlg(self):
	top = self.top

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

	do_apply = self.do_apply

	frame = Frame(top)
	frame.pack(side = TOP, fill = X, expand = 1, ipady = 2)

	label = Label(frame, text = _("Origin:"), anchor = E)
	label.grid(row = 0, column = 0, sticky = 'E')
	f = Frame(frame)
	self.var_xorig = create_length_entry(top, f, do_apply)
	f.grid(row = 0, column = 1)
	label = Label(frame, text = ',', width = 1)
	label.grid(row = 0, column = 2)
	f = Frame(frame)
	self.var_yorig = create_length_entry(top, f, do_apply)
	f.grid(row = 0, column = 3)

	label = Label(frame, text = _("Widths:"), anchor = E)
	label.grid(row = 1, column = 0, sticky = 'E')
	f = Frame(frame)
	self.var_xwidth = create_length_entry(top, f, do_apply)
	f.grid(row = 1, column = 1)
	label = Label(frame, text = 'x', width = 1)
	label.grid(row = 1, column = 2)
	f = Frame(frame)
	self.var_ywidth = create_length_entry(top, f, do_apply)
	f.grid(row = 1, column = 3)
Exemplo n.º 6
0
    def build_dlg(self):
        self.var_ppi = IntVar(self.top)
        self.var_ppi.set(72)
        label = Label(self.top, text=_("ppi"))
        label.grid(column=0, row=0, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_ppi)
        entry.grid(column=1, row=0)

        self.var_alpha = BooleanVar(self.top)
        self.var_alpha.set(1)
        label = Label(self.top, text=_("w. Transparency"))
        label.grid(column=0, row=1, sticky=E)
        entry = Checkbutton(self.top, variable=self.var_alpha)
        entry.grid(column=1, row=1)

        self.var_use_bbox = BooleanVar(self.top)
        self.var_use_bbox.set(0)
        label = Label(self.top, text=_("use BB information"))
        label.grid(column=0, row=2, sticky=E)
        entry = Checkbutton(self.top, variable=self.var_use_bbox)
        entry.grid(column=1, row=2)


        button = Button(self.top, text=_("OK"), command=self.ok)
        button.grid(column=0, row=3, sticky=W)
        button = Button(self.top, text=_("Cancel"), command=self.cancel)
        button.grid(column=1, row=3, sticky=E)
Exemplo n.º 7
0
    def build_dlg(self):
	top = self.top

	button = UpdatedButton(top, text = _("Close"), name = 'close',
				       command = self.close_dlg)
	button.pack(side = BOTTOM, expand = 0, fill = X)
	button = UpdatedButton(top, text = _("Apply"),
			       command = self.apply_style,
			       sensitivecb = self.can_apply)
	button.pack(side = BOTTOM, expand = 0, fill = X)
	self.Subscribe(SELECTION, button.Update)

	button = UpdatedButton(top, text = _("Delete"),
			       command = self.remove_style,
			       sensitivecb = self.can_remove)
	button.pack(side = BOTTOM, expand = 0, fill = X)

	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)
	styles = UpdatedListbox(list_frame, name = 'list')
	styles.pack(expand = 1, fill = BOTH)
	styles.Subscribe(COMMAND, self.apply_style)
	sb_vert['command'] = (styles, 'yview')
	styles['yscrollcommand'] = (sb_vert, 'set')
	self.styles = styles
Exemplo n.º 8
0
 def CurrentInfoText(self):
     if self.horizontal:
         text = _("Horizontal Guide Line at %(coord)[length]")
         dict = {'coord': self.drag_cur.y}
     else:
         text = _("Vertical Guide Line at %(coord)[length]")
         dict = {'coord': self.drag_cur.x}
     return text, dict
Exemplo n.º 9
0
 def RedoText(self):
     # Return a string to describe the operation that would be redone
     # next, in a format suitable for a menu entry.
     if self.redoinfo:
         redolabel = self.redoinfo[0][0]
         if type(redolabel) == StringType:
             return _("Redo %s") % redolabel
     return _("Redo")
Exemplo n.º 10
0
    def Info(self):
	width, height = self.data.Size()
	x, y = self.trafo.offset()
	if self.IsEmbedded():
	    return _("Embedded Image %(width)d x %(height)d "
		     "at (%(x)d, %(y)d)") % locals()
	else:
	    filename = os.path.basename(self.data.Filename())
	    return _("Linked Image `%(filename)s' %(width)d x %(height)d "
		     "at (%(x)d, %(y)d)") % locals()
Exemplo n.º 11
0
 def CurrentInfoText(self):
     t = self.trafo
     data = {}
     if abs(round(t.m11, 2)) == abs(round(t.m22, 2)):
         text = _("Circle %(radius)[length], center %(center)[position]")
         data['radius'] = t.m11
     else:
         text = _("Ellipse %(size)[size], center %(center)[position]")
         data['size'] = (abs(t.m11), abs(t.m22))
     data['center'] = t.offset()
     return text, data
Exemplo n.º 12
0
    def Info(self):
	trafo = self.trafo
	w = hypot(trafo.m11, trafo.m21)
	h = hypot(trafo.m12, trafo.m22)
	dict = {'center': trafo.offset(), 'radius': w, 'axes': (w, h)}
	if w == h:
	    text = _("Circle radius %(radius)[length], "
                     "center %(center)[position]")
        else:
            text = _("Ellipse axes %(axes)[size], center %(center)[position]")
        return text, dict
Exemplo n.º 13
0
 def insert_file(self, event=None):
     name = askopenfilename(filetypes=[(_("styletext files"), "*.st"), (_("all files"), "*")])
     if name:
         try:
             text, styling = load_text(name)
         except Exception, value:
             self.warn(
                 title=_("Insert File"),
                 message=_("Cannot insert %(filename)s:\n" "%(message)s")
                 % {"filename": ` os.path.split(name)[1] `, "message": value},
             )
Exemplo n.º 14
0
    def PopupContextMenu(self, event):
	self.context_idx = self.x_to_idx(event.x)
	self.context_pos = (event.x - self.orig_x) / float(self.ximage.width)
	if self.context_menu is None:
	    items = [MenuCommand(_("Set Handle Color"), self.set_handle_color,
				 sensitivecb = self.can_set_handle_color),
		     MenuCommand(_("Delete Handle"), self.delete_handle,
				 sensitivecb = self.can_delete_handle),
		     MenuCommand(_("Insert Handle"), self.insert_handle,
				 sensitivecb = self.can_insert_handle)]
	    self.context_menu = UpdatedMenu(self, items)
	self.context_menu.Popup(event.x_root, event.y_root)
Exemplo n.º 15
0
    def select_guide(self, *rest):
	sel = self.guides.curselection()
	if sel:
	    self.selected = atoi(sel[0])
	    pos, horizontal = self.guide_lines[self.selected].Coordinates()
	    self.var_pos.set(pos)
	    if horizontal:
		self.var_label.set(_("Y:"))
	    else:
		self.var_label.set(_("X:"))
	else:
	    self.selected = None
Exemplo n.º 16
0
    def create_std_buttons(self, master):
	frame = Frame(master)

	button = UpdatedButton(frame, text = _("Apply"),
			       command = self.do_apply,
			       sensitivecb = self.can_apply)
	button.pack(side = LEFT, expand = 1, fill = X)
	button = UpdatedButton(frame, text = _("Close"),
			       command = self.close_dlg)
	button.pack(side = RIGHT, expand = 1, fill = X)

	return frame
Exemplo n.º 17
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)
Exemplo n.º 18
0
 def saveas(self, event=None):
     name = asksaveasfilename(filetypes=[(_("styletext files"), "*.st"), (_("all files"), "*")])
     if name:
         text = self.get("1.0", "end")
         styling = self.styling_get("1.0", "end")
         try:
             save_text(name, text, styling)
         except IOError, value:
             self.warn(
                 title=_("Save File"),
                 message=_("Cannot Save %(filename)s:\n" "%(message)s")
                 % {"filename": ` os.path.split(name)[1] `, "message": value},
             )
Exemplo n.º 19
0
def GetStandardPalette():
    palette = read_standard_palette(config.preferences.palette)
    if not palette:
	warn(USER, _("Could not load palette %s; trying mini.spl..."),
	     config.preferences.palette)
	palette = read_standard_palette('mini.spl')
	if not palette:
	    warn(USER,
		_("Could not load palette mini.spl; reverting to black&white"))
	    palette = RGBPalette()
	    for r, g, b, name in _mini_pal:
		palette.AddEntry((r, g, b), name)
    return palette
Exemplo n.º 20
0
def StandardDashes():
    global std_dashes
    if std_dashes is None:
	filename = os.path.join(config.std_res_dir, config.preferences.dashes)
	try:
	    std_dashes = []
	    read_resource_file(filename, '##Sketch Dashes 0',
			       _("%s is not dashes file"),
			       {'dashes': std_dashes.append})
	except:
	    warn_tb(USER, _("Error trying to read dashes from %s\n"
                            "Using builtin defaults"), filename)
	    std_dashes = [(), (5, 5)]
    return std_dashes
Exemplo n.º 21
0
def StandardDashes():
    global std_dashes
    if std_dashes is None:
        filename = os.path.join(config.std_res_dir, config.preferences.dashes)
        try:
            std_dashes = []
            read_resource_file(filename, '##Sketch Dashes 0',
                               _("%s is not dashes file"),
                               {'dashes': std_dashes.append})
        except:
            warn_tb(USER, _("Error trying to read dashes from %s\n"
                            "Using builtin defaults"), filename)
            std_dashes = [(), (5, 5)]
    return std_dashes
Exemplo n.º 22
0
 def insert_file(self, event=None):
     name = askopenfilename( \
         filetypes=[(_("styletext files"), "*.st"), \
                    (_("all files"), "*")])
     if name:
         try:
             text, styling = load_text(name) 
         except Exception, value:
             self.warn( 
                 title = _("Insert File"),
                 message = _("Cannot insert %(filename)s:\n"
                             "%(message)s") \
                 % {'filename':`os.path.split(name)[1]`,
                    'message':value})
Exemplo n.º 23
0
    def do_print(self):
        app = self.main_window.application
        bbox = self.document.BoundingRect(visible = 0, printable = 1)
        if bbox is None:
            app.MessageBox(title = _("Save As PostScript"),
                           message = _("The document doesn't have "
                                       "any printable layers."),
                           icon = "warning")
            return
        try:
            filename = ''
            file = None
            if self.print_dest.get() == 'file':
                # print to file
                filename = self.print_filename.get()
                # use filename as file just in case the user is trying
                # to save into an EPS that is referenced by the
                # document. The psdevice knows how to handle such cases.
                file = filename
                title = os.path.basename(filename)
            else:
                file = os.popen(self.print_command.get(), 'w')
                title = 'sketch'
            try:
                dev = Sketch.PostScriptDevice
                ps_dev = dev(file, as_eps = 1, bounding_box = tuple(bbox),
                             rotate = self.var_rotate.get(),
                             embed_fonts = self.var_embfnt.get(),
                             For = util.get_real_username(),
                             CreationDate = util.current_date(), Title = title,
                             document = self.document)
                self.document.Draw(ps_dev)
                ps_dev.Close()
                if filename:
                    self.document.meta.ps_filename = filename
                    self.document.meta.ps_directory =os.path.split(filename)[0]
            finally:
                # close the file. Check for the close attribute first
                # because file can be either a string or a file object.
                if hasattr(file, "close"):
                    file.close()

        except IOError, value:
            app.MessageBox(title = _("Save As PostScript"),
                           message = _("Cannot save %(filename)s:\n"
                                       "%(message)s") \
                           % {'filename':`os.path.split(filename)[1]`,
                              'message':value[1]},
                           icon = 'warning')
            return
Exemplo n.º 24
0
def GetStandardPalette():
    palette = read_standard_palette(config.preferences.palette)
    if not palette:
        warn(USER, _("Could not load palette %s; trying mini.spl..."),
             config.preferences.palette)
        palette = read_standard_palette('mini.spl')
        if not palette:
            warn(
                USER,
                _("Could not load palette mini.spl; reverting to black&white"))
            palette = RGBPalette()
            for r, g, b, name in _mini_pal:
                palette.AddEntry((r, g, b), name)
    return palette
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
class CurvePanel(CommandPanel):

    title = _("Curve")

    def __init__(self, master, main_window, doc):
        CommandPanel.__init__(self, master, main_window, doc, name='curvedlg')

    def build_dlg(self):
        names = (('ContAngle', 'CloseNodes',
                  'OpenNodes'), ('ContSmooth', 'InsertNodes', 'DeleteNodes'),
                 ('ContSymmetrical', 'SegmentsToLines', 'SegmentsToCurve'))

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

        # XXX This dialog should have its own ObjectCommand objects
        cmds = self.main_window.canvas.commands.PolyBezierEditor
        for i in range(len(names)):
            for j in range(len(names[i])):
                button = CommandButton(frame,
                                       getattr(cmds, names[i][j]),
                                       highlightthickness=0)
                button.grid(column=j, row=i)

        frame = Frame(top)
        frame.pack(side=BOTTOM, expand=0, fill=X)

        button = UpdatedButton(frame, text=_("Close"), command=self.close_dlg)
        button.pack(anchor=CENTER)
Exemplo n.º 27
0
def read_metric(ps_name):
    for afm in ps_to_filename[ps_name]:
        afm = afm + '.afm'
        filename = find_in_path(config.font_path, afm)
        if filename:
            if __debug__:
                import time
                start = time.clock()
            metric = read_afm_file(filename)
            if __debug__:
                pdebug('timing', 'time to read afm %s: %g', afm,
                       time.clock() - start)
            return metric
    else:
        if not _warned_about_afm.get(afm):
            warn(USER,
                 _("I cannot find the metrics for the font %(ps_name)s.\n"
                   "The file %(afm)s is not in the font_path.\n"
                   "I'll use the metrics for %(fallback)s instead."),
                 ps_name = ps_name, afm = afm,
                 fallback = config.preferences.fallback_font)
            _warned_about_afm[afm] = 1
        if ps_name != config.preferences.fallback_font:
            return read_metric(config.preferences.fallback_font)
        else:
            raise SketchError("Can't load metrics for fallback font %s",
                              config.preferences.fallback_font)
Exemplo n.º 28
0
 def __call__(self, document, filename, file=None, options=None):
     poptkey = 'Export.' + self.format_name
     if poptkey not in document.options:
         document.options[poptkey] = self.get_default_options()
     myoptions = document.options[poptkey]
     if options is None:
         if len(self.parameters):
             self.ask_options(myoptions)
     elif len(options):
         myoptions.update(options)
     try:
         module = self.load_module()
     except:
         warn_tb(INTERNAL, 'When importing plugin %s', self.module_name)
         raise SketchError(
             _("Cannot load filter %(name)s") % {'name': self.module_name})
     if file is None and self.preopen_output:
         file = open(filename, 'w')
         close = 1
     else:
         close = 0
     if module is not None:
         module.save(document, file, filename, myoptions)
     if close:
         file.close()
     if self.format_name == NativeFormat:
         document.ClearEdited()
     self.UnloadPlugin()
Exemplo n.º 29
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())
Exemplo n.º 30
0
 def saveas(self, event=None):
     name = asksaveasfilename( \
         filetypes=[(_("styletext files"), "*.st"), \
                    (_("all files"), "*")])
     if name:
         text = self.get('1.0', 'end')
         styling = self.styling_get('1.0', 'end')
         try:
             save_text(name, text, styling)
         except IOError, value:
             self.warn( 
                 title = _("Save File"),
                 message = _("Cannot Save %(filename)s:\n"
                             "%(message)s") \
                 % {'filename':`os.path.split(name)[1]`,
                    'message':value})
Exemplo n.º 31
0
 def ButtonUp(self, p, button, state):
     if self.selection == self.selCenter:
         p = self.constrain_center(p, state)
     SelectAndDrag.DragStop(self, p)
     sel = self.selection
     if sel == self.selCenter:
         self.center = self.drag_cur
         return '', None
     else:
         self.compute_trafo(state)
         trafo = self.trafo
         if self.selection in self.selShear:
             text = _("Shear Objects")
         else:
             text = _("Rotate Objects")
         return text, trafo
Exemplo n.º 32
0
    def build_dlg(self):
        top = self.top

        frame = Frame(top)
        frame.pack(side=BOTTOM, fill=BOTH, expand=1)
        button = Button(frame, text=_("Reverse"), command=self.reverse)
        button.pack(side=LEFT, 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)

        view = GradientView(top, gradient_size[0], gradient_size[1],
                            self.gradient)
        view.pack(side=LEFT)
        self.gradient_view = view
Exemplo n.º 33
0
def read_metric(ps_name):
    for afm in ps_to_filename[ps_name]:
	afm = afm + '.afm'
	filename = find_in_path(config.font_path, afm)
	if filename:
	    if __debug__:
		import time
		start = time.clock()
	    metric = read_afm_file(filename)
	    if __debug__:
		pdebug('timing', 'time to read afm %s: %g', afm,
		       time.clock() - start)
	    return metric
    else:
	if not _warned_about_afm.get(afm):
	    warn(USER,
                 _("I cannot find the metrics for the font %(ps_name)s.\n"
                   "The file %(afm)s is not in the font_path.\n"
                   "I'll use the metrics for %(fallback)s instead."),
		 ps_name = ps_name, afm = afm,
                 fallback = config.preferences.fallback_font)
	    _warned_about_afm[afm] = 1
        if ps_name != config.preferences.fallback_font:
            return read_metric(config.preferences.fallback_font)
        else:
            raise SketchError("Can't load metrics for fallback font %s",
                              config.preferences.fallback_font)
Exemplo n.º 34
0
    def build_dlg(self):
	top = self.top

	frame = Frame(top)
	frame.pack(side = BOTTOM, fill = X)
	button = UpdatedButton(frame, bitmap = pixmaps.LayerNew, name = 'new',
			       command = self.new_layer)
	button.pack(side = LEFT, fill = BOTH, expand = 1)
	button = UpdatedButton(frame, bitmap = pixmaps.LayerUp, name = 'up',
			       command = self.layer_up)
	button.pack(side = LEFT, fill = BOTH, expand = 1)
	button = UpdatedButton(frame, bitmap = pixmaps.LayerDown,
			       name = 'down', command = self.layer_down)
	button.pack(side = LEFT, fill = BOTH, expand = 1)
	button = UpdatedButton(frame, text = _("Close"), name = 'close',
			       command = self.close_dlg)
	button.pack(side = LEFT, fill = BOTH, expand = 1)

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

	sb_vert = Scrollbar(list_frame, takefocus = 0)
	sb_vert.pack(side = RIGHT, fill = Y)

	self.canvas = canvas = Canvas(list_frame)
	canvas.pack(expand = 1, fill = BOTH)

	self.frame = frame = Frame(canvas, name = 'list')
	canvas.create_window(0, 0, window = frame, anchor = NW)
	sb_vert['command'] = (canvas, 'yview')
	canvas['yscrollcommand'] = (sb_vert, 'set')

	self.active_var = IntVar(top)
Exemplo n.º 35
0
def load_drawing_from_file(file, filename = '', doc_class = None):
    # Note: the doc_class argument is only here for plugin interface
    # compatibility with 0.7 (especiall e.g. gziploader)
    line = file.readline()
    # XXX ugly hack for riff-based files, e.g. Corel's CMX. The length
    # might contain newline characters.
    if line[:4] == 'RIFF' and len(line) < 12:
        line = line + file.read(12 - len(line))
    #print line
    for info in plugins.import_plugins:
        match = info.rx_magic.match(line)
        if match:
            loader = info(file, filename, match)
            try:
                if do_profile:
                    import profile
                    warn(INTERNAL, 'profiling...')
                    prof = profile.Profile()
                    prof.runctx('loader.Load()', globals(), locals())
                    prof.dump_stats(os.path.join(info.dir,
                                                 info.module_name + '.prof'))
                    warn(INTERNAL, 'profiling... (done)')
                    doc = loader.object
                else:
                    #t = time.clock()
                    doc = loader.Load()
                    #print 'load in', time.clock() - t, 'sec.'
                messages = loader.Messages()
                if messages:
                    doc.meta.load_messages = messages
                return doc
            finally:
                info.UnloadPlugin()
    else:
        raise SketchLoadError(_("unrecognised file type"))
Exemplo n.º 36
0
    def ButtonUp(self, p, button, state):
	if self.selection == self.selCenter:
	    p = self.constrain_center(p, state)
	SelectAndDrag.DragStop(self, p)
	sel = self.selection
	if sel == self.selCenter:
	    self.center = self.drag_cur
	    return '', None
	else:
            self.compute_trafo(state)
	    trafo = self.trafo
	    if self.selection in self.selShear:
		text = _("Shear Objects")
	    else:
		text = _("Rotate Objects")
	    return text, trafo
Exemplo n.º 37
0
    def InfoText(self):
	# Return a string describing the selected object(s)
	# XXX we shouldn't access document.layers directly
	if self.editor is not None:
	    return self.editor.Info()
	else:
	    return _("No Selection")
Exemplo n.º 38
0
 def InfoText(self):
     # Return a string describing the selected object(s)
     # XXX we shouldn't access document.layers directly
     if self.editor is not None:
         return self.editor.Info()
     else:
         return _("No Selection")
Exemplo n.º 39
0
class CreateStarDlg(SKModal):

    title = _("Create Spiral")

    def build_dlg(self):
        self.var_rotation = IntVar(self.top)
        self.var_rotation.set(4)
        label = Label(self.top, text=_("Rotations"))
        label.grid(column=0, row=0, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_rotation)
        entry.grid(column=1, row=0)

        self.var_radius = StringVar(self.top)
        self.var_radius.set("100pt")
        label = Label(self.top, text=_("Radius"))
        label.grid(column=0, row=1, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_radius)
        entry.grid(column=1, row=1)

        button = Button(self.top, text=_("OK"), command=self.ok)
        button.grid(column=0, row=2, sticky=W)
        button = Button(self.top, text=_("Cancel"), command=self.cancel)
        button.grid(column=1, row=2, sticky=E)

    def ok(self):
        self.close_dlg((self.var_rotation.get(), self.var_radius.get()))
Exemplo n.º 40
0
    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)
Exemplo n.º 41
0
class EditGradientDlg(SKModal):

    title = _("Edit Gradient")

    def __init__(self, master, gradient, **kw):
        self.gradient = gradient
        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=_("Reverse"), command=self.reverse)
        button.pack(side=LEFT, 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)

        view = GradientView(top, gradient_size[0], gradient_size[1],
                            self.gradient)
        view.pack(side=LEFT)
        self.gradient_view = view

    def reverse(self, *args):
        self.gradient_view.reverse()

    def ok(self, *args):
        self.close_dlg(self.gradient_view.GetGradient())
Exemplo n.º 42
0
def load_drawing_from_file(file, filename = '', doc_class = None):
    # Note: the doc_class argument is only here for plugin interface
    # compatibility with 0.7 (especiall e.g. gziploader)
    line = file.readline()
    # XXX ugly hack for riff-based files, e.g. Corel's CMX. The length
    # might contain newline characters.
    if line[:4] == 'RIFF' and len(line) < 12:
        line = line + file.read(12 - len(line))
    #print line
    for info in plugins.import_plugins:
	match = info.rx_magic.match(line)
	if match:
	    loader = info(file, filename, match)
	    try:
		if do_profile:
		    import profile
		    warn(INTERNAL, 'profiling...')
		    prof = profile.Profile()
		    prof.runctx('loader.Load()', globals(), locals())
		    prof.dump_stats(os.path.join(info.dir,
						 info.module_name + '.prof'))
		    warn(INTERNAL, 'profiling... (done)')
		    doc = loader.object
		else:
                    #t = time.clock()
		    doc = loader.Load()
                    #print 'load in', time.clock() - t, 'sec.'
		messages = loader.Messages()
		if messages:
		    doc.meta.load_messages = messages
		return doc
	    finally:
		info.UnloadPlugin()
    else:
	raise SketchLoadError(_("unrecognised file type"))
Exemplo n.º 43
0
class CreateStarDlg(SKModal):

    title = _("Create Star")

    def build_dlg(self):
        self.var_corners = IntVar(self.top)
        self.var_corners.set(10)
        label = Label(self.top, text=_("Corners"))
        label.grid(column=0, row=0, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_corners)
        entry.grid(column=1, row=0)

        self.var_outer_radius = StringVar(self.top)
        self.var_outer_radius.set("100pt")
        label = Label(self.top, text=_("Outer Radius"))
        label.grid(column=0, row=1, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_outer_radius)
        entry.grid(column=1, row=1)

        self.var_inner_radius = StringVar(self.top)
        self.var_inner_radius.set("75pt")
        label = Label(self.top, text=_("Inner Radius"))
        label.grid(column=0, row=2, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_inner_radius)
        entry.grid(column=1, row=2)

        button = Button(self.top, text=_("OK"), command=self.ok)
        button.grid(column=0, row=3, sticky=W)
        button = Button(self.top, text=_("Cancel"), command=self.cancel)
        button.grid(column=1, row=3, sticky=E)

    def ok(self):
        self.close_dlg((self.var_corners.get(),
                        self.var_outer_radius.get(),
                        self.var_inner_radius.get()))
Exemplo n.º 44
0
class CreateRasterParametersDlg(SKModal):
    "Create Tk Dialog to ask for raster parameters."
    title = _("Choose Raster Parameters")

    def build_dlg(self):
        self.var_ppi = IntVar(self.top)
        self.var_ppi.set(72)
        label = Label(self.top, text=_("ppi"))
        label.grid(column=0, row=0, sticky=E)
        entry = Entry(self.top, width=15, textvariable=self.var_ppi)
        entry.grid(column=1, row=0)

        self.var_alpha = BooleanVar(self.top)
        self.var_alpha.set(1)
        label = Label(self.top, text=_("w. Transparency"))
        label.grid(column=0, row=1, sticky=E)
        entry = Checkbutton(self.top, variable=self.var_alpha)
        entry.grid(column=1, row=1)

        self.var_use_bbox = BooleanVar(self.top)
        self.var_use_bbox.set(0)
        label = Label(self.top, text=_("use BB information"))
        label.grid(column=0, row=2, sticky=E)
        entry = Checkbutton(self.top, variable=self.var_use_bbox)
        entry.grid(column=1, row=2)

        button = Button(self.top, text=_("OK"), command=self.ok)
        button.grid(column=0, row=3, sticky=W)
        button = Button(self.top, text=_("Cancel"), command=self.cancel)
        button.grid(column=1, row=3, sticky=E)

    def ok(self):
        self.close_dlg((self.var_ppi.get(), self.var_alpha.get(),
                        self.var_use_bbox.get()))
Exemplo n.º 45
0
    def build_dlg(self):
	top = self.top

	frame = Frame(top)
	frame.pack(side = BOTTOM, fill = BOTH, expand = 1)
	button = Button(frame, text = _("Reverse"), command = self.reverse)
	button.pack(side = LEFT, 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)

	view = GradientView(top, gradient_size[0], gradient_size[1],
			    self.gradient)
	view.pack(side = LEFT)
	self.gradient_view = view
Exemplo n.º 46
0
def _search_dir(dir, recurse, package = 'Sketch.Plugins'):
    try:
	files = os.listdir(dir)
    except os.error, value:
	warn(USER, _("Cannot list directory %(filename)s\n%(message)s"),
	     filename = dir, message = value[1])
	return
Exemplo n.º 47
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)
Exemplo n.º 48
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)
Exemplo n.º 49
0
 def do_apply(self):
     kw = {}
     if self.active_frame:
         kw['fill_pattern'] = self.active_frame.Pattern().Duplicate()
         kw['fill_transform'] = self.var_transform.get()
     else:
         kw['fill_pattern'] = EmptyFillStyle
     self.set_properties(_("Set Fill"), 'fill', kw)
Exemplo n.º 50
0
def load_drawing(filename):
    if type(filename) == StringType:
        try:
            file = open(filename, 'r')
        except IOError, value:
            message = value.strerror
            raise SketchLoadError(_("Cannot open %(filename)s:\n%(message)s")
                                  % locals())
Exemplo n.º 51
0
 def PopupContextMenu(self, event):
     self.context_idx = self.x_to_idx(event.x)
     self.context_pos = (event.x - self.orig_x) / float(self.ximage.width)
     if self.context_menu is None:
         items = [
             MenuCommand(_("Set Handle Color"),
                         self.set_handle_color,
                         sensitivecb=self.can_set_handle_color),
             MenuCommand(_("Delete Handle"),
                         self.delete_handle,
                         sensitivecb=self.can_delete_handle),
             MenuCommand(_("Insert Handle"),
                         self.insert_handle,
                         sensitivecb=self.can_insert_handle)
         ]
         self.context_menu = UpdatedMenu(self, items)
     self.context_menu.Popup(event.x_root, event.y_root)
Exemplo n.º 52
0
 def Load(self):
     self.document()
     self.layer(name=_("WMF objects"))
     self.read_headers()
     self.interpret()
     self.end_all()
     self.object.load_Completed()
     return self.object
Exemplo n.º 53
0
 def update_list(self):
     strings = []
     factor = self.var_pos.Factor()
     unit = self.var_pos.UnitName()
     if unit in ('in', 'cm'):
         prec = 2
     else:
         prec = 1
     for line in self.guide_lines:
         pos, horizontal = line.Coordinates()
         if horizontal:
             format = _("% 6.*f %s    horizontal")
         else:
             format = _("% 6.*f %s    vertical")
         strings.append(format % (prec, pos / factor, unit))
     self.guides.SetList(strings)
     self.select_index(self.selected)
Exemplo n.º 54
0
def read_font_dirs():
    #print 'read_font_dirs'
    if __debug__:
        import time
        start = time.clock()

    rx_sfd = re.compile(r'^.*\.sfd$')
    for directory in config.font_path:
        #print directory
        try:
            filenames = os.listdir(directory)
        except os.error, exc:
            warn(USER, _("Cannot list directory %s:%s\n"
                         "ignoring it in font_path"),
                 directory, str(exc))
            continue
        dirfiles = filter(rx_sfd.match, filenames)
        for filename in dirfiles:
            filename = os.path.join(directory, filename)
            #print filename
            try:
                file = open(filename, 'r')
                line_nr = 0
                for line in file.readlines():
                    line_nr = line_nr + 1
                    line = strip(line)
                    if not line or line[0] == '#':
                        continue
                    info = map(intern, split(line, ','))
                    if len(info) == 6:
                        psname = info[0]
                        fontlist.append(tuple(info[:-1]))
                        _add_ps_filename(psname, info[-1])
                        fontmap[psname] = tuple(info[1:-1])
                    elif len(info) == 2:
                        psname, basename = info
                        _add_ps_filename(psname, basename)
                    else:
                        warn(INTERNAL,'%s:%d: line must have exactly 6 fields',
                             filename, line_nr)
                file.close()
            except IOError, value:
                warn(USER, _("Cannot load sfd file %(filename)s:%(message)s;"
                             "ignoring it"),
                     filename = filename, message = value.strerror)
Exemplo n.º 55
0
 def CurrentInfoText(self):
     t = self.trafo
     data = {}
     if type(t) == TrafoType:
         x = t.m11
         y = t.m22
         #if round(x, 3) == round(y, 3):
         #    text = _("Uniform Scale %(factor)[factor]")
         #    data['factor'] = x
         #else:
         text = _("Scale %(factorx)[factor], %(factory)[factor]")
         data['factorx'] = x
         data['factory'] = y
     else:
         text = _("Move %(x)[length], %(y)[length]")
         data['x'] = t.x
         data['y'] = t.y
     return text, data
Exemplo n.º 56
0
 def load_image(self):
     dir = config.preferences.pattern_dir
     filename = self.main_window.GetOpenImageFilename(no_eps = 1,
                                                      initialdir = dir)
     if not filename:
         return
     try:
         tile = load_image(filename)
     except IOError, value:
         if type(value) == type(()):
             value = value[1]
         basename = os.path.split(filename)[1]
         self.main_window.application.MessageBox(title = _("Load Image"),
                                                 message=_("Cannot load %(filename)s:\n"
                                                           "%(message)s") \
                                                 % {'filename':`basename`,
                                                    'message':value},
                                                 icon = 'warning')
Exemplo n.º 57
0
    def __init__(self, master, main_window, **kw):
        apply(PatternFrame.__init__, (self, master), kw)
        self.main_window = main_window
        button = UpdatedButton(self, text = _("Load Image..."),
                               command = self.load_image)
        button.pack(side = TOP, fill = X)
        button = UpdatedButton(self, text = _("Pick Image..."),
                               command = self.pick_image)
        button.pack(side = TOP, fill = X)

        file = os.path.join(config.std_res_dir, config.preferences.pattern)
        try:
            file = open(file)
            tile = load_image(file)
        except:
            warn_tb(INTERNAL, "Cannot load %s", file)
            return
        self.SetPattern(ImageTilePattern(tile))
Exemplo n.º 58
0
def _search_dir(dir, recurse, package='Sketch.Plugins'):
    try:
        files = os.listdir(dir)
    except os.error, value:
        warn(USER,
             _("Cannot list directory %(filename)s\n%(message)s"),
             filename=dir,
             message=value[1])
        return
Exemplo n.º 59
0
    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)
Exemplo n.º 60
0
 def __init__(self,
              name=_("Guides"),
              visible=1,
              printable=0,
              locked=0,
              outlined=1,
              outline_color=None):
     if outline_color is None:
         outline_color = config.preferences.guide_color
     SpecialLayer.__init__(self, name, visible, 0, locked, 1, outline_color)