-
Notifications
You must be signed in to change notification settings - Fork 4
/
observers.py
55 lines (42 loc) · 1.5 KB
/
observers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from undo import UndoableAction
class spriteAdded(UndoableAction):
def __init__(self, atlas, sprite):
self.atlas = atlas
self.sprite = sprite
def do(self):
self.atlas.readdSprite(self.sprite)
self._done()
def undo(self):
self.atlas.removeSprite(self.sprite)
self._undone()
class spriteRemoved(UndoableAction):
def __init__(self, atlas, sprite):
self.atlas = atlas
self.sprite = sprite
def do(self):
self.atlas.removeSprite(self.sprite)
self._done()
def undo(self):
self.atlas.readdSprite(self.sprite)
self._undone()
class AtlasLogObserver(object):
spriteAddedAction = spriteAdded
spriteRemovedAction = spriteRemoved
def __init__(self, log):
self.log = log
def startObserving(self, atlas):
self._connectToAtlas(atlas)
def stopObserving(self, atlas):
self._disconnectFromAtlas(atlas)
def _connectToAtlas(self, atlas):
atlas.connect("sprite-added", self._spriteAddedCb)
atlas.connect("sprite-removed", self._spriteRemovedCb)
def _disconnectFromAtlas(self, atlas):
atlas.disconnect_by_func(self._spriteAddedCb)
atlas.disconnect_by_func(self._spriteRemovedCb)
def _spriteAddedCb(self, atlas, sprite):
action = self.spriteAddedAction(atlas, sprite)
self.log.push(action)
def _spriteRemovedCb(self, atlas, sprite):
action = self.spriteRemovedAction(atlas, sprite)
self.log.push(action)