Mercurial > fife-parpg
comparison engine/extensions/pychan/__init__.py @ 129:9a1529f9625e
* Indentation patch by GreyGhost
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 07 Aug 2008 15:46:46 +0000 |
parents | 4a0efb7baf70 |
children | bb9902910067 |
comparison
equal
deleted
inserted
replaced
128:6e1fd3571440 | 129:9a1529f9625e |
---|---|
245 This has to be called before any other pychan methods can be used. | 245 This has to be called before any other pychan methods can be used. |
246 It sets up a manager object which is available under pychan.manager. | 246 It sets up a manager object which is available under pychan.manager. |
247 | 247 |
248 @param engine: The FIFE engine object. | 248 @param engine: The FIFE engine object. |
249 """ | 249 """ |
250 from manager import Manager | 250 from manager import Manager |
251 global manager | 251 global manager |
252 manager = Manager(engine,debug) | 252 manager = Manager(engine,debug) |
253 | |
254 | 253 |
255 # XML Loader | 254 # XML Loader |
256 | 255 |
257 from xml.sax import saxutils, handler | 256 from xml.sax import saxutils, handler |
258 from traceback import print_exc | 257 from traceback import print_exc |
325 self._setAttr(obj,k,v) | 324 self._setAttr(obj,k,v) |
326 | 325 |
327 if self.root: | 326 if self.root: |
328 self.root.addChild( obj ) | 327 self.root.addChild( obj ) |
329 self.root = obj | 328 self.root = obj |
330 | 329 |
331 def _createSpacer(self,cls,name,attrs): | 330 def _createSpacer(self,cls,name,attrs): |
332 obj = cls(parent=self.root) | 331 obj = cls(parent=self.root) |
333 if hasattr(self.root,'add'): | 332 if hasattr(self.root,'add'): |
334 self.root.addSpacer(obj) | 333 self.root.addSpacer(obj) |
335 else: | 334 else: |
343 self.root = self.root._parent or self.root | 342 self.root = self.root._parent or self.root |
344 | 343 |
345 def loadXML(filename_or_stream): | 344 def loadXML(filename_or_stream): |
346 """ | 345 """ |
347 Loads a PyChan XML file and generates a widget from it. | 346 Loads a PyChan XML file and generates a widget from it. |
348 | 347 |
349 @param filename_or_stream: A filename or a file-like object (for example using StringIO). | 348 @param filename_or_stream: A filename or a file-like object (for example using StringIO). |
350 | 349 |
351 The XML format is very dynamic, in the sense, that the actual allowed tags and attributes | 350 The XML format is very dynamic, in the sense, that the actual allowed tags and attributes |
352 depend on the PyChan code. | 351 depend on the PyChan code. |
353 | 352 |
354 So when a tag C{Button} is encountered, an instance of class Button will be generated, | 353 So when a tag C{Button} is encountered, an instance of class Button will be generated, |
355 and added to the parent object. | 354 and added to the parent object. |
356 All attributes will then be parsed and then set in the following way: | 355 All attributes will then be parsed and then set in the following way: |
357 | 356 |
358 - position,size,min_size,max_size,margins - These are assumed to be comma separated tuples | 357 - position,size,min_size,max_size,margins - These are assumed to be comma separated tuples |
359 of integers. | 358 of integers. |
360 - foreground_color,base_color,background_color - These are assumed to be triples of comma | 359 - foreground_color,base_color,background_color - These are assumed to be triples of comma |
361 separated integers. | 360 separated integers. |
362 - opaque,border_size,padding - These are assumed to be simple integers. | 361 - opaque,border_size,padding - These are assumed to be simple integers. |
363 | 362 |
364 All other attributes are set verbatim as strings on the generated instance. | 363 All other attributes are set verbatim as strings on the generated instance. |
365 In case a Widget does not accept an attribute to be set or the attribute can not be parsed | 364 In case a Widget does not accept an attribute to be set or the attribute can not be parsed |
366 correctly, the function will raise a GuiXMLError. | 365 correctly, the function will raise a GuiXMLError. |
367 | 366 |
368 In short:: | 367 In short:: |
369 <VBox> | 368 <VBox> |
370 <Button text="X" min_size="20,20" base_color="255,0,0" border_size="2" /> | 369 <Button text="X" min_size="20,20" base_color="255,0,0" border_size="2" /> |
371 </VBox> | 370 </VBox> |
372 | 371 |
373 This result in the following code executed:: | 372 This result in the following code executed:: |
374 | 373 |
375 vbox = VBox(parent=None) | 374 vbox = VBox(parent=None) |
376 button = Button(parent=vbox) | 375 button = Button(parent=vbox) |
377 button.text = "X" | 376 button.text = "X" |
378 button.min_size = (20,20) | 377 button.min_size = (20,20) |
379 button.base_color = (255,0,0) | 378 button.base_color = (255,0,0) |
386 return loader.root | 385 return loader.root |
387 | 386 |
388 def setupModalExecution(mainLoop,breakFromMainLoop): | 387 def setupModalExecution(mainLoop,breakFromMainLoop): |
389 """ | 388 """ |
390 Setup the synchronous dialog execution feature. | 389 Setup the synchronous dialog execution feature. |
391 | 390 |
392 You can enable synchronous dialog execution by | 391 You can enable synchronous dialog execution by |
393 passing to functions to this function. | 392 passing to functions to this function. |
394 | 393 |
395 @param mainLoop: Function - This is regarded as the applications | 394 @param mainLoop: Function - This is regarded as the applications |
396 main loop, which should be able to be called recursively. | 395 main loop, which should be able to be called recursively. |
397 It should not take no arguments and return the argument | 396 It should not take no arguments and return the argument |
398 passed to the second function (breakFromMainLoop). | 397 passed to the second function (breakFromMainLoop). |
399 | 398 |
400 @param breakFromMainLoop: Function -This function should cause the | 399 @param breakFromMainLoop: Function -This function should cause the |
401 first function to finish and return the passed argument. | 400 first function to finish and return the passed argument. |
402 | 401 |
403 With these to functions dialogs can be executed synchronously. | 402 With these to functions dialogs can be executed synchronously. |
404 See L{widgets.Widget.execute}. | 403 See L{widgets.Widget.execute}. |
405 """ | 404 """ |
406 if not manager: | 405 if not manager: |
407 raise InitializationError("PyChan is not initialized yet.") | 406 raise InitializationError("PyChan is not initialized yet.") |