Changeset 1249
- Timestamp:
- 04/24/07 23:21:21 (2 years ago)
- Files:
-
- gaphas/trunk/ChangeLog (modified) (1 diff)
- gaphas/trunk/gaphas/constraint.py (modified) (12 diffs)
- gaphas/trunk/gaphas/decorators.py (modified) (2 diffs)
- gaphas/trunk/gaphas/examples.py (modified) (5 diffs)
- gaphas/trunk/gaphas/geometry.py (modified) (4 diffs)
- gaphas/trunk/gaphas/solver.py (modified) (5 diffs)
- gaphas/trunk/gaphas/tree.py (modified) (12 diffs)
- gaphas/trunk/gaphas/util.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/ChangeLog
r1161 r1249 1 2 [ for log entries, see svn log ] 3 1 4 2007-03-16 Arjan Molenaar <arjan_at_yirdis_dot_nl> 2 5 gaphas/trunk/gaphas/constraint.py
r1133 r1249 27 27 28 28 class Constraint(object): 29 """Constraint base class. 29 """ 30 Constraint base class. 30 31 """ 31 32 disabled = False 32 33 33 34 def variables(self): 34 """return an iterator which iterates over the variables that are 35 """ 36 Return an iterator which iterates over the variables that are 35 37 held by this constraint. 36 38 """ … … 38 40 39 41 def solve_for(self, var): 40 """Solve the constraint for a given variable. 42 """ 43 Solve the constraint for a given variable. 41 44 The variable itself is updated. 42 45 """ … … 45 48 46 49 class EqualsConstraint(Constraint): 47 """Simple Constraint, takes two arguments: 'a' and 'b'. When solved the 50 """ 51 Simple Constraint, takes two arguments: 'a' and 'b'. When solved the 48 52 attribute passed to solve_for() is set equal to the other. 49 53 … … 78 82 79 83 class LessThanConstraint(Constraint): 80 """Ensure @smaller is less than @bigger. The variable that is passed 84 """ 85 Ensure @smaller is less than @bigger. The variable that is passed 81 86 as to-be-solved is left alone (cause it is the variable that has not 82 87 been moved lately). Instead the other variable is solved. … … 115 120 116 121 class EquationConstraint(Constraint): 117 """Equation solver using attributes and introspection. 122 """ 123 Equation solver using attributes and introspection. 118 124 119 125 Takes a function, named arg value (opt.) and returns a Constraint object … … 152 158 153 159 def __getattr__(self, name): 154 """used to extract function argument values 160 """ 161 Used to extract function argument values. 155 162 """ 156 163 self._args[name] … … 158 165 159 166 def __setattr__(self, name, value): 160 """sets function argument values""" 167 """ 168 Sets function argument values. 169 """ 161 170 # Note - once self._args is created, no new attributes can 162 171 # be added to self.__dict__. This is a good thing as it throws … … 172 181 173 182 def _set(self, **args): 174 """sets values of function arguments 183 """ 184 Sets values of function arguments. 175 185 """ 176 186 for arg in args: … … 182 192 183 193 def solve_for(self, var): 184 """Solve this constraint for the variable named 'arg' in the 194 """ 195 Solve this constraint for the variable named 'arg' in the 185 196 constraint. 186 197 """ … … 192 203 193 204 def _solve_for(self, arg, args): 194 """Newton's method solver""" 205 """ 206 Newton's method solver 207 """ 195 208 #args = self._args 196 209 close_runs = 10 # after getting close, do more passes … … 240 253 241 254 class LineConstraint(Constraint): 242 """Ensure a point is kept on a line, taking into account item 255 """ 256 Ensure a point is kept on a line, taking into account item 243 257 specific coordinates. 244 258 … … 316 330 317 331 def _solve(self): 318 """Solve the equation for the connected_handle. 332 """ 333 Solve the equation for the connected_handle. 319 334 >>> from item import Handle, Item 320 335 >>> from canvas import Canvas gaphas/trunk/gaphas/decorators.py
r1133 r1249 16 16 17 17 class async(object): 18 """Instead of calling the function, schedule an idle handler at a given 18 """ 19 Instead of calling the function, schedule an idle handler at a given 19 20 priority. This requires the async'ed method to be called from within 20 21 the GTK main loop. Otherwise the method is executed directly. … … 124 125 """ 125 126 def wrapper(*args, **kwargs): 126 """Decorate function with a mutex that prohibits recursice execution. 127 """ 128 Decorate function with a mutex that prohibits recursice execution. 127 129 """ 128 130 try: gaphas/trunk/gaphas/examples.py
r1196 r1249 1 """Simple example items. 1 """ 2 Simple example items. 2 3 These items are used in various tests. 3 4 """ … … 38 39 39 40 def glue(self, item, handle, x, y): 40 """Special glue method used by the ConnectingHandleTool to find 41 """ 42 Special glue method used by the ConnectingHandleTool to find 41 43 a connection point. 42 44 """ … … 79 81 80 82 class ConnectingHandleTool(tool.HandleTool): 81 """This is a HandleTool which supports a simple connection algerithm, 83 """ 84 This is a HandleTool which supports a simple connection algerithm, 82 85 Using LineConstraint. 83 86 """ 84 87 85 88 def glue(self, view, item, handle, wx, wy): 86 """It allows the tool to glue to a Box or (other) Line item. 89 """ 90 It allows the tool to glue to a Box or (other) Line item. 87 91 The distance from the item to the handle is determined in canvas 88 92 coordinates, using a 10 pixel glue distance. … … 116 120 117 121 def connect(self, view, item, handle, wx, wy): 118 """Connect a handle to another item. 122 """ 123 Connect a handle to another item. 119 124 120 125 In this "method" the following assumptios are made: … … 181 186 182 187 def DefaultExampleTool(): 183 """The default tool chain build from HoverTool, ItemTool and HandleTool. 188 """ 189 The default tool chain build from HoverTool, ItemTool and HandleTool. 184 190 """ 185 191 chain = tool.ToolChain() gaphas/trunk/gaphas/geometry.py
r1230 r1249 16 16 17 17 class Rectangle(object): 18 """Python Rectangle implementation. Rectangles can be added (union), 18 """ 19 Python Rectangle implementation. Rectangles can be added (union), 19 20 substituted (intersection) and points and rectangles can be tested to 20 21 be in the rectangle. … … 114 115 115 116 def __add__(self, obj): 116 """Create a new Rectangle is the union of the current rectangle 117 """ 118 Create a new Rectangle is the union of the current rectangle 117 119 with another Rectangle, tuple (x,y) or tuple (x0, y0, x1, y1). 118 120 … … 156 158 157 159 def __sub__(self, obj): 158 """Create a new Rectangle is the union of the current rectangle 160 """ 161 Create a new Rectangle is the union of the current rectangle 159 162 with another Rectangle or tuple (x0, y0, x1, y1). 160 163 … … 274 277 275 278 def point_on_rectangle(rect, point, border=False): 276 """Return the point on which @point can be projecten on the rectangle. 279 """ 280 Return the point on which @point can be projecten on the rectangle. 277 281 border = True will make sure the point is bound to the border of 278 282 the reactangle. Otherwise, if the point is in the rectangle, it's okay. gaphas/trunk/gaphas/solver.py
r1174 r1249 281 281 282 282 def mark_dirty(self, *variables): 283 """Mark a variable as "dirty". This means it it solved the next time 283 """ 284 Mark a variable as "dirty". This means it it solved the next time 284 285 the constraints are resolved. 285 286 … … 322 323 @observed 323 324 def add_constraint(self, constraint): 324 """Add a constraint. 325 """ 326 Add a constraint. 325 327 The actual constraint is returned, so the constraint can be removed 326 328 later on. … … 378 380 379 381 def constraints_with_variable(self, variable): 380 """Return an iterator of constraints that work with variable. 382 """ 383 Return an iterator of constraints that work with variable. 381 384 The variable in question should be exposed by the constraints 382 385 variables() method. … … 402 405 403 406 def weakest_variable(self, variables): 404 """Returns the name(!) of the weakest variable. 407 """ 408 Returns the name(!) of the weakest variable. 405 409 406 410 Example: … … 474 478 475 479 class solvable(object): 476 """Easy-to-use drop Variable descriptor. 480 """ 481 Easy-to-use drop Variable descriptor. 477 482 478 483 >>> class A(object): gaphas/trunk/gaphas/tree.py
r1158 r1249 11 11 12 12 class Tree(object): 13 """A Tree structure. 13 """ 14 A Tree structure. 14 15 None is the root node. 15 16 … … 28 29 29 30 def get_parent(self, node): 30 """Return the parent item of @node. 31 """ 32 Return the parent item of @node. 31 33 """ 32 34 for item, children in self._children.items(): … … 35 37 36 38 def get_children(self, node): 37 """Return all child objects of @node. 39 """ 40 Return all child objects of @node. 38 41 """ 39 42 return self._children[node] 40 43 41 44 def get_siblings(self, node): 42 """Get all siblings of @node, including @node. 45 """ 46 Get all siblings of @node, including @node. 43 47 """ 44 48 parent = self.get_parent(node) … … 46 50 47 51 def get_next_sibling(self, node): 48 """Return the node on the same level after @node. 52 """ 53 Return the node on the same level after @node. 49 54 """ 50 55 parent = self.get_parent(node) … … 53 58 54 59 def get_previous_sibling(self, node): 55 """Return the node on the same level before @node. 60 """ 61 Return the node on the same level before @node. 56 62 """ 57 63 parent = self.get_parent(node) … … 60 66 61 67 def get_all_children(self, node): 62 """Iterate all children (and children of children and so forth) 68 """ 69 Iterate all children (and children of children and so forth) 63 70 """ 64 71 children = self.get_children(node) … … 69 76 70 77 def get_ancestors(self, node): 71 """Iterate all parents and parents of parents, etc. 78 """ 79 Iterate all parents and parents of parents, etc. 72 80 """ 73 81 parent = self.get_parent(node) … … 77 85 78 86 def _add_to_nodes(self, node, parent): 79 """Called only from add() 87 """ 88 Called only from add() 80 89 """ 81 90 nodes = self._nodes … … 95 104 @observed 96 105 def add(self, node, parent=None): 97 """Add @node to the tree. @parent is the parent node, which may 106 """ 107 Add @node to the tree. @parent is the parent node, which may 98 108 be None if the item should be added to the root item. 99 109 """ … … 107 117 @observed 108 118 def remove(self, node): 109 """Remove @node from the tree. 119 """ 120 Remove @node from the tree. 110 121 """ 111 122 # First remove children: … … 127 138 128 139 def test_add(): 129 """Test creating node trees. 140 """ 141 Test creating node trees. 130 142 """ 131 143 print 'test_add' … … 182 194 183 195 def test_remove(): 184 """Test removal of nodes. 196 """ 197 Test removal of nodes. 185 198 """ 186 199 print 'test_remove' gaphas/trunk/gaphas/util.py
r1196 r1249 81 81 82 82 def text_set_font(cr, font): 83 """Set the font from a string. E.g. 'sans 10' or 'sans italic bold 12' 83 """ 84 Set the font from a string. E.g. 'sans 10' or 'sans italic bold 12' 84 85 only restriction is that the font name should be the first option and 85 86 the font size as last argument … … 95 96 96 97 def path_ellipse (cr, x, y, width, height, angle=0): 97 """Draw an ellipse. 98 """ 99 Draw an ellipse. 98 100 x - center x 99 101 y - center y
