def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()

        if is_secondary_color:
            pen.setColor(self.data_singleton.secondary_color)
        else:
            pen.setColor(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        painter.setPen(pen)

        if is_secondary_color:
            painter.setBrush(self.data_singleton.primary_color)
        else:
            painter.setBrush(self.data_singleton.secondary_color)

        if self._start_point != self._end_point:
            painter.drawRect(QRect(self._start_point, self._end_point))

        painter.end()

        canvas.edited = True
        canvas.update()
Example #2
0
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        if is_secondary_color:
            pen.setBrush(self.data_singleton.secondary_color)
        else:
            pen.setBrush(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setPen(pen)

        if self._start_point != self._end_point:
            painter.drawLine(self._start_point, self._end_point)

        if self._start_point == self._end_point:
            painter.drawPoint(self._start_point)

        painter.end()

        canvas.edited = True
        canvas.update()
Example #3
0
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        pen = QPen()
        pen.setColor(Qt.GlobalColor.black)
        pen.setWidth(2)
        pen.setJoinStyle(Qt.MiterJoin)
        p.setPen(pen)

        h = self.associated_label.sizeHint().height()
        w = h
        pw = pen.width()

        b = self.italic_block(pw+0,w,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step]))
        p.drawPath(b)
        b = self.italic_block(pw+w*1.25,w*0.75,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step+1]))
        p.drawPath(b)
        b = self.italic_block(pw+w*2.25,w*0.4,h)
        p.translate(self.shadow_size,self.shadow_size)
        p.fillPath(b, QBrush(Qt.gray))
        p.translate(-self.shadow_size,-self.shadow_size)
        p.fillPath(b, QBrush(self.Colors[self.step+2]))
        p.drawPath(b)
Example #4
0
def default_roi_pen(dashed=True,color=Qt.green):
    pen = QPen()
    if dashed:
        pen.setStyle(Qt.DashLine)
    pen.setBrush(color)
    pen.setCapStyle(Qt.RoundCap)
    pen.setJoinStyle(Qt.RoundJoin)
    return pen
Example #5
0
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
Example #6
0
    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