Beispiel #1
0
class NewProject(Widget):

    info = {}
    key = 'NewProject'

    def __init__(self, parent=None):
        super(NewProject, self).__init__(parent)
        # self.setWindowIcon(AppIcon(32, "NewProject"))

        self.layout = GridLayout(self)
        self.buildUI()
        self.setLayout(self.layout)

    def buildUI(self):

        MESSAGE = "DUE TO THE POSSIBILITY OF USING RENDER FARM SERVICE, PLEAE SET PROJECT PATH TO E DRIVE\n " \
                  "IF YOU DO NOT USE RENDER FARM, DRIVE E IS STILL PREFER."

        TITLE = "SET UP NEW PROJECT"

        # Title
        headGrp, headGrid = self.styleGB()
        headGrid.addWidget(Label({'txt': TITLE}))

        # Project Info
        prjInfGrp, prjInfGrid   = self.styleGB("Project Info")
        self.prjLong            = LineEdit({'txt': "DAMG team project"})
        self.prjShort           = LineEdit({'txt': "damg"})
        self.prjPth             = LineEdit({'txt': "E:/"})

        setPthBtn = Button({'txt': "Set Path", 'stt': "Set project path", 'cl': self.onSetPthBtnClicked})

        prjInfGrid.addWidget(Label({'txt': "Project Name"}), 0, 0, 1, 1)
        prjInfGrid.addWidget(self.prjLong, 0, 1, 1, 1)
        prjInfGrid.addWidget(Label({'txt': "Abbreviated as"}), 0, 2, 1, 1)
        prjInfGrid.addWidget(self.prjShort, 0, 3, 1, 1)
        prjInfGrid.addWidget(setPthBtn, 1, 0, 1, 1)
        prjInfGrid.addWidget(self.prjPth, 1, 1, 1, 3)

        # Notice!!!
        noticeGrp, noticeGrid = self.styleGB("NOTE!!!")
        noticeGrid.addWidget(Label({'txt': MESSAGE}), 0, 0, 1, 4)

        # Project details
        prjDetailGrp, prjDetailGrid = self.styleGB("Project Details")

        self.prjMode = QComboBox()
        self.prjMode.addItem("Studio Mode")
        self.prjMode.addItem("Group Mode")

        self.numOfChar = LineEdit({'txt': "1", 'validator': 'int'})
        self.numOfChar.textChanged.connect(partial(self.populate_lst, "char"))

        self.numOfEnv = LineEdit({'txt': "1", 'validator': 'int'})
        self.numOfEnv.textChanged.connect(partial(self.populate_lst, "env"))

        self.numOfProp = LineEdit({'txt': "1", 'validator': 'int'})
        self.numOfProp.textChanged.connect(partial(self.populate_lst, "prop"))

        self.numOfSeq = LineEdit({'txt': "1", 'validator': 'int'})
        self.numOfSeq.textChanged.connect(partial(self.populate_lst, "seq"))

        prjDetailGrid.addWidget(Label({'txt':"Project Mode"}), 0,0,1,1)
        prjDetailGrid.addWidget(self.prjMode, 0, 1, 1, 1)
        prjDetailGrid.addWidget(Label({'txt':"Character: "}), 1,0,1,1)
        prjDetailGrid.addWidget(self.numOfChar, 2, 0, 1, 1)
        prjDetailGrid.addWidget(Label({'txt':"Environment: "}), 1,1,1,1)
        prjDetailGrid.addWidget(self.numOfEnv, 2, 1, 1, 1)
        prjDetailGrid.addWidget(Label({'txt':"Props: "}), 1,2,1,1)
        prjDetailGrid.addWidget(self.numOfProp, 2, 2, 1, 1)
        prjDetailGrid.addWidget(Label({'txt':"Sequences: "}), 1,3,1,1)
        prjDetailGrid.addWidget(self.numOfSeq, 2, 3, 1, 1)

        # Asset details
        charGrp, self.charLst = self.styleGBLst("Character List")
        envGrp, self.envLst = self.styleGBLst("Environment List")
        propGrp, self.propLst = self.styleGBLst("Props List")

        # Shot details
        seqGrp, self.seqLst = self.styleGBLst("Sequences List")

        # Buttons
        btnGrp, btnGrid = self.styleGB()

        prjLstBtn = Button({'txt': "Project List", 'stt': "Project List"})
        crewLstBtn = Button({'txt': "Crews List", 'stt': "Crews List"})
        newPrjBtn = Button({'txt': "Create Project", 'stt': "Create New Project"})
        cancelBtn = Button({'txt': "Cancel", 'stt': "Cancel"})

        btnGrid.addWidget(prjLstBtn, 0, 0)
        btnGrid.addWidget(crewLstBtn, 0, 1)
        btnGrid.addWidget(newPrjBtn, 0, 2)
        btnGrid.addWidget(cancelBtn, 0, 3)

        self.layout.addWidget(headGrp, 0, 0, 1, 4)
        self.layout.addWidget(prjInfGrp, 1, 0, 2, 4)
        self.layout.addWidget(noticeGrp, 3, 0, 1, 4)
        self.layout.addWidget(prjDetailGrp, 5,0,3,4)
        self.layout.addWidget(charGrp, 8,0,1,1)
        self.layout.addWidget(envGrp, 8,1,1,1)
        self.layout.addWidget(propGrp, 8,2,1,1)
        self.layout.addWidget(seqGrp, 8,3,1,1)
        self.layout.addWidget(btnGrp, 9,0,1,4)

        sections = ["char", "env", "prop", "seq"]
        for section in sections:
            self.populate_lst(section)

    def getZ(self, value):
        if value < 10:
            z = 1
        elif value < 100:
            z = 2
        elif value < 1000:
            z = 3
        else:
            z = 4
        return z

    def styleGB(self, title="", tl="grid"):
        if title == "":
            grpBox = QGroupBox()
        else:
            grpBox = QGroupBox(title)

        if tl.lower() == "grid":
            layout = GridLayout()
        elif tl.lower() == "hbox":
            layout = HBoxLayout()
        elif tl.lower() == "vbox":
            layout = VBoxLayout()

        grpBox.setLayout(layout)

        return grpBox, layout

    def styleGBLst(self, title=""):
        grpBox, hbox = self.styleGB(title, "hbox")
        listWidget = QListWidget()
        hbox.addWidget(listWidget)

        return grpBox, listWidget

    def onSetPthBtnClicked(self):
        opts = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
        dir = QFileDialog.getExistingDirectory(self, "Set production path", self.prjPth.text(), options=opts)

        if dir:
            self.prjPth.setText(dir)
        else:
            self.logger.debug("You should set a valid path")

    def populate_lst(self, name="char"):
        if name.lower() == "char":
            lst = self.charLst
            value = int(self.numOfChar.text())
        elif name.lower() == "env":
            lst = self.envLst
            value = int(self.numOfEnv.text())
        elif name.lower() == "prop":
            lst = self.propLst
            value = int(self.numOfProp.text())
        elif name.lower() == "seq":
            lst = self.seqLst
            value = int(self.numOfSeq.text())
        else:
            lst = None
            value = 0

        lst.clear()
        z = self.getZ(value)

        for i in range(value):
            item = QListWidgetItem(lst)
            itemWidget = ItemWidget(name.lower(), "{0}_{1}".format(name.lower(), str(i+1).zfill(z)))
            item.setSizeHint(itemWidget.sizeHint())
            lst.addItem(item)
            lst.setItemWidget(item, itemWidget)
Beispiel #2
0
class Calculator(Widget):

    key = 'Calculator'
    NumDigitButtons = 10
    digitButtons = DAMGLIST()

    def __init__(self, parent=None):
        super(Calculator, self).__init__(parent)

        self.setWindowIcon(AppIcon(32, 'Calculator'))
        self.setWindowTitle(self.key)
        self.buildUI()

    def buildUI(self):
        self.layout = QGridLayout(self)

        self.pendingAdditiveOperator            = ''
        self.pendingMultiplicativeOperator      = ''
        self.sumInMemory                        = 0.0
        self.sumSoFar                           = 0.0
        self.factorSoFar                        = 0.0
        self.waitingForOperand                  = True

        self.display = LineEdit({'txt': '0'})
        self.display.setReadOnly(True)
        self.display.setAlignment(Qt.AlignRight)

        for i in range(self.NumDigitButtons):
            self.digitButtons.append(self.createButton(str(i), self.digitClicked))

        self.pointButton            = self.createButton(".", self.pointClicked)
        self.changeSignButton       = self.createButton(u"\N{PLUS-MINUS SIGN}",  self.changeSignClicked)
        self.backspaceButton        = self.createButton("Backspace", self.backspaceClicked)
        self.clearButton            = self.createButton("Clear", self.clear)
        self.clearAllButton         = self.createButton("Clear All", self.clearAll)
        self.clearMemoryButton      = self.createButton("MC", self.clearMemory)
        self.readMemoryButton       = self.createButton("MR", self.readMemory)
        self.setMemoryButton        = self.createButton("MS", self.setMemory)
        self.addToMemoryButton      = self.createButton("M+", self.addToMemory)
        self.divisionButton         = self.createButton(u"\N{DIVISION SIGN}", self.multiplicativeOperatorClicked)
        self.timesButton            = self.createButton(u"\N{MULTIPLICATION SIGN}", self.multiplicativeOperatorClicked)
        self.minusButton            = self.createButton("-", self.additiveOperatorClicked)
        self.plusButton             = self.createButton("+", self.additiveOperatorClicked)
        self.squareRootButton       = self.createButton("Sqrt", self.unaryOperatorClicked)
        self.powerButton            = self.createButton(u"x\N{SUPERSCRIPT TWO}", self.unaryOperatorClicked)
        self.reciprocalButton       = self.createButton("1/x", self.unaryOperatorClicked)
        self.equalButton            = self.createButton("=", self.equalClicked)

        self.layout.addWidget(self.display, 0,0,1,6)
        self.layout.addWidget(self.backspaceButton, 1,0,1,2)
        self.layout.addWidget(self.clearButton, 1,2,1,2)
        self.layout.addWidget(self.clearAllButton, 1,4,1,2)
        self.layout.addWidget(self.clearMemoryButton,2,0)
        self.layout.addWidget(self.readMemoryButton,3,0)
        self.layout.addWidget(self.setMemoryButton,4,0)
        self.layout.addWidget(self.addToMemoryButton,5,0)

        for i in range(1, self.NumDigitButtons):
            row = ((9 - i) / 3) + 2
            column = ((i - 1) % 3) + 1
            self.layout.addWidget(self.digitButtons[i], row, column)

        self.layout.addWidget(self.digitButtons[0],5,1)
        self.layout.addWidget(self.pointButton,5,2)
        self.layout.addWidget(self.changeSignButton,5,3)
        self.layout.addWidget(self.divisionButton,2,4)
        self.layout.addWidget(self.timesButton,3,4)
        self.layout.addWidget(self.minusButton,4,4)
        self.layout.addWidget(self.plusButton,5,4)
        self.layout.addWidget(self.squareRootButton,2,5)
        self.layout.addWidget(self.powerButton,3,5)
        self.layout.addWidget(self.reciprocalButton,4,5)
        self.layout.addWidget(self.equalButton,5,5)

        self.display.setMaxLength(15)
        font = self.display.font()
        font.setPointSize(font.pointSize() + 8)
        self.display.setFont(font)

        self.setLayout(self.layout)

    def digitClicked(self):
        clickedButton = self.sender()
        digitValue = int(clickedButton.text())

        if self.display.text() == '0' and digitValue == 0.0:
            return

        if self.waitingForOperand:
            self.display.clear()
            self.waitingForOperand = False

        self.display.setText(self.display.text() + str(digitValue))

    def unaryOperatorClicked(self):
        clickedButton = self.sender()
        clickedOperator = clickedButton.text()
        operand = float(self.display.text())

        if clickedOperator == "Sqrt":
            if operand < 0.0:
                self.abortOperation()
                return

            result = math.sqrt(operand)
        elif clickedOperator == u"x\N{SUPERSCRIPT TWO}":
            result = math.pow(operand, 2.0)
        elif clickedOperator == "1/x":
            if operand == 0.0:
                self.abortOperation()
                return

            result = 1.0 / operand

        self.display.setText(str(result))
        self.waitingForOperand = True

    def additiveOperatorClicked(self):
        clickedButton = self.sender()
        clickedOperator = clickedButton.text()
        operand = float(self.display.text())

        if self.pendingMultiplicativeOperator:
            if not self.calculate(operand, self.pendingMultiplicativeOperator):
                self.abortOperation()
                return

            self.display.setText(str(self.factorSoFar))
            operand = self.factorSoFar
            self.factorSoFar = 0.0
            self.pendingMultiplicativeOperator = ''

        if self.pendingAdditiveOperator:
            if not self.calculate(operand, self.pendingAdditiveOperator):
                self.abortOperation()
                return

            self.display.setText(str(self.sumSoFar))
        else:
            self.sumSoFar = operand

        self.pendingAdditiveOperator = clickedOperator
        self.waitingForOperand = True

    def multiplicativeOperatorClicked(self):
        clickedButton = self.sender()
        clickedOperator = clickedButton.text()
        operand = float(self.display.text())

        if self.pendingMultiplicativeOperator:
            if not self.calculate(operand, self.pendingMultiplicativeOperator):
                self.abortOperation()
                return

            self.display.setText(str(self.factorSoFar))
        else:
            self.factorSoFar = operand

        self.pendingMultiplicativeOperator = clickedOperator
        self.waitingForOperand = True

    def equalClicked(self):
        operand = float(self.display.text())

        if self.pendingMultiplicativeOperator:
            if not self.calculate(operand, self.pendingMultiplicativeOperator):
                self.abortOperation()
                return

            operand = self.factorSoFar
            self.factorSoFar = 0.0
            self.pendingMultiplicativeOperator = ''

        if self.pendingAdditiveOperator:
            if not self.calculate(operand, self.pendingAdditiveOperator):
                self.abortOperation()
                return

            self.pendingAdditiveOperator = ''
        else:
            self.sumSoFar = operand

        self.display.setText(str(self.sumSoFar))
        self.sumSoFar = 0.0
        self.waitingForOperand = True

    def pointClicked(self):
        if self.waitingForOperand:
            self.display.setText('0')

        if "." not in self.display.text():
            self.display.setText(self.display.text() + ".")

        self.waitingForOperand = False

    def changeSignClicked(self):
        text = self.display.text()
        value = float(text)

        if value > 0.0:
            text = "-" + text
        elif value < 0.0:
            text = text[1:]

        self.display.setText(text)

    def backspaceClicked(self):
        if self.waitingForOperand:
            return

        text = self.display.text()[:-1]
        if not text:
            text = '0'
            self.waitingForOperand = True

        self.display.setText(text)

    def clear(self):
        # type: () -> object
        if self.waitingForOperand:
            return

        self.display.setText('0')
        self.waitingForOperand = True

    def clearAll(self):
        self.sumSoFar = 0.0
        self.factorSoFar = 0.0
        self.pendingAdditiveOperator = ''
        self.pendingMultiplicativeOperator = ''
        self.display.setText('0')
        self.waitingForOperand = True

    def clearMemory(self):
        self.sumInMemory = 0.0

    def readMemory(self):
        self.display.setText(str(self.sumInMemory))
        self.waitingForOperand = True

    def setMemory(self):
        self.equalClicked()
        self.sumInMemory = float(self.display.text())

    def addToMemory(self):
        self.equalClicked()
        self.sumInMemory += float(self.display.text())

    def createButton(self, text, member):
        button = ToolButton(text)
        button.clicked.connect(member)
        return button

    def abortOperation(self):
        self.clearAll()
        self.display.setText("####")

    def calculate(self, rightOperand, pendingOperator):
        if pendingOperator == "+":
            self.sumSoFar += rightOperand
        elif pendingOperator == "-":
            self.sumSoFar -= rightOperand
        elif pendingOperator == u"\N{MULTIPLICATION SIGN}":
            self.factorSoFar *= rightOperand
        elif pendingOperator == u"\N{DIVISION SIGN}":
            if rightOperand == 0.0:
                return False

            self.factorSoFar /= rightOperand

        return True