def Load(self): file = self.file if type(file) == StringType: file = open(file, 'r') dict = self.get_func_dict() from app 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))
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
def Load(self): try: self.document() self.layer() error_handler = ErrorHandler() entity_resolver = EntityResolver() dtd_handler = DTDHandler() input = open(self.filename, "r") input_source = InputSource() input_source.setByteStream(input) xml_reader = xml.sax.make_parser() xml_reader.setContentHandler(SVGHandler(self)) xml_reader.setErrorHandler(error_handler) xml_reader.setEntityResolver(entity_resolver) xml_reader.setDTDHandler(dtd_handler) xml_reader.setFeature(handler.feature_external_ges, False) xml_reader.parse(input_source) input.close self.end_all() if self.page_layout: self.object.load_SetLayout(self.page_layout) self.object.load_Completed() return self.object except: warn_tb('INTERNAL') raise
def Invoke(self, args=()): if type(args) != TupleType: args = (args, ) try: apply(self.get_method(self.command), self.args + args) except: warn_tb(INTERNAL)
def Invoke(self, args = ()): if type(args) != TupleType: args = (args,) try: apply(self.get_method(self.command), self.args + args) except: warn_tb(INTERNAL)
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)
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)
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)
def load_module_attr(self, attr): try: module = self.load_module() if module is not None: return getattr(module, attr) except: warn_tb(INTERNAL, 'When importing plugin %s', self.module_name) raise SketchError(_("Cannot load plugin %(name)s.%(attr)s") % {'name':self.module_name, 'attr':attr})
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)
def __call__(self, *args, **kw): try: module = self.load_module() if module is not None: return apply(getattr(module, self.class_name), args, kw) except: warn_tb(INTERNAL, 'When analysing plugin %s', self.module_name) raise SketchError('Cannot load filter %(name)s.%(message)s' % {'name':self.module_name, 'message':self.class_name})
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()
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 MaskGroup(blended) except: warn_tb(INTERNAL) raise MismatchError
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
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
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()
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
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()
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)
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')
def run(self,keyword,args): if keyword is None: return unknown_operator=(None, None) funclist=self.funclist if keyword is not None: method, argc=funclist.get(keyword, unknown_operator) if method is not None: try: if len(args): i=0 while i<len(args): apply(method, args[i:argc+i]) i+=argc else: method() except: warn_tb(INTERNAL, 'PLTLoader: error')
def run(self, keyword, args): if keyword is None: return unknown_operator = (None, None) funclist = self.funclist if keyword is not None: method, argc = funclist.get(keyword, unknown_operator) if method is not None: #print method.__name__, args try: if len(args): i = 0 while i < len(args): apply(method, args[i:argc + i]) i += argc else: method() except: warn_tb(INTERNAL, 'PLTLoader: error')
def interpret(self): file = self.file if type(file) == StringType: file = open(file, 'r') file.seek(0) readline = file.readline fileinfo = os.stat(self.filename) totalsize = fileinfo[6] self.parsed = 0 self.parsed_interval = totalsize / 99 + 1 line1, line2 = self.read_record() while line1 or line2: if line1 == '0': if line2 == 'EOF': break elif not self.load_sections(): warn_tb(INTERNAL, _('DXFLoader: error. Non find end of sections')) line1, line2 = self.read_record()
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
def Undo(info): # execute a single undoinfo func = info[0] if type(func) == StringType: text = func func = info[1] args = info[2:] else: args = info[1:] text = None try: redo = apply(func, args) if text is not None and callable(redo[0]): return (text,) + redo else: return redo except: warn(INTERNAL, 'Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s', info, func, args) warn_tb(INTERNAL)
def Undo(info): # execute a single undoinfo func = info[0] if type(func) == StringType: text = func func = info[1] args = info[2:] else: args = info[1:] text = None try: redo = apply(func, args) if text is not None and callable(redo[0]): return (text, ) + redo else: return redo except: warn(INTERNAL, 'Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s', info, func, args) warn_tb(INTERNAL)
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
def read_resource_file(filename, magic, errmsg, functions): file = open(filename, 'r') try: line = file.readline() if line[:len(magic)] != magic: raise SketchError(errmsg % filename) from app.skread import parse_sk_line linenr = 1 while 1: line = file.readline() if not line: break linenr = linenr + 1 try: parse_sk_line(line, functions) except: warn_tb(USER, '%s:%d', filename, linenr) finally: file.close()
def __call__(self, document, filename, file=None, options=None): if options is None: 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: file = open(filename, 'wb') close = 1 else: close = 0 if module is not None: module.save(document, file, filename, options) if close: file.close() if self.format_name == NativeFormat: document.ClearEdited() self.UnloadPlugin()
def __call__(self, document, filename, file = None, options = None): if options is None: 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: file = open(filename, 'wb') close = 1 else: close = 0 if module is not None: module.save(document, file, filename, options) if close: file.close() if self.format_name == NativeFormat: document.ClearEdited() self.UnloadPlugin()
def load_module(self): if self.module is not None: return self.module try: file, filename, desc = imp.find_module(self.module_name, [self.dir]) except: warn_tb(INTERNAL, 'Cannot find plugin module %s', self.module_name) return None try: try: create_packages(self.package) module_name = self.package + '.' + self.module_name self.module = imp.load_module(module_name, file, filename, desc) except: warn_tb(USER, _("Cannot load plugin module %s"), self.module_name) raise finally: if file is not None: file.close() self.module._ = self.nls_function() return self.module
def run(self,keyword, *args): if keyword is None: return return_code = False unknown_operator = (None, None) funclist = self.funclist if keyword is not None: method, argc = funclist.get(keyword, unknown_operator) if method is not None: try: ##print '******', keyword if len(args): i = 0 while i<len(args): return_code = apply(method, args[i:argc+i]) i+=argc else: return_code = method() except: warn_tb(INTERNAL, 'DXFLoader: error') else: self.add_message(_('Not interpreted %s') % keyword) return return_code
def Load(self): file = self.file if type(file) == StringType: file = open(file, 'r') dict = self.get_func_dict() from app import skread parse = skread.parse_sk_line2 readline = file.readline bezier_load = self.bezier_load num = 1 line = '#' fileinfo = os.stat(self.filename) totalsize = fileinfo[6] interval = int((totalsize / 200) / 10) + 1 interval_count = 0 if __debug__: import time start_time = time.clock() try: line = readline() parsed = int(file.tell() * 100 / totalsize) app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) while line: num = num + 1 if line[0] == 'b' and line[1] in 'sc': line = bezier_load(line) continue funcname, args, kwargs = parse(line) if funcname is not None: function = dict.get(funcname) if function is not None: try: if line[:3] == 'txt': args = (readline, ) + args 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() interval_count += 1 if interval_count > interval: interval_count = 0 parsed = int(file.tell() * 100 / totalsize) app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) 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))
def _call_cmd(self, *args): try: apply(self.issue, (COMMAND,) + args) except: warn_tb(INTERNAL)
def Update(self): try: for entry in self.entries: entry.Update() except: warn_tb(INTERNAL, 'Updating menu Entries')
def Load(self): file = self.file if type(file) == StringType: file = open(file, "r") dict = self.get_func_dict() from app import skread parse = skread.parse_sk_line2 readline = file.readline bezier_load = self.bezier_load num = 1 line = "#" fileinfo = os.stat(self.filename) totalsize = fileinfo[6] interval = int((totalsize / 200) / 10) + 1 interval_count = 0 if __debug__: import time start_time = time.clock() try: line = readline() parsed = int(file.tell() * 100 / totalsize) app.updateInfo(inf2="%u" % parsed + "% of file is parsed...", inf3=parsed) 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() interval_count += 1 if interval_count > interval: interval_count = 0 parsed = int(file.tell() * 100 / totalsize) app.updateInfo(inf2="%u" % parsed + "% of file is parsed...", inf3=parsed) 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))
if interval_count>interval: interval_count=0 parsed=int(file.tell()*100/totalsize) app.updateInfo(inf2='%u'%parsed+'% of file is parsed...',inf3=parsed) 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() app.updateInfo(inf2='Pasing is finished',inf3=100) self.object.meta.native_format = 1
def Load(self): # Begin read EPS Binary File Header header = self.match.string[0:32] if header[0] == chr(0xC5): if len(header) < 32: header += self.file.read(32 - len(header)) filetype, startPS, sizePS, startWMF, sizeWMF, \ startTIFF, sizeTIFF, Checksum = unpack(struct_eps_header, header) self.file.seek(startPS) # End read EPS Binary File Header 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
try: module_name = os.path.splitext(os.path.basename(filename))[0] vars = {'_':_} # hack cfg = extract_cfg(filename) exec cfg in config_types, vars infoclass = vars.get('type') if infoclass is None: warn(USER, _("No plugin-type information in %(filename)s"), filename = filename) else: del vars['type'] del vars['_'] info = apply(infoclass, (module_name, dir), vars) info.package = package except: warn_tb(INTERNAL, 'In config file %s', filename) warn(USER, _("can't read configuration information from " "%(filename)s"), filename = filename) def find_export_plugin(name): return export_formats.get(name) def guess_export_plugin(extension): for plugin in export_plugins: if extension in plugin.extensions: return plugin.format_name return ''
def _call_cmd(self, *args): try: apply(self.issue, (COMMAND, ) + args) except: warn_tb(INTERNAL)
if interval_count > interval: interval_count = 0 parsed = int(file.tell() * 100 / totalsize) app.updateInfo(inf2="%u" % parsed + "% of file is parsed...", inf3=parsed) 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() app.updateInfo(inf2="Pasing is finished", inf3=100) self.object.meta.native_format = 1
module_name = os.path.splitext(os.path.basename(filename))[0] vars = {'_': _} # hack cfg = extract_cfg(filename) exec cfg in config_types, vars infoclass = vars.get('type') if infoclass is None: warn(USER, _("No plugin-type information in %(filename)s"), filename=filename) else: del vars['type'] del vars['_'] info = apply(infoclass, (module_name, dir), vars) info.package = package except: warn_tb(INTERNAL, 'In config file %s', filename) warn(USER, _("can't read configuration information from " "%(filename)s"), filename=filename) def find_export_plugin(name): return export_formats.get(name) def guess_export_plugin(extension): for plugin in export_plugins: if extension in plugin.extensions: return plugin.format_name return ''
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