Mercurial > fife-parpg
comparison tools/editor/scripts/gui/cameradialog.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | 9d94f4676d17 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 from fife import fife | |
25 from fife.extensions import pychan | |
26 | |
27 class CameraDialog(object): | |
28 """ | |
29 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 """ | |
32 def __init__(self, engine, callback=None, onCancel=None, map=None, layer=None): | |
33 self.engine = engine | |
34 self.callback = callback | |
35 self.onCancel = onCancel | |
36 self._widget = pychan.loadXML('gui/cameradialog.xml') | |
37 | |
38 if map: | |
39 self._widget.distributeData({ | |
40 'mapBox' : unicode(map.getId()), | |
41 }) | |
42 | |
43 if layer: | |
44 self._widget.distributeData({ | |
45 'layerBox' : unicode(layer.getId()), | |
46 }) | |
47 | |
48 self._widget.mapEvents({ | |
49 'okButton' : self._finished, | |
50 'cancelButton' : self._cancelled | |
51 }) | |
52 | |
53 self._widget.show() | |
54 | |
55 def _cancelled(self): | |
56 if self.onCancel: | |
57 self.onCancel() | |
58 self._widget.hide() | |
59 | |
60 | |
61 def _finished(self): | |
62 id = self._widget.collectData('idBox') | |
63 if id == '': | |
64 print 'Please enter a camera id.' | |
65 return | |
66 | |
67 try: | |
68 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox'))) | |
69 except fife.Exception: | |
70 print 'Cannot find the specified map id.' | |
71 return | |
72 | |
73 try: | |
74 layer = map.getLayer(str(self._widget.collectData('layerBox'))) | |
75 except fife.Exception: | |
76 print 'Cannot find the specified layer id.' | |
77 return | |
78 | |
79 try: | |
80 vals = self._widget.collectData('viewBox').split(',') | |
81 if len(vals) != 4: | |
82 raise ValueError | |
83 | |
84 viewport = fife.Rect(*[int(c) for c in vals]) | |
85 except ValueError: | |
86 print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.' | |
87 return | |
88 | |
89 try: | |
90 refh = int(self._widget.collectData('refhBox')) | |
91 refw = int(self._widget.collectData('refwBox')) | |
92 except ValueError: | |
93 print 'Please enter positive integer values for reference width and height.' | |
94 return | |
95 | |
96 try: | |
97 rot = int(self._widget.collectData('rotBox')) | |
98 tilt = int(self._widget.collectData('tiltBox')) | |
99 except ValueError: | |
100 print 'Please enter positive integer values for rotation and tilt.' | |
101 return | |
102 | |
103 cam = self.engine.getView().addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0)) | |
104 cam.setCellImageDimensions(refw, refh) | |
105 cam.setRotation(rot) | |
106 cam.setTilt(tilt) | |
107 | |
108 self._widget.hide() | |
109 | |
110 if self.callback: | |
111 self.callback() |