def graphicsArc(xml: QXmlStreamWriter, points: [QPoint], pen: QPen): xml.writeStartElement("graphics") for p in points: PFSXmlBase.position(xml, p.x(), p.y()) if pen is not None: PFSXmlBase.line(xml, pen) xml.writeEndElement() #fecha graphics
def graphicsNode(xml: QXmlStreamWriter, rect: QRect, pen: QPen, brush: QBrush): xml.writeStartElement("graphics") PFSXmlBase.position(xml, rect.x(), rect.y()) PFSXmlBase.position(xml, rect.width(), rect.height(), "dimension") if brush is not None: PFSXmlBase.fill(xml, brush) if pen is not None: PFSXmlBase.line(xml, pen) xml.writeEndElement() #fecha graphics
def generateXml(self, xml: QXmlStreamWriter): PFSXmlBase.open(xml) xml.writeStartElement("activity") xml.writeAttribute("id", self._id) xml.writeAttribute("inputnum", str(self._inputNum)) xml.writeAttribute("outputnum", str(self._outputNum)) PFSXmlBase.graphicsNode(xml, QRectF(self.x(), self.y(), self._width, self._height), self._pen, self._brush) PFSXmlBase.text(xml, self._text, 0, 0, font=self._textFont, tag="text", align="center") PFSBasicElement.generateXml(self, xml) xml.writeEndElement() #fecha activity PFSXmlBase.close(xml)
def generateXml(self, xml: QXmlStreamWriter): PFSXmlBase.open(xml) xml.writeStartElement("secondaryflow") xml.writeAttribute("id", self._id) xml.writeAttribute("source", self._source._id) xml.writeAttribute("target", self._target._id) xml.writeAttribute("linex", str(self._lineX)) PFSXmlBase.graphicsArc(xml, self._midPoints, self._pen) PFSBasicElement.generateXml(self, xml) xml.writeEndElement() #fecha distributor PFSXmlBase.close(xml)
def graphicsText(xml: QXmlStreamWriter, x: int, y: int, font: QFont, pen: QPen, brush: QBrush, align: str, rotation: int): xml.writeStartElement("graphics") PFSXmlBase.position(xml, x, y, "offset") if font is None: font = PFSXmlBase.STANDARDTEXTFONT PFSXmlBase.font(xml, font, align) if brush is not None: PFSXmlBase.fill(xml, brush) if pen is not None: PFSXmlBase.line(xml, pen) xml.writeEndElement() #fecha graphics
def text(xml: QXmlStreamWriter, text: str, x: int, y: int, font: QFont = None, rotation: int = 0, pen: QPen = None, brush: QBrush = None, tag: str = "name", align: str = "left"): xml.writeStartElement(tag) xml.writeStartElement("annotation") xml.writeCharacters(text) xml.writeEndElement() #fecha annotation PFSXmlBase.graphicsText(xml, x, y, font, pen, brush, align, rotation) xml.writeEndElement() #fecha text
def saveFile(self, net, filepath, filename, store=True): file = QFile(QFileInfo(QDir(filepath), filename).absoluteFilePath()) file.open(QIODevice.WriteOnly) xml = QXmlStreamWriter(file) net.generateXml(xml) file.close() if store: net._filename = filename net._filepath = filepath self._tab.setTabText(self._tab.currentIndex(), net.getTabName())
def generateXml(self, xml: QXmlStreamWriter): PFSXmlBase.open(xml) xml.writeStartElement("distributor") xml.writeAttribute("id", self._id) PFSXmlBase.graphicsNode(xml, QRectF(self.x(), self.y(), self._width, self._height), self._pen, self._brush) PFSBasicElement.generateXml(self, xml) xml.writeEndElement() #fecha distributor PFSXmlBase.close(xml)
def generateXml(self, xml: QXmlStreamWriter): PFSXmlBase.open(xml) xml.writeStartElement("closeactivity") xml.writeAttribute("id", self._id) PFSXmlBase.graphicsNode(xml, QRectF(self.x() - 6, self.y(), 6, self._h), self.scene()._page._subRef._pen, None) PFSBasicElement.generateXml(self, xml) xml.writeEndElement() #fecha closeactivity PFSXmlBase.close(xml)
def close(xml: QXmlStreamWriter): xml.writeEndElement()
def open(xml: QXmlStreamWriter): xml.writeStartElement("toolspecific") xml.writeAttribute("tool", "PFS") xml.writeAttribute("version", "1.0.0")
def createWriter(device): writer = QXmlStreamWriter(device) writer.setAutoFormatting(True) writer.setAutoFormattingIndent(1) return writer
def makeqrcodeoutputfile(self, id, file_route): for item in self.orderlist: if item['autoid'] == id: proddetail = item break key_dict = {'pwdid': id} res = self.WC.get_pwqrcode(False, *VALUES_LIST_QRCODE, **key_dict) if not len(res): return # 把二维码按比例分组 q_list, ppid_list, batchno_list = self.sort_qrcode( res.order_by('ppid')) xml = QXmlStreamWriter() qfile = QFile(file_route) if qfile.open(QIODevice.WriteOnly): xml.setDevice(qfile) else: return xml.setAutoFormatting(True) xml.writeStartDocument() # 添加头文件信息 self.addxmlheader(xml) self.addxmlproddetail(xml, proddetail) temp_ppid = '' for i in range(0, len(ppid_list)): if temp_ppid != ppid_list[i]: if temp_ppid != '': # 把上一个ppid结束了 xml.writeEndElement() temp_ppid = ppid_list[i] xml.writeStartElement("Batch") xml.writeAttribute('batchNo', batchno_list[i]) xml.writeAttribute('operator', proddetail['creatorname']) xml.writeAttribute('oprDate', str(proddetail['wdate'])) xml.writeStartElement("Data") xml.writeAttribute('code', q_list[i]) xml.writeEndElement() xml.writeEndElement() xml.writeEndElement() xml.writeEndDocument()
def generateXml(self, xml: QXmlStreamWriter): PFSXmlBase.open(xml) xml.writeStartElement("relation") xml.writeAttribute("id", self._id) xml.writeAttribute("source", self._source._id) xml.writeAttribute("sourceport", str(self._sourceNum)) xml.writeAttribute("target", self._target._id) xml.writeAttribute("targetport", str(self._targetNum)) PFSXmlBase.graphicsArc(xml, self._midPoints, self._pen) PFSBasicElement.generateXml(self, xml) xml.writeEndElement() #fecha distributor PFSXmlBase.close(xml)
def makeqrcodeinputfile(self, ppid, file_route): for item in self.prodlist: if item['autoid'] == ppid: proddetail = item break key_dict = {'ppid': ppid} res = self.WC.get_qrcoderep(False, *VALUES_LIST_QRCODE, **key_dict) if not len(res): return # 把二维码按比例分组 q_list, proportion_list = self.sort_qrcode(res) # 把比例相同的合并成一个同一个项目 q_list_merge, proportion_list_merge = self.merge_qrcode( q_list, proportion_list) xml = QXmlStreamWriter() qfile = QFile(file_route) if qfile.open(QIODevice.WriteOnly): xml.setDevice(qfile) else: return xml.setAutoFormatting(True) xml.writeStartDocument() # 添加头文件信息 self.addxmlheader(xml) self.addxmlproddetail(xml, proddetail) for i in range(0, len(proportion_list_merge)): spnum = proportion_list[i][0] mpnum = proportion_list[i][1] bpnum = proportion_list[i][2] lpnum = proportion_list[i][3] xml.writeStartElement("Batch") xml.writeAttribute('batchNo', proddetail['batchno']) xml.writeAttribute('specification', proddetail['spec']) xml.writeAttribute('minPackUnit', proddetail['spunit']) if spnum != 0: minTagUnit = proddetail['spunit'] elif mpnum != 0: minTagUnit = proddetail['mpunit'] else: minTagUnit = proddetail['bpunit'] tagPackRatio = '' for num in (lpnum, bpnum, mpnum, spnum): if num != 0: if tagPackRatio == '': tagPackRatio = str(num) else: tagPackRatio += ':' + str(num) xml.writeAttribute('minTagUnit', minTagUnit) xml.writeAttribute('tagPackRatio', tagPackRatio) xml.writeAttribute('produceDate', str(proddetail['makedate'])) xml.writeAttribute('operator', user.user_name) xml.writeAttribute('oprDate', str(user.now_date)) xml.writeAttribute('count', str(len(q_list_merge[i]))) xml.writeAttribute('countUnit', '1' if minTagUnit == tagPackRatio else '2') qrcode = q_list_merge[i] for code in qrcode: xml.writeStartElement("Data") xml.writeAttribute('code', code) xml.writeEndElement() xml.writeEndElement() xml.writeEndElement() xml.writeEndElement() xml.writeEndDocument()
def generateXml(self, xml: QXmlStreamWriter): xml.writeStartDocument() xml.writeStartElement("PetriNetDoc") xml.writeStartElement("net") xml.writeAttribute("id", self._id) pages = self.getAllPages() for p in pages: p.generateXml(xml) xml.writeEndElement() xml.writeEndElement() xml.writeEndDocument()
def writeObjectTypes(self, fileName, objectTypes): self.mError = '' file = QFile(fileName) if (not file.open(QIODevice.WriteOnly | QIODevice.Text)): self.mError = QCoreApplication.translate( "ObjectTypes", "Could not open file for writing.") return False writer = QXmlStreamWriter(file) writer.setAutoFormatting(True) writer.setAutoFormattingIndent(1) writer.writeStartDocument() writer.writeStartElement("objecttypes") for objectType in objectTypes: writer.writeStartElement("objecttype") writer.writeAttribute("name", objectType.name) writer.writeAttribute("color", objectType.color.name()) writer.writeEndElement() writer.writeEndElement() writer.writeEndDocument() if (file.error() != QFile.NoError): self.mError = file.errorString() return False return True
def line(xml: QXmlStreamWriter, pen: QPen, tag: str = "line"): xml.writeStartElement(tag) xml.writeAttribute("color", pen.color().name()) xml.writeAttribute("width", str(pen.width())) if pen.style() == Qt.DashLine: xml.writeAttribute("style", "dash") elif pen.style() == Qt.DotLine: xml.writeAttribute("style", "dot") else: xml.writeAttribute("style", "solid") xml.writeEndElement() #fecha line
def fill(xml: QXmlStreamWriter, brush: QBrush, tag: str = "fill"): xml.writeStartElement(tag) if brush.gradient( ) is not None and brush.gradient().type() != QGradient.NoGradient: grad = brush.gradient() if grad.type() != QGradient.LinearGradient: xml.writeAttribute("gradient-rotation", "diagonal") else: if grad.start().x() == grad.finalStop().x(): xml.writeAttribute("gradient-rotation", "vertical") elif grad.start().y() == grad.finalStop().y(): xml.writeAttribute("gradient-rotation", "horizontal") else: xml.writeAttribute("gradient-rotation", "diagonal") xml.writeAttribute("color", grad.stops()[0][1].name()) xml.writeAttribute("gradient-color", grad.stops()[1][1].name()) else: xml.writeAttribute("color", brush.color().name()) xml.writeEndElement() #fecha fill
def storeNodesStreamWriter(fname, root): assert isinstance(fname, str), '' assert isinstance(root, TagTreeItem), '' xmlFile = QFile(fname) if xmlFile.open(QIODevice.WriteOnly | QIODevice.Text): writer = QXmlStreamWriter(xmlFile) writer.setAutoFormatting(True) writer.writeStartDocument() writer.writeStartElement("items") storeNodesRecursive(root, writer) writer.writeEndElement() writer.writeEndDocument() xmlFile.close()
def position(xml: QXmlStreamWriter, x: int, y: int, tag: str = "position"): xml.writeStartElement(tag) xml.writeAttribute("x", str(x)) xml.writeAttribute("y", str(y)) xml.writeEndElement() #fecha pos
def store(self, root, fname=None): __fname = fname or self.__fname assert isinstance(__fname, str), '' assert isinstance(root, TagTreeItem), '' try: xmlFile = QFile(__fname) if xmlFile.open(QIODevice.WriteOnly | QIODevice.Text): try: writer = QXmlStreamWriter(xmlFile) writer.setAutoFormatting(True) writer.writeStartDocument() writer.writeStartElement("items") self.__storeNodesRecursive(root, writer) writer.writeEndElement() writer.writeEndDocument() except Exception as e: self.__error = str(e) self.__error_flag = True return False finally: xmlFile.close() except Exception as e: self.__error = str(e) self.__error_flag = True return False return True
def font(xml: QXmlStreamWriter, font: QFont, align: str = "left", rotation: int = 0, tag: str = "font"): xml.writeStartElement("font") xml.writeAttribute("family", font.family()) if font.style() == QFont.StyleItalic: xml.writeAttribute("style", "italic") elif font.style() == QFont.StyleOblique: xml.writeAttribute("style", "oblique") else: xml.writeAttribute("style", "normal") xml.writeAttribute("size", str(font.pointSize())) v = [ "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", "900" ] if font.weight() <= 50: xml.writeAttribute("weight", "normal") else: xml.writeAttribute("weight", v[int((font.weight() - 50) / 4)]) dec = [] if font.underline(): dec.append("underline") if font.overline(): dec.append("overline") if font.strikeOut(): dec.append("line-through") if len(dec) > 0: xml.writeAttribute("decoration", ";".join(dec)) xml.writeAttribute("align", align) xml.writeAttribute("rotation", str(rotation)) xml.writeEndElement() #fecha font
def generateXml(self, xml: QXmlStreamWriter): xml.writeStartElement("page") PFSXmlBase.open(xml) xml.writeStartElement("pagetype") xml.writeAttribute("id", self._id) if self._subRef is None: xml.writeAttribute("mainpage", "true") xml.writeAttribute("ref", "") else: xml.writeAttribute("mainpage", "false") xml.writeAttribute("ref", self._subRef._id) xml.writeEndElement() #fim da pagetype xml.writeStartElement("pagegraphics") PFSXmlBase.position(xml, str(self._scene.width()), str(self._scene.height()), "dimension") xml.writeEndElement() #fim da pagegraphics PFSBasicElement.generateXml(self, xml) PFSXmlBase.close(xml) for e in self._scene.items(): if isinstance(e, PFSActive) or isinstance( e, PFSPassive) or isinstance(e, PFSRelation): e.generateXml(xml) xml.writeEndElement() #fim da page
def makeqrcodeoutputfile(self, id, file_route): for item in self.orderlist: if item['autoid'] == id: proddetail = item break clientid = proddetail['clientid'] key_dict_client = {'clientid': clientid} clients_detail = self.SLC.get_client(False, *VALUES_LIST_CLIENT, **key_dict_client) if len(clients_detail) != 1: return client = clients_detail[0] key_dict = {'ppopid': id} res = self.WC.get_ppopqrcode(False, *VALUES_LIST_QRCODE, **key_dict) if not len(res): return # 把二维码按比例分组 q_list, ppid_list, batchno_list = self.sort_qrcode( res.order_by('batchno')) xml = QXmlStreamWriter() qfile = QFile(file_route) if qfile.open(QIODevice.WriteOnly): xml.setDevice(qfile) else: return xml.setAutoFormatting(True) xml.writeStartDocument() # 添加头文件信息 self.addxmlheader(xml, client['kind']) self.addxmlproddetail(xml, proddetail) temp_ppid = '' for i in range(0, len(ppid_list)): if temp_ppid != ppid_list[i]: if temp_ppid != '': # 把上一个Batch结束了 xml.writeEndElement() temp_ppid = ppid_list[i] xml.writeStartElement("Batch") xml.writeAttribute('batchNo', batchno_list[i]) xml.writeAttribute('operator', proddetail['auditorname']) xml.writeAttribute('oprDate', str(proddetail['putoutdate'])) xml.writeAttribute(' toUnit', client['clientname']) xml.writeAttribute('toProvince', client['province']) xml.writeAttribute('toCity', client['city']) xml.writeAttribute('toCounty', client['county']) xml.writeAttribute('toUnitcode', client['unitcode']) xml.writeStartElement("Data") xml.writeAttribute('code', q_list[i]) xml.writeEndElement() xml.writeEndElement() xml.writeEndElement() xml.writeEndDocument()
def generateXml(self, xml: QXmlStreamWriter): if len(self._tags) == 0: return xml.writeStartElement("tags") for tag in self._tags: xml.writeStartElement("tag") xml.writeAttribute("name", tag._name) xml.writeAttribute("use", tag._use) xml.writeEndElement() xml.writeEndElement()