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


Python Life.reset方法代码示例

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


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

示例1: SubWindow

# 需要导入模块: from Life import Life [as 别名]
# 或者: from Life.Life import reset [as 别名]
class SubWindow(QtGui.QScrollArea):
    sequenceNumber = 1
    x = 0
    y = 0
    timerId = 0
    step = 2
    delay = 50
    cellsCount = 0

    def __init__(self, width, height):
        super(SubWindow, self).__init__()
        self.width = width
        self.height = height
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.isUntitled = True
        widget = QtGui.QScrollArea()
        self.qp = QtGui.QPainter()
        if width and height:
            self.field = Field(width, height)
            self.setWidget(self.field)
            self.life = Life(width, height, False)
            self.reset()
            self.field.cells = self.life.cells

    def isSimulate(self):
        if self.timerId:
            return True
        return False

    def reset(self):
        self.life.reset(self.width, self.height)
        self.field.cells = self.life.cells
        self.field.update()
        if self.timerId:
            self.killTimer(self.timerId)
            self.timerId = 0

    def changeSpeed(self, speed):
        self.delay = speed
        if self.timerId:
            self.killTimer(self.timerId)
            self.timerId = self.startTimer(speed)

    def play(self):
        if not self.timerId:
            self.timerId = self.startTimer(self.delay)
        else:
            self.killTimer(self.timerId)
            self.timerId = 0

    def nextStep(self):
        self.field.cells = self.life.simulate()
        self.field.update()

    def timerEvent(self, event):
        self.field.cells = self.life.simulate()
        self.field.update()

    def currentFile(self):
        return self.curFile

    def new(self):
        self.isUntitled = True
        self.curFile = "Game %d" % SubWindow.sequenceNumber
        SubWindow.sequenceNumber += 1
        self.setWindowTitle(self.curFile + '[*]')

    def loadFile(self, fileName):
        file = QtCore.QFile(fileName)
        if not file.open( QtCore.QFile.ReadOnly | QtCore.QFile.Text):
            QtGui.QMessageBox.warning(self, "Reading error",
                    "Cannot read file %s:\n%s." % (fileName, file.errorString()))
            return False
        instr = QtCore.QTextStream(file)
        start = False
        width = 0
        lines = []

        while not instr.atEnd():
            line = instr.readLine()
            if width < len(line):
                width = len(line)
            if line[0] != '#':
                start = True
                lines.append(line)
            if line[0] == '#' and start:
                break

        height = len(lines)   
        if not width or not height:
            return False 
        self.width = width
        self.height = height
        self.field = Field(width, height)
        self.setWidget(self.field)
        self.life = Life(width, height, False)
        self.field.cells = self.life.cells
        y=0
        for line in lines:
            x = 0
#.........这里部分代码省略.........
开发者ID:annikoff,项目名称:Life,代码行数:103,代码来源:SubWindow.py


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