diff --git a/GUI/UI/cv.ui b/GUI/UI/cv.ui index a45e614..798283d 100644 --- a/GUI/UI/cv.ui +++ b/GUI/UI/cv.ui @@ -15,14 +15,27 @@ - + + + + Qt::Vertical + + + + 20 + 40 + + + + + - 1296 - 970 + 600 + 600 @@ -96,13 +109,13 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">清晰度指数:</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">纤芯直径(um):</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">包层直径(um):</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">纤芯不圆度:</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">包层不圆度:</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'SimSun'; font-size:9pt;">芯包同心度(um):</span></p></body></html> +</style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">清晰度指数:</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">纤芯直径(um):</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">包层直径(um):</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">纤芯不圆度:</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">包层不圆度:</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">芯包同心度(um):</p></body></html> @@ -235,19 +248,6 @@ p, li { white-space: pre-wrap; } - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -256,7 +256,7 @@ p, li { white-space: pre-wrap; } 0 0 1809 - 37 + 23 diff --git a/GUI/UI/cvUI.py b/GUI/UI/cvUI.py index 9a0830f..5973906 100644 --- a/GUI/UI/cvUI.py +++ b/GUI/UI/cvUI.py @@ -30,10 +30,12 @@ def setupUi(self, MainWindow): self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.gridLayout_2 = QtGui.QGridLayout(self.centralwidget) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.gridLayout_2.addItem(spacerItem, 3, 0, 1, 1) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.graphicsView = QtGui.QGraphicsView(self.centralwidget) - self.graphicsView.setMinimumSize(QtCore.QSize(1296, 970)) + self.graphicsView.setMinimumSize(QtCore.QSize(600, 400)) self.graphicsView.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.CrossCursor)) self.graphicsView.setMidLineWidth(0) self.graphicsView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) @@ -123,12 +125,10 @@ def setupUi(self, MainWindow): self.extendwidget.setObjectName(_fromUtf8("extendwidget")) self.cvOperatorLayout.addWidget(self.extendwidget) self.horizontalLayout.addLayout(self.cvOperatorLayout) - self.gridLayout_2.addLayout(self.horizontalLayout, 0, 0, 2, 2) - spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) - self.gridLayout_2.addItem(spacerItem, 2, 0, 1, 1) + self.gridLayout_2.addLayout(self.horizontalLayout, 2, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) - self.menubar.setGeometry(QtCore.QRect(0, 0, 1809, 37)) + self.menubar.setGeometry(QtCore.QRect(0, 0, 1809, 23)) self.menubar.setObjectName(_fromUtf8("menubar")) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) @@ -146,13 +146,13 @@ def retranslateUi(self, MainWindow): self.resultShowCV.setHtml(_translate("MainWindow", "\n" "\n" -"

清晰度指数:

\n" -"

纤芯直径(um):

\n" -"

包层直径(um):

\n" -"

纤芯不圆度:

\n" -"

包层不圆度:

\n" -"

芯包同心度(um):

", None)) +"\n" +"

清晰度指数:

\n" +"

纤芯直径(um):

\n" +"

包层直径(um):

\n" +"

纤芯不圆度:

\n" +"

包层不圆度:

\n" +"

芯包同心度(um):

", None)) self.light.setText(_translate("MainWindow", "0.0", None)) self.label.setText(_translate("MainWindow", "光强:", None)) self.label_2.setText(_translate("MainWindow", "清晰度:", None)) diff --git a/GUI/view/mplqt4.py b/GUI/view/mplqt4.py index 8e02e34..1b7751c 100644 --- a/GUI/view/mplqt4.py +++ b/GUI/view/mplqt4.py @@ -56,8 +56,8 @@ def update_figure(self, x, h,y,v): # lastprices, yellowlines = LastPrice[::20].copy(), YellowLine[::20] # print 'plot len', len(numbers), len(lastprices), len(yellowlines) self.axes.cla() - self.axes.plot(x,h,'y') - self.axes_twinx.plot(y,v,'r') + self.axes.plot(x,h,'y')#yellow line + self.axes_twinx.plot(y,v,'r')#red line self.axes.set_facecolor('none') self.draw() diff --git a/GUI/view/reporter.py b/GUI/view/reporter.py index e29465f..d5882f2 100644 --- a/GUI/view/reporter.py +++ b/GUI/view/reporter.py @@ -3,6 +3,8 @@ from datetime import datetime as dt from PyQt4.QtGui import QWidget, QFileDialog, QMessageBox from report.pdf import writePdfabs +from setting.config import PDF_PARAMETER + def Reporter(father): if not isinstance(father, QWidget): diff --git a/GUI/view/view.py b/GUI/view/view.py index fa4a7ff..c587eb7 100644 --- a/GUI/view/view.py +++ b/GUI/view/view.py @@ -1,6 +1,8 @@ # coding:utf-8 import threading from functools import partial + +import cv2 from PyQt4.QtCore import QObject from PyQt4.QtCore import pyqtSignal from PyQt4.QtGui import QWidget @@ -22,7 +24,6 @@ import logging logger = logging.getLogger(__name__) - class CVViewModel(object): """docstring for View""" @@ -134,7 +135,6 @@ def writeReporterCV(self): def relative_index_show(self, plots): self.relative_index_canvas.update_figure(*plots) - class MyQGraphicsScene(QGraphicsScene): def __init__(self): QGraphicsScene.__init__(self) diff --git a/onefile/__init__.py b/onefile/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/onefile/base_css.css b/onefile/base_css.css new file mode 100644 index 0000000..5e01499 --- /dev/null +++ b/onefile/base_css.css @@ -0,0 +1,16 @@ +table { + border-collapse: collapse; + width:70%; + border:1; + cellspacing:1; + cellpadding:0; + bgcolor: #000000; + border-color: #999999; +} +table, td, th { + border: 1px solid black; +} +td{ + width:15%; + font-size:15px; +} \ No newline at end of file diff --git a/onefile/convert.py b/onefile/convert.py new file mode 100644 index 0000000..bf01159 --- /dev/null +++ b/onefile/convert.py @@ -0,0 +1,49 @@ +import sys +from PyQt4.QtGui import QPrinter, QTextDocument, QApplication +from jinja2 import Environment, PackageLoader, select_autoescape +import os +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +def to_html(): + # print 'Base', BASE_DIR + + env = Environment( + loader=PackageLoader('onefile', 'template'), + autoescape=select_autoescape(['html', 'xml']) + ) + + template = env.get_template('tabel.html') + # d = {"title":unicode("ssx", "utf-8")} + para={'title':"xxx", + 'worker':"a", + 'fibertype':"b", + 'producer':"c", + 'fiberNo':"d", + 'corediameter':"e", + 'claddiameter':"f", + 'coreroundness':"g", + 'cladroundness':"h", + 'concentricity':"i", + 'sharpindex':"j", + # lightindex=PDF_PARAMETER['lightindex'], + 'date':"k", + 'fiberLength':"1", + "src":"E:\Python\\fiberwmx\\fiberGeometry\onefile\img.jpg" +} + myhtml = template.render(**para) + + return myhtml + +def to_pdf(dir_,myhtml): + # try: + # app = QApplication(sys.argv) + printer = QPrinter() + printer.setOutputFormat(QPrinter.PdfFormat) + printer.setOutputFileName(dir_) + printer.setPageSize(QPrinter.A4) + text = QTextDocument() + text.setHtml(myhtml) + text.print_(printer) + # sys.exit(app.exec_()) + + diff --git a/onefile/template/tabel.html b/onefile/template/tabel.html new file mode 100644 index 0000000..3699dc3 --- /dev/null +++ b/onefile/template/tabel.html @@ -0,0 +1,71 @@ + + + + + tabel + + + + + + + + + +

{{title}}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

测试人员

操作人员{{worker}}
日期{{date}}
光纤型号{{fibertype}}
生产厂家{{producer}}
光线编号{{fiberNo}}
光纤长度{{fiberLength}}

测试结果

纤芯直径{{corediameter}}
包层直径{{claddiameter}}
纤芯不圆度{{coreroundness}}
包层不圆度{{cladroundness}}
芯包同心度{{concentricity}}

测试图片

image
+
+ + \ No newline at end of file diff --git a/onefile/test.py b/onefile/test.py new file mode 100644 index 0000000..bf1b520 --- /dev/null +++ b/onefile/test.py @@ -0,0 +1,16 @@ +import sys + +import os +from PyQt4.QtGui import QApplication + +from onefile.convert import to_html, to_pdf + +if __name__ == '__main__': + os.system('del test_pdf\\test.pdf') + app = QApplication(sys.argv) + dir_ = "test_pdf\\test.pdf" + # myhtml = to_html() + with open("test_pdf\\test.html", 'r') as f: + myhtml = "".join(f.readlines()) + to_pdf(dir_, myhtml) + sys.exit(app.exec_()) \ No newline at end of file diff --git a/report/first.py b/report/first.py new file mode 100644 index 0000000..8a1ce62 --- /dev/null +++ b/report/first.py @@ -0,0 +1,35 @@ +#coding=utf-8 +from jinja2 import Environment, PackageLoader, select_autoescape + +env = Environment( + loader=PackageLoader('report', 'template'), + autoescape=select_autoescape(['html', 'xml']) +) + + +template = env.get_template('template.html') + +x= template.render( + title=u'测试', + worker= '1', + fibertype= '2', + producer= '3', + fiberNo='4', + corediameter= '5', + claddiameter= '6', + coreroundness= '7', + cladroundness= '8', + concentricity= '9', + sharpindex='10', + lightindex= '11', + date='12', + fiberLength= '13', + src="img\img.jpg" +) + +print x +print type(x) +# x=str(x) +# y=x.decode("utf-8") +# print y +# print type(y) \ No newline at end of file diff --git a/report/mypdf.py b/report/mypdf.py new file mode 100644 index 0000000..e69de29 diff --git a/report/pdf.py b/report/pdf.py index a6d4fb0..5afd3f1 100644 --- a/report/pdf.py +++ b/report/pdf.py @@ -1,9 +1,13 @@ -#coding:utf-8 +#coding=utf-8 +import os +from PyQt4.QtCore import QString + from setting.config import PDF_PARAMETER from .origin import * from setting.orderset import SETTING import sys from PyQt4.QtGui import QTextDocument, QPrinter, QApplication +from jinja2 import Environment, PackageLoader, select_autoescape def writePdf(dir_): newbody = originHTML.format(**htmlpara) @@ -13,22 +17,43 @@ def writePdf(dir_): printer.setOutputFileName(dir_+'.pdf') printer.setPageSize(QPrinter.A4) text = QTextDocument() - text.setHtml(newbody.decode('utf-8')) + text.setHtml(newbody.decode('utf-8'))#将utf-8编码的字符串解码为unicode text.print_(printer) # sys.exit(app.exec_()) # sys.exit(0) +# def writePdfabs(dir_): +# updates = PDF_PARAMETER +# htmlpara.update(updates) +# newbody = originHTML.format(**htmlpara) +# # with open('t.html', 'wb') as f: +# # f.write(newbody) +# # f.close() +# printer = QPrinter() +# printer.setOutputFormat(QPrinter.PdfFormat) +# printer.setOutputFileName(dir_) +# printer.setPageSize(QPrinter.A4) +# text = QTextDocument() +# text.setHtml(newbody.decode('utf-8')) +# text.print_(printer) + + def writePdfabs(dir_): - updates = PDF_PARAMETER - htmlpara.update(updates) - newbody = originHTML.format(**htmlpara) - # with open('t.html', 'wb') as f: - # f.write(newbody) - # f.close() + env = Environment( + loader=PackageLoader('report', 'template'), + autoescape=select_autoescape(['html', 'xml']) + ) + + + template = env.get_template('tabel.html') + PDF_PARAMETER['title']=PDF_PARAMETER['title'].decode("utf-8") + PDF_PARAMETER['src']="E:\Python\\fiberwmx\\fiberGeometry\onefile\img.jpg" + myhtml = template.render(**PDF_PARAMETER) + printer = QPrinter() printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(dir_) printer.setPageSize(QPrinter.A4) text = QTextDocument() - text.setHtml(newbody.decode('utf-8')) - text.print_(printer) \ No newline at end of file + text.setHtml(myhtml) + text.print_(printer) diff --git a/report/template/tabel.html b/report/template/tabel.html new file mode 100644 index 0000000..3699dc3 --- /dev/null +++ b/report/template/tabel.html @@ -0,0 +1,71 @@ + + + + + tabel + + + + + + + + + +

{{title}}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

测试人员

操作人员{{worker}}
日期{{date}}
光纤型号{{fibertype}}
生产厂家{{producer}}
光线编号{{fiberNo}}
光纤长度{{fiberLength}}

测试结果

纤芯直径{{corediameter}}
包层直径{{claddiameter}}
纤芯不圆度{{coreroundness}}
包层不圆度{{cladroundness}}
芯包同心度{{concentricity}}

测试图片

image
+
+ + \ No newline at end of file diff --git a/setting/old.json b/setting/old.json index c78c0b7..31855d9 100644 --- a/setting/old.json +++ b/setting/old.json @@ -1 +1 @@ -{"producer": "yofc", "title": "G652\u5149\u7ea4\u7aef\u9762\u51e0\u4f55\u6d4b\u8bd5\u62a5\u544a", "fiberLength": "22", "fibertypeindex": "0", "date": "2017-08-22 13:18:35", "worker": "12345", "fiberNo": "123456", "fibertype": "G652"} \ No newline at end of file +{"producer": "yofc", "title": "G652\u5149\u7ea4\u7aef\u9762\u51e0\u4f55\u6d4b\u8bd5\u62a5\u544a", "fiberLength": "24", "worker": "12345", "date": "2017-08-30 10:06:36", "fibertypeindex": "0", "fiberNo": "123456", "fibertype": "G652"} \ No newline at end of file diff --git a/tests/test_mypdf.py b/tests/test_mypdf.py new file mode 100644 index 0000000..da5900f --- /dev/null +++ b/tests/test_mypdf.py @@ -0,0 +1,21 @@ +import os +import sys + +from PyQt4.QtGui import QApplication +from onefile.convert import to_html, to_pdf + + +def test_writePdfabs(): + os.system('del ..\\test.pdf') + app = QApplication(sys.argv) + dir_ = "..\\test.pdf" + myhtml = to_html() + # with open("test.html", 'rb') as f: + # myhtml = f.read() + # with open("test_pdf\\test.html","wb") as f: + # f.write(myhtml.encode('utf-8')) + to_pdf(dir_, myhtml) + # listdir = os.listdir("test_pdf") + # assert 'test.pdf' in listdir + # sys.exit(app.exec_()) + diff --git a/tests/test_pdf.py b/tests/test_pdf.py index 13dae7d..e5894c5 100644 --- a/tests/test_pdf.py +++ b/tests/test_pdf.py @@ -1,4 +1,4 @@ -from report.pdf import writePdf, writePdfabs +from report.pdf import writePdfabs, writePdf import os import sys import time