def open_callback(self, arg): app.updateInfo(inf1=_("Document parsing"), inf2=_("Start document processing"), inf3=3) filename = arg[0] doc = load.load_drawing(filename) app.updateInfo(inf1=_("Document parsing"), inf2=_("Document has been loaded"), inf3=100) time.sleep(0.1) return doc
def import_callback(self, arg): app.updateInfo(inf1=_("File importing"), inf2=_("Start file parsing"), inf3=3) filename = arg[0] doc = load.load_drawing(filename) app.updateInfo(inf1=_("File importing"), inf2=_("File has been imported"), inf3=100) time.sleep(0.1) return doc
def Load(self): file = self.file fileinfo = os.stat(self.filename) totalsize = fileinfo[6] self.initialize() self.document() self.layer(name=_("EXP_objects")) #Beginning of stitch data file.seek(0) parsed = 0 parsed_interval = totalsize / 99 + 1 flag = UNKNOWN while 1: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) val1 = self.readInt8(file) val2 = self.readInt8(file) #print val1, val2 if val1 is None or val2 is None: flag = END elif val1 == 0x80 and val2 == 0x01: flag = CHANGECOLOR val1 = self.readInt8(file) val2 = self.readInt8(file) elif val1 == 0x80 and val2 > 0x01: flag = JUMP val1 = self.readInt8(file) val2 = self.readInt8(file) else: flag = NORMAL x, y = val1, val2 if val1 > 0x7F: x = -1 * (0x100 - val1) if val2 > 0x7F: y = -1 * (0x100 - val2) if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up() self.needle_down(x, y) #self.bezier() self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope self.jump(x, y) #self.needle_down(x, y) elif flag == END: self.needle_up() break self.end_all() self.object.load_Completed() return self.object
def Load(self): file = self.file fileinfo=os.stat(self.filename) totalsize=fileinfo[6] self.initialize() self.document() self.layer(name=_("EXP_objects")) #Beginning of stitch data file.seek(0) parsed = 0 parsed_interval=totalsize/99+1 flag = UNKNOWN while 1: interval_count=file.tell()/parsed_interval if interval_count > parsed: parsed+=10 # 10% progress app.updateInfo(inf2='%u'%parsed+'% of file is parsed...',inf3=parsed) val1 = self.readInt8(file) val2 = self.readInt8(file) #print val1, val2 if val1 is None or val2 is None: flag = END elif val1 == 0x80 and val2 == 0x01: flag = CHANGECOLOR val1 = self.readInt8(file) val2 = self.readInt8(file) elif val1 == 0x80 and val2 > 0x01: flag = JUMP val1 = self.readInt8(file) val2 = self.readInt8(file) else: flag = NORMAL x, y = val1, val2 if val1 > 0x7F: x = -1 * (0x100 - val1) if val2 > 0x7F: y = -1 * (0x100 - val2) if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up() self.needle_down(x, y) #self.bezier() self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope self.jump(x, y) #self.needle_down(x, y) elif flag == END: self.needle_up() break self.end_all() self.object.load_Completed() return self.object
def save(document, file, filename, options={}): app.updateInfo(inf1=_('PDF generation.'), inf2=_('Start document composing'), inf3=3) saver = PDFGenSaver(file, filename, document, options) saver.Save() saver.close() app.updateInfo(inf2=_('Document generation is finished'), inf3=100)
def save_callback(self, arg): app.updateInfo(inf1=_('Document saving/exporting'), inf2=_('Start document processing'), inf3=3) self.SaveToFile(arg[0], arg[1], arg[2], arg[3], arg[4]) app.updateInfo(inf2=_('Finish document processing'), inf3=100) time.sleep(.1) return None
def interpret(self): import shlex def is_number(a): try: i = float(a) except ValueError: return 0 return 1 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] lexer = shlex.shlex(file) lexer.debug = 0 lexer.wordchars = lexer.wordchars + ".-+" lexer.whitespace = lexer.whitespace + ';,' keyword = None args = [] parsed = 0 parsed_interval = totalsize / 99 + 1 while 1: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2='%u' % parsed + _('% of file is parsed...'), inf3=parsed) token = lexer.get_token() if not token: # run last command self.run(keyword, args) # pun up self.run('PU', []) # END INTERPRETATION app.updateInfo(inf2=_('Parsing is finished'), inf3=100) break if keyword and is_number(token): args.append(token) else: self.run(keyword, args) keyword = token[0:2] args = [] if token[2:]: lexer.push_token(token[2:])
def import_callback(self, arg): app.updateInfo(inf1=_('File importing'), inf2=_('Start file parsing'), inf3=3) filename = arg[0] doc = load.load_drawing(filename) app.updateInfo(inf1=_('File importing'), inf2=_('File has been imported'), inf3=100) time.sleep(.1) return doc
def open_callback(self, arg): app.updateInfo(inf1=_('Document parsing'), inf2=_('Start document processing'), inf3=3) filename = arg[0] doc = load.load_drawing(filename) app.updateInfo(inf1=_('Document parsing'), inf2=_('Document has been loaded'), inf3=100) time.sleep(.1) return doc
def interpret(self): import shlex def is_number(a): try: i = float(a) except ValueError: return 0 return 1 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] lexer = shlex.shlex(file) lexer.debug = 0 lexer.wordchars = lexer.wordchars + ".-+" lexer.whitespace = lexer.whitespace + ";," keyword = None args = [] parsed = 0 parsed_interval = totalsize / 99 + 1 while 1: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2="%u" % parsed + _("% of file is parsed..."), inf3=parsed) token = lexer.get_token() if not token: # run last command self.run(keyword, args) # pun up self.run("PU", []) # END INTERPRETATION app.updateInfo(inf2=_("Parsing is finished"), inf3=100) break if keyword and is_number(token): args.append(token) else: self.run(keyword, args) keyword = token[0:2] args = [] if token[2:]: lexer.push_token(token[2:])
def Save(self): self.document.updateActivePage() masters = self.document.getMasterLayers() count = 0 pagenum = len(self.document.pages) interval = int(97 / pagenum) for page in self.document.pages: count += 1 app.updateInfo(inf2=_('Composing page %u of %u') % (count, pagenum), inf3=count * interval) layers = page + masters for layer in layers: if not layer.is_SpecialLayer and layer.Printable(): self.save_objects(layer.GetObjects())
def import_curves(self): objcount=0 objnum=len(self.info.paths_heap) jump=87.0/objnum interval=int((objnum/20)/10)+1 interval_count=0 for obj in self.info.paths_heap: objcount+=1 interval_count+=1 if interval_count>interval: interval_count=0 app.updateInfo(inf2=_("Interpreting object %u of %u")%(objcount,objnum),inf3=10+int(jump*objcount)) if obj==1: self.begin_group() elif obj==0: self.end_group() elif type(obj)==TupleType and obj[0]=='BMP': self.image(obj[1],obj[2]) elif obj.is_Rectangle: self.set_style(obj) [m11,m21,m12,m22,v1,v2]=obj.trafo if len(obj.radiuses): self.rectangle(m11, m21, m12, m22, v1, v2, obj.radiuses[0], obj.radiuses[1]) else: self.rectangle(m11, m21, m12, m22, v1, v2) elif obj.is_Ellipse: ellipse_type=app.conf.const.ArcPieSlice if obj.ellipse_type: ellipse_type=app.conf.const.ArcArc obj.colorIndex=False self.set_style(obj) [m11,m21,m12,m22,v1,v2]=obj.trafo self.ellipse(m11, m21, m12, m22, v1, v2, obj.angles[0], obj.angles[1],ellipse_type) else: self.set_style(obj) object = PolyBezier(paths = tuple(obj.paths), properties = self.get_prop_stack()) self.append_object(object) if obj.outlineIndex: if self.info.outl_data[obj.outlineIndex].spec & 0x10: copy = object.Duplicate() copy.properties.SetProperty(line_width=0) self.append_object(copy) else: if self.info.default_outl_data.spec & 0x10: copy = object.Duplicate() copy.properties.SetProperty(line_width=0) self.append_object(copy)
def save(doc, file, filename, options = {}): app.updateInfo(inf1=_('Postscript generation.'),inf2=_('Start document composing'),inf3=3) bbox = doc.BoundingRect(visible = 0, printable = 1) dev = PostScriptDevice ps_dev = dev(file, as_eps = 1, bounding_box = tuple(bbox), rotate = 0, # page rotate? For = os_utils.get_real_username(), CreationDate = os_utils.current_date(), Title = 'generated by sK1', document = doc) doc.Draw(ps_dev) ps_dev.Close() app.updateInfo(inf2=_('Document generation is finished'),inf3=100)
def save(doc, file, filename, options = {}): app.updateInfo(inf1=_('Postscript generation.'),inf2=_('Start document composing'),inf3=3) bbox = doc.BoundingRect(visible = 0, printable = 1) dev = PostScriptDevice ps_dev = dev(file, as_eps = 1, bounding_box = tuple(bbox), rotate = 0, # page rotate? For = system.get_real_username(), CreationDate = system.current_date(), Title = 'generated by sK1', document = doc) doc.Draw(ps_dev) ps_dev.Close() app.updateInfo(inf2=_('Document generation is finished'),inf3=100)
def Load(self): try: self.file.seek(0) cdr = RiffChunk() cdr.load(self.file.read()) app.updateInfo(inf2=_("Parsing is finished"),inf3=10) self.document() if self.verbosity: text='' if cdr.infocollector.cdr_version>0: text+='CorelDRAW ver.%u'%cdr.infocollector.cdr_version+' \n' text+=' Pages: %u'%(cdr.infocollector.pages-1)+'\n' text+=' Layers: %u'%(cdr.infocollector.layers/cdr.infocollector.pages)+'\n' text+=' Groups: %u'%cdr.infocollector.groups+'\n' text+=' Objects: %u'%cdr.infocollector.objects+'\n' text+=' Bitmaps: %u'%cdr.infocollector.bitmaps+'\n' if cdr.infocollector.compression: text+=' COMPRESSED' sys.stderr.write(text) if cdr.infocollector.cdr_version>6: self.info=cdr.infocollector self.info.loader=self self.info.process_properties() self.import_curves() else: warn(USER, 'File <'+self.filename+ '> contains usupported CorelDRAW ver.%u'%cdr.infocollector.cdr_version+'.0 drawing') self.end_all() self.object.load_Completed() self.object.pages.remove(self.object.pages[-1]) self.object.pages.reverse() self.object.active_page=len(self.object.pages)-1 self.object.setActivePage(0) return self.object except RiffEOF: raise SketchLoadError(_("Unexpected problems in file parsing")) except: import traceback traceback.print_exc() raise
def Load(self): file = self.file fileinfo = os.stat(self.filename) totalsize = fileinfo[6] self.initialize() self.readheader(file) self.document() self.layer(name=_("DST_objects")) parsed = 0 parsed_interval = totalsize / 99 + 1 flag = UNKNOWN while 1: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) data = file.read(3) if len(data) < 3 or flag == 'END': self.needle_up() ## END INTERPRETATION app.updateInfo(inf2=_('Parsing is finished'), inf3=100) break d1, d2, d3 = unpack('BBB', data) x = self.decode_x(d1, d2, d3) y = self.decode_y(d1, d2, d3) #XXX swap coordinate x, y = y, x flag = self.decode_flag(d3) if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up(x, y) self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope self.jump(x, y) self.end_all() self.object.load_Completed() return self.object
def Load(self): file = self.file fileinfo=os.stat(self.filename) totalsize=fileinfo[6] self.initialize() self.readheader(file) self.document() self.layer(name=_("DST_objects")) parsed=0 parsed_interval=totalsize/99+1 flag = UNKNOWN while 1: interval_count=file.tell()/parsed_interval if interval_count > parsed: parsed+=10 # 10% progress app.updateInfo(inf2='%u'%parsed+'% of file is parsed...',inf3=parsed) data = file.read(3) if len(data) < 3 or flag == 'END': self.needle_up() ## END INTERPRETATION app.updateInfo(inf2=_('Parsing is finished'),inf3=100) break d1, d2, d3 = unpack('BBB', data) x = self.decode_x(d1, d2, d3) y = self.decode_y(d1, d2, d3) #XXX swap coordinate x, y = y, x flag = self.decode_flag(d3) if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up(x, y) self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope self.jump(x, y) self.end_all() self.object.load_Completed() return self.object
def load_section(self): return_code = False file = self.file parsed = self.parsed parsed_interval = self.parsed_interval line1, line2 = self.read_record() while line1 or line2: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2 = '%u' % parsed + _('% of file is parsed...'), inf3 = parsed) if line1 == '0' and line2 == 'ENDSEC': return_code = True break elif line1 == '0': self.run(line2) line1, line2 = self.read_record() self.parsed = parsed return return_code
def Load(self): file = self.file fileinfo = os.stat(self.filename) totalsize = fileinfo[6] self.initialize() self.readheader(file) self.scale = .472440944882 self.document() self.layer(name=_("PCS_objects")) parsed = 0 parsed_interval = totalsize / 99 + 1 for i in xrange(self.LSB): interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) data = file.read(9) if len(data) < 9: break val1, val2, val4, val5, val6, val7, val9 = unpack('<BHBBHBB', data) if val9 == 0x03: self.needle_up() self.cur_style.line_pattern = self.palette.next_color(val1 + 1) else: x = val2 y = val6 self.cur_x = self.cur_y = 0 self.needle_down(x, y) self.needle_up() self.end_all() self.object.load_Completed() return self.object
def Load(self): file = self.file fileinfo=os.stat(self.filename) totalsize=fileinfo[6] self.initialize() self.readheader(file) self.scale = .472440944882 self.document() self.layer(name=_("PCS_objects")) parsed = 0 parsed_interval=totalsize/99+1 for i in xrange(self.LSB): interval_count=file.tell()/parsed_interval if interval_count > parsed: parsed+=10 # 10% progress app.updateInfo(inf2='%u'%parsed+'% of file is parsed...',inf3=parsed) data = file.read(9) if len(data) < 9: break val1, val2, val4, val5, val6, val7, val9 = unpack('<BHBBHBB', data) if val9 == 0x03: self.needle_up() self.cur_style.line_pattern = self.palette.next_color(val1+1) else: x = val2 y = val6 self.cur_x = self.cur_y = 0 self.needle_down(x, y) self.needle_up() self.end_all() self.object.load_Completed() return self.object
def save_callback(self, arg): app.updateInfo(inf1=_("Document saving/exporting"), inf2=_("Start document processing"), inf3=3) self.SaveToFile(arg[0], arg[1], arg[2], arg[3], arg[4]) app.updateInfo(inf2=_("Finish document processing"), inf3=100) time.sleep(0.1) return None
def save(document, file, filename, options = {}): app.updateInfo(inf1=_('PDF generation.'),inf2=_('Start document composing'),inf3=3) saver = PDFGenSaver(file, filename, document, options) saver.Save() saver.close() app.updateInfo(inf2=_('Document generation is finished'),inf3=100)
def Load(self): file = self.file fileinfo=os.stat(self.filename) totalsize=fileinfo[6] self.initialize() self.readheader(file) self.cur_style.line_pattern = self.palette.next_color(1) self.document() self.layer(name=_("PES_objects")) #Beginning of stitch data file.seek(self.pecstart + 532) parsed = 0 parsed_interval=totalsize/99+1 while 1: interval_count=file.tell()/parsed_interval if interval_count > parsed: parsed+=10 # 10% progress app.updateInfo(inf2='%u'%parsed+'% of file is parsed...',inf3=parsed) val1 = self.readInt8(file) val2 = self.readInt8(file) if val1 is None or val2 is None: break elif val1 == 255 and val2 == 0: #end of stitches flag = END app.updateInfo(inf2=_('Parsing is finished'),inf3=100) elif val1 == 254 and val2 == 176: # color switch, start a new block flag = CHANGECOLOR nn = self.readInt8(file) else: if val1 & 128 == 128: # 0x80 #this is a jump stitch flag = JUMP x = ((val1 & 15) * 256) + val2 if x & 2048 == 2048: # 0x0800 x= x - 4096 #read next byte for Y value val2 = self.readInt8(file) else: #normal stitch flag = NORMAL x = val1 if x > 63: x = x - 128 if val2 & 128 == 128: # 0x80 #this is a jump stitch flag = JUMP val3 = self.readInt8(file) y = ((val2 & 15) * 256) + val3 if y & 2048 == 2048: # 0x0800 y = y - 4096 else: #normal stitch flag = NORMAL y = val2 if y > 63: y = y - 128 #XXX flip vertical coordinate x, y = x, -y if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up() #self.bezier() self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope #self.jump(x, y) self.needle_down(x, y) elif flag == END: self.needle_up() break self.end_all() self.object.load_Completed() return self.object
def import_curves(self): objcount=0 objnum=len(self.info.paths_heap) jump=87.0/objnum interval=int((objnum/20)/10)+1 interval_count=0 for obj in self.info.paths_heap: objcount+=1 interval_count+=1 if interval_count>interval: interval_count=0 app.updateInfo(inf2=_("Interpreting object %u of %u")%(objcount,objnum),inf3=10+int(jump*objcount)) if obj==1: self.begin_group() elif obj==0: self.end_group() elif type(obj)==TupleType and obj[0]=='BMP': self.image(obj[1],obj[2]) else: style = self.style if obj.colorIndex: if self.info.fill_data.has_key(obj.colorIndex): style.fill_pattern = SolidPattern(self.info.fill_data[obj.colorIndex]) else: style.fill_pattern = EmptyPattern else: style.fill_pattern = EmptyPattern if obj.outlineIndex: if self.info.outl_data.has_key(obj.outlineIndex): if self.info.outl_data[obj.outlineIndex].spec & 0x01: style.line_pattern = EmptyPattern else: style.line_pattern = SolidPattern(self.info.outl_data[obj.outlineIndex].color) if self.info.outl_data[obj.outlineIndex].spec & 0x04: style.line_dashes = self.info.outl_data[obj.outlineIndex].dashes if self.info.outl_data[obj.outlineIndex].spec & 0x20: style.line_width = self.info.outl_data[obj.outlineIndex].width*obj.scale else: style.line_width = self.info.outl_data[obj.outlineIndex].width style.line_cap = self.info.outl_data[obj.outlineIndex].caps + 1 style.line_join = self.info.outl_data[obj.outlineIndex].corner else: style.line_pattern = EmptyPattern else: if self.info.default_outl_data: if self.info.default_outl_data.spec & 0x01: style.line_pattern = EmptyPattern else: style.line_pattern = SolidPattern(self.info.default_outl_data.color) if self.info.default_outl_data.spec & 0x04: style.line_dashes = self.info.default_outl_data.dashes if self.info.default_outl_data.spec & 0x20: style.line_width = self.info.default_outl_data.width*obj.scale else: style.line_width = self.info.default_outl_data.width style.line_cap = self.info.default_outl_data.caps + 1 style.line_join = self.info.default_outl_data.corner else: style.line_pattern = EmptyPattern object = PolyBezier(paths = tuple(obj.paths), properties = self.get_prop_stack()) self.append_object(object) if obj.outlineIndex: if self.info.outl_data[obj.outlineIndex].spec & 0x10: copy = object.Duplicate() copy.properties.SetProperty(line_width=0) self.append_object(copy) else: if self.info.default_outl_data.spec & 0x10: copy = object.Duplicate() copy.properties.SetProperty(line_width=0) self.append_object(copy)
def Load(self): try: self.file.seek(0) cdr = RiffChunk() cdr.load(self.file.read()) app.updateInfo(inf2=_("Parsing is finished"),inf3=10) summary=[ ('CDR version', cdr.infocollector.cdr_version), ('pages', cdr.infocollector.pages-1), ('layers', cdr.infocollector.layers/cdr.infocollector.pages), ('groups', cdr.infocollector.groups), ('objects', cdr.infocollector.objects), ('bitmaps', cdr.infocollector.bitmaps), ] if cdr.infocollector.compression: summary.append(('compression','yes')) else: summary.append(('compression','no')) if self.filename == None: return from xml.sax.saxutils import XMLGenerator try: file = open(self.filename, 'w') except (IOError, os.error), value: import sys sys.stderr('cannot write parsing result into %s: %s'% (`filename`, value[1])) return writer = XMLGenerator(out=file,encoding='utf-8') writer.startDocument() writer.startElement('riffDocument',{}) writer.characters('\n') writer.startElement('docSummary',{}) writer.characters('\n') for key, value in summary: writer.characters('\t') writer.startElement('%s' % key,{}) writer.characters('%s' % `value`) writer.endElement('%s' % key) writer.characters('\n') writer.endElement('docSummary') writer.characters('\n') writer.startElement('docStructure',{}) writer.characters('\n') if cdr.infocollector.cdr_version>6: self.info=cdr.infocollector self.info.loader=self self.info.process_properties() self.import_curves(writer) else: writer.characters('\t') writer.startElement('info',{}) value='Parsed file contains usupported CorelDRAW ver.%u'%cdr.infocollector.cdr_version+'.0 drawing' writer.characters('%s' % `value`) writer.endElement('info') writer.characters('\n')
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))
def Load(self): file = self.file fileinfo = os.stat(self.filename) totalsize = fileinfo[6] self.initialize() self.readheader(file) self.cur_style.line_pattern = self.palette.next_color(1) self.document() self.layer(name=_("PES_objects")) #Beginning of stitch data file.seek(self.pecstart + 532) parsed = 0 parsed_interval = totalsize / 99 + 1 while 1: interval_count = file.tell() / parsed_interval if interval_count > parsed: parsed += 10 # 10% progress app.updateInfo(inf2='%u' % parsed + '% of file is parsed...', inf3=parsed) val1 = self.readInt8(file) val2 = self.readInt8(file) if val1 is None or val2 is None: break elif val1 == 255 and val2 == 0: #end of stitches flag = END app.updateInfo(inf2=_('Parsing is finished'), inf3=100) elif val1 == 254 and val2 == 176: # color switch, start a new block flag = CHANGECOLOR nn = self.readInt8(file) else: if val1 & 128 == 128: # 0x80 #this is a jump stitch flag = JUMP x = ((val1 & 15) * 256) + val2 if x & 2048 == 2048: # 0x0800 x = x - 4096 #read next byte for Y value val2 = self.readInt8(file) else: #normal stitch flag = NORMAL x = val1 if x > 63: x = x - 128 if val2 & 128 == 128: # 0x80 #this is a jump stitch flag = JUMP val3 = self.readInt8(file) y = ((val2 & 15) * 256) + val3 if y & 2048 == 2048: # 0x0800 y = y - 4096 else: #normal stitch flag = NORMAL y = val2 if y > 63: y = y - 128 #XXX flip vertical coordinate x, y = x, -y if flag == NORMAL: self.needle_down(x, y) elif flag == CHANGECOLOR: self.needle_up() #self.bezier() self.cur_style.line_pattern = self.palette.next_color() elif flag == JUMP: #self.bezier() # cut the rope #self.jump(x, y) self.needle_down(x, y) elif flag == END: self.needle_up() break self.end_all() self.object.load_Completed() return self.object
# 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 if __debug__: pdebug('timing', 'time:', time.clock() - start_time) return self.object 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
def Load(self): try: self.file.seek(0) cdr = RiffChunk() cdr.load(self.file.read()) app.updateInfo(inf2=_("Parsing is finished"), inf3=10) summary = [ ('CDR version', cdr.infocollector.cdr_version), ('pages', cdr.infocollector.pages - 1), ('layers', cdr.infocollector.layers / cdr.infocollector.pages), ('groups', cdr.infocollector.groups), ('objects', cdr.infocollector.objects), ('bitmaps', cdr.infocollector.bitmaps), ] if cdr.infocollector.compression: summary.append(('compression', 'yes')) else: summary.append(('compression', 'no')) if self.filename == None: return from xml.sax.saxutils import XMLGenerator try: file = open(self.filename, 'w') except (IOError, os.error), value: import sys sys.stderr('cannot write parsing result into %s: %s' % ( ` filename `, value[1])) return writer = XMLGenerator(out=file, encoding='utf-8') writer.startDocument() writer.startElement('riffDocument', {}) writer.characters('\n') writer.startElement('docSummary', {}) writer.characters('\n') for key, value in summary: writer.characters('\t') writer.startElement('%s' % key, {}) writer.characters('%s' % ` value `) writer.endElement('%s' % key) writer.characters('\n') writer.endElement('docSummary') writer.characters('\n') writer.startElement('docStructure', {}) writer.characters('\n') if cdr.infocollector.cdr_version > 6: self.info = cdr.infocollector self.info.loader = self self.info.process_properties() self.import_curves(writer) else: writer.characters('\t') writer.startElement('info', {}) value = 'Parsed file contains usupported CorelDRAW ver.%u' % cdr.infocollector.cdr_version + '.0 drawing' writer.characters('%s' % ` value `) writer.endElement('info') writer.characters('\n')
# 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 if __debug__: pdebug('timing', 'time:', time.clock() - start_time) return self.object 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
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 if __debug__: pdebug("timing", "time:", time.clock() - start_time) return self.object 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
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))