Mercurial > fife-parpg
comparison clients/editor/plugins/objectselector.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 | afdca61c314b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 # coding: utf-8 | |
2 | |
3 from pychan import widgets | |
4 import fife | |
5 | |
6 class ObjectSelector(object): | |
7 def __init__(self,engine,map,selectNotify): | |
8 self.engine = engine | |
9 self.map = map | |
10 self.notify = selectNotify | |
11 | |
12 self.buildGui() | |
13 | |
14 def buildGui(self): | |
15 self.gui = widgets.Window(title="Object selector") | |
16 hbox = widgets.HBox(parent=self.gui) | |
17 self.gui.addChild(hbox) | |
18 scrollArea = widgets.ScrollArea(parent=hbox,size=(120,300)) | |
19 hbox.addChild(scrollArea) | |
20 self.namespaces = widgets.ListBox(parent=scrollArea) | |
21 scrollArea.content = self.namespaces | |
22 scrollArea = widgets.ScrollArea(parent=hbox,size=(120,300)) | |
23 hbox.addChild(scrollArea) | |
24 self.objects = widgets.ListBox(parent=scrollArea) | |
25 scrollArea.content = self.objects | |
26 scrollArea = widgets.ScrollArea(parent=hbox, size=(120,300)) | |
27 hbox.addChild(scrollArea) | |
28 self.preview = widgets.Icon() | |
29 scrollArea.content = self.preview | |
30 | |
31 hbox = widgets.HBox(parent=self.gui) | |
32 self.gui.addChild(hbox) | |
33 hbox.addSpacer( widgets.Spacer() ) | |
34 closeButton = widgets.Button(parent=hbox,text="Close") | |
35 hbox.addChild( closeButton ) | |
36 closeButton.capture(self.hide) | |
37 | |
38 self.namespaces.capture(self.updateObjects) | |
39 self.namespaces.items = self.engine.getModel().getNamespaces() | |
40 self.namespaces.selected = 0 | |
41 self.updateObjects() | |
42 | |
43 self.objects.capture(self.objectSelected) | |
44 | |
45 def update(self): | |
46 self.namespaces.items = self.engine.getModel().getNamespaces() | |
47 self.namespaces.selected = 0 | |
48 self.updateObjects() | |
49 | |
50 def updateObjects(self): | |
51 if not self.namespaces.selected_item: return | |
52 | |
53 self.objects.items = [obj.getId() for obj in self.engine.getModel().getObjects(self.namespaces.selected_item)] | |
54 if not self.objects.selected_item: | |
55 self.objects.selected = 0 | |
56 self.objectSelected() | |
57 | |
58 def objectSelected(self): | |
59 if not self.objects.selected_item: return | |
60 object = self.engine.getModel().getObject(self.objects.selected_item, self.namespaces.selected_item) | |
61 self.notify(object) | |
62 self._refreshPreview(object) | |
63 | |
64 def _refreshPreview(self, object): | |
65 visual = None | |
66 | |
67 try: | |
68 visual = object.get2dGfxVisual() | |
69 except: | |
70 print 'Visual Selection created for type without a visual?' | |
71 raise | |
72 | |
73 index = visual.getStaticImageIndexByAngle(0) | |
74 if index == -1: | |
75 # no static image available, try default action | |
76 action = object.getDefaultAction() | |
77 if action: | |
78 animation_id = action.get2dGfxVisual().getAnimationIndexByAngle(0) | |
79 animation = self.engine.getAnimationPool().getAnimation(animation_id) | |
80 image = animation.getFrameByTimestamp(0) | |
81 index = image.getPoolId() | |
82 | |
83 if index != -1: | |
84 image = fife.GuiImage(index, self.engine.getImagePool()) | |
85 self.preview.image = image | |
86 self.gui.adaptLayout() | |
87 else: | |
88 print 'No image available for selected object' | |
89 | |
90 | |
91 def show(self): | |
92 self.update() | |
93 self.gui.show() | |
94 def hide(self): | |
95 self.gui.hide() |