Mercurial > fife-parpg
view clients/editor/plugins/objectselector.py @ 108:0c017b8e4ab2
Added an undo feature to the map editor. Just press u to undo insert placement/removals.
author | jwt@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 26 Jul 2008 03:04:03 +0000 |
parents | afdca61c314b |
children | bec4b69ad83a |
line wrap: on
line source
# coding: utf-8 from pychan import widgets import fife class ObjectSelector(object): def __init__(self,engine,map,selectNotify): self.engine = engine self.map = map self.notify = selectNotify self.buildGui() def buildGui(self): self.gui = widgets.Window(title="Object selector") hbox = widgets.HBox(parent=self.gui) self.gui.addChild(hbox) scrollArea = widgets.ScrollArea(parent=hbox,size=(200,300)) hbox.addChild(scrollArea) self.namespaces = widgets.ListBox(parent=scrollArea) scrollArea.content = self.namespaces scrollArea = widgets.ScrollArea(parent=hbox,size=(200,300)) hbox.addChild(scrollArea) self.objects = widgets.ListBox(parent=scrollArea) scrollArea.content = self.objects scrollArea = widgets.ScrollArea(parent=hbox, size=(200,300)) hbox.addChild(scrollArea) self.preview = widgets.Icon() scrollArea.content = self.preview hbox = widgets.HBox(parent=self.gui) self.gui.addChild(hbox) hbox.addSpacer( widgets.Spacer() ) closeButton = widgets.Button(parent=hbox,text="Close") hbox.addChild( closeButton ) closeButton.capture(self.hide) self.namespaces.capture(self.updateObjects) self.namespaces.items = self.engine.getModel().getNamespaces() self.namespaces.selected = 0 self.updateObjects() self.objects.capture(self.objectSelected) def update(self): self.namespaces.items = self.engine.getModel().getNamespaces() self.namespaces.selected = 0 self.updateObjects() def updateObjects(self): if not self.namespaces.selected_item: return self.objects.items = [obj.getId() for obj in self.engine.getModel().getObjects(self.namespaces.selected_item)] if not self.objects.selected_item: self.objects.selected = 0 self.objectSelected() def objectSelected(self): if not self.objects.selected_item: return object = self.engine.getModel().getObject(self.objects.selected_item, self.namespaces.selected_item) self.notify(object) self._refreshPreview(object) def _refreshPreview(self, object): visual = None try: visual = object.get2dGfxVisual() except: print 'Visual Selection created for type without a visual?' raise index = visual.getStaticImageIndexByAngle(0) if index == -1: # no static image available, try default action action = object.getDefaultAction() if action: animation_id = action.get2dGfxVisual().getAnimationIndexByAngle(0) animation = self.engine.getAnimationPool().getAnimation(animation_id) image = animation.getFrameByTimestamp(0) index = image.getPoolId() if index != -1: image = fife.GuiImage(index, self.engine.getImagePool()) self.preview.image = image self.gui.adaptLayout() else: print 'No image available for selected object' def show(self): self.update() self.gui.show() def hide(self): self.gui.hide()