annotate clients/editor/scripts/gui/cameradialog.py @ 359:ad5818097cd6

* Some cleanups for Editor class to match new coding standards * Minor cleanups in imports
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 26 Sep 2009 10:38:24 +0000
parents 8b125ec749d7
children
rev   line source
355
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
1 # -*- coding: utf-8 -*-
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
2
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
3 # ####################################################################
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
5 # http://www.fifengine.de
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
6 # This file is part of FIFE.
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
7 #
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
8 # FIFE is free software; you can redistribute it and/or
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
10 # License as published by the Free Software Foundation; either
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
12 #
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
13 # This library is distributed in the hope that it will be useful,
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
16 # Lesser General Public License for more details.
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
17 #
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
19 # License along with this library; if not, write to the
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
20 # Free Software Foundation, Inc.,
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
22 # ####################################################################
8b125ec749d7 Started cleaning up the editor source code:
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 345
diff changeset
23
345
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 import fife
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 import pychan
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 class CameraDialog(object):
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 """
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 B{CameraDialog} provides a gui dialog for camera creation. The callback is called when camera creation is complete. A
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 partial specification of the camera parameters may optionally be given.
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 """
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 def __init__(self, engine, callback=None, onCancel=None, map=None, layer=None):
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 self.engine = engine
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 self.callback = callback
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 self.onCancel = onCancel
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self._widget = pychan.loadXML('gui/cameradialog.xml')
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 if map:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self._widget.distributeData({
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 'mapBox' : unicode(map.getId()),
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 })
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 if layer:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 self._widget.distributeData({
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 'layerBox' : unicode(layer.getId()),
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 })
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 self._widget.mapEvents({
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 'okButton' : self._finished,
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 'cancelButton' : self._cancelled
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 })
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self._widget.show()
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 def _cancelled(self):
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 if self.onCancel:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self.onCancel()
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 self._widget.hide()
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 def _finished(self):
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 id = self._widget.collectData('idBox')
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 if id == '':
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 print 'Please enter a camera id.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 try:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 except fife.Exception:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 print 'Cannot find the specified map id.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 try:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 layer = map.getLayer(str(self._widget.collectData('layerBox')))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 except fife.Exception:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 print 'Cannot find the specified layer id.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 try:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 vals = self._widget.collectData('viewBox').split(',')
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 if len(vals) != 4:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 raise ValueError
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 viewport = fife.Rect(*[int(c) for c in vals])
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 except ValueError:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 try:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 refh = int(self._widget.collectData('refhBox'))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 refw = int(self._widget.collectData('refwBox'))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 except ValueError:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 print 'Please enter positive integer values for reference width and height.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 try:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 rot = int(self._widget.collectData('rotBox'))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 tilt = int(self._widget.collectData('tiltBox'))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 except ValueError:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 print 'Please enter positive integer values for rotation and tilt.'
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 return
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 cam = self.engine.getView().addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0))
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 cam.setCellImageDimensions(refw, refh)
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 cam.setRotation(rot)
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 cam.setTilt(tilt)
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 self._widget.hide()
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 if self.callback:
e3efe2cde5a9 Forgot to add CameraDialog... oops!
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 self.callback()