Example #1
0
    def Load(self):
        file = self.file
        funclist = self.get_compiled()
        # binding frequently used functions to local variables speeds up
        # the process considerably...
        readline = file.readline
        tokenize = skread.tokenize_line
        self.document()
        self.layer(_("Layer 1"))
        try:
            self.read_header()
            line = self.readline()
            while line:
                tokens = tokenize(line, 1)
                if len(tokens) > 1:
                    function, rest = tokens
                else:
                    function = tokens[0]
                    rest = ""
                if type(function) == type(0):
                    function = funclist.get(function)
                    if function:
                        function(rest)
                line = self.readline()

        except SketchLoadError, value:
            warn_tb(INTERNAL)
            raise SketchLoadError("%d:%s" % (self.lineno, str(value))), None, sys.exc_traceback
Example #2
0
    def Load(self):
	file = self.file
	if type(file) == StringType:
	    file = open(file, 'r')
	dict = self.get_func_dict()
	from Sketch import skread
	parse = skread.parse_sk_line2
	readline = file.readline
	bezier_load = self.bezier_load
	num = 1
	line = '#'
	if __debug__:
	    import time
	    start_time = time.clock()
	try:
	    line = readline()
	    while line:
		num = num + 1
		if line[0] == 'b' and line[1] in 'sc':
		    line = bezier_load(line)
		    continue
		#parse(line, dict)
                funcname, args, kwargs = parse(line)
                if funcname is not None:
                    function = dict.get(funcname)
                    if function is not None:
                        try:
                            apply(function, args, kwargs)
                        except TypeError:
                            tb = sys.exc_info()[2]
                            try:
                                if tb.tb_next is None:
                                    # the exception was raised by apply
                                    # and not within the function. Try to
                                    # invoke the function with fewer
                                    # arguments
                                    if call_function(function, args, kwargs):
                                        message = _("Omitted some arguments "
                                                    "for function %s")
                                    else:
                                        message = _("Cannot call function %s")
                                    self.add_message(message
                                                     % function.__name__)

                                else:
                                    raise
                            finally:
                                del tb
                    else:
                        self.add_message(_("Unknown function %s") % funcname)
                    
		line = readline()

	except (SketchLoadError, SyntaxError), value:
	    # a loader specific error occurred
            warn_tb(INTERNAL, 'error in line %d', num)
	    if load._dont_handle_exceptions:
		raise
	    else:
		raise SketchLoadError('%d:%s' % (num, value))
Example #3
0
    def Invoke(self, args = ()):
	if type(args) != TupleType:
	    args = (args,)
	try:
	    apply(self.get_method(self.command), self.args + args)
	except:
	    warn_tb(INTERNAL)
Example #4
0
    def Load(self):
        file = self.file
        if type(file) == StringType:
            file = open(file, 'r')
        dict = self.get_func_dict()
        from Sketch import skread
        parse = skread.parse_sk_line2
        readline = file.readline
        bezier_load = self.bezier_load
        num = 1
        line = '#'
        if __debug__:
            import time
            start_time = time.clock()
        try:
            line = readline()
            while line:
                num = num + 1
                if line[0] == 'b' and line[1] in 'sc':
                    line = bezier_load(line)
                    continue
                #parse(line, dict)
                funcname, args, kwargs = parse(line)
                if funcname is not None:
                    function = dict.get(funcname)
                    if function is not None:
                        try:
                            apply(function, args, kwargs)
                        except TypeError:
                            tb = sys.exc_info()[2]
                            try:
                                if tb.tb_next is None:
                                    # the exception was raised by apply
                                    # and not within the function. Try to
                                    # invoke the function with fewer
                                    # arguments
                                    if call_function(function, args, kwargs):
                                        message = _("Omitted some arguments "
                                                    "for function %s")
                                    else:
                                        message = _("Cannot call function %s")
                                    self.add_message(message %
                                                     function.__name__)

                                else:
                                    raise
                            finally:
                                del tb
                    else:
                        self.add_message(_("Unknown function %s") % funcname)

                line = readline()

        except (SketchLoadError, SyntaxError), value:
            # a loader specific error occurred
            warn_tb(INTERNAL, 'error in line %d', num)
            if load._dont_handle_exceptions:
                raise
            else:
                raise SketchLoadError('%d:%s' % (num, value))
Example #5
0
 def Invoke(self, args=()):
     if type(args) != TupleType:
         args = (args, )
     try:
         apply(self.get_method(self.command), self.args + args)
     except:
         warn_tb(INTERNAL)
Example #6
0
    def Load(self):
        file = self.file
        funclist = self.get_compiled()
        # binding frequently used functions to local variables speeds up
        # the process considerably...
        readline = file.readline
        tokenize = skread.tokenize_line
        self.document()
        self.layer(_("Layer 1"))
        try:
            self.read_header()
            line = self.readline()
            while line:
                tokens = tokenize(line, 1)
                if len(tokens) > 1:
                    function, rest = tokens
                else:
                    function = tokens[0]
                    rest = ''
                if type(function) == type(0):
                    function = funclist.get(function)
                    if function:
                        function(rest)
                line = self.readline()

        except SketchLoadError, value:
            warn_tb(INTERNAL)
            raise SketchLoadError('%d:%s' % (self.lineno, str(value))), None,\
                  sys.exc_traceback
Example #7
0
 def _call_cmd(self, *args):
     if self.two:
         try:
             apply(self.issue, ('COMMAND2',) + args)
         except:
             warn_tb(INTERNAL)
     else:
         apply(UpdatedButton._call_cmd, (self,) + args)
Example #8
0
 def _call_cmd(self, *args):
     if self.two:
         try:
             apply(self.issue, ('COMMAND2',) + args)
         except:
             warn_tb(INTERNAL)
     else:
         apply(UpdatedButton._call_cmd, (self,) + args)
Example #9
0
    def do_reload(self):
        index = self.module_list.curselection()
        index = string.atoi(index[0])

        pdebug(None, 'reloading', self.modules[index])
        try:
            reload(self.modules[index][1])
        except:
            warn_tb(INTERNAL)
Example #10
0
    def do_reload(self):
        index = self.module_list.curselection()
        index = string.atoi(index[0])

        pdebug(None, "reloading", self.modules[index])
        try:
            reload(self.modules[index][1])
        except:
            warn_tb(INTERNAL)
Example #11
0
    def Invoke(self, args = ()):
	if type(args) != TupleType:
	    args = (args,)
	try:
	    apply(self.object.document.CallObjectMethod,
		  (self.object_class, self.menu_name, self.command) \
		  + self.args + args)
	except:
	    warn_tb(INTERNAL)
Example #12
0
 def Invoke(self, args=()):
     if type(args) != TupleType:
         args = (args, )
     try:
         apply(self.object.document.CallObjectMethod,
               (self.object_class, self.menu_name, self.command) \
               + self.args + args)
     except:
         warn_tb(INTERNAL)
Example #13
0
    def RebuildMenu(self):
	if self.entries is not None:
	    self.menu.delete(0, END)
	if self.rebuild_func is not None:
	    try:
		self.entries = self.rebuild_func()
	    except:
		warn_tb(INTERNAL, 'Trying to rebuild menu')
	self.__build_menu()
        self.Update()
Example #14
0
    def Blend(self, other, frac1, frac2):
	try:
	    objs = self.objects
	    oobjs = other.objects
	    blended = []
	    for i in range(min(len(objs), len(oobjs))):
		blended.append(Blend(objs[i], oobjs[i], frac1, frac2))
	    return Group(blended)
	except:
	    warn_tb(INTERNAL)
	    raise MismatchError
Example #15
0
def StandardArrows():
    global std_arrows
    if std_arrows is None:
        filename = os.path.join(config.std_res_dir, config.preferences.arrows)
        try:
            std_arrows = read_arrows(filename)
        except:
            warn_tb(USER, _("Error trying to read arrows from %s\n"
                            "Using builtin defaults"), filename)
            std_arrows = []
    return std_arrows
Example #16
0
    def RebuildMenu(self):
        if self.entries is not None:
#        self.menu.delete(0, END)
            self.menu.tk.call(self.menu._w, 'delete', 0, END)
        if self.rebuild_func is not None:
            try:
                self.entries = self.rebuild_func()
            except:
                warn_tb(INTERNAL, 'Trying to rebuild menu')
        self.__build_menu()
        self.Update()
Example #17
0
def StandardArrows():
    global std_arrows
    if std_arrows is None:
	filename = os.path.join(config.std_res_dir, config.preferences.arrows)
	try:
	    std_arrows = read_arrows(filename)
	except:
	    warn_tb(USER, _("Error trying to read arrows from %s\n"
                            "Using builtin defaults"), filename)
	    std_arrows = []
    return std_arrows
Example #18
0
 def Blend(self, other, frac1, frac2):
     try:
         objs = self.objects
         oobjs = other.objects
         blended = []
         for i in range(min(len(objs), len(oobjs))):
             blended.append(Blend(objs[i], oobjs[i], frac1, frac2))
         return Group(blended)
     except:
         warn_tb(INTERNAL)
         raise MismatchError
Example #19
0
 def execute(self, context, *args, **kw):
     document = context.main_window.document
     apply(document.BeginTransaction, args, kw)
     try:
         try:
             kw = self.kwargs
             if kw is None:
                 kw = {}
             apply(self.function, (context, ) + self.args, kw)
         except:
             warn_tb(USER, 'Error in user script "%s"', self.name)
             document.AbortTransaction()
     finally:
         document.EndTransaction()
Example #20
0
def read_palette_file(filename):
    """Read the palette file filename"""
    file = open(filename)
    line = file.readline()
    line = strip(line)
    palette = None
    try:
        if line == magic_rgb_palette:
            palette = ReadRGBPaletteFile(filename)
        elif line == magic_gimp_palette:
            palette = Read_X_RGB_TXT(filename)
    except:
	warn_tb(USER)
    return palette
Example #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
Example #22
0
 def execute(self, context, *args, **kw):
     document = context.main_window.document
     apply(document.BeginTransaction, args, kw)
     try:
         try:
             kw = self.kwargs
             if kw is None:
                 kw = {}
             apply(self.function, (context,) + self.args, kw)
         except:
             warn_tb(USER, 'Error in user script "%s"', self.name)
             document.AbortTransaction()
     finally:
         document.EndTransaction()
Example #23
0
def read_palette_file(filename):
    """Read the palette file filename"""
    file = open(filename)
    line = file.readline()
    line = strip(line)
    palette = None
    try:
        if line == magic_rgb_palette:
            palette = ReadRGBPaletteFile(filename)
        elif line == magic_gimp_palette:
            palette = Read_X_RGB_TXT(filename)
    except:
        warn_tb(USER)
    return palette
Example #24
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
Example #25
0
    def close_dlg(self):
	self.issue(CLOSED, self)
	if self.document:
	    self.unsubscribe_receivers()
	self.document = None
	try:
	    self.main_window.Unsubscribe(DOCUMENT, self.doc_changed)
	except:
	    warn_tb(INTERNAL)
	self.main_window = None
	Publisher.Destroy(self)
	self.save_prefs()
	self.top.destroy()
	self.master = None
	import pax
	pax.unregister_object(self)
Example #26
0
 def close_dlg(self):
     self.issue(CLOSED, self)
     if self.document:
         self.unsubscribe_receivers()
     self.document = None
     try:
         self.main_window.Unsubscribe(DOCUMENT, self.doc_changed)
     except:
         warn_tb(INTERNAL)
     self.main_window = None
     Publisher.Destroy(self)
     self.save_prefs()
     self.top.destroy()
     self.master = None
     import pax
     pax.unregister_object(self)
Example #27
0
 def _tearoff(self, menu, tearoff):
     # tk8 needs this on my machine... (afterstep 1.4)
     # in tk4.2 this wasn't necessary.
     try:
         call = self.menu.tk.call
         # Set the group and transient window properties so that
         # torn-off menus stay on top of the main window. It seems
         # that tk4.2 did this itself, but not tk8.
         call('wm', 'group', tearoff, '.')
         call('wm', 'transient', tearoff, '.')
         # withdraw and deiconify needed for `braindead' Window
         # managers that don't recognize property changes after
         # windows are mapped.
         if config.preferences.menu_tearoff_fix:
             call('wm', 'withdraw', tearoff)
             call('wm', 'deiconify', tearoff)
     except:
         warn_tb(INTERNAL, 'tearoffcommand')
Example #28
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))
Example #29
0
    def _tearoff(self, menu, tearoff):
	# tk8 needs this on my machine... (afterstep 1.4)
	# in tk4.2 this wasn't necessary.
        try:
	    call = self.menu.tk.call
            # Set the group and transient window properties so that
            # torn-off menus stay on top of the main window. It seems
            # that tk4.2 did this itself, but not tk8.
	    call('wm', 'group', tearoff, '.')
	    call('wm', 'transient', tearoff, '.')
	    # withdraw and deiconify needed for `braindead' Window
	    # managers that don't recognize property changes after
	    # windows are mapped.
            if config.preferences.menu_tearoff_fix:
                call('wm', 'withdraw', tearoff)
                call('wm', 'deiconify', tearoff)
	except:
	    warn_tb(INTERNAL, 'tearoffcommand')
Example #30
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))
Example #31
0
def call_function(function, args, kwargs):
    if hasattr(function, 'im_func'):
        args = (function.im_self,) + args
        function = function.im_func
    code = function.func_code
    if code.co_flags & 0x000C:
        # uses *args or **kwargs
        return 0
    args = args[:code.co_argcount]
    argnames = code.co_varnames[:code.co_argcount]
    for key in kwargs.keys():
        if key not in argnames:
            del kwargs[key]
    try:
        apply(function, args, kwargs)
    except:
        warn_tb(INTERNAL, 'Trying to call function %s with reduced arglist',
                function.func_name)
        return 0
    return 1
Example #32
0
    def Load(self):
        try:
            self.document()
            self.layer()

            parser = saxexts.make_parser()
            parser.setDocumentHandler(SVGHandler(self))
            try:
                self.file.seek(0)
                file = self.file
            except:
                file = streamfilter.StringDecode(self.match.string, self.file)
            parser.parseFile(file)

            self.end_all()
            self.object.load_Completed()
            return self.object
        except:
            warn_tb('INTERNAL')
            raise
Example #33
0
def call_function(function, args, kwargs):
    if hasattr(function, 'im_func'):
        args = (function.im_self, ) + args
        function = function.im_func
    code = function.func_code
    if code.co_flags & 0x000C:
        # uses *args or **kwargs
        return 0
    args = args[:code.co_argcount]
    argnames = code.co_varnames[:code.co_argcount]
    for key in kwargs.keys():
        if key not in argnames:
            del kwargs[key]
    try:
        apply(function, args, kwargs)
    except:
        warn_tb(INTERNAL, 'Trying to call function %s with reduced arglist',
                function.func_name)
        return 0
    return 1
Example #34
0
    def Load(self):
        try:
            self.document()
            self.layer()

            parser = saxexts.make_parser()
            parser.setDocumentHandler(SVGHandler(self))
            try:
                self.file.seek(0)
                file = self.file
            except:
                file = streamfilter.StringDecode(self.match.string, self.file)
            parser.parseFile(file)

            self.end_all()
            self.object.load_Completed()
            return self.object
        except:
            warn_tb('INTERNAL')
            raise
Example #35
0
    def Update(self):
	try:
	    for entry in self.entries:
		entry.Update()
	except:
	    warn_tb(INTERNAL, 'Updating menu Entries')
Example #36
0
 def _call_cmd(self, *args):
     try:
         apply(self.issue, (COMMAND,) + args)
     except:
         warn_tb(INTERNAL)
Example #37
0
    def Load(self):
        funclist = self.get_compiled()
        # binding frequently used functions to local variables speeds up
        # the process considerably...
        a = apply
        t = tuple
        DSC = DSC_COMMENT
        MAX = MAX_DATA_TOKEN
        split = string.split
        stack = self.stack
        push = self.stack.append
        unknown_operator = (None, None)

        decoder = streamfilter.StringDecode(self.match.string, self.file)
        self.tokenizer = PSTokenizer(decoder)
        self.tokenizer.ai_pseudo_comments = 1
        self.tokenizer.ai_dsc = 1
        next = self.tokenizer.next

        self.document()

        value = self.read_prolog()

        while 1:
            token, value = next()
            if token <= MAX:
                push(value)
            elif token == DSC:
                if ':' in value:
                    keyword, value = split(value, ':', 1)
                else:
                    keyword = value
                if keyword in ('PageTrailer', 'Trailer'):
                    break
                elif keyword == 'AI5_BeginPalette':
                    self.skip_to_dsc('AI5_EndPalette', 'EndSetup')
                elif keyword == "AI8_BeginBrushPattern":
                    self.skip_to_dsc('AI8_EndBrushPattern', 'EndSetup')

            elif token == END:
                break
            elif token == OPERATOR:
                method, argc = funclist.get(value, unknown_operator)
                #if method is not None:
                #    name = method.__name__
                #else:
                #    name = `method`
                if method is None:
                    del stack[:]
                else:
                    try:
                        if argc:
                            args = t(stack[-argc:])
                            del stack[-argc:]
                            a(method, args)
                        else:
                            method()
                    except:
                        warn_tb(INTERNAL, 'AILoader: error')

        self.end_all()
        self.object.load_Completed()
        for obj in self.guides:
            self.object.guide_layer.Insert(obj, None)

        return self.object
Example #38
0
    def Load(self):
        funclist = self.get_compiled()
        # binding frequently used functions to local variables speeds up
        # the process considerably...
        a = apply
        t = tuple
        DSC = DSC_COMMENT
        MAX = MAX_DATA_TOKEN
        split = string.split
        stack = self.stack
        push = self.stack.append
        unknown_operator = (None, None)

        decoder = streamfilter.StringDecode(self.match.string, self.file)
        self.tokenizer = PSTokenizer(decoder)
        self.tokenizer.ai_pseudo_comments = 1
        self.tokenizer.ai_dsc = 1
        next = self.tokenizer.next

        self.document()

        value = self.read_prolog()

        while 1:
            token, value = next()
            if token <= MAX:
                push(value)
            elif token == DSC:
                if ":" in value:
                    keyword, value = split(value, ":", 1)
                else:
                    keyword = value
                if keyword in ("PageTrailer", "Trailer"):
                    break
                elif keyword == "AI5_BeginPalette":
                    self.skip_to_dsc("AI5_EndPalette", "EndSetup")
                elif keyword == "AI8_BeginBrushPattern":
                    self.skip_to_dsc("AI8_EndBrushPattern", "EndSetup")

            elif token == END:
                break
            elif token == OPERATOR:
                method, argc = funclist.get(value, unknown_operator)
                # if method is not None:
                #    name = method.__name__
                # else:
                #    name = `method`
                if method is None:
                    del stack[:]
                else:
                    try:
                        if argc:
                            args = t(stack[-argc:])
                            del stack[-argc:]
                            a(method, args)
                        else:
                            method()
                    except:
                        warn_tb(INTERNAL, "AILoader: error")

        self.end_all()
        self.object.load_Completed()
        for obj in self.guides:
            self.object.guide_layer.Insert(obj, None)

        return self.object
Example #39
0
                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
        except:
            warn_tb(INTERNAL, 'printing to %s', file)
Example #40
0
                             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
        except:
            warn_tb(INTERNAL, 'printing to %s', file)
Example #41
0
     CreateRGBColor, CreateCMYKColor, MultiGradient, \
     Trafo, Translation, Rotation, Scale, Point, Polar, \
     StandardColors, GetFont, PathText, SimpleText, const, UnionRects, \
     Bezier, Line, load_image, skread

from Sketch.warn import INTERNAL, USER, warn_tb

from Sketch.load import GenericLoader, EmptyCompositeError

from Sketch.Graphics import text, properties

try:
    from xml.sax import saxlib, saxexts
except ImportError:
    warn_tb(
        USER, "The Python xml package has to be installed for the svg "
        "import filter.\n"
        "See the README for more information.")
    raise

# beginning with Python 2.0, the XML modules return Unicode strings,
# while for older versions they're 'normal' 8-bit strings. Provide some
# functions to make this code work with both string types.


def as_latin1(s):
    # convert the string s to iso-latin-1 if it's a unicode string
    encode = getattr(s, "encode", None)
    if encode is not None:
        s = encode("iso-8859-1", "replace")
    return s
Example #42
0
                    else:
                        self.add_message(_("Unknown function %s") % funcname)
                    
		line = readline()

	except (SketchLoadError, SyntaxError), value:
	    # a loader specific error occurred
            warn_tb(INTERNAL, 'error in line %d', num)
	    if load._dont_handle_exceptions:
		raise
	    else:
		raise SketchLoadError('%d:%s' % (num, value))
	except:
	    # An exception was not converted to a SketchLoadError.
	    # This should be considered a bug.
            warn_tb(INTERNAL, 'error in line %d:\n%s', num, `line`)
	    if load._dont_handle_exceptions:
		raise
	    else:
		raise SketchLoadError(_("error %s:%s in line %d:\n%s")
				      % (sys.exc_info()[:2] +(num, `line`)))

	self.end_all()
	if self.page_layout:
	    self.object.load_SetLayout(self.page_layout)
	for style in self.style_dict.values():
	    self.object.load_AddStyle(style)
	self.object.load_Completed()

	self.object.meta.native_format = 1
Example #43
0
     CreateRGBColor, CreateCMYKColor, MultiGradient, \
     Trafo, Translation, Rotation, Scale, Point, Polar, \
     StandardColors, GetFont, PathText, SimpleText, const, UnionRects, \
     Bezier, Line, load_image, skread

from Sketch.warn import INTERNAL, USER, warn_tb

from Sketch.load import GenericLoader, EmptyCompositeError

from Sketch.Graphics import text, properties

try:
    from xml.sax import saxlib, saxexts
except ImportError:
    warn_tb(USER, "The Python xml package has to be installed for the svg "
            "import filter.\n"
            "See the README for more information.")
    raise

# beginning with Python 2.0, the XML modules return Unicode strings,
# while for older versions they're 'normal' 8-bit strings. Provide some
# functions to make this code work with both string types.

def as_latin1(s):
    # convert the string s to iso-latin-1 if it's a unicode string
    encode = getattr(s, "encode", None)
    if encode is not None:
        s = encode("iso-8859-1", "replace")
    return s

Example #44
0
    def _call_cmd(self, *args):
	try:
	    apply(self.issue, (COMMAND,) + args)
	except:
	    warn_tb(INTERNAL)
Example #45
0
 def Update(self):
     try:
         for entry in self.entries:
             entry.Update()
     except:
         warn_tb(INTERNAL, 'Updating menu Entries')