Changeset 1159
- Timestamp:
- 03/14/07 00:29:35 (2 years ago)
- Files:
-
- gaphas/trunk/demo.py (modified) (3 diffs)
- gaphas/trunk/gaphas/canvas.py (modified) (1 diff)
- gaphas/trunk/gaphas/geometry.py (modified) (2 diffs)
- gaphas/trunk/gaphas/item.py (modified) (1 diff)
- gaphas/trunk/gaphas/matrix.py (added)
- gaphas/trunk/gaphas/state.py (modified) (4 diffs)
- gaphas/trunk/state.txt (modified) (2 diffs)
- gaphas/trunk/undo.txt (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/demo.py
r1149 r1159 18 18 from gaphas.tool import PlacementTool, HandleTool 19 19 from gaphas.painter import ItemPainter 20 21 20 from gaphas import state 21 22 # Global undo list 23 undo_list = [] 24 25 def undo_handler(event): 26 global undo_list 27 undo_list.append(event) 22 28 23 29 … … 125 131 canvas.remove(view.focused_item) 126 132 print 'items:', canvas.get_all_items() 133 134 b.connect('clicked', on_clicked) 135 v.add(b) 136 137 v.add(gtk.Label('State:')) 138 b = gtk.ToggleButton('Record') 139 140 def on_toggled(button): 141 global undo_list 142 if button.get_active(): 143 print 'start recording' 144 del undo_list[:] 145 state.subscribers.add(undo_handler) 146 else: 147 print 'stop recording' 148 state.subscribers.remove(undo_handler) 149 150 b.connect('toggled', on_toggled) 151 v.add(b) 152 153 b = gtk.Button('Play back') 154 155 def on_clicked(self): 156 global undo_list 157 apply_me = list(undo_list) 158 del undo_list[:] 159 apply_me.reverse() 160 saveapply = state.saveapply 161 for event in apply_me: 162 saveapply(*event) 127 163 128 164 b.connect('clicked', on_clicked) … … 265 301 266 302 # First, activate the revert handler: 267 state. subscribers.append(state.revert_handler)303 state.observers.add(state.revert_handler) 268 304 269 305 def print_handler(event): 270 306 print 'event:', event 271 307 272 state. observers.append(print_handler)308 state.subscribers.add(print_handler) 273 309 274 310 gaphas/trunk/gaphas/canvas.py
r1152 r1159 12 12 13 13 import cairo 14 from cairo import Matrix 14 15 from gaphas import tree 15 16 from gaphas import solver 16 from gaphas.geometry import Matrix17 17 from gaphas.decorators import async, PRIORITY_HIGH_IDLE 18 18 from state import observed, reversible_pair gaphas/trunk/gaphas/geometry.py
r1092 r1159 2 2 Geometry functions. 3 3 4 Matrix is imported from cairo.5 6 4 Rectangle is a utility class for working with rectangles (unions and 7 5 intersections) … … 15 13 16 14 from math import sqrt 17 # This saves me a lot of coding:18 from cairo import Matrix19 15 20 16 gaphas/trunk/gaphas/item.py
r1158 r1159 8 8 from math import atan2 9 9 10 from geometry import Matrix, distance_line_point, distance_rectangle_point 10 from matrix import Matrix 11 from geometry import distance_line_point, distance_rectangle_point 11 12 from solver import solvable, WEAK, NORMAL, STRONG 12 13 from constraint import EqualsConstraint, LessThanConstraint gaphas/trunk/gaphas/state.py
r1157 r1159 132 132 133 133 _reverse = dict() 134 135 136 def reversible_function(func, reverse, bind={}): 137 """ 138 Straight forward reversible method, if func is invoked, reverse 139 is dispatched with bind as arguments. 140 """ 141 global _reverse 142 func = getfunction(func) 143 _reverse[func] = (reverse, inspect.getargspec(reverse), bind) 144 145 146 reversible_method = reversible_function 147 134 148 135 149 def reversible_pair(func1, func2, bind1={}, bind2={}): … … 236 250 237 251 """ 238 #print 'in handler!', event239 252 global _reverse 240 253 func, args, kwargs = event … … 242 255 reverse, revspec, bind = _reverse.get(func, (None, None, {})) 243 256 if not reverse: 244 #print 'no reverse'245 257 return 246 258 … … 271 283 for arg in argnames: 272 284 kwargs[arg] = kw.get(arg) 273 #args = map(dict.get, [kw]*len(argnames), argnames)274 #print 'args:', func, args275 285 return func(**kwargs) 276 286 gaphas/trunk/state.txt
r1157 r1159 19 19 >>> from gaphas.tree import Tree 20 20 >>> tree = Tree() 21 22 For this demonistration let's use the Tree class (which contains an add/remove 23 method pair). It's methods are not dispatched by default though (because they're 24 only used in the Canvas class. So first dispatching should be enabled: 25 26 >>> state.enable_dispatching(Tree.add) 27 >>> state.enable_dispatching(Tree.remove) 28 29 It works: 30 21 31 >>> def handler(event): 22 32 ... print 'event handled', event … … 181 191 add() and remove() 182 192 193 matrix.py: 194 Matrix: 195 invert, translate, rotate and scale 196 197 Testcases are described in test_state.txt. 198
