当前位置: 首页>>代码示例>>Python>>正文


Python Rule.setName方法代码示例

本文整理汇总了Python中Rule.Rule.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.setName方法的具体用法?Python Rule.setName怎么用?Python Rule.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rule.Rule的用法示例。


在下文中一共展示了Rule.setName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RuleEditor

# 需要导入模块: from Rule import Rule [as 别名]
# 或者: from Rule.Rule import setName [as 别名]

#.........这里部分代码省略.........

        st = '\n'.join(file.readlines())

        self.ruleSet.fromString(st)

        if len(self.scene.items()) > 0:
            for item in self.scene.items():
                self.scene.removeItem(item)

        self.currentElementFile = self.ruleSet.elementsFileName
        self.fileName.setText(os.path.basename(self.currentElementFile))
        self.loadElementsFile()
        self.scene.setMode(ChainScene.MoveItem)
        self.updateRuleList()
        self.changeCurrentRule(0)

        self.setWindowTitle("WordChain : Rule editor : " + self.currentRuleFile)

    ###########################################################################
    def showWindow(self):
        self.show()
        self.updateRuleList()

    def updateRuleList(self):
        self.ruleListWidget.clear()
        rowCount = 0
        for rule in self.ruleSet.ruleList:
            self.ruleListWidget.insertItem(rowCount, rule.name)
            rowCount += 1

    def newRule(self):
        name, ok = QInputDialog.getText(None, "Create new rule", "Enter new rule name:")
        if name is not None and ok:
            self.rule = Rule()
            self.rule.setName(name)
            self.ruleSet.addRule(self.rule)
        self.updateRuleList()
        self.changeCurrentRule(len(self.ruleSet.ruleList) - 1)
        self.ruleListWidget.setCurrentRow(len(self.ruleSet.ruleList) - 1)

    def changeCurrentRule(self, idx):
        self.rule.fromElementList(self.scene.items())
        self.rule = self.ruleSet.getRule(idx)
        self.loadRuleToScene()

    def removeRule(self):
        self.ruleSet.deleteRule(self.ruleListWidget.currentRow())
        self.updateRuleList()

    def loadRuleToScene(self):
        self.scene.clear()
        for ruleElem in self.rule.elements:
            for el in self.elementSet.elementList:
                if el.elementName == ruleElem['elementName']:
                    item = MetaElement(el.leftConnectorType,
                                       el.rightConnectorType,
                                       el.elementName,
                                       el.color)
                    item.addProperties(el.properties)
                    self.scene.addItem(item)
                    item.setPos(QPoint(ruleElem['x'], ruleElem['y']))

        for ruleConn in self.rule.connections:
            el1 = self.scene.items()[ruleConn['p1']]
            el2 = self.scene.items()[ruleConn['p2']]
            name = ruleConn.get('name', '')
            conn = self.scene.addConnection(el2, el1, name)
            conn.p1Properties = ruleConn['p1Properties']
            conn.p2Properties = ruleConn['p2Properties']
            self.scene.addItem(conn)

    ###########################################################################
    def chooseElementsFile(self):
        ret = QFileDialog.getOpenFileName(filter='*.elms')
        self.currentElementFile = ret[0]
        self.ruleSet.setElementsFileName(self.currentElementFile)
        self.fileName.setText(os.path.basename(self.currentElementFile))

    ###########################################################################
    def loadElementsFile(self):
        if self.currentElementFile is not None:
            file = open(self.currentElementFile, 'r')

            st = '\n'.join(file.readlines())

            self.elementSet.fromString(st)
            file.close()
            self.layoutToolBox()

    ###########################################################################
    def updateElementListView(self):
        self.elemListWidget.clear()

        for item in self.elementSet.elementList:
            self.elemListWidget.addItem(item.elementName)

    ###########################################################################
    def testRule(self):
        self.rule.fromElementList(self.scene.items())
        print(self.ruleSet.toString())
开发者ID:offtirael,项目名称:WordChain,代码行数:104,代码来源:RuleEditor.py


注:本文中的Rule.Rule.setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。