예제 #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
예제 #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))
예제 #3
0
파일: command.py 프로젝트: shumik/skencil-c
    def Invoke(self, args = ()):
	if type(args) != TupleType:
	    args = (args,)
	try:
	    apply(self.get_method(self.command), self.args + args)
	except:
	    warn_tb(INTERNAL)
예제 #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))
예제 #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)
예제 #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
예제 #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)
예제 #8
0
파일: tkext.py 프로젝트: shumik/skencil-c
 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)
예제 #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)
예제 #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)
예제 #11
0
파일: command.py 프로젝트: shumik/skencil-c
    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)
예제 #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)
예제 #13
0
파일: tkext.py 프로젝트: shumik/skencil-c
    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()
예제 #14
0
파일: group.py 프로젝트: shumik/skencil-c
    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
예제 #15
0
파일: arrow.py 프로젝트: veltsov/skencil-tk
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
예제 #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()
예제 #17
0
파일: arrow.py 프로젝트: shumik/skencil-c
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
예제 #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
예제 #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()
예제 #20
0
파일: palette.py 프로젝트: shumik/skencil-c
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
예제 #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
예제 #22
0
파일: script.py 프로젝트: shumik/skencil-c
 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()
예제 #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
예제 #24
0
파일: dashes.py 프로젝트: shumik/skencil-c
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
예제 #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)
예제 #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)
예제 #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')
예제 #28
0
파일: filldlg.py 프로젝트: shumik/skencil-c
    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))
예제 #29
0
파일: tkext.py 프로젝트: shumik/skencil-c
    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')
예제 #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))
예제 #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
예제 #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
예제 #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
예제 #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
예제 #35
0
파일: tkext.py 프로젝트: shumik/skencil-c
    def Update(self):
	try:
	    for entry in self.entries:
		entry.Update()
	except:
	    warn_tb(INTERNAL, 'Updating menu Entries')
예제 #36
0
 def _call_cmd(self, *args):
     try:
         apply(self.issue, (COMMAND,) + args)
     except:
         warn_tb(INTERNAL)
예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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

예제 #44
0
파일: tkext.py 프로젝트: shumik/skencil-c
    def _call_cmd(self, *args):
	try:
	    apply(self.issue, (COMMAND,) + args)
	except:
	    warn_tb(INTERNAL)
예제 #45
0
 def Update(self):
     try:
         for entry in self.entries:
             entry.Update()
     except:
         warn_tb(INTERNAL, 'Updating menu Entries')