Mercurial > fife-parpg
comparison clients/pychan_demo/pychan_test.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 97d6946bd917 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 #!/usr/bin/env python | |
2 # coding: utf-8 | |
3 # This is the pychan demo client for FIFE. | |
4 | |
5 import sys, os, re | |
6 | |
7 def _jp(path): | |
8 return os.path.sep.join(path.split('/')) | |
9 | |
10 _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') | |
11 for p in _paths: | |
12 if p not in sys.path: | |
13 sys.path.append(_jp(p)) | |
14 | |
15 import fife | |
16 import fifelog | |
17 import basicapplication | |
18 import pychan | |
19 | |
20 class PyChanExample(object): | |
21 def __init__(self,xmlFile): | |
22 self.xmlFile = xmlFile | |
23 self.widget = None | |
24 | |
25 def start(self): | |
26 self.widget = pychan.loadXML(self.xmlFile) | |
27 eventMap = { | |
28 'closeButton':self.stop, | |
29 'okButton' :self.stop | |
30 } | |
31 self.widget.mapEvents(eventMap, ignoreMissing = True) | |
32 self.widget.show() | |
33 | |
34 def stop(self): | |
35 if self.widget: | |
36 self.widget.hide() | |
37 self.widget = None | |
38 | |
39 class DemoApplication(basicapplication.ApplicationBase): | |
40 def __init__(self): | |
41 super(DemoApplication,self).__init__() | |
42 | |
43 pychan.init(self.engine,debug=True) | |
44 pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) | |
45 | |
46 self.gui = pychan.loadXML('content/gui/demoapp.xml') | |
47 | |
48 eventMap = { | |
49 'creditsLink' : self.showCredits, | |
50 'closeButton' : self.quit, | |
51 'demoList' : self.selectExample | |
52 } | |
53 self.gui.mapEvents(eventMap) | |
54 | |
55 from dynamic import DynamicExample | |
56 from styling import StylingExample | |
57 | |
58 self.examples = { | |
59 'Absolute Positioning' : PyChanExample('content/gui/absolute.xml'), | |
60 'Basic Styling' : StylingExample(), | |
61 'All Widgets' : PyChanExample('content/gui/all_widgets.xml'), | |
62 'Dynamic Widgets' : DynamicExample(), | |
63 } | |
64 self.demoList = self.gui.findChild(name='demoList') | |
65 self.demoList.items += self.examples.keys() | |
66 self.gui.show() | |
67 | |
68 self.currentExample = None | |
69 self.creditsWidget = None | |
70 | |
71 def selectExample(self): | |
72 if self.demoList.selected_item is None: return | |
73 print "selected",self.demoList.selected_item | |
74 if self.currentExample: self.currentExample.stop() | |
75 self.currentExample = self.examples[self.demoList.selected_item] | |
76 self.gui.findChild(name="xmlSource").text = open(self.currentExample.xmlFile).read() | |
77 self.currentExample.start() | |
78 | |
79 def showCredits(self): | |
80 print pychan.loadXML('content/gui/credits.xml').execute({ 'okButton' : "Yay!" }) | |
81 | |
82 class TestXMLApplication(basicapplication.ApplicationBase): | |
83 """ | |
84 Test Application. Run the pychan_test.py file | |
85 with the XML file you want to load as argument. | |
86 """ | |
87 def __init__(self,xmlfile): | |
88 super(TestXMLApplication,self).__init__() | |
89 pychan.init(self.engine,debug=True) | |
90 self.widget = pychan.loadXML(xmlfile) | |
91 self.widget.show() | |
92 | |
93 if __name__ == '__main__': | |
94 import sys | |
95 if len(sys.argv) == 2: | |
96 app = TestXMLApplication(sys.argv[1]) | |
97 else: | |
98 app = DemoApplication() | |
99 app.run() |