comparison tools/editor/scripts/gui/cameradialog.py @ 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 0e0a30f0eb20
comparison
equal deleted inserted replaced
561:85e8986e7b8f 562:e34b44afd428
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # #################################################################### 22 # ####################################################################
23 23
24 from fife import fife 24 from fife import fife
25 from fife.extensions import pychan 25 from fife.extensions import pychan
26 from fife.extensions.pychan import dialogs
26 27
27 class CameraDialog(object): 28 class CameraDialog(object):
28 """ 29 """
29 B{CameraDialog} provides a gui dialog for camera creation. The callback is called when camera creation is complete. A 30 B{CameraDialog} provides a gui dialog for camera creation. The callback is called when camera creation is complete. A
30 partial specification of the camera parameters may optionally be given. 31 partial specification of the camera parameters may optionally be given.
59 60
60 61
61 def _finished(self): 62 def _finished(self):
62 id = self._widget.collectData('idBox') 63 id = self._widget.collectData('idBox')
63 if id == '': 64 if id == '':
64 print 'Please enter a camera id.' 65 dialogs.message(message=unicode("Please enter a camera ID."), caption=unicode("Error"))
65 return 66 return
66 67
67 try: 68 try:
68 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox'))) 69 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
69 except fife.Exception: 70 except fife.Exception:
70 print 'Cannot find the specified map id.' 71 dialogs.message(message=unicode("Cannot find the specified map id."), caption=unicode("Error"))
71 return 72 return
72 73
73 try: 74 try:
74 layer = map.getLayer(str(self._widget.collectData('layerBox'))) 75 layer = map.getLayer(str(self._widget.collectData('layerBox')))
75 except fife.Exception: 76 except fife.Exception:
76 print 'Cannot find the specified layer id.' 77 dialogs.message(message=unicode("Cannot find the specified layer id."), caption=unicode("Error"))
77 return 78 return
78 79
79 try: 80 try:
80 vals = self._widget.collectData('viewBox').split(',') 81 vals = self._widget.collectData('viewBox').split(',')
81 if len(vals) != 4: 82 if len(vals) != 4:
82 raise ValueError 83 raise ValueError
83 84
84 viewport = fife.Rect(*[int(c) for c in vals]) 85 viewport = fife.Rect(*[int(c) for c in vals])
85 except ValueError: 86 except ValueError:
86 print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.' 87 dialogs.message(message=unicode("Please enter 4 comma (,) delimited values for viewport x,y,width,height."), caption=unicode("Error"))
87 return 88 return
88 89
89 try: 90 try:
90 refh = int(self._widget.collectData('refhBox')) 91 refh = int(self._widget.collectData('refhBox'))
91 refw = int(self._widget.collectData('refwBox')) 92 refw = int(self._widget.collectData('refwBox'))
92 except ValueError: 93 except ValueError:
93 print 'Please enter positive integer values for reference width and height.' 94 dialogs.message(message=unicode("Please enter positive integer values for reference width and height."), caption=unicode("Error"))
94 return 95 return
95 96
96 try: 97 try:
97 rot = int(self._widget.collectData('rotBox')) 98 rot = int(self._widget.collectData('rotBox'))
98 tilt = int(self._widget.collectData('tiltBox')) 99 tilt = int(self._widget.collectData('tiltBox'))
99 except ValueError: 100 except ValueError:
100 print 'Please enter positive integer values for rotation and tilt.' 101 dialogs.message(message=unicode("Please enter positive integer values for rotation and tilt."), caption=unicode("Error"))
102
101 return 103 return
102 104
103 cam = map.addCamera(str(id), layer, viewport) 105 cam = map.addCamera(str(id), layer, viewport)
104 cam.setCellImageDimensions(refw, refh) 106 cam.setCellImageDimensions(refw, refh)
105 cam.setRotation(rot) 107 cam.setRotation(rot)