Mercurial > fife-parpg
comparison clients/editor/plugins/objectselector.py @ 224:567863be0abc
* First version of previewmode icons in ObjectSelector
- Needs better event handling to enable keyboard users to select items
* Fixed a small bug which caused longer loading times when entering previewmode
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 19 Mar 2009 23:05:43 +0000 |
parents | 68ae8f4234ca |
children | 1beb7a3692f4 |
comparison
equal
deleted
inserted
replaced
223:da2ca208c221 | 224:567863be0abc |
---|---|
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 from pychan import widgets, tools | 3 from pychan import widgets, tools, attrs |
4 import fife | 4 import fife |
5 | 5 |
6 # TODO: | |
7 # - Scrollarea in previewmode does not display the last item properly | |
8 # - Better event handling in ObjectIcon | |
9 | |
10 class ObjectIcon(widgets.VBox): | |
11 """ The ObjectIcon is used to represent the object in the object selector. | |
12 Unlike | |
13 """ | |
14 ATTRIBUTES = widgets.VBox.ATTRIBUTES + [ attrs.Attr("text"), attrs.Attr("image") ] | |
15 | |
16 def __init__(self,**kwargs): | |
17 self.real_widget = fife.Container() | |
18 super(ObjectIcon,self).__init__(_real_widget=self.real_widget,**kwargs) | |
19 | |
20 vbox = widgets.VBox(padding=3) | |
21 | |
22 # Icon | |
23 self.icon = widgets.Icon(**kwargs) | |
24 self.addChild(self.icon) | |
25 | |
26 # Label | |
27 hbox = widgets.HBox(padding=1) | |
28 self.addChild(hbox) | |
29 self.label = widgets.Label(**kwargs) | |
30 hbox.addChild(self.label) | |
31 | |
32 | |
33 def _setText(self, text): | |
34 self.label.text = text | |
35 | |
36 def _getText(self): | |
37 return self.label.text | |
38 text = property(_getText, _setText) | |
39 | |
40 def _setImage(self, image): | |
41 self.icon.image = image | |
42 | |
43 def _getImage(self): | |
44 return self.icon.image | |
45 image = property(_getImage, _setImage) | |
46 | |
6 class ObjectSelector(object): | 47 class ObjectSelector(object): |
7 """The ObjectSelector class offers a gui Widget that let's you select the object you | 48 """The ObjectSelector class offers a gui Widget that let's you select the object you |
8 wish to use to in the editor. | 49 wish to use to in the editor. |
9 @param engine: fife instance | 50 @param engine: fife instance |
10 @param map: fife.Map instance containing your map | 51 @param map: fife.Map instance containing your map |
25 self.gui.addChild(vbox) | 66 self.gui.addChild(vbox) |
26 | 67 |
27 # Add the drop down with list of namespaces | 68 # Add the drop down with list of namespaces |
28 self.namespaces = widgets.DropDown() | 69 self.namespaces = widgets.DropDown() |
29 vbox.addChild(self.namespaces) | 70 vbox.addChild(self.namespaces) |
30 self.namespaces.capture(self.update_namespace) | 71 |
31 self.namespaces.items = self.engine.getModel().getNamespaces() | 72 self.namespaces.items = self.engine.getModel().getNamespaces() |
32 self.namespaces.selected = 0 | 73 self.namespaces.selected = 0 |
74 | |
75 # Events for namespacelist | |
76 # TODO: Replace with SelectionEvent, once pychan supports it | |
77 self.namespaces.capture(self.update_namespace, "action") | |
78 self.namespaces.capture(self.update_namespace, "mouseWheelMovedUp") | |
79 self.namespaces.capture(self.update_namespace, "mouseWheelMovedDown") | |
80 self.namespaces.capture(self.update_namespace, "keyReleased") | |
33 | 81 |
34 # This scrollarea is used to display the preview images | 82 # This scrollarea is used to display the preview images |
35 self.mainScrollArea = widgets.ScrollArea(size=(230,300)) | 83 self.mainScrollArea = widgets.ScrollArea(size=(230,300)) |
36 self.objects = None | 84 self.objects = None |
37 if self.mode == 'list': | 85 if self.mode == 'list': |
38 self.setTextList() | 86 self.setTextList() |
39 else: # Assuming self.mode is 'preview' | 87 else: # Assuming self.mode is 'preview' |
40 self.setImageList() | 88 self.setImageList() |
41 vbox.addChild(self.mainScrollArea) | 89 vbox.addChild(self.mainScrollArea) |
42 | |
43 | 90 |
44 # Add another Hbox to hold the close button | 91 # Add another Hbox to hold the close button |
45 hbox = widgets.HBox(parent=self.gui) | 92 hbox = widgets.HBox(parent=self.gui) |
46 vbox.addChild(hbox) | 93 vbox.addChild(hbox) |
47 hbox.addSpacer(widgets.Spacer()) | 94 hbox.addSpacer(widgets.Spacer()) |
73 """Sets the mainScrollArea to contain a Vbox that can be used to fill in | 120 """Sets the mainScrollArea to contain a Vbox that can be used to fill in |
74 preview Images""" | 121 preview Images""" |
75 if self.objects is not None: | 122 if self.objects is not None: |
76 self.mainScrollArea.removeChild(self.objects) | 123 self.mainScrollArea.removeChild(self.objects) |
77 self.objects = widgets.VBox(name='list', size=(200,300)) | 124 self.objects = widgets.VBox(name='list', size=(200,300)) |
125 self.objects.base_color = self.mainScrollArea.background_color | |
78 self.mainScrollArea.addChild(self.objects) | 126 self.mainScrollArea.addChild(self.objects) |
79 | 127 |
80 def setTextList(self): | 128 def setTextList(self): |
81 """Sets the mainScrollArea to contain a List that can be used to fill in | 129 """Sets the mainScrollArea to contain a List that can be used to fill in |
82 Object names/paths""" | 130 Object names/paths""" |
101 | 149 |
102 def fillPreviewList(self): | 150 def fillPreviewList(self): |
103 objects = self.engine.getModel().getObjects(self.namespaces.selected_item) | 151 objects = self.engine.getModel().getObjects(self.namespaces.selected_item) |
104 for obj in objects: | 152 for obj in objects: |
105 image = self._getImage(obj) | 153 image = self._getImage(obj) |
106 if image is not None: | 154 if image is None: |
107 imagebutton = widgets.ImageButton(up_image=image, down_image=image, hover_image=image) | |
108 imagebutton.capture(tools.callbackWithArguments(self.objectSelected, obj)) | |
109 self.objects.addChild(imagebutton) | |
110 self.objects._recursiveResizeToContent() | |
111 self.gui.adaptLayout() | |
112 else: | |
113 print 'No image available for selected object' | 155 print 'No image available for selected object' |
156 image = "" | |
157 | |
158 icon = ObjectIcon(image=image, text=obj.getId()) | |
159 icon.capture(tools.callbackWithArguments(self.objectSelected, obj), "mouseClicked") | |
160 self.objects.addChild(icon) | |
161 | |
162 self.objects._recursiveResizeToContent() | |
163 self.gui.adaptLayout() | |
164 | |
114 if len(objects)>0: | 165 if len(objects)>0: |
115 self.objectSelected(objects[0]) | 166 self.objectSelected(objects[0]) |
116 | 167 |
117 | 168 |
118 def objectSelected(self, obj): | 169 def objectSelected(self, obj): |