changeset 325:54de5aebf732

* ObjectSelector will now select and scroll to selected object automatically * ObjectSelector will now update after importing new objects * New event signal: onObjectsImported
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 21 Aug 2009 20:34:26 +0000
parents e249fa887259
children 671e22a1cc8d
files clients/editor/plugins/ObjectSelector.py clients/editor/scripts/events/events.py clients/editor/scripts/gui/filemanager.py
diffstat 3 files changed, 58 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/clients/editor/plugins/ObjectSelector.py	Fri Aug 21 14:39:54 2009 +0000
+++ b/clients/editor/plugins/ObjectSelector.py	Fri Aug 21 20:34:26 2009 +0000
@@ -11,6 +11,7 @@
 from fife import Color
 
 # TODO:
+# - Clean up code
 # - Better event handling
 
 _DEFAULT_BASE_COLOR = internal.DEFAULT_STYLE['default']['base_color']
@@ -113,7 +114,9 @@
 				self._selectedItem = item
 				tmp.selected = False
 			else:
-				self._selectedItem = item	
+				self._selectedItem = item
+		#if item is not None:
+		#	item.selected = True
 
 	def _getSelectedItem(self):
 		return self._selectedItem
@@ -132,6 +135,7 @@
 		self.mode = 'list' # Other mode is 'preview'
 		
 		self._enabled = False
+		self.object = None
 
 	def enable(self):
 		if self._enabled is True:
@@ -147,6 +151,7 @@
 		
 		events.postMapShown.connect(self.update_namespace)
 		events.onObjectSelected.connect(self.setPreview)
+		events.onObjectsImported.connect(self.update_namespace)
 		
 		self.buildGui()
 
@@ -159,6 +164,7 @@
 		
 		events.postMapShown.disconnect(self.update_namespace)
 		events.onObjectSelected.disconnect(self.setPreview)
+		events.onObjectsImported.disconnect(self.update_namespace)
 		
 		self.editor._toolsMenu.removeAction(self._showAction)
 
@@ -277,11 +283,25 @@
 			def __str__( self ):
 				return self.name
 			
-		if self.namespaces.selected_item:
-			self.objects.items = [_ListItem(obj.getId(), obj.getNamespace()) for obj in objects]
-			if not self.objects.selected_item:
+		
+		self.objects.items = [_ListItem(obj.getId(), obj.getNamespace()) for obj in objects]
+			
+		if not self.object:
+			if self.namespaces.selected_item:
 				self.objects.selected = 0
 				self.listEntrySelected()
+		else:
+			for i in range(0, len(self.objects.items)):
+				if self.objects.items[i].name != self.object.getId(): continue
+				if self.objects.items[i].namespace != self.object.getNamespace(): continue
+				
+				self.objects.selected = i
+				break
+				
+				
+		self.mainScrollArea.adaptLayout(False)
+		scrollY = (self.objects.real_font.getHeight() + 0) * self.objects.selected
+		self.mainScrollArea.real_widget.setVerticalScrollAmount(scrollY)
 
 	def listEntrySelected(self):
 		"""This function is used as callback for the TextList."""
@@ -308,10 +328,15 @@
 			callback = tools.callbackWithArguments(self.objectSelected, obj)	
 			icon = ObjectIcon(callback=callback, image=image, text=unicode(obj.getId()))
 			self.objects.addChild(icon)
+			if obj == self.object:
+				icon.selected = True
 			
-		if len(objects)>0:
-			objects[0].selected = True
-			self.objectSelected(objects[0])
+		if not self.object:
+			if len(objects) > 0:
+				self.objectSelected(objects[0])
+				
+		self.mainScrollArea.adaptLayout(False)
+		self.mainScrollArea.real_widget.setVerticalScrollAmount(self.objects.selected_item.y)
 
 
 	def objectSelected(self, obj):
@@ -321,18 +346,36 @@
 
 		self.setPreview(obj)
 		
-		self.gui.adaptLayout(False)
 		events.onObjectSelected.send(sender=self, object=obj)
 
-		self.objects.adaptLayout(False)
 		self.gui.adaptLayout(False)
 		
 	# Set preview image
 	def setPreview(self, object):
+		if not object: return
+		if self.object and object == self.object:
+			return
+			
+		self.object = object
+		self.scrollToObject(object)
 		self.preview.image = self._getImage(object)
 		height = self.preview.image.getHeight();
 		if height > 200: height = 200
 		self.preview.parent.max_height = height
+		
+	def scrollToObject(self, object):
+		# Select namespace
+		names = self.namespaces
+		if not names.selected_item: 
+			self.namespaces.selected = 0
+		
+		if names.selected_item != object.getNamespace():
+			for i in range(0, len(names.items)):
+				if names.items[i] == object.getNamespace():
+					self.namespaces.selected = i
+					break
+					
+		self.update()
 
 	def update_namespace(self):
 		
--- a/clients/editor/scripts/events/events.py	Fri Aug 21 14:39:54 2009 +0000
+++ b/clients/editor/scripts/events/events.py	Fri Aug 21 20:34:26 2009 +0000
@@ -16,6 +16,7 @@
 postMapShown = Signal(providing_args=["mapview"])
 onInstancesSelected = Signal(providing_args=["instances"])
 onObjectSelected = Signal(providing_args=["object"])
+onObjectsImported = Signal(providing_args=[])
 
 # Signals emitted by EventListener
 onQuit			= Signal(providing_args=[])
--- a/clients/editor/scripts/gui/filemanager.py	Fri Aug 21 14:39:54 2009 +0000
+++ b/clients/editor/scripts/gui/filemanager.py	Fri Aug 21 20:34:26 2009 +0000
@@ -8,6 +8,7 @@
 from action import Action, ActionGroup
 from input import InputDialog
 from selection import SelectionDialog, ClickSelectionDialog
+from scripts.events import events
 
 class FileManager(object):
 	def __init__(self):
@@ -176,6 +177,8 @@
 			errormsg += u"Error: "+unicode(sys.exc_info()[1])
 			ErrorDialog(errormsg)
 			return None
+		
+		events.onObjectsImported.send(sender=self)
 			
 	def importDir(self, path, filename=""):
 		if os.path.isdir(os.path.join(path, filename)):
@@ -199,6 +202,8 @@
 			errormsg += u"Error: "+unicode(sys.exc_info()[1])
 			ErrorDialog(errormsg)
 			return None
+			
+		events.onObjectsImported.send(sender=self)
 
 class CameraEditor(object):
 	"""