本文整理汇总了Python中stack.Stack.create_memento方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.create_memento方法的具体用法?Python Stack.create_memento怎么用?Python Stack.create_memento使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.create_memento方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mediator
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import create_memento [as 别名]
#.........这里部分代码省略.........
self.right_frame_is_active = False
def add(self,card):
# The Add button was pressed on one of the StoryCards in self.storyCards
for box in self.right_vbox:
if box.contents is None:
box.fill(card)
# self.activate_right_frame()
return
zcanvas.message('The stack is full!\nDrag another card from the stack first.')
def remove(self,editableCard):
# The Remove button was pressed on one of the StoryCards in
# self.myStoryMap
editableCard.getPythonTag('box').empty()
for choosableCard in self.storyCards.items():
if choosableCard.function == editableCard.function:
choosableCard.enable()
return
# Implement the Originator interface of the memento design pattern. (For
# saving and loading.)
class Memento:
"""A passive class that stores the state of a Mediator object."""
def __init__(self, storycards, mystorymap, stack):
# MediatorMemento just holds mementos for mediator's two StoryMap
# objects.
self.storycards = storycards
self.mystorymap = mystorymap
self.stack = stack
def __str__(self):
return self.mystorymap.__str__()
def create_memento(self):
"""Return a memento object holding the current internal state of this
object."""
return Mediator.Memento(self.storyCards.create_memento(),
self.myStoryMap.create_memento(),
self.right_vbox.create_memento())
def restore_memento(self,memento):
"""Restore the internal state of this object to that held by the given
memento."""
self.storyCards.restore_memento(memento.storycards)
self.myStoryMap.restore_memento(memento.mystorymap)
self.right_vbox.restore_memento(memento.stack)
# Implement the Caretaker interface of the memento design pattern. (For
# saving and loading.)
def save(self):
"""Save the current state of the application to file."""
memento = self.create_memento()
import datetime
f = open(str(datetime.datetime.now()).replace(' ','_')+'.saved_story','w')
cPickle.dump(memento,f)
f.close()
zcanvas.message("Saved!")
def _load(self,args):
self.load_list.removeNode()
f = open(args,'r')
memento = cPickle.load(f)
f.close()
self.restore_memento(memento)