changeset 562:e34b44afd428

Fixed the built in pychan dialogs as they didin't work at all. Updated the editor to support modal execution and now use the pychan dialog message boxes for displaying some error messages.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 24 Jun 2010 19:58:59 +0000
parents 85e8986e7b8f
children f85762e634c5
files engine/python/fife/extensions/pychan/dialogs.py tools/editor/scripts/editor.py tools/editor/scripts/gui/cameradialog.py tools/editor/scripts/gui/layerdialog.py tools/editor/settings-dist.xml
diffstat 5 files changed, 42 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/engine/python/fife/extensions/pychan/dialogs.py	Thu Jun 24 18:40:30 2010 +0000
+++ b/engine/python/fife/extensions/pychan/dialogs.py	Thu Jun 24 19:58:59 2010 +0000
@@ -42,7 +42,7 @@
 		self.data= data
 		self.max_size=None
 		self.min_size=None
-		self.gui.capture(print_event,"mouseEntered")
+#		self.gui.capture(print_event,"mouseEntered")
 
 	def execute(self):
 		self.gui.distributeInitialData(self.initial_data)
@@ -87,7 +87,7 @@
 MESSAGE_BOX_XML = """\
 <Window name="window" title="Message">
 <ScrollArea>
-<Label wrap_text="1" text="$MESSAGE" name="message" vexpanding="1"/>
+<Label wrap_text="1" text="$MESSAGE" name="message" vexpand="1"/>
 </ScrollArea>
 <HBox>
 <Spacer/><Button min_size="50,0" name="okButton" text="OK"/>
@@ -98,7 +98,7 @@
 YESNO_BOX_XML = """\
 <Window name="window" title="Question">
 <ScrollArea>
-<Label wrap_text="1" text="$MESSAGE" name="message" vexpanding="1"/>
+<Label wrap_text="1" text="$MESSAGE" name="message" vexpand="1"/>
 </ScrollArea>
 <HBox>
 <Spacer/>
@@ -111,7 +111,7 @@
 YESNOCANCEL_BOX_XML = """\
 <Window name="window" title="Question">
 <ScrollArea>
-<Label wrap_text="1" text="$MESSAGE" name="message" vexpanding="1"/>
+<Label wrap_text="1" text="$MESSAGE" name="message" vexpand="1"/>
 </ScrollArea>
 <HBox>
 <Spacer/>
@@ -163,32 +163,39 @@
 
 def message(message="",caption="Message"):
 	text = _make_text(message)
-	dialog = XMLDialog(StringIO(MESSAGE_BOX_XML),
-		initial_data={'message':text,'window':caption})
+	dialog = XMLDialog(StringIO(MESSAGE_BOX_XML))
 	dialog.gui.findChild(name="message").max_width = screen_width()/2 - 50
+	dialog.gui.findChild(name="message").text = text
+	dialog.gui.findChild(name="window").title = caption
+
 	dialog.execute()
 
 def yesNo(message="",caption="Message"):
 	text = _make_text(message)
-	dialog = XMLDialog(StringIO(YESNO_BOX_XML),
-		initial_data={'message':text,'window':caption})
+	dialog = XMLDialog(StringIO(YESNO_BOX_XML))
 	dialog.gui.findChild(name="message").max_width = screen_width()/2 - 50
+	dialog.gui.findChild(name="message").text = text
+	dialog.gui.findChild(name="window").title = caption
+
 	return dialog.execute()
 
 def yesNoCancel(message="",caption="Message"):
 	text = _make_text(message)
-	dialog = XMLDialog(StringIO(YESNOCANCEL_BOX_XML),
-		initial_data={'message':text,'window':caption})
+	dialog = XMLDialog(StringIO(YESNOCANCEL_BOX_XML))
 	dialog.gui.findChild(name="message").max_width = screen_width()/2 - 50
+	dialog.gui.findChild(name="message").text = text
+	dialog.gui.findChild(name="window").title = caption
+
 	return dialog.execute()
 
 def select(message="",options=[],caption="Message"):
 	text = _make_text(message)
-	dialog = XMLDialog(StringIO(SELECT_BOX_XML),
-		initial_data={'message':text,'window':caption})
+	dialog = XMLDialog(StringIO(SELECT_BOX_XML))
 	dialog.size = screen_width()/3, 2*screen_height()/3
-
 	dialog.gui.findChild(name="message").max_width = screen_width()/2 - 50
+	dialog.gui.findChild(name="message").text = text
+	dialog.gui.findChild(name="window").title = caption
+	
 	listbox = dialog.gui.findChild(name="selection")
 	listbox.items = options
 	if dialog.execute():
@@ -202,9 +209,10 @@
 			return pychan.tools.applyOnlySuitable(f,*args,**kwargs)
 
 		except Exception, e:
-			dialog = XMLDialog(StringIO(EXCEPTION_CATCHER_XML),
-			  initial_data={'message':str(e)}
-			)
+			dialog = XMLDialog(StringIO(EXCEPTION_CATCHER_XML))
+			
+			dialog.gui.findChild(name="message").text = str(e)
+			
 			tb = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
 			dialog.gui.findChild(name="traceback").text = "".join(tb)
 			dialog.min_size = screen_width()/2,3*screen_height()/4
--- a/tools/editor/scripts/editor.py	Thu Jun 24 18:40:30 2010 +0000
+++ b/tools/editor/scripts/editor.py	Thu Jun 24 19:58:59 2010 +0000
@@ -105,6 +105,8 @@
 		MainWindow.__init__(self, *args, **kwargs)
 		pychan.init(self.engine, debug=False)
 		
+		pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop)
+		
 	def _initTools(self):
 		""" Initializes tools """
 		self._pluginmanager = plugin.PluginManager(self.getSettings())
--- a/tools/editor/scripts/gui/cameradialog.py	Thu Jun 24 18:40:30 2010 +0000
+++ b/tools/editor/scripts/gui/cameradialog.py	Thu Jun 24 19:58:59 2010 +0000
@@ -23,6 +23,7 @@
 
 from fife import fife
 from fife.extensions import pychan
+from fife.extensions.pychan import dialogs
 
 class CameraDialog(object):
 	"""
@@ -61,19 +62,19 @@
 	def _finished(self):
 		id = self._widget.collectData('idBox')
 		if id == '':
-			print 'Please enter a camera id.'
+			dialogs.message(message=unicode("Please enter a camera ID."), caption=unicode("Error"))
 			return
 
 		try:
 			map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
 		except fife.Exception:
-			print 'Cannot find the specified map id.'
+			dialogs.message(message=unicode("Cannot find the specified map id."), caption=unicode("Error"))
 			return
 
 		try:
 			layer = map.getLayer(str(self._widget.collectData('layerBox')))
 		except fife.Exception:
-			print 'Cannot find the specified layer id.'	
+			dialogs.message(message=unicode("Cannot find the specified layer id."), caption=unicode("Error"))
 			return
 
 		try:
@@ -83,21 +84,22 @@
 
 			viewport = fife.Rect(*[int(c) for c in vals])
 		except ValueError:
-			print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.'
+			dialogs.message(message=unicode("Please enter 4 comma (,) delimited values for viewport x,y,width,height."), caption=unicode("Error"))
 			return
 
 		try:
 			refh = int(self._widget.collectData('refhBox'))
 			refw = int(self._widget.collectData('refwBox'))
 		except ValueError:
-			print 'Please enter positive integer values for reference width and height.'
+			dialogs.message(message=unicode("Please enter positive integer values for reference width and height."), caption=unicode("Error"))
 			return
 
 		try:
 			rot = int(self._widget.collectData('rotBox'))
 			tilt = int(self._widget.collectData('tiltBox'))
 		except ValueError:
-			print 'Please enter positive integer values for rotation and tilt.'
+			dialogs.message(message=unicode("Please enter positive integer values for rotation and tilt."), caption=unicode("Error"))
+
 			return
 
 		cam = map.addCamera(str(id), layer, viewport)
--- a/tools/editor/scripts/gui/layerdialog.py	Thu Jun 24 18:40:30 2010 +0000
+++ b/tools/editor/scripts/gui/layerdialog.py	Thu Jun 24 19:58:59 2010 +0000
@@ -23,6 +23,7 @@
 
 from fife import fife
 from fife.extensions import pychan
+from fife.extensions.pychan import dialogs
 
 class LayerDialog(object):
 	""" The B{LayerDialog} provides a gui dialog for creating and editing layers.
@@ -86,33 +87,33 @@
 		# Collect and validate data
 		layerId = self._widget.collectData('layerBox')
 		if layerId == '':
-			print 'Please enter a layer id.'
+			dialogs.message(message=unicode("Please enter a layer id."), caption=unicode("Error"))
 			return
 			
 		try:
 			x_offset = float(self._widget.collectData('xOffsetBox'))
 			y_offset = float(self._widget.collectData('yOffsetBox'))
 		except ValueError:
-			print 'Please enter integer or decimal values for offset.'
+			dialogs.message(message=unicode("Please enter integer or decimal values for offset."), caption=unicode("Error"))
 			return
 
 		try:
 			x_scale = float(self._widget.collectData('xScaleBox'))
 			y_scale = float(self._widget.collectData('yScaleBox'))
 		except ValueError:
-			print 'Please enter integer or decimal values for scale.'
+			dialogs.message(message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error"))
 			return
 
 		try:
 			rotation = float(self._widget.collectData('rotBox'))
 		except ValueError:
-			print 'Please enter integer or decimal value for rotation.'
+			dialogs.message(message=unicode("Please enter integer or decimal value for rotation."), caption=unicode("Error"))
 			return
 			
 		try:
 			transparency = int(self._widget.collectData('transBox'))
 		except ValueError:
-			print 'Please enter an integer value in the range of 0-255 for transparency.'
+			dialogs.message(message=unicode("Please enter an integer value in the range of 0-255 for transparency."), caption=unicode("Error"))
 			return
 			
 		
@@ -170,4 +171,4 @@
 		self._widget.hide()
 		
 		if self.callback:
-			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
\ No newline at end of file
+			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
--- a/tools/editor/settings-dist.xml	Thu Jun 24 18:40:30 2010 +0000
+++ b/tools/editor/settings-dist.xml	Thu Jun 24 19:58:59 2010 +0000
@@ -22,6 +22,7 @@
 	<Module name="Plugins">
 		<Setting name="HistoryManager" type="bool">True</Setting>
 		<Setting name="LayerTool" type="bool">True</Setting>
+		<Setting name="CameraEdit" type="bool">True</Setting>
 		<Setting name="ObjectEdit" type="bool">True</Setting>
 		<Setting name="ObjectSelector" type="bool">True</Setting>
 	</Module>