class selectionLayer(layer): def __init__(self, size, dynamic, controller, prototypeLine, opaqueBack = False): layer.__init__(self,size,dynamic) self.controller = controller self.points = set() if opaqueBack: self.backgroundColor = Qt.white else: self.backgroundColor = Qt.transparent lineColor = QColor() lineColor.setNamedColor(prototypeLine.getAttribute('stroke')) lineColor.setAlphaF(float(prototypeLine.getAttribute('stroke-opacity'))) self.pen = QPen(lineColor) self.pen.setWidthF(prototypeLine.getAttribute('stroke-width')) def handleFrame(self, event, signals): return signals def refreshLines(self, points): self.points = points self.setDirty() def draw(self,painter): if len(self.points) >= self.controller.app.resolution_threshold: return pointList = list(self.points) self.image.fill(self.backgroundColor) painter.setPen(self.pen) painter.setRenderHint(QPainter.Antialiasing) lastA = self.controller.axisOrder[0] lastValues = self.controller.vData.getData(pointList,lastA) lastX = self.controller.axes[lastA].visAxis.axisLine.left() for a in self.controller.axisOrder[1:]: if not self.controller.axes[a].visible: continue values = self.controller.vData.getData(pointList,a) x = self.controller.axes[a].visAxis.axisLine.left() for y0,y1 in zip(lastValues,values): y0 = self.controller.axes[lastA].dataToScreen(y0) y1 = self.controller.axes[a].dataToScreen(y1) if len(y0) > len(y1): if len(y1) > 1: raise Exception("Mismatched number of values between attributes: %s %s" % (y0,y1)) else: for y00 in y0: painter.drawLine(lastX,y00,x,y1[0]) elif len(y1) > len(y0): if len(y0) > 1: raise Exception("Mismatched number of values between attributes: %s %s" % (y0,y1)) else: for y11 in y1: painter.drawLine(lastX,y0[0],x,y11) else: for i,y00 in enumerate(y0): painter.drawLine(lastX,y00,x,y1[i]) lastA = a lastValues = values lastX = x
def _cutPen(self): if self.edit_mode: pen = QPen() pen.setWidthF(0.03) return pen else: pen = QPen(Qt.gray) pen.setWidthF(0.02) return pen
def realRender(self, painter, renderPath): # TODO/PORT: Still needs work. """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `renderPath`: TOWRITE :type `renderPath`: `QPainterPath`_ """ color1 = objectColor() #QColor # lighter color color2 = color1.darker(150) #QColor # darker color # If we have a dark color, lighten it darkness = color1.lightness() #int threshold = 32 #int #TODO: This number may need adjusted or maybe just add it to settings. if darkness < threshold: color2 = color1 if not darkness: color1 = QColor( threshold, threshold, threshold) # lighter() does not affect pure black else: color1 = color2.lighter(100 + threshold) count = renderPath.elementCount() # int for i in range(0, count - 1): # for(int i = 0; i < count-1; ++i); elem = renderPath.elementAt(i) # QPainterPath::Element next = renderPath.elementAt(i + 1) # QPainterPath::Element if next.isMoveTo(): continue elemPath = QPainterPath() elemPath.moveTo(elem.x, elem.y) elemPath.lineTo(next.x, next.y) renderPen = QPen(QColor(0, 0, 0, 0)) renderPen.setWidthF(0) painter.setPen(renderPen) stroker = QPainterPathStroker() stroker.setWidth(0.35) stroker.setCapStyle(Qt.RoundCap) stroker.setJoinStyle(Qt.RoundJoin) realPath = stroker.createStroke(elemPath) # QPainterPath painter.drawPath(realPath) grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0)) grad.setColorAt(0, color1) grad.setColorAt(1, color2) grad.setSpread(QGradient.ReflectSpread) painter.fillPath(realPath, QBrush(grad))
def realRender(self, painter, renderPath): # TODO/PORT: Still needs work. """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `renderPath`: TOWRITE :type `renderPath`: `QPainterPath`_ """ color1 = self.objectColor() #QColor # lighter color color2 = color1.darker(150) #QColor # darker color # If we have a dark color, lighten it darkness = color1.lightness() #int threshold = 32 #int #TODO: This number may need adjusted or maybe just add it to settings. if darkness < threshold: color2 = color1 if not darkness: color1 = QColor(threshold, threshold, threshold) # lighter() does not affect pure black else : color1 = color2.lighter(100 + threshold) count = renderPath.elementCount() # int for i in range(0, count - 1): # for(int i = 0; i < count-1; ++i); elem = renderPath.elementAt(i) # QPainterPath::Element next = renderPath.elementAt(i + 1) # QPainterPath::Element if next.isMoveTo(): continue elemPath = QPainterPath() elemPath.moveTo(elem.x, elem.y) elemPath.lineTo(next.x, next.y) renderPen = QPen(QColor(0, 0, 0, 0)) renderPen.setWidthF(0) painter.setPen(renderPen) stroker = QPainterPathStroker() stroker.setWidth(0.35) stroker.setCapStyle(Qt.RoundCap) stroker.setJoinStyle(Qt.RoundJoin) realPath = stroker.createStroke(elemPath) # QPainterPath painter.drawPath(realPath) grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0)) grad.setColorAt(0, color1) grad.setColorAt(1, color2) grad.setSpread(QGradient.ReflectSpread) painter.fillPath(realPath, QBrush(grad))
class BaseObject(QGraphicsPathItem): """ Subclass of `QGraphicsPathItem`_ TOWRITE """ Type = OBJ_TYPE_BASE def __init__(self, parent=None): """ Default class constructor. :param `parent`: Pointer to a parent widget instance. :type `parent`: `QGraphicsItem`_ """ super(BaseObject, self).__init__(parent) qDebug("BaseObject Constructor()") self.objPen = QPen() # QPen objPen; self.lwtPen = QPen() # QPen lwtPen; self.objLine = QLineF() # QLineF objLine; self.objRubberMode = int() # int objRubberMode; self.objRubberPoints = {} # QHash<QString, QPointF> objRubberPoints; self.objRubberTexts = {} # QHash<QString, QString> objRubberTexts; self.objID = int() # qint64 objID; self.objPen.setCapStyle(Qt.RoundCap) self.objPen.setJoinStyle(Qt.RoundJoin) self.lwtPen.setCapStyle(Qt.RoundCap) self.lwtPen.setJoinStyle(Qt.RoundJoin) self.objID = QDateTime.currentMSecsSinceEpoch() def __del__(self): """Class destructor.""" qDebug("BaseObject Destructor()") def type(self): """ TOWRITE :return: TOWRITE :rtype: int """ return self.Type def setObjectColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: `QColor`_ """ self.objPen.setColor(color) self.lwtPen.setColor(color) def setObjectColorRGB(self, rgb): """ TOWRITE :param `rgb`: TOWRITE :type `rgb`: `QRgb`_ """ self.objPen.setColor(QColor(rgb)) self.lwtPen.setColor(QColor(rgb)) def setObjectLineType(self, lineType): """ TOWRITE :param `rgb`: TOWRITE :type `rgb`: Qt.PenStyle """ self.objPen.setStyle(lineType) self.lwtPen.setStyle(lineType) def setObjectLineWeight(self, lineWeight): """ TOWRITE :param `lineWeight`: TOWRITE :type `lineWeight`: qreal """ self.objPen.setWidthF(0) # NOTE: The objPen will always be cosmetic if lineWeight < 0: if lineWeight == OBJ_LWT_BYLAYER: self.lwtPen.setWidthF(0.35) # TODO: getLayerLineWeight elif lineWeight == OBJ_LWT_BYBLOCK: self.lwtPen.setWidthF(0.35) # TODO: getBlockLineWeight else: QMessageBox.warning(0, QObject.tr("Error - Negative Lineweight"), QObject.tr("Lineweight: %f" % lineWeight)) qDebug("Lineweight cannot be negative! Inverting sign.") self.lwtPen.setWidthF(-lineWeight) else: self.lwtPen.setWidthF(lineWeight) def objectRubberPoint(self, key): """ TOWRITE :param `key`: TOWRITE :type `key`: QString :rtype: `QPointF`_ """ if key in self.objRubberPoints: # if(objRubberTexts.contains(key)) return self.objRubberPoints[key] # return objRubberTexts.value(key); gscene = self.scene() # QGraphicsScene* gscene = scene() if gscene: return self.scene().property("SCENE_QSNAP_POINT") # .toPointF() return QPointF() def objectRubberText(self, key): """ TOWRITE :param `key`: TOWRITE :type `key`: QString :rtype: QString """ if key in self.objRubberTexts: # if(objRubberTexts.contains(key)) return self.objRubberTexts[key] # return objRubberTexts.value(key); return "" # QString() def boundingRect(self): """ TOWRITE :rtype: `QRectF`_ """ # If gripped, force this object to be drawn even if it is offscreen if self.objectRubberMode() == OBJ_RUBBER_GRIP: return self.scene().sceneRect() return self.path().boundingRect() def drawRubberLine(self, rubLine, painter=None, colorFromScene=''): """ TOWRITE :param `rubLine`: TOWRITE :type `rubLine`: `QLineF`_ :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `colorFromScene`: TOWRITE :type `colorFromScene`: str """ if painter: objScene = self.scene() # QGraphicsScene* objScene = scene(); if not objScene: return colorPen = self.objPen # QPen colorPen = objPen colorPen.setColor(QColor(objScene.property(colorFromScene))) # .toUInt())) painter.setPen(colorPen) painter.drawLine(rubLine) painter.setPen(self.objPen) def realRender(self, painter, renderPath): # TODO/PORT: Still needs work. """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `renderPath`: TOWRITE :type `renderPath`: `QPainterPath`_ """ color1 = self.objectColor() #QColor # lighter color color2 = color1.darker(150) #QColor # darker color # If we have a dark color, lighten it darkness = color1.lightness() #int threshold = 32 #int #TODO: This number may need adjusted or maybe just add it to settings. if darkness < threshold: color2 = color1 if not darkness: color1 = QColor(threshold, threshold, threshold) # lighter() does not affect pure black else : color1 = color2.lighter(100 + threshold) count = renderPath.elementCount() # int for i in range(0, count - 1): # for(int i = 0; i < count-1; ++i); elem = renderPath.elementAt(i) # QPainterPath::Element next = renderPath.elementAt(i + 1) # QPainterPath::Element if next.isMoveTo(): continue elemPath = QPainterPath() elemPath.moveTo(elem.x, elem.y) elemPath.lineTo(next.x, next.y) renderPen = QPen(QColor(0, 0, 0, 0)) renderPen.setWidthF(0) painter.setPen(renderPen) stroker = QPainterPathStroker() stroker.setWidth(0.35) stroker.setCapStyle(Qt.RoundCap) stroker.setJoinStyle(Qt.RoundJoin) realPath = stroker.createStroke(elemPath) # QPainterPath painter.drawPath(realPath) grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0)) grad.setColorAt(0, color1) grad.setColorAt(1, color2) grad.setSpread(QGradient.ReflectSpread) painter.fillPath(realPath, QBrush(grad)) def objectID(self): """ TOWRITE :return: TOWRITE :rtype: int """ return self.objID def objectPen(self): """ TOWRITE :return: TOWRITE :rtype: `QPen`_ """ return self.objPen def objectColor(self): """ TOWRITE :return: TOWRITE :rtype: `QColor`_ """ return self.objPen.color() def objectColorRGB(self): """ TOWRITE :return: TOWRITE :rtype: int """ return self.objPen.color().rgb() def objectLineType(self): """ TOWRITE :return: TOWRITE :rtype: Qt.PenStyle """ return self.objPen.style() def objectLineWeight(self): """ TOWRITE :return: TOWRITE :rtype: float """ return self.lwtPen.widthF() def objectPath(self): """ TOWRITE :return: TOWRITE :rtype: `QPainterPath`_ """ return self.path() def objectRubberMode(self): """ TOWRITE :return: TOWRITE :rtype: int """ return self.objRubberMode def rect(self): """ TOWRITE :return: TOWRITE :rtype: `QRectF`_ """ return self.path().boundingRect() # pythonic setRect overload @signature(QPointF) def setRectFromRect(self, r): """ TOWRITE :param `r`: TOWRITE :type `r`: QPointF """ p = QPainterPath() p.addRect(r) self.setPath(p) # pythonic setRect overload @signature(float, float, float, float) def setRectFromXYWH(self, x, y, w, h): """ TOWRITE :param `x`: TOWRITE :type `x`: qreal :param `y`: TOWRITE :type `y`: qreal :param `w`: TOWRITE :type `w`: qreal :param `h`: TOWRITE :type `h`: qreal """ p = QPainterPath() p.addRect(x, y, w, h) self.setPath(p) @overloaded(setRectFromRect, setRectFromXYWH) def setRect(self, *args): """ TOWRITE """ pass def line(self): """ TOWRITE :return: TOWRITE :rtype: `QLineF`_ """ return self.objLine # pythonic setLine overload @signature(QPointF) def setLineFromLine(self, li): """ TOWRITE :param `li`: TOWRITE :type `li`: QPointF """ p = QPainterPath() p.moveTo(li.p1()) p.lineTo(li.p2()) self.setPath(p) self.objLine = li # pythonic setLine overload @signature(float, float, float, float) def setLineFromXXYY(self, x1, y1, x2, y2): """ TOWRITE :param `x1`: TOWRITE :type `x1`: qreal :param `y1`: TOWRITE :type `y1`: qreal :param `x2`: TOWRITE :type `x2`: qreal :param `y2`: TOWRITE :type `y2`: qreal """ p = QPainterPath() p.moveTo(x1, y1) p.lineTo(x2, y2) self.setPath(p) self.objLine.setLine(x1, y1, x2, y2) @overloaded(setLineFromLine, setLineFromXXYY) def setLine(self, *args): """ TOWRITE """ pass def setObjectPath(self, p): """ TOWRITE :param `p`: TOWRITE :type `p`: `QPainterPath`_ """ self.setPath(p) def setObjectRubberMode(self, mode): """ TOWRITE :param `mode`: TOWRITE :type `mode`: int """ self.objRubberMode = mode def setObjectRubberPoint(self, key, point): """ TOWRITE :param `key`: TOWRITE :type `key`: str :param `point`: TOWRITE :type `point`: `QPointF`_ """ self.objRubberPoints[key] = point # .insert(key, point) def setObjectRubberText(self, key, txt): """ TOWRITE :param `key`: TOWRITE :type `key`: str :param `txt`: TOWRITE :type `txt`: str """ self.objRubberTexts[key] = txt # .insert(key, txt) def shape(self): """ TOWRITE :return: TOWRITE :rtype: `QPainterPath`_ """ return self.path() def vulcanize(self): """ TOWRITE """ raise NotImplementedError def mouseSnapPoint(self, mousePoint): """ TOWRITE :param `mousePoint`: TOWRITE :type `mousePoint`: `QPointF`_ :return: TOWRITE :rtype: `QPointF`_ """ raise NotImplementedError def allGripPoints(self): """ TOWRITE :return: TOWRITE :rtype: list[`QPointF`_] """ raise NotImplementedError def gripEdit(self, before, after): """ TOWRITE :param `before`: TOWRITE :type `before`: `QPointF`_ :param `after`: TOWRITE :type `after`: `QPointF`_ """ raise NotImplementedError def lineWeightPen(self): """ TOWRITE :return: TOWRITE :rtype: `QPen`_ """ return self.lwtPen
def paintEvent( self, event ): painter = QPainter() painter.begin(self) painter.setRenderHint(painter.Antialiasing) font = painter.font() font.setBold(True) painter.setFont(font) x = self.rect().x() y = self.rect().y() w = self.rect().width() - 1 h = self.rect().height() - 1 r = 8 # draw a rounded style if self._rolloutStyle == 2: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) # draw the triangle self.__drawTriangle(painter, x, y) # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRoundedRect(x, y, w - 1, h - 1, r, r) # draw a square style if self._rolloutStyle == 3: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) self.__drawTriangle(painter, x, y) # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(x + 1, y + 1, w - 1, h - 1) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(x, y, w - 1, h - 1) # draw a Maya style if self._rolloutStyle == 4: # draw the text painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title()) painter.setRenderHint(QPainter.Antialiasing, False) self.__drawTriangle(painter, x, y) # draw the borders - top headerHeight = 20 headerRect = QRect(x + 1, y + 1, w - 1, headerHeight) headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2) # Highlight pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(headerRect) painter.fillRect(headerRect, QColor(255, 255, 255, 18)) # Shadow pen.setColor(self.palette().color(QPalette.Dark)) painter.setPen(pen) painter.drawRect(headerRectShadow) if not self.isCollapsed(): # draw the lover border pen = QPen(self.palette().color(QPalette.Dark)) pen.setWidthF(0.8) painter.setPen(pen) offSet = headerHeight + 3 bodyRect = QRect(x, y + offSet, w, h - offSet) bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1) painter.drawRect(bodyRect) pen.setColor(self.palette().color(QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(bodyRectShadow) # draw a boxed style elif self._rolloutStyle == 1: if self.isCollapsed(): arect = QRect(x + 1, y + 9, w - 1, 4) brect = QRect(x, y + 8, w - 1, 4) text = '+' else: arect = QRect(x + 1, y + 9, w - 1, h - 9) brect = QRect(x, y + 8, w - 1, h - 9) text = '-' # draw the borders pen = QPen(self.palette().color(QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(arect) pen.setColor(self.palette().color(QPalette.Shadow)) painter.setPen(pen) painter.drawRect(brect) painter.setRenderHint(painter.Antialiasing, False) painter.setBrush(self.palette().color(QPalette.Window).darker(120)) painter.drawRect(x + 10, y + 1, w - 20, 16) painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text) painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title()) if self.dragDropMode(): rect = self.dragDropRect() # draw the lines l = rect.left() r = rect.right() cy = rect.center().y() for y in (cy - 3, cy, cy + 3): painter.drawLine(l, y, r, y) painter.end()
def loadFile(self, fileName): """ TOWRITE :param `fileName`: TOWRITE :type `fileName`: QString :rtype: bool """ qDebug("MdiWindow loadFile()") tmpColor = self.getCurrentColor() # QRgb file = QFile(fileName) if not file.open(QFile.ReadOnly | QFile.Text): QMessageBox.warning( self, self.tr("Error reading file"), self.tr("Cannot read file %s:\n%s." % (fileName, file.errorString())) ) return False QApplication.setOverrideCursor(Qt.WaitCursor) ext = self.fileExtension(fileName) # QString qDebug("ext: %s" % qPrintable(ext)) # Read p = embPattern_create() # EmbPattern* if not p: print("Could not allocate memory for embroidery pattern\n") exit(1) readSuccessful = 0 # int ## QString readError reader = embReaderWriter_getByFileName(qPrintable(fileName)) # EmbReaderWriter* if not reader: readSuccessful = 0 readError = "Unsupported read file type: " + fileName qDebug("Unsupported read file type: %s\n" % qPrintable(fileName)) else: readSuccessful = reader.reader(p, qPrintable(fileName)) if not readSuccessful: readError = "Reading file was unsuccessful: " + fileName qDebug("Reading file was unsuccessful: %s\n" % qPrintable(fileName)) ## free(reader) #TODO/REMOVE# not needed in python if not readSuccessful: QMessageBox.warning(self, self.tr("Error reading pattern"), self.tr(qPrintable(readError))) if readSuccessful: embPattern_moveStitchListToPolylines(p) # TODO: Test more stitchCount = embStitchList_count(p.stitchList) # int path = QPainterPath() if p.circleObjList: curCircleObj = p.circleObjList # EmbCircleObjectList* while curCircleObj: c = curCircleObj.circleObj.circle # EmbCircle thisColor = curCircleObj.circleObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) # NOTE: With natives, the Y+ is up and libembroidery Y+ is up, so inverting the Y is NOT needed. self.mainWin.nativeAddCircle(embCircle_centerX(c), embCircle_centerY(c), embCircle_radius(c), False, OBJ_RUBBER_OFF) # TODO: fill curCircleObj = curCircleObj.next if p.ellipseObjList: curEllipseObj = p.ellipseObjList # EmbEllipseObjectList* while curEllipseObj: e = curEllipseObj.ellipseObj.ellipse # EmbEllipse thisColor = curEllipseObj.ellipseObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) # NOTE: With natives, the Y+ is up and libembroidery Y+ is up, so inverting the Y is NOT needed. self.mainWin.nativeAddEllipse(embEllipse_centerX(e), embEllipse_centerY(e), embEllipse_width(e), embEllipse_height(e), 0, False, OBJ_RUBBER_OFF) # TODO: rotation and fill curEllipseObj = curEllipseObj.next if p.lineObjList: curLineObj = p.lineObjList # EmbLineObjectList* while curLineObj: li = curLineObj.lineObj.line # EmbLine thisColor = curLineObj.lineObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) # NOTE: With natives, the Y+ is up and libembroidery Y+ is up, so inverting the Y is NOT needed. self.mainWin.nativeAddLine(embLine_x1(li), embLine_y1(li), embLine_x2(li), embLine_y2(li), 0, OBJ_RUBBER_OFF) # TODO: rotation curLineObj = curLineObj.next if p.pathObjList: # TODO: This is unfinished. It needs more work curPathObjList = p.pathObjList # EmbPathObjectList* while curPathObjList: pathPath = QPainterPath() curPointList = curPathObjList.pathObj.pointList # EmbPointList* thisColor = curPathObjList.pathObj.color # EmbColor if curPointList: pp = curPointList.point # EmbPoint pathPath.moveTo(embPoint_x(pp), -embPoint_y(pp)) # NOTE: Qt Y+ is down and libembroidery Y+ is up, so inverting the Y is needed. curPointList = curPointList.next while curPointList: pp = curPointList.point # EmbPoint pathPath.lineTo(embPoint_x(pp), -embPoint_y(pp)) # NOTE: Qt Y+ is down and libembroidery Y+ is up, so inverting the Y is needed. curPointList = curPointList.next loadPen = QPen(qRgb(thisColor.r, thisColor.g, thisColor.b)) loadPen.setWidthF(0.35) loadPen.setCapStyle(Qt.RoundCap) loadPen.setJoinStyle(Qt.RoundJoin) obj = PathObject(0, 0, pathPath, loadPen.color().rgb()) # PathObject* obj.setObjectRubberMode(OBJ_RUBBER_OFF) self.gscene.addItem(obj) curPathObjList = curPathObjList.next if p.pointObjList: curPointObj = p.pointObjList # EmbPointObjectList* while curPointObj: po = curPointObj.pointObj.point # EmbPoint thisColor = curPointObj.pointObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) # NOTE: With natives, the Y+ is up and libembroidery Y+ is up, so inverting the Y is NOT needed. self.mainWin.nativeAddPoint(embPoint_x(po), embPoint_y(po)) curPointObj = curPointObj.next if p.polygonObjList: curPolygonObjList = p.polygonObjList # EmbPolygonObjectList* while curPolygonObjList: polygonPath = QPainterPath() firstPoint = False # bool startX = 0; startY = 0 # qreal x = 0; y = 0 # qreal curPointList = curPolygonObjList.polygonObj.pointList # EmbPointList* thisColor = curPolygonObjList.polygonObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) while curPointList: pp = curPointList.point # EmbPoint x = embPoint_x(pp) y = -embPoint_y(pp) # NOTE: Qt Y+ is down and libembroidery Y+ is up, so inverting the Y is needed. if firstPoint: polygonPath.lineTo(x,y) else: polygonPath.moveTo(x,y) firstPoint = True startX = x startY = y curPointList = curPointList.next polygonPath.translate(-startX, -startY) self.mainWin.nativeAddPolygon(startX, startY, polygonPath, OBJ_RUBBER_OFF) curPolygonObjList = curPolygonObjList.next # NOTE: Polylines should only contain NORMAL stitches. if p.polylineObjList: curPolylineObjList = p.polylineObjList # EmbPolylineObjectList* while curPolylineObjList: polylinePath = QPainterPath() firstPoint = False # bool startX = 0; startY = 0 # qreal x = 0; y = 0 # qreal curPointList = curPolylineObjList.polylineObj.pointList # EmbPointList* thisColor = curPolylineObjList.polylineObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) while curPointList: pp = curPointList.point # EmbPoint x = embPoint_x(pp) y = -embPoint_y(pp) # NOTE: Qt Y+ is down and libembroidery Y+ is up, so inverting the Y is needed. if firstPoint: polylinePath.lineTo(x,y) else: polylinePath.moveTo(x,y) firstPoint = True startX = x startY = y curPointList = curPointList.next polylinePath.translate(-startX, -startY) self.mainWin.nativeAddPolyline(startX, startY, polylinePath, OBJ_RUBBER_OFF) curPolylineObjList = curPolylineObjList.next if p.rectObjList: curRectObj = p.rectObjList # EmbRectObjectList* while curRectObj: r = curRectObj.rectObj.rect # EmbRect thisColor = curRectObj.rectObj.color # EmbColor self.setCurrentColor(qRgb(thisColor.r, thisColor.g, thisColor.b)) # NOTE: With natives, the Y+ is up and libembroidery Y+ is up, so inverting the Y is NOT needed. self.mainWin.nativeAddRectangle(embRect_x(r), embRect_y(r), embRect_width(r), embRect_height(r), 0, False, OBJ_RUBBER_OFF) # TODO: rotation and fill curRectObj = curRectObj.next self.setCurrentFile(fileName) self.mainWin.statusbar.showMessage("File loaded.") stitches = str(stitchCount) # QString: stitches.setNum(stitchCount) if self.mainWin.getSettingsGridLoadFromFile(): # TODO: Josh, provide me a hoop size and/or grid spacing from the pattern. pass QApplication.restoreOverrideCursor() else: #TODO/PORT# warning shown twice?! redundant ?! QApplication.restoreOverrideCursor() QMessageBox.warning(self, self.tr("Error reading pattern"), self.tr("Cannot read pattern")) ## embPattern_free(p) #TODO/REMOVE# not needed in python # Clear the undo stack so it is not possible to undo past this point. self.gview.getUndoStack().clear() self.setCurrentColor(tmpColor) fileWasLoaded = True self.mainWin.setUndoCleanIcon(fileWasLoaded) return fileWasLoaded
from PySide.QtGui import QColor, QBrush, QPen from PySide.QtCore import Qt print "Initializing Color" colorHexLine = QColor(Qt.green) colorHexBrush = QColor(192,255,192) colorHexRoute = QColor(255,192,0) colorHexRoute.setAlpha(128) colorHexRouteSel = QColor(192,128,0) colorHexRouteSel.setAlpha(128) penLine = QPen(colorHexLine) penLine.setWidthF(2.0) penRoute = QPen(colorHexRoute) penRoute.setWidthF(12.0) penRouteSel = QPen(colorHexRouteSel) penRouteSel.setWidthF(12.0) brushHex = QBrush(colorHexBrush)