Beispiel #1
0
class NodeItem():
    ''' 
    This represents one node on the diagram.
    This class creates the ellipse graphics item and the text graphics item and adds them to the scene.
    '''
    def __init__(self, scene, x, y, nodeInstance=None):
        self.scene = scene
        self.logMsg = None

        self.x = x
        self.y = y
        self.itemInstance = nodeInstance
        self.diagramType = self.itemInstance.diagramType
        self.displayText = None
        self.model = self.scene.parent.model
        self.neoCon = self.scene.parent.model.modelNeoCon
        self.getFormat()
        # remember current width and height
        self.oldNodeWidth = 0
        self.oldNodeHeight = 0
        # init graphics objects to none
        self.INode = None
        self.INtext = None
        #        # init list of qgrapphicellipseitems to none
        #        self.ellipsePoints = []
        #        self.ellipseGraphicItems = []
        # draw the ellipse
        self.drawIt()

    def name(self, ):
        return self.itemInstance.NZID

    def NZID(self, ):
        return self.itemInstance.NZID

    def getFormat(self, ):
        '''
        determine the format to use to draw the instance node
        - start with the project default
        - if the instance node has a template then use the instance format defined on the template
        '''
        # get the default
        self.nodeFormat = INodeFormat(
            formatDict=self.model.modelData["INformat"])
        # get a custom template format if there is one
        if not self.itemInstance.nodeTemplate is None:
            index, nodeTemplateDict = self.model.getDictByName(
                topLevel="Node Template",
                objectName=self.itemInstance.nodeTemplate)
            if not nodeTemplateDict is None:
                self.instanceNodeFormatDict = nodeTemplateDict.get(
                    "INformat", None)
                if not self.instanceNodeFormatDict is None:
                    self.nodeFormat = INodeFormat(
                        formatDict=self.instanceNodeFormatDict)

    def clearItem(self, ):

        if (not self.INode is None and not self.INode.scene() is None):
            self.INode.scene().removeItem(self.INode)
        if (not self.INtext is None and not self.INtext.scene() is None):
            self.INtext.scene().removeItem(self.INtext)

#        # remove the points on the ellipse - this code is only for debugging
#        for point in self.ellipseGraphicItems:
#            if (not point is None and not point.scene() is None):
#                point.scene().removeItem(point)

    def drawIt(self, ):
        # force the node instance to update its values in case it has been updated from another diagram or the tree view
        self.itemInstance.reloadDictValues()
        # get current format as it may have changed
        self.getFormat()
        if self.oldNodeWidth != self.nodeFormat.formatDict[
                "nodeWidth"] or self.oldNodeHeight != self.nodeFormat.formatDict[
                    "nodeHeight"]:
            # remove graphic items that already exist
            self.clearItem()
            # create the node ellipse
            self.INode = QGraphicsEllipseItem(QRectF(
                self.x, self.y, self.nodeFormat.formatDict["nodeWidth"],
                self.nodeFormat.formatDict["nodeHeight"]),
                                              parent=None)
            # create the node text
            self.INtext = QGraphicsTextItem("", parent=None)
            self.INtext.setPos(self.x, self.y)
            self.x = self.INode.sceneBoundingRect().x()
            self.y = self.INode.sceneBoundingRect().y()
            #            print("after create items before drawIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))
            #            print("x:{} y:{}".format(self.x, self.y))
            self.formatItem()
            self.scene.addItem(self.INode)
            self.scene.addItem(self.INtext)
            #            # add points
            #            for point in self.ellipseGraphicItems:
            #                self.scene.addItem(point)

            # redraw all the rels associated to this node.
            self.moveRels()
        else:
            #            print("before drawIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))
            #            print("x:{} y:{}".format(self.x, self.y))
            self.formatItem()
        # remember current width and height
        self.oldNodeWidth = self.nodeFormat.formatDict["nodeWidth"]
        self.oldNodeHeight = self.nodeFormat.formatDict["nodeHeight"]
#        print("after drawIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))
#        print("x:{} y:{}".format(self.x, self.y))

#    def genPoints(self, ):
#        '''Ellipse Constructor - not sure of these, need to verify
#        def __init__(self, mx, my, rh, rv):
#        mx - center point x
#        my - center point y
#        rh - height of ellipse
#        rv - width of ellipse'''
#        x = self.INode.sceneBoundingRect().center().x()
#        y = self.INode.sceneBoundingRect().center().y()
#        w = self.INode.sceneBoundingRect().width()/2.0
#        h = self.INode.sceneBoundingRect().height()/2.0
#        myEllipse = Ellipse(x, y, w, h)
#        for d in range(0, 360, 10):
#            x, y = myEllipse.pointFromAngle(radians(d))
#            self.ellipsePoints.append([d, x, y])
#            aPoint = QGraphicsEllipseItem(QRectF(x-2.5,y-2.5,5, 5), parent=None)
#            self.ellipseGraphicItems.append(aPoint)
##        print(self.ellipsePoints)

    def formatItem(self, ):
        # configure the formatting aspects of the qgraphics item
        pen = self.nodeFormat.pen()
        brush = self.nodeFormat.brush()
        self.INode.setZValue(NODELAYER)
        self.INode.setBrush(brush)
        self.INode.setPen(pen)
        self.INode.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.INode.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        self.INode.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.INode.setSelected(True)
        self.INode.setData(
            1, self.itemInstance.NZID)  # get with self.INode.data(1)
        self.INode.setData(ITEMTYPE, NODEINSTANCE)
        # draw the text
        self.updateText()
        self.INtext.setZValue(NODELAYER)
        self.INtext.setTextWidth(self.INode.boundingRect().width())
        self.INtext.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.INtext.setFlag(QGraphicsItem.ItemIsSelectable, False)
        self.INtext.setData(NODEID, self.itemInstance.NZID)
        self.INtext.setData(ITEMTYPE, NODEINSTANCETEXT)

    def updateText(self, ):
        '''
        Generate the HTML that formats the node  data inside the ellipse
        '''
        # generate the html
        prefix = "<!DOCTYPE html><html><body>"
        suffix = "</body></html>"
        try:
            Lbl = str(self.itemInstance.labelList[0][0])
        except:
            Lbl = "No Labels"
        firstLbl = "<center><b>{}</b></center>".format(Lbl)
        try:
            propName = str(self.itemInstance.propList[0][PROPERTY])
            propVal = str(self.itemInstance.propList[0][VALUE])
            prop = "{}: {}".format(propName, propVal)
        except:
            prop = "No Properties"
        firstProp = "<center>{}</center>".format(prop)
        genHTML = '{}{}<hr width="75%">{}{}'.format(prefix, firstLbl,
                                                    firstProp, suffix)
        self.INtext.setHtml(genHTML)

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

        self.INode.moveBy(dx, dy)
        self.x = self.INode.sceneBoundingRect().x()
        self.y = self.INode.sceneBoundingRect().y()
        self.INtext.moveBy(dx, dy)
        #        print("after moveIt: sceneboundingrect {} ".format( self.INode.sceneBoundingRect()))

        #        # recalc points
        #        self.genPoints()

        #        for point in self.ellipseGraphicItems:
        #            point.moveBy(dx, dy)

        self.moveRels()

    def moveRels(self, ):
        '''Redraw all the relationship arcs connected to the Node ellipse.'''
        #        print("moveRels")
        for key, diagramItem in self.scene.parent.itemDict.items():
            if diagramItem.diagramType == "Instance Relationship":
                if self.itemInstance.NZID in [
                        diagramItem.relationInstance.startNZID,
                        diagramItem.relationInstance.endNZID
                ]:
                    diagramItem.drawRelationship()
#                if diagramItem.relationInstance.startNZID == self.itemInstance.NZID:
#                    diagramItem.moveRelationshipLine()
##                    print("move startnode {}-{}".format(self.x, self.y))
#                if diagramItem.relationInstance.endNZID == self.itemInstance.NZID:
#                    diagramItem.moveRelationshipLine()
##                    print("move endnode {}-{}".format(self.x, self.y))

    def getObjectDict(self, ):
        '''
        This function returns a dictionary with all the data that represents this node item.  
        The dictionary is added to the Instance Diagram dictionary.'''
        objectDict = {}
        objectDict["NZID"] = self.itemInstance.NZID
        objectDict["x"] = self.INode.sceneBoundingRect().x()
        objectDict["y"] = self.INode.sceneBoundingRect().y()
        objectDict["diagramType"] = self.diagramType
        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 #2
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)
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)