本文整理汇总了Python中view.View.reset方法的典型用法代码示例。如果您正苦于以下问题:Python View.reset方法的具体用法?Python View.reset怎么用?Python View.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import reset [as 别名]
#.........这里部分代码省略.........
char = charsetGenerators.ASCIIGenerator()
elif charset == 'printable':
if upper:
char = charsetGenerators.PrintableASCIIGeneratorUpper()
else:
char = charsetGenerators.PrintableASCIIGenerator()
elif charset == 'ascii':
if upper:
char = charsetGenerators.ASCIIGeneratorUpper()
else:
char = charsetGenerators.ASCIIGenerator()
self.log('Signal','Determined the charset to be: %s' % repr(char),'determineCharset')
return char
def setHashFunction(self,hash):
hashFunctions = self.getPossibleHashes()
if hash not in hashFunctions:
raise ValueError('Hashfunction "%s" not available' % hash)
else:
self.model.setHashFunction(hash)
def getPossibleHashes(self):
return Hash().getPossibleHashes()
def runBenchmark(self):
"""WorkMaster method"""
self.view.reset()
self.timeRunning = 0
self.runningBench = True
self.benches = {}
self.interval()
self.log('Signal','Running benchmark','runBenchmark')
self.model.runBenchmark()
self.fetchBenches()
def fetchBenches(self):
if self.runningBench or not self.benchQueue.empty():
if not self.benchQueue.empty():
try:
self.benches = self.benchQueue.get()
self.benchCallback()
self.log('Signal','Benchmark results found','fetchBenches')
except:
pass
reactor.callLater(1.0,self.fetchBenches)
def benchCallback(self):
hashSpeed = self.model.sumBenches(self.benches)
self.runningBench = False
self.timeRunning = 0
self.log('Signal','Received benchmark results: %s p/s' % hashSpeed,'benchCallback')
self.view.reset()
self.updateBenchResults(hashSpeed)
示例2: Controller
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import reset [as 别名]
class Controller():
"""
The controller classs.
Controller for modifying the state of the board with legal moves as per
the rules of the game.
"""
def __init__(self, root, size):
"""
Initialize the controller class instance.
root - Tk object to handle view
size - size of board
"""
self.root = root
self.size = size
self.game_over = False
self.moves = []
self.model = Model(size)
self.view = View(root, size)
self.valid_moves = {
"Up": lambda: self.model.shift_blocks_up(),
"Down": lambda: self.model.shift_blocks_down(),
"Left": lambda: self.model.shift_blocks_left(),
"Right": lambda: self.model.shift_blocks_right(),
"s": lambda: self.backdoor()
}
self.view.bind_all("<Key>", self.move)
self.view.new_game_button.config(command=self.new_game)
coords = self.model.add_new_block()
val = self.model.value_at(coords[0], coords[1])
self.view.draw_new(coords, val)
self.model.subscribe_to_moves(self.update_moves)
def move(self, user_move):
"""
Execute one move.
Expects a user move - as defined by the dictionary valid_moves
Returns a string when the game is over
"""
if self.game_over:
return
key = user_move.keysym
if self.view.is_animating():
return
no_sliding = self.valid_moves[key]()
try:
self.do_moves()
except IndexError:
self.view.redraw_from_model()
game_check = self.model.game_state_check()
if game_check:
self.view.game_end(game_check)
self.game_over = True
elif not no_sliding:
coords = self.model.add_new_block()
val = self.model.value_at(coords[0], coords[1])
self.view.draw_new(coords, val)
def new_game(self):
"""
Starts a new game by deleting the model and creating a new one
"""
self.model = Model(self.size)
self.game_over = False
self.view.reset()
coords = self.model.add_new_block()
val = self.model.value_at(coords[0], coords[1])
self.view.draw_new(coords, val)
self.model.subscribe_to_moves(self.update_moves)
def update_moves(self, move):
"""
Collects the moves made by the model
"""
self.moves.append(move)
def do_moves(self):
"""
Executes the moves collected from the model
"""
fin = self.view.draw_moves(self.moves)
if fin:
self.moves = []
def redraw_from_model(self):
"""
Has the view redraw the board based on the values in the model.
Used if
"""
self.view.reset()
for x in range(self.size):
for y in range(self.size):
val = self.model.value_at(x, y)
self.view.draw_from_value(x, y, val)
def backdoor(self):
for x in range(self.size):
for y in range(self.size):
#.........这里部分代码省略.........