hytos / HYTOS / HYTOS / Shapes / EngineeringEqpDescTextItem.py @ 680cee6a
이력 | 보기 | 이력해설 | 다운로드 (2.72 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is engineering equipment description text item module """
|
3 |
|
4 |
import os.path |
5 |
import sys |
6 |
import copy |
7 |
|
8 |
try:
|
9 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
10 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont, QColor |
11 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \ |
12 |
QGraphicsTextItem
|
13 |
except ImportError: |
14 |
try:
|
15 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
16 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont |
17 |
except ImportError: |
18 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
19 |
|
20 |
|
21 |
class QEngineeringEqpDescTextItem(QGraphicsTextItem): |
22 |
""" This is engineering equipment description text item class """
|
23 |
|
24 |
def __init__(self, text, parent=None): |
25 |
import uuid |
26 |
|
27 |
QGraphicsTextItem.__init__(self, text, parent)
|
28 |
self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
|
29 |
|
30 |
self.type = 'EQP DESC' |
31 |
self.setHtml(text)
|
32 |
|
33 |
font = QFont('Arial')
|
34 |
font.setPointSizeF(6)
|
35 |
self.setFont(font)
|
36 |
|
37 |
self.setDefaultTextColor(Qt.black)
|
38 |
|
39 |
def set_font_size(self, size): |
40 |
font = QFont('Arial')
|
41 |
font.setPointSizeF(float(size))
|
42 |
self.setFont(font)
|
43 |
|
44 |
def set_font_color(self, color): |
45 |
self.setDefaultTextColor(QColor(color))
|
46 |
|
47 |
def mouseDoubleClickEvent(self, event): |
48 |
"""pop up nozzle description dialog"""
|
49 |
from App import App |
50 |
from NozzleDescriptionDialog import QNozzleDescriptionDialog |
51 |
|
52 |
dlg = QNozzleDescriptionDialog(App.mainWnd(), self.toPlainText())
|
53 |
if dlg.exec_():
|
54 |
self.setHtml(dlg.desc.replace('\n', '<br>')) |
55 |
|
56 |
def toSql(self, conn): |
57 |
""" generate sql string to save label to database """
|
58 |
res = [] |
59 |
|
60 |
try:
|
61 |
cols = ['UID', 'Symbols_UID', 'Name', 'X', 'Y'] |
62 |
values = ['?', '?', '?', '?', '?'] |
63 |
|
64 |
param = [str(conn.uid), str(self.parentItem().dbUid), self.toHtml(), self.pos().x(), self.pos().y()] |
65 |
sql = f"insert or replace into Components({','.join(cols)}) values({','.join(values)})"
|
66 |
res.append((sql, tuple(param)))
|
67 |
except Exception as ex: |
68 |
from App import App |
69 |
from AppDocData import MessageType |
70 |
|
71 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
72 |
sys.exc_info()[-1].tb_lineno)
|
73 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
74 |
|
75 |
return res
|