Mercurial > fife-parpg
diff 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 |
line wrap: on
line diff
--- a/clients/editor/plugins/objectselector.py Thu Mar 19 22:04:48 2009 +0000 +++ b/clients/editor/plugins/objectselector.py Thu Mar 19 23:05:43 2009 +0000 @@ -1,8 +1,49 @@ # coding: utf-8 -from pychan import widgets, tools +from pychan import widgets, tools, attrs import fife +# TODO: +# - Scrollarea in previewmode does not display the last item properly +# - Better event handling in ObjectIcon + +class ObjectIcon(widgets.VBox): + """ The ObjectIcon is used to represent the object in the object selector. + Unlike + """ + ATTRIBUTES = widgets.VBox.ATTRIBUTES + [ attrs.Attr("text"), attrs.Attr("image") ] + + def __init__(self,**kwargs): + self.real_widget = fife.Container() + super(ObjectIcon,self).__init__(_real_widget=self.real_widget,**kwargs) + + vbox = widgets.VBox(padding=3) + + # Icon + self.icon = widgets.Icon(**kwargs) + self.addChild(self.icon) + + # Label + hbox = widgets.HBox(padding=1) + self.addChild(hbox) + self.label = widgets.Label(**kwargs) + hbox.addChild(self.label) + + + def _setText(self, text): + self.label.text = text + + def _getText(self): + return self.label.text + text = property(_getText, _setText) + + def _setImage(self, image): + self.icon.image = image + + def _getImage(self): + return self.icon.image + image = property(_getImage, _setImage) + class ObjectSelector(object): """The ObjectSelector class offers a gui Widget that let's you select the object you wish to use to in the editor. @@ -27,10 +68,17 @@ # Add the drop down with list of namespaces self.namespaces = widgets.DropDown() vbox.addChild(self.namespaces) - self.namespaces.capture(self.update_namespace) + self.namespaces.items = self.engine.getModel().getNamespaces() self.namespaces.selected = 0 + # Events for namespacelist + # TODO: Replace with SelectionEvent, once pychan supports it + self.namespaces.capture(self.update_namespace, "action") + self.namespaces.capture(self.update_namespace, "mouseWheelMovedUp") + self.namespaces.capture(self.update_namespace, "mouseWheelMovedDown") + self.namespaces.capture(self.update_namespace, "keyReleased") + # This scrollarea is used to display the preview images self.mainScrollArea = widgets.ScrollArea(size=(230,300)) self.objects = None @@ -40,7 +88,6 @@ self.setImageList() vbox.addChild(self.mainScrollArea) - # Add another Hbox to hold the close button hbox = widgets.HBox(parent=self.gui) vbox.addChild(hbox) @@ -75,6 +122,7 @@ if self.objects is not None: self.mainScrollArea.removeChild(self.objects) self.objects = widgets.VBox(name='list', size=(200,300)) + self.objects.base_color = self.mainScrollArea.background_color self.mainScrollArea.addChild(self.objects) def setTextList(self): @@ -103,14 +151,17 @@ objects = self.engine.getModel().getObjects(self.namespaces.selected_item) for obj in objects: image = self._getImage(obj) - if image is not None: - imagebutton = widgets.ImageButton(up_image=image, down_image=image, hover_image=image) - imagebutton.capture(tools.callbackWithArguments(self.objectSelected, obj)) - self.objects.addChild(imagebutton) - self.objects._recursiveResizeToContent() - self.gui.adaptLayout() - else: + if image is None: print 'No image available for selected object' + image = "" + + icon = ObjectIcon(image=image, text=obj.getId()) + icon.capture(tools.callbackWithArguments(self.objectSelected, obj), "mouseClicked") + self.objects.addChild(icon) + + self.objects._recursiveResizeToContent() + self.gui.adaptLayout() + if len(objects)>0: self.objectSelected(objects[0])