def on_pbTemplateNode_clicked(self):
     """
     Display the Template Node format dialog box and allow the user to change the project level Template node format
     """
     d = TNodeFormatDlg(self,
                        modelData=None,
                        nodeFormat=TNodeFormat(
                            formatDict=self.templateNodeFormat.formatDict))
     if d.exec_():
         self.templateNodeFormat = TNodeFormat(
             formatDict=d.nodeFormat.formatDict)
         self.drawTemplateNode()
         self.formatChanged = True
    def getFormat(self, ):
        '''
        determine if the Node Template  has a template format or should use the project default format
        '''
        # get the node Template custom format
        customFormat = self.nodeTemplateDict.get("TNformat", None)

        if not customFormat is None:
            # get the template custom format
            self.nodeFormat = TNodeFormat(formatDict=customFormat)
        else:
            # get the project default format
            self.nodeFormat = TNodeFormat(
                formatDict=self.model.modelData["TNformat"])
Beispiel #3
0
 def on_pbTemplateNode_clicked(self):
     """
     User requests edit a Node Template Format
     """
     # create a TNodeFormat object from the system settings dictionary
     x = self.settings.value("Default/Format/TemplateNode")
     d = TNodeFormatDlg(self,
                        modelData=None,
                        nodeFormat=TNodeFormat(formatDict=x))
     if d.exec_():
         self.settings.setValue("Default/Format/TemplateNode",
                                d.nodeFormat.formatDict)
         self.templateNodeFormat = TNodeFormat(
             formatDict=self.settings.value("Default/Format/TemplateNode"))
         self.drawTemplateNode()
class NodeTemplateItem():
    ''' 
    This represents one node template on the diagram.  A node template can be on many diagrams
    This class creates the rectangle graphics item and the text graphics item and adds them to the scene.
    '''
    def __init__(self, scene, x, y, nodeTemplateDict=None, NZID=None):
        self.scene = scene
        self.logMsg = None
        self.x = x
        self.y = y
        self.nodeTemplateDict = nodeTemplateDict
        #        self.name = self.nodeTemplateDict.get("name", "")   THIS HAS BEEN REPLACED BY THE name FUNCTION - SEE BELOW
        self.diagramType = "Node Template"
        self.displayText = None
        self.model = self.scene.parent.model
        self.gap = 100
        self.relList = []
        # assign a unique key if it doesn't already have one
        if NZID == None:
            self.NZID = str(uuid.uuid4())
        else:
            self.NZID = NZID

        # init graphics objects to none
        self.TNode = None
        self.TNtext = None

        # draw the node template on the diagram
        self.drawIt()

    def name(self, ):
        return self.nodeTemplateDict.get("name", "")

    def getX(self, ):
        return self.TNode.boundingRect().x()

    def getY(self, ):
        return self.TNode.boundingRect().y()

    def getHeight(self, ):
        return self.TNode.boundingRect().height()

    def getWidth(self, ):
        return self.TNode.boundingRect().width()

    def getRelList(self, ):
        '''return a list of all relationitems that are inbound or outbound from this node template.
          do not include self referencing relationships
        '''
        return [
            diagramItem
            for key, diagramItem in self.scene.parent.itemDict.items()
            if diagramItem.diagramType == "Relationship Template" and (
                diagramItem.startNZID == self.NZID
                or diagramItem.endNZID == self.NZID)
        ]

    def getPoint(self, offset=None):
        '''
        This function is used by the template diagram to calculate the location to drop a node template on the diagram
        '''
        if offset is None:
            return QPointF(self.x, self.y)
        else:
            return QPointF(self.x + offset, self.y + offset)

    def getFormat(self, ):
        '''
        determine if the Node Template  has a template format or should use the project default format
        '''
        # get the node Template custom format
        customFormat = self.nodeTemplateDict.get("TNformat", None)

        if not customFormat is None:
            # get the template custom format
            self.nodeFormat = TNodeFormat(formatDict=customFormat)
        else:
            # get the project default format
            self.nodeFormat = TNodeFormat(
                formatDict=self.model.modelData["TNformat"])

    def clearItem(self, ):

        if (not self.TNode is None and not self.TNode.scene() is None):
            self.TNode.scene().removeItem(self.TNode)
        if (not self.TNtext is None and not self.TNtext.scene() is None):
            self.TNtext.scene().removeItem(self.TNtext)

    def drawIt(self, ):

        # get current format as it may have changed
        self.getFormat()

        # create the qgraphicsItems if they don't exist
        if self.TNode is None:
            # create the rectangle
            self.TNode = QGraphicsRectItem(QRectF(
                self.x, self.y, self.nodeFormat.formatDict["nodeWidth"],
                self.nodeFormat.formatDict["nodeHeight"]),
                                           parent=None)
            self.TNode.setZValue(NODELAYER)
            self.TNode.setFlag(QGraphicsItem.ItemIsMovable, True)
            self.TNode.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
            self.TNode.setFlag(QGraphicsItem.ItemIsSelectable, True)
            self.TNode.setSelected(True)
            self.TNode.setData(1, self.NZID)  # get with self.INode.data(1)
            self.TNode.setData(ITEMTYPE, NODETEMPLATE)
            # create the text box
            self.TNtext = QGraphicsTextItem("", parent=None)
            self.TNtext.setPos(self.x, self.y)
            self.TNtext.setFlag(QGraphicsItem.ItemIsMovable, True)
            self.TNtext.setFlag(QGraphicsItem.ItemIsSelectable, False)
            self.TNtext.setData(NODEID, self.NZID)
            self.TNtext.setData(ITEMTYPE, NODETEMPLATETEXT)
            self.TNtext.setZValue(NODELAYER)
            # save the location
            self.x = self.TNode.sceneBoundingRect().x()
            self.y = self.TNode.sceneBoundingRect().y()
            # generate the html and resize the rectangle
            self.formatItem()
            # add the graphics items to the scene
            self.scene.addItem(self.TNode)
            self.scene.addItem(self.TNtext)
        else:
            # generate the html and resize the rectangle
            self.formatItem()

    def formatItem(self, ):

        # configure the formatting aspects of the qgraphics item
        pen = self.nodeFormat.pen()
        brush = self.nodeFormat.brush()
        self.TNode.setBrush(brush)
        self.TNode.setPen(pen)

        # generate the HTML
        genHTML = self.generateHTML()
        self.TNtext.prepareGeometryChange()
        #        print("before html bounding rectangle width:{}".format(self.TNtext.boundingRect().width()))
        #        print("before html text width:{}".format(self.TNtext.textWidth()))
        self.TNtext.setTextWidth(
            -1
        )  # reset the width to unkonwn so it will calculate a new width based on the new html
        self.TNtext.setHtml(genHTML)
        #        print("after html bounding rectangle width:{}".format(self.TNtext.boundingRect().width()))
        #        print("after html text width:{}".format(self.TNtext.textWidth()))

        # make sure minimum width of 120
        if self.TNtext.boundingRect().width() < 120:
            self.TNtext.setTextWidth(120)
        else:
            self.TNtext.setTextWidth(
                self.TNtext.boundingRect().width()
            )  # you have to do a setTextWidth to get the html to render correctly.

        # set the rectangle item to the same size as the formatted html
        self.TNode.prepareGeometryChange()
        currentRect = self.TNode.rect()
        # insure minimum height of 120
        if self.TNtext.boundingRect().height() < 120:
            currentRect.setHeight(120)
        else:
            currentRect.setHeight(self.TNtext.boundingRect().height())
        currentRect.setWidth(self.TNtext.boundingRect().width())
        self.TNode.setRect(currentRect)

    def generateHTML(self, ):
        '''
        Generate the HTML that formats the node template data inside the rectangle
        '''
        # generate the html
        prefix = "<!DOCTYPE html><html><body>"
        #        head = "<head><style>table, th, td {border: 1px solid black; border-collapse: collapse;}</style></head>"
        suffix = "</body></html>"
        #        blankRow = "<tr><td><left>{}</left></td><td><left>{}</left></td><td><left>{}</left></td><td><left>{}</left></td></tr>".format("", "", "", "")

        name = "<center><b>{}</b></center>".format(
            self.nodeTemplateDict.get("name", ""))
        lbls = self.genLblHTML()
        props = self.genPropHTML()
        genHTML = "{}{}<hr>{}<br><hr>{}{}".format(prefix, name, lbls, props,
                                                  suffix)
        #        print("{} html: {}".format(self.name(), genHTML))

        return genHTML

    def genLblHTML(self):
        #        html = '<table width="90%">'
        html = '<table style="width:90%;border:1px solid black;">'
        if len(self.nodeTemplateDict.get("labels", [])) > 0:
            for lbl in self.nodeTemplateDict.get("labels", []):
                if lbl[NODEKEY] == Qt.Checked:
                    nk = "NK"
                else:
                    nk = "&nbsp;&nbsp;"
                if lbl[REQUIRED] == Qt.Checked:
                    rq = "R"
                else:
                    rq = ""

                html = html + '<tr align="left"><td width="15%"><left>{}</left></td><td width="65%"><left>{}</left></td><td width="10%"><left>{}</left></td><td width="10%"><left>{}</left></td></tr>'.format(
                    nk, lbl[LABEL], "", rq)
            html = html + "</table>"
        else:
            html = '<tr align="left"><td width="15%"><left>{}</left></td><td  width="65%"><left>{}</left></td><td width="10%"><left>{}</left></td><td width="10%"><left>{}</left></td></tr>'.format(
                "  ", "NO{}LABELS".format("&nbsp;"), "", "")
            html = html + "</table>"

        return html

    def genPropHTML(self):
        #        PROPERTY, DATATYPE, PROPREQ, DEFAULT, EXISTS, UNIQUE, PROPNODEKEY
        html = '<table style="width:90%;border:1px solid black;">'
        if len(self.nodeTemplateDict.get("properties", [])) > 0:
            for prop in self.nodeTemplateDict.get("properties", []):
                if prop[PROPNODEKEY] == Qt.Checked:
                    nk = "NK"
                else:
                    nk = "&nbsp;&nbsp;"
                if prop[PROPREQ] == Qt.Checked:
                    rq = "R"
                else:
                    rq = ""
                if prop[EXISTS] == Qt.Checked:
                    ex = "E"
                else:
                    ex = ""
                if prop[UNIQUE] == Qt.Checked:
                    uq = "U"
                else:
                    uq = ""
                html = html + '<tr align="left"><td width="15%"><left>{}</left></td><td width="65%"><left>{}</left></td><td width="10%"><left>{}</left></td><td width="10%"><left>{}</left></td><td width="10%"><left>{}</left></td></tr>'.format(
                    nk, prop[PROPERTY], rq, ex, uq)
            html = html + "</table>"
        else:
            html = html + '<tr align="left"><td width="15%"><left>{}</left></td><td width="65%"><left>{}</left></td><td width="10%"><left>{}</left></td><td width="10%"><left>{}</left></td></tr>'.format(
                "&nbsp;&nbsp;", "NO{}PROPERTIES".format("&nbsp;"), "", "", "")
            html = html + "</table>"
        return html

    def moveIt(self, dx, dy):
        '''
        Move the node rectangle and the node textbox to the delta x,y coordinate.
        '''
        #        print("before moveIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))

        self.TNode.moveBy(dx, dy)
        self.x = self.TNode.sceneBoundingRect().x()
        self.y = self.TNode.sceneBoundingRect().y()
        self.TNtext.moveBy(dx, dy)
        #        print("after moveIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))
        # now redraw all the relationships
        self.drawRels()

    def drawRels(self, ):
        '''Redraw all the relationship lines connected to the Node Template Rectangle'''
        # get a list of the relationship items connected to this node template
        self.relList = self.getRelList()

        # assign the correct inbound/outbound side for the rel
        for rel in self.relList:
            if rel.endNodeItem.NZID != rel.startNodeItem.NZID:  # ignore bunny ears
                rel.assignSide()
        # get a set of all the nodes and sides involved
        nodeSet = set()
        for rel in self.relList:
            if rel.endNodeItem.NZID != rel.startNodeItem.NZID:  # ignore bunny ears
                nodeSet.add((rel.endNodeItem, rel.inboundSide))
                nodeSet.add((rel.startNodeItem, rel.outboundSide))

        # tell each node side to assign rel locations
        for nodeSide in nodeSet:
            nodeSide[0].assignPoint(nodeSide[1])

        ############################################

        # now tell them all to redraw
        for rel in self.relList:
            rel.drawIt2()

    def calcOffset(self, index, totRels):
        offset = [-60, -40, -20, 0, 20, 40, 60]
        offsetStart = [3, 2, 2, 1, 1, 0, 0]
        if totRels > 7:
            totRels = 7
        return offset[offsetStart[totRels - 1] + index]

    def assignPoint(self, side):
        # go through all the rels on a side and assign their x,y coord for that side
        self.relList = self.getRelList()
        sideList = [
            rel for rel in self.relList
            if ((rel.startNZID == self.NZID and rel.outboundSide == side) or (
                rel.endNZID == self.NZID and rel.inboundSide == side))
        ]
        totRels = len(sideList)
        if totRels > 0:
            if side == R:
                # calc center of the side
                x = self.x + self.getWidth()
                y = self.y + self.getHeight() / 2
                # sort the rels connected to this side by the y value
                sideList.sort(key=self.getSortY)
                # assign each of them a position on the side starting in the center and working out in both directions
                for index, rel in enumerate(sideList):
                    if rel.startNZID == self.NZID:
                        rel.outboundPoint = QPointF(
                            x, y + (self.calcOffset(index, totRels)))
                    if rel.endNZID == self.NZID:
                        rel.inboundPoint = QPointF(
                            x, y + (self.calcOffset(index, totRels)))
            elif side == L:
                x = self.x
                y = self.y + self.getHeight() / 2
                sideList.sort(key=self.getSortY)
                for index, rel in enumerate(sideList):
                    if rel.startNZID == self.NZID:
                        rel.outboundPoint = QPointF(
                            x, y + (self.calcOffset(index, totRels)))
                    if rel.endNZID == self.NZID:
                        rel.inboundPoint = QPointF(
                            x, y + (self.calcOffset(index, totRels)))
            elif side == TOP:
                x = self.x + self.getWidth() / 2
                y = self.y
                sideList.sort(key=self.getSortX)
                for index, rel in enumerate(sideList):
                    if rel.startNZID == self.NZID:
                        rel.outboundPoint = QPointF(
                            x + (self.calcOffset(index, totRels)), y)
                    if rel.endNZID == self.NZID:
                        rel.inboundPoint = QPointF(
                            x + (self.calcOffset(index, totRels)), y)
            elif side == BOTTOM:
                x = self.x + self.getWidth() / 2
                y = self.y + self.getHeight()
                sideList.sort(key=self.getSortX)
                for index, rel in enumerate(sideList):
                    if rel.startNZID == self.NZID:
                        rel.outboundPoint = QPointF(
                            x + (self.calcOffset(index, totRels)), y)
                    if rel.endNZID == self.NZID:
                        rel.inboundPoint = QPointF(
                            x + (self.calcOffset(index, totRels)), y)
            else:
                print("error, no side")

    def getSortY(self, rel):
        # if this node is the start node then return the end node's Y
        if rel.startNZID == self.NZID:
            return rel.endNodeItem.TNode.sceneBoundingRect().center().y()
        # if this node is the end node then return the start node's Y
        if rel.endNZID == self.NZID:
            return rel.startNodeItem.TNode.sceneBoundingRect().center().y()
        # this should never happen
        return 0

    def getSortX(self, rel):
        # if this node is the start node then return the end node's X
        if rel.startNZID == self.NZID:
            return rel.endNodeItem.TNode.sceneBoundingRect().center().x()
        # if this node is the end node then return the start node's X
        if rel.endNZID == self.NZID:
            return rel.startNodeItem.TNode.sceneBoundingRect().center().x()
        # this should never happen
        return 0

    def getObjectDict(self, ):
        '''
        This function returns a dictionary with all the data that represents this node template item.  
        The dictionary is added to the Instance Diagram dictionary.'''
        objectDict = {}
        objectDict["NZID"] = self.NZID
        objectDict["name"] = self.nodeTemplateDict.get("name", "")
        objectDict["displayText"] = self.displayText
        objectDict["x"] = self.TNode.sceneBoundingRect().x()
        objectDict["y"] = self.TNode.sceneBoundingRect().y()
        objectDict["diagramType"] = self.diagramType
        objectDict["labels"] = self.nodeTemplateDict.get("labels", [])
        objectDict["properties"] = self.nodeTemplateDict.get("properties", [])

        return objectDict

    def setLogMethod(self, logMethod=None):
        if logMethod is None:
            if self.logMsg is None:
                self.logMsg = self.noLog
        else:
            self.logMsg = logMethod

    def noLog(self, msg):
        return
Beispiel #5
0
    def initSettings(self, ):
        '''
        get the system settings needed to start NodeEra.
        If a system setting doesn't exist then create it with default value - this happens on initial startup
        '''
        self.settings = QSettings()
        try:
            self.expirationDate = self.helper.getText(
                self.settings.value("License/expirationDate"))
            if self.expirationDate is None:
                self.expirationDate = 'No expiration date set'
                self.settings.setValue(
                    "License/expirationDate",
                    self.helper.putText(self.expirationDate))
        except:
            self.expirationDate = 'No expiration date set'
            self.settings.setValue("License/expirationDate",
                                   self.helper.putText(self.expirationDate))

        try:
            self.currentVersion = self.settings.value("License/currentVersion")
            if self.currentVersion is None:
                self.currentVersion = currentVersion
                self.settings.setValue("License/currentVersion",
                                       self.currentVersion)
            elif self.currentVersion != currentVersion:
                self.currentVersion = currentVersion
                self.settings.setValue("License/currentVersion",
                                       self.currentVersion)
        except:
            self.currentVersion = currentVersion
            self.settings.setValue("License/currentVersion",
                                   self.currentVersion)

        try:
            self.winSize = self.settings.value("MainWindow/Size")
            if self.winSize is None:
                self.winSize = QSize(800, 500)
        except:
            self.winSize = QSize(800, 500)

        try:
            self.position = self.settings.value("MainWindow/Position")
            if self.position is None:
                self.position = QPoint(0, 0)
        except:
            self.position = QPoint(0, 0)

        try:
            self.recentList = self.settings.value("Default/RecentList")
            if self.recentList is None:
                self.recentList = []
                self.settings.setValue("Default/RecentList", self.recentList)
        except:
            self.recentList = []
            self.settings.setValue("Default/RecentList", self.recentList)

        try:
            self.defaultLoggingPath = self.settings.value(
                "Default/LoggingPath")
            if self.defaultLoggingPath is None:
                self.logDir = os.getcwd()
                self.logDir = os.path.realpath(os.path.abspath(self.logDir))
                self.settings.setValue("Default/LoggingPath", self.logDir)
        except:
            self.logDir = os.getcwd()
            self.logDir = os.path.realpath(os.path.abspath(self.logDir))
            self.settings.setValue("Default/LoggingPath", self.logDir)

        try:
            self.defaultProjPath = self.settings.value("Default/ProjPath")
            if self.defaultProjPath is None:
                self.defaultProjPath = os.getcwd()
                self.defaultProjPath = os.path.realpath(
                    os.path.abspath(self.defaultProjPath))
                self.settings.setValue("Default/ProjectPath",
                                       self.defaultProjPath)
        except:
            self.defaultProjPath = os.getcwd()
            self.defaultProjPath = os.path.realpath(
                os.path.abspath(self.defaultProjPath))
            self.settings.setValue("Default/ProjectPath", self.defaultProjPath)

        # default custom formats for diagram objects
        # Display Format - Instance Node
        try:
            test = self.settings.value("Default/Format/InstanceNode")
            if test is None:
                self.settings.setValue("Default/Format/InstanceNode",
                                       INodeFormat().formatDict)
        except:
            self.settings.setValue("Default/Format/InstanceNode",
                                   INodeFormat().formatDict)

        # Display Format - Instance Relationship
        try:
            test = self.settings.value("Default/Format/InstanceRelation")
            if test is None:
                self.settings.setValue("Default/Format/InstanceRelation",
                                       IRelFormat().formatDict)
        except:
            self.settings.setValue("Default/Format/InstanceRelation",
                                   IRelFormat().formatDict)

        # Display Format - Template Node
        try:
            test = self.settings.value("Default/Format/TemplateNode")
            if test is None:
                self.settings.setValue("Default/Format/TemplateNode",
                                       TNodeFormat().formatDict)
        except:
            self.settings.setValue("Default/Format/TemplateNode",
                                   TNodeFormat().formatDict)

        # Display Format - Template Relationship
        try:
            test = self.settings.value("Default/Format/TemplateRelation")
            if test is None:
                self.settings.setValue("Default/Format/TemplateRelation",
                                       TRelFormat().formatDict)
        except:
            self.settings.setValue("Default/Format/TemplateRelation",
                                   TRelFormat().formatDict)

        # page setup
        try:
            test = self.settings.value("Default/PageSetup")
            if test is None:
                self.settings.setValue("Default/PageSetup",
                                       PageSetup().objectDict)
        except:
            self.settings.setValue("Default/PageSetup", PageSetup().objectDict)

        # default project neocon
        try:
            defaultNeoConName = self.settings.value("NeoCon/Default")
            if defaultNeoConName is None:
                self.settings.setValue("NeoCon/Default", "LOCAL")
        except:
            self.settings.setValue("NeoCon/Default", "LOCAL")

        # LOCAL neocon definition
        try:
            self.localNeoCon = self.settings.value("NeoCon/connection/LOCAL")
            if self.localNeoCon is None:
                self.settings.setValue("NeoCon/connection/LOCAL",
                                       NeoDriver().localNeoConDict())
        except:
            self.settings.setValue("NeoCon/connection/LOCAL",
                                   NeoDriver().localNeoConDict())

        # default lexer font size
        try:
            defaultLexerFontSize = self.settings.value("Lexer/FontSize")
            if defaultLexerFontSize is None:
                self.settings.setValue("Lexer/FontSize", "10")
        except:
            self.settings.setValue("Lexer/FontSize", "10")

        # validate all neocons have the prompt dictionary key which was added in 1.04
        self.settings.beginGroup("NeoCon/connection")
        neoKeys = self.settings.childKeys()
        for key in neoKeys:
            neoDict = self.settings.value(key)
            promptVal = neoDict.get("prompt", None)
            if promptVal is None:
                neoDict["prompt"] = "False"
                self.settings.setValue(key, neoDict)

        self.settings.endGroup()
Beispiel #6
0
    def initUI(self, ):
        #General Page
        dir = str(self.settings.value("Default/ProjPath"))
        self.lblProjPath.setText(dir)
        self.lblProjPath.setToolTip(dir)

        logdir = str(self.settings.value("Default/LoggingPath"))
        self.lblLoggingPath.setText(logdir)
        self.lblLoggingPath.setToolTip(logdir)

        # page settings
        self.pageSizes = PageSizes()
        self.pageSizes.loadDropDown(self.cmbPageSize)
        self.pageSetup = PageSetup(
            objectDict=self.settings.value("Default/PageSetup"))
        index = self.cmbPageSize.findText(
            self.pageSetup.objectDict["pageSize"])
        if index >= 0:
            self.cmbPageSize.setCurrentIndex(index)
        if self.pageSetup.objectDict["pageOrientation"] == "Portrait":
            self.rbPortrait.setChecked(True)
            self.rbLandscape.setChecked(False)
        else:
            self.rbLandscape.setChecked(True)
            self.rbPortrait.setChecked(False)
        self.setPageHeightWidth()
        self.spinRows.setValue(self.pageSetup.objectDict["pageRows"])
        self.spinColumns.setValue(self.pageSetup.objectDict["pageCols"])

        #Instance Formats
        #        print("node format is {}".format(self.settings.value("Default/Format/InstanceNode")))
        formatDict = self.settings.value("Default/Format/InstanceNode")
        self.instanceNodeFormat = INodeFormat(formatDict=formatDict)
        relFormatDict = self.settings.value("Default/Format/InstanceRelation")
        self.instanceRelFormat = IRelFormat(formatDict=relFormatDict)

        #Template Formats
        formatDict = self.settings.value("Default/Format/TemplateNode")
        self.templateNodeFormat = TNodeFormat(formatDict=formatDict)
        relFormatDict = self.settings.value("Default/Format/TemplateRelation")
        self.templateRelFormat = IRelFormat(formatDict=relFormatDict)

        # complete scene setups
        self.INgraphicsView = QGraphicsView(parent=self.frmInstanceNodeViewer)
        self.INscene = QGraphicsScene(self)
        self.INscene.setSceneRect(0, 0, 300, 600)
        self.INgraphicsView.setScene(self.INscene)
        self.drawInstanceNode()

        self.IRgraphicsView = QGraphicsView(parent=self.frmInstanceRelViewer)
        self.IRscene = QGraphicsScene(self)
        self.IRscene.setSceneRect(0, 0, 300, 600)
        self.IRgraphicsView.setScene(self.IRscene)
        self.drawInstanceRel()

        self.TNgraphicsView = QGraphicsView(parent=self.frmTemplateNodeViewer)
        self.TNscene = QGraphicsScene(self)
        self.TNscene.setSceneRect(0, 0, 300, 600)
        self.TNgraphicsView.setScene(self.TNscene)
        self.drawTemplateNode()

        self.TRgraphicsView = QGraphicsView(parent=self.frmRelTemplateViewer)
        self.TRscene = QGraphicsScene(self)
        self.TRscene.setSceneRect(0, 0, 300, 600)
        self.TRgraphicsView.setScene(self.TRscene)
        self.drawTemplateRel()
Beispiel #7
0
class SystemPreferenceBox(QDialog, Ui_SystemPreferenceBox):
    """
    Modal Dialog box that displays System Preferences.
    The user may update and save the preferences.
    """
    def __init__(self, parent=None, settings=None):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        """
        super(SystemPreferenceBox, self).__init__(parent)
        self.settings = settings
        self.INtestItem = None
        self.IRtestItem = None
        self.TNtestItem = None
        self.TRtestItem = None
        self.pageSetup = None
        self.setupUi(self)
        self.initUI()
        self.stackedWidget.setCurrentIndex(0)

    def initUI(self, ):
        #General Page
        dir = str(self.settings.value("Default/ProjPath"))
        self.lblProjPath.setText(dir)
        self.lblProjPath.setToolTip(dir)

        logdir = str(self.settings.value("Default/LoggingPath"))
        self.lblLoggingPath.setText(logdir)
        self.lblLoggingPath.setToolTip(logdir)

        # page settings
        self.pageSizes = PageSizes()
        self.pageSizes.loadDropDown(self.cmbPageSize)
        self.pageSetup = PageSetup(
            objectDict=self.settings.value("Default/PageSetup"))
        index = self.cmbPageSize.findText(
            self.pageSetup.objectDict["pageSize"])
        if index >= 0:
            self.cmbPageSize.setCurrentIndex(index)
        if self.pageSetup.objectDict["pageOrientation"] == "Portrait":
            self.rbPortrait.setChecked(True)
            self.rbLandscape.setChecked(False)
        else:
            self.rbLandscape.setChecked(True)
            self.rbPortrait.setChecked(False)
        self.setPageHeightWidth()
        self.spinRows.setValue(self.pageSetup.objectDict["pageRows"])
        self.spinColumns.setValue(self.pageSetup.objectDict["pageCols"])

        #Instance Formats
        #        print("node format is {}".format(self.settings.value("Default/Format/InstanceNode")))
        formatDict = self.settings.value("Default/Format/InstanceNode")
        self.instanceNodeFormat = INodeFormat(formatDict=formatDict)
        relFormatDict = self.settings.value("Default/Format/InstanceRelation")
        self.instanceRelFormat = IRelFormat(formatDict=relFormatDict)

        #Template Formats
        formatDict = self.settings.value("Default/Format/TemplateNode")
        self.templateNodeFormat = TNodeFormat(formatDict=formatDict)
        relFormatDict = self.settings.value("Default/Format/TemplateRelation")
        self.templateRelFormat = IRelFormat(formatDict=relFormatDict)

        # complete scene setups
        self.INgraphicsView = QGraphicsView(parent=self.frmInstanceNodeViewer)
        self.INscene = QGraphicsScene(self)
        self.INscene.setSceneRect(0, 0, 300, 600)
        self.INgraphicsView.setScene(self.INscene)
        self.drawInstanceNode()

        self.IRgraphicsView = QGraphicsView(parent=self.frmInstanceRelViewer)
        self.IRscene = QGraphicsScene(self)
        self.IRscene.setSceneRect(0, 0, 300, 600)
        self.IRgraphicsView.setScene(self.IRscene)
        self.drawInstanceRel()

        self.TNgraphicsView = QGraphicsView(parent=self.frmTemplateNodeViewer)
        self.TNscene = QGraphicsScene(self)
        self.TNscene.setSceneRect(0, 0, 300, 600)
        self.TNgraphicsView.setScene(self.TNscene)
        self.drawTemplateNode()

        self.TRgraphicsView = QGraphicsView(parent=self.frmRelTemplateViewer)
        self.TRscene = QGraphicsScene(self)
        self.TRscene.setSceneRect(0, 0, 300, 600)
        self.TRgraphicsView.setScene(self.TRscene)
        self.drawTemplateRel()

####################################################################################
# PAGE SETTING METHODS
####################################################################################

    def setPageHeightWidth(self, ):
        # this sets the page height width based on page type and orientation
        height, width = self.pageSetup.getHeightWidth()
        self.txtHeight.setText(str(height))
        self.txtWidth.setText(str(width))

    @pyqtSlot()
    def on_rbLandscape_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("landscape")
        self.pageSetup.objectDict["pageOrientation"] = "Landscape"
        self.setPageHeightWidth()

    @pyqtSlot()
    def on_rbPortrait_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("portrait")
        self.pageSetup.objectDict["pageOrientation"] = "Portrait"
        self.setPageHeightWidth()

    @pyqtSlot(int)
    def on_cmbPageSize_currentIndexChanged(self, index):
        """
        Slot documentation goes here.
        
        @param index DESCRIPTION
        @type int
        """
        #        print("dropdown changed {}".format(self.cmbPageSize.currentText()))
        if self.pageSetup is None:
            return
        newPageSize = str(self.cmbPageSize.currentText())
        self.pageSetup.objectDict["pageSize"] = self.pageSizes.pageTypes[
            newPageSize].name
        self.pageSetup.objectDict["pageHeight"] = self.pageSizes.pageTypes[
            newPageSize].height
        self.pageSetup.objectDict["pageWidth"] = self.pageSizes.pageTypes[
            newPageSize].width
        self.setPageHeightWidth()

    @pyqtSlot(int)
    def on_spinRows_valueChanged(self, p0):
        """
        Slot documentation goes here.
        
        @param p0 DESCRIPTION
        @type int
        """
        self.pageSetup.objectDict["pageRows"] = self.spinRows.value()

    @pyqtSlot(int)
    def on_spinColumns_valueChanged(self, p0):
        """
        Slot documentation goes here.
        
        @param p0 DESCRIPTION
        @type int
        """
        self.pageSetup.objectDict["pageCols"] = self.spinColumns.value()

    def drawInstanceRel(self, ):
        if not (self.IRtestItem is None):
            self.IRscene.removeItem(self.IRtestItem)
        rpen = self.instanceRelFormat.pen()
        rbrush = self.instanceRelFormat.brush()
        self.IRtestItem = QGraphicsLineItem(5, 50, 100, 50, parent=None)
        self.IRtestItem.setPen(rpen)
        self.IRscene.addItem(self.IRtestItem)

    def drawTemplateRel(self, ):
        if not (self.TRtestItem is None):
            self.TRscene.removeItem(self.TRtestItem)
        rpen = self.templateRelFormat.pen()
        rbrush = self.templateRelFormat.brush()
        self.TRtestItem = QGraphicsLineItem(5, 50, 100, 50, parent=None)
        self.TRtestItem.setPen(rpen)
        self.TRscene.addItem(self.TRtestItem)

    def drawInstanceNode(self, ):
        if not (self.INtestItem is None):
            self.INscene.removeItem(self.INtestItem)
        npen = self.instanceNodeFormat.pen()
        nbrush = self.instanceNodeFormat.brush()
        self.INtestItem = QGraphicsEllipseItem(QRectF(
            5, 5, self.instanceNodeFormat.formatDict["nodeWidth"],
            self.instanceNodeFormat.formatDict["nodeHeight"]),
                                               parent=None)
        self.INtestItem.setBrush(nbrush)
        self.INtestItem.setPen(npen)
        self.INscene.addItem(self.INtestItem)

    def drawTemplateNode(self, ):
        if not (self.TNtestItem is None):
            self.TNscene.removeItem(self.TNtestItem)
        npen = self.templateNodeFormat.pen()
        nbrush = self.templateNodeFormat.brush()
        self.TNtestItem = QGraphicsRectItem(QRectF(
            5, 5, self.templateNodeFormat.formatDict["nodeWidth"],
            self.templateNodeFormat.formatDict["nodeHeight"]),
                                            parent=None)
        self.TNtestItem.setBrush(nbrush)
        self.TNtestItem.setPen(npen)
        self.TNscene.addItem(self.TNtestItem)

    def validate(self, ):
        return True

    def apply(self, ):
        self.settings.setValue("Default/ProjPath", self.lblProjPath.text())
        self.settings.setValue("Default/LoggingPath",
                               self.lblLoggingPath.text())
        self.settings.setValue("Default/PageSetup", self.pageSetup.objectDict)

#####################################################################
# template format methods
#####################################################################

    @pyqtSlot()
    def on_pbTemplateNode_clicked(self):
        """
        User requests edit a Node Template Format
        """
        # create a TNodeFormat object from the system settings dictionary
        x = self.settings.value("Default/Format/TemplateNode")
        d = TNodeFormatDlg(self,
                           modelData=None,
                           nodeFormat=TNodeFormat(formatDict=x))
        if d.exec_():
            self.settings.setValue("Default/Format/TemplateNode",
                                   d.nodeFormat.formatDict)
            self.templateNodeFormat = TNodeFormat(
                formatDict=self.settings.value("Default/Format/TemplateNode"))
            self.drawTemplateNode()

    @pyqtSlot()
    def on_pbRelTemplate_clicked(self):
        """
        User requests edit a Relationship Template Format
        """
        # create a RelFormat object from the system settings dictionary
        x = self.settings.value("Default/Format/TemplateRelation")
        d = TRelFormatDlg(self,
                          modelData=None,
                          relFormat=TRelFormat(formatDict=x))
        if d.exec_():
            self.settings.setValue("Default/Format/TemplateRelation",
                                   d.relFormat.formatDict)
            self.templateRelFormat = TRelFormat(formatDict=self.settings.value(
                "Default/Format/TemplateRelation"))
            self.drawTemplateRel()

#####################################################################
# instance format methods
#####################################################################

    @pyqtSlot()
    def on_pbInstanceNode_clicked(self):
        """
        Slot documentation goes here.
        """
        # create a NodeFormat object from the system settings dictionary
        x = self.settings.value("Default/Format/InstanceNode")
        d = INodeFormatDlg(self,
                           modelData=None,
                           nodeFormat=INodeFormat(formatDict=x))
        if d.exec_():
            self.settings.setValue("Default/Format/InstanceNode",
                                   d.nodeFormat.formatDict)
            self.instanceNodeFormat = INodeFormat(
                formatDict=self.settings.value("Default/Format/InstanceNode"))
            self.drawInstanceNode()

    @pyqtSlot()
    def on_pbInstanceRel_clicked(self):
        """
        Slot documentation goes here.
        """
        # create a RelFormat object from the system settings dictionary
        x = self.settings.value("Default/Format/InstanceRelation")
        d = IRelFormatDlg(self,
                          modelData=None,
                          relFormat=IRelFormat(formatDict=x))
        if d.exec_():
            self.settings.setValue("Default/Format/InstanceRelation",
                                   d.relFormat.formatDict)
            self.instanceRelFormat = IRelFormat(formatDict=self.settings.value(
                "Default/Format/InstanceRelation"))
            self.drawInstanceRel()

#    @pyqtSlot()
#    def on_pbTestConnection_clicked(self):
#        """
#        Slot documentation goes here.
#        """
#        print("pbTestConnection clicked")
#
#    @pyqtSlot()
#    def on_pbDefineConnection_clicked(self):
#        """
#        Slot documentation goes here.
#        """
#        print("DefineConnection clicked")

########################################################################
# General Settings
########################################################################

    @pyqtSlot()
    def on_btnProjPath_clicked(self):
        """
        User selects Path button to select a default project path
        """
        curDir = self.lblProjPath.text()
        dlg = QFileDialog()
        dlg.setFileMode(QFileDialog.Directory)
        dlg.setDirectory(curDir)
        file = str(dlg.getExistingDirectory(self, "Select Directory"))
        if file:
            self.lblProjPath.setText(str(file))
            self.lblProjPath.setToolTip(str(file))

    @pyqtSlot()
    def on_btnLoggingPath_clicked(self):
        """
        User selects Path button to select a logging path
        """
        curDir = self.lblLoggingPath.text()
        dlg = QFileDialog()
        dlg.setFileMode(QFileDialog.Directory)
        dlg.setDirectory(curDir)
        file = str(dlg.getExistingDirectory(self, "Select Directory"))
        if file:
            self.lblLoggingPath.setText(str(file))
            self.lblLoggingPath.setToolTip(str(file))

########################################################################
# side buttons that control what settings page to show
########################################################################

    @pyqtSlot()
    def on_pushButton_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("general preferences clicked")
        self.stackedWidget.setCurrentIndex(0)

    @pyqtSlot()
    def on_pbPageSettings_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("page settings clicked")
        self.stackedWidget.setCurrentIndex(1)

    @pyqtSlot()
    def on_pbInstanceFormats_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("instance formats clicked")
        self.stackedWidget.setCurrentIndex(2)

    @pyqtSlot()
    def on_pbTemplateFormats_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("template formats clicked")
        self.stackedWidget.setCurrentIndex(3)

    @pyqtSlot()
    def on_btnClose_clicked(self):
        """
        User presses close.  Save changes and close dialog box.
        """
        self.apply()
        QDialog.accept(self)
    def initUI(self, ):
        # page settings
        self.pageSizes = PageSizes()
        self.pageSizes.loadDropDown(self.cmbPageSize)
        self.pageSetup = PageSetup(objectDict=self.modelData["pageSetup"])
        index = self.cmbPageSize.findText(
            self.pageSetup.objectDict["pageSize"])
        if index >= 0:
            self.cmbPageSize.setCurrentIndex(index)
        if self.pageSetup.objectDict["pageOrientation"] == "Portrait":
            self.rbPortrait.setChecked(True)
            self.rbLandscape.setChecked(False)
        else:
            self.rbLandscape.setChecked(True)
            self.rbPortrait.setChecked(False)
        self.setPageHeightWidth()
        self.spinRows.setValue(self.pageSetup.objectDict["pageRows"])
        self.spinColumns.setValue(self.pageSetup.objectDict["pageCols"])

        # general settings
        self.txtAuthor.setText(self.modelData["Author"])
        self.txtDescription.appendPlainText(self.modelData["Description"])

        # diagram settings
        if self.modelData["TemplateLineType"] == "Elbows":
            self.rbElbow.setChecked(True)
            self.rbStraight.setChecked(False)
        else:
            self.rbElbow.setChecked(False)
            self.rbStraight.setChecked(True)

        #Instance Formats
#        print("node format is {}".format(self.settings.value("Default/Format/InstanceNode")))

# complete scene setups
        self.INgraphicsView = QGraphicsView(parent=self.frmInstanceNodeViewer)
        self.INscene = QGraphicsScene(self)
        self.INscene.setSceneRect(0, 0, 300, 600)
        self.INgraphicsView.setScene(self.INscene)
        x = self.modelData["INformat"]
        self.instanceNodeFormat = INodeFormat(formatDict=x)
        self.drawInstanceNode()

        self.IRgraphicsView = QGraphicsView(parent=self.frmInstanceRelViewer)
        self.IRscene = QGraphicsScene(self)
        self.IRscene.setSceneRect(0, 0, 300, 600)
        self.IRgraphicsView.setScene(self.IRscene)
        x = self.modelData["IRformat"]
        self.instanceRelFormat = IRelFormat(formatDict=x)
        self.drawInstanceRel()

        self.TNgraphicsView = QGraphicsView(parent=self.frmTemplateNodeViewer)
        self.TNscene = QGraphicsScene(self)
        self.TNscene.setSceneRect(0, 0, 300, 600)
        self.TNgraphicsView.setScene(self.TNscene)
        x = self.modelData["TNformat"]
        self.templateNodeFormat = TNodeFormat(formatDict=x)
        self.drawTemplateNode()

        self.TRgraphicsView = QGraphicsView(parent=self.frmRelTemplateViewer)
        self.TRscene = QGraphicsScene(self)
        self.TRscene.setSceneRect(0, 0, 300, 600)
        self.TRgraphicsView.setScene(self.TRscene)
        x = self.modelData["TRformat"]
        self.templateRelFormat = IRelFormat(formatDict=x)
        self.drawTemplateRel()
class ProjectPropertyBox(QDialog, Ui_dlgProjectPreferences):
    """
    Display the project property box UI
    """
    def __init__(self, parent=None, model=None, settings=None):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        """
        super(ProjectPropertyBox, self).__init__(parent)
        self.model = model
        self.formatChanged = False
        self.modelData = self.model.modelData
        self.settings = settings
        self.INtestItem = None
        self.IRtestItem = None
        self.TNtestItem = None
        self.TRtestItem = None
        self.pageSetup = None
        self.setupUi(self)
        self.initUI()

    def initUI(self, ):
        # page settings
        self.pageSizes = PageSizes()
        self.pageSizes.loadDropDown(self.cmbPageSize)
        self.pageSetup = PageSetup(objectDict=self.modelData["pageSetup"])
        index = self.cmbPageSize.findText(
            self.pageSetup.objectDict["pageSize"])
        if index >= 0:
            self.cmbPageSize.setCurrentIndex(index)
        if self.pageSetup.objectDict["pageOrientation"] == "Portrait":
            self.rbPortrait.setChecked(True)
            self.rbLandscape.setChecked(False)
        else:
            self.rbLandscape.setChecked(True)
            self.rbPortrait.setChecked(False)
        self.setPageHeightWidth()
        self.spinRows.setValue(self.pageSetup.objectDict["pageRows"])
        self.spinColumns.setValue(self.pageSetup.objectDict["pageCols"])

        # general settings
        self.txtAuthor.setText(self.modelData["Author"])
        self.txtDescription.appendPlainText(self.modelData["Description"])

        # diagram settings
        if self.modelData["TemplateLineType"] == "Elbows":
            self.rbElbow.setChecked(True)
            self.rbStraight.setChecked(False)
        else:
            self.rbElbow.setChecked(False)
            self.rbStraight.setChecked(True)

        #Instance Formats
#        print("node format is {}".format(self.settings.value("Default/Format/InstanceNode")))

# complete scene setups
        self.INgraphicsView = QGraphicsView(parent=self.frmInstanceNodeViewer)
        self.INscene = QGraphicsScene(self)
        self.INscene.setSceneRect(0, 0, 300, 600)
        self.INgraphicsView.setScene(self.INscene)
        x = self.modelData["INformat"]
        self.instanceNodeFormat = INodeFormat(formatDict=x)
        self.drawInstanceNode()

        self.IRgraphicsView = QGraphicsView(parent=self.frmInstanceRelViewer)
        self.IRscene = QGraphicsScene(self)
        self.IRscene.setSceneRect(0, 0, 300, 600)
        self.IRgraphicsView.setScene(self.IRscene)
        x = self.modelData["IRformat"]
        self.instanceRelFormat = IRelFormat(formatDict=x)
        self.drawInstanceRel()

        self.TNgraphicsView = QGraphicsView(parent=self.frmTemplateNodeViewer)
        self.TNscene = QGraphicsScene(self)
        self.TNscene.setSceneRect(0, 0, 300, 600)
        self.TNgraphicsView.setScene(self.TNscene)
        x = self.modelData["TNformat"]
        self.templateNodeFormat = TNodeFormat(formatDict=x)
        self.drawTemplateNode()

        self.TRgraphicsView = QGraphicsView(parent=self.frmRelTemplateViewer)
        self.TRscene = QGraphicsScene(self)
        self.TRscene.setSceneRect(0, 0, 300, 600)
        self.TRgraphicsView.setScene(self.TRscene)
        x = self.modelData["TRformat"]
        self.templateRelFormat = IRelFormat(formatDict=x)
        self.drawTemplateRel()

    def validate(self, ):
        return True

    def apply(self, ):
        # what about rel format?
        self.modelData["INformat"] = self.instanceNodeFormat.formatDict
        self.modelData["pageSetup"] = self.pageSetup.objectDict
        self.modelData["Description"] = self.txtDescription.toPlainText()
        self.modelData["Author"] = self.txtAuthor.text()
        return

####################################################################################
# PAGE SETTING METHODS
####################################################################################

    def setPageHeightWidth(self, ):
        # this sets the page height width based on page type and orientation
        height, width = self.pageSetup.getHeightWidth()
        self.txtHeight.setText(str(height))
        self.txtWidth.setText(str(width))

    @pyqtSlot()
    def on_rbLandscape_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("landscape")
        self.pageSetup.objectDict["pageOrientation"] = "Landscape"
        self.setPageHeightWidth()

    @pyqtSlot()
    def on_rbPortrait_clicked(self):
        """
        Slot documentation goes here.
        """
        #        print("portrait")
        self.pageSetup.objectDict["pageOrientation"] = "Portrait"
        self.setPageHeightWidth()

    @pyqtSlot(int)
    def on_cmbPageSize_currentIndexChanged(self, index):
        """
        Slot documentation goes here.
        
        @param index DESCRIPTION
        @type int
        """
        #        print("dropdown changed {}".format(self.cmbPageSize.currentText()))
        if self.pageSetup is None:
            return
        newPageSize = str(self.cmbPageSize.currentText())
        self.pageSetup.objectDict["pageSize"] = self.pageSizes.pageTypes[
            newPageSize].name
        self.pageSetup.objectDict["pageHeight"] = self.pageSizes.pageTypes[
            newPageSize].height
        self.pageSetup.objectDict["pageWidth"] = self.pageSizes.pageTypes[
            newPageSize].width
        self.setPageHeightWidth()

    @pyqtSlot(int)
    def on_spinRows_valueChanged(self, p0):
        """
        Slot documentation goes here.
        
        @param p0 DESCRIPTION
        @type int
        """
        self.pageSetup.objectDict["pageRows"] = self.spinRows.value()

    @pyqtSlot(int)
    def on_spinColumns_valueChanged(self, p0):
        """
        Slot documentation goes here.
        
        @param p0 DESCRIPTION
        @type int
        """
        self.pageSetup.objectDict["pageCols"] = self.spinColumns.value()

    def drawInstanceRel(self, ):
        if not (self.IRtestItem is None):
            self.IRscene.removeItem(self.IRtestItem)
        rpen = self.instanceRelFormat.pen()
        #        rbrush = self.instanceRelFormat.brush()
        self.IRtestItem = QGraphicsLineItem(5, 50, 100, 50, parent=None)
        self.IRtestItem.setPen(rpen)
        self.IRscene.addItem(self.IRtestItem)

    def drawTemplateRel(self, ):
        if not (self.TRtestItem is None):
            self.TRscene.removeItem(self.TRtestItem)
        rpen = self.templateRelFormat.pen()
        #        rbrush = self.templateRelFormat.brush()
        self.TRtestItem = QGraphicsLineItem(5, 50, 100, 50, parent=None)
        self.TRtestItem.setPen(rpen)
        self.TRscene.addItem(self.TRtestItem)

    def drawInstanceNode(self, ):
        if not (self.INtestItem is None):
            self.INscene.removeItem(self.INtestItem)
        pen = self.instanceNodeFormat.pen()
        brush = self.instanceNodeFormat.brush()
        self.INtestItem = QGraphicsEllipseItem(QRectF(
            5, 5, self.instanceNodeFormat.formatDict["nodeWidth"],
            self.instanceNodeFormat.formatDict["nodeHeight"]),
                                               parent=None)
        self.INtestItem.setBrush(brush)
        self.INtestItem.setPen(pen)
        self.INscene.addItem(self.INtestItem)

    def drawTemplateNode(self, ):
        if not (self.TNtestItem is None):
            self.TNscene.removeItem(self.TNtestItem)
        npen = self.templateNodeFormat.pen()
        nbrush = self.templateNodeFormat.brush()
        self.TNtestItem = QGraphicsRectItem(QRectF(
            5, 5, self.templateNodeFormat.formatDict["nodeWidth"],
            self.templateNodeFormat.formatDict["nodeHeight"]),
                                            parent=None)
        self.TNtestItem.setBrush(nbrush)
        self.TNtestItem.setPen(npen)
        self.TNscene.addItem(self.TNtestItem)

    @pyqtSlot()
    def on_pbTemplateNode_clicked(self):
        """
        Display the Template Node format dialog box and allow the user to change the project level Template node format
        """
        d = TNodeFormatDlg(self,
                           modelData=None,
                           nodeFormat=TNodeFormat(
                               formatDict=self.templateNodeFormat.formatDict))
        if d.exec_():
            self.templateNodeFormat = TNodeFormat(
                formatDict=d.nodeFormat.formatDict)
            self.drawTemplateNode()
            self.formatChanged = True

    @pyqtSlot()
    def on_pbRelTemplate_clicked(self):
        """
        Slot documentation goes here.
        """
        d = IRelFormatDlg(
            self,
            modelData=None,
            relFormat=IRelFormat(formatDict=self.templateRelFormat.formatDict))
        if d.exec_():
            self.instanceRelFormat = IRelFormat(
                formatDict=d.relFormat.formatDict)
            self.drawTemplateRel()
            self.formatChanged = True

    @pyqtSlot()
    def on_okButton_clicked(self):
        """
        Slot documentation goes here.
        """
        if self.validate():
            self.apply()
            QDialog.accept(self)

    @pyqtSlot()
    def on_cancelButton_clicked(self):
        """
        Slot documentation goes here.
        """
        QDialog.reject(self)

    @pyqtSlot()
    def on_pbInstanceNode_clicked(self):
        """
        Display the Instance Node format dialog box and allow the user to change the project level instance node format
        """
        d = INodeFormatDlg(self,
                           modelData=None,
                           nodeFormat=INodeFormat(
                               formatDict=self.instanceNodeFormat.formatDict))
        if d.exec_():
            self.instanceNodeFormat = INodeFormat(
                formatDict=d.nodeFormat.formatDict)
            self.drawInstanceNode()
            self.formatChanged = True

    @pyqtSlot()
    def on_pbInstanceRel_clicked(self):
        """
        Slot documentation goes here.
        """
        d = IRelFormatDlg(
            self,
            modelData=None,
            relFormat=IRelFormat(formatDict=self.instanceRelFormat.formatDict))
        if d.exec_():
            self.instanceRelFormat = IRelFormat(
                formatDict=d.relFormat.formatDict)
            self.drawInstanceRel()
            self.formatChanged = True

    @pyqtSlot()
    def on_pbPageSettings_clicked(self):
        """
        User clicks page settings button
        """
        #        print("instance formats clicked")
        self.stackedWidget.setCurrentIndex(1)

    @pyqtSlot()
    def on_pbInstanceFormats_clicked(self):
        """
        User clicks instance format button
        """
        #        print("instance formats clicked")
        self.stackedWidget.setCurrentIndex(2)

    @pyqtSlot()
    def on_pbTemplateFormats_clicked(self):
        """
        User click template formats button
        """
        #        print("template formats clicked")
        self.stackedWidget.setCurrentIndex(3)

    @pyqtSlot()
    def on_pbTemplateDiagram_clicked(self):
        """
        User clicks template diagram button
        """
        self.stackedWidget.setCurrentIndex(4)

    @pyqtSlot()
    def on_rbElbow_clicked(self):
        """
        User clicks the elbows radio button
        """
        self.modelData["TemplateLineType"] = "Elbows"
        self.formatChanged = True

    @pyqtSlot()
    def on_rbStraight_clicked(self):
        """
        user clicks the straight line radio button
        """
        self.modelData["TemplateLineType"] = "Straight"
        self.formatChanged = True

    @pyqtSlot()
    def on_pbGeneral_clicked(self):
        """
        User clicks on general settings button
        """
        self.stackedWidget.setCurrentIndex(0)