annotate clients/editor/plugins/LayerTool.py @ 322:3853f8659598

- small changes to code layout to make it more readable - minor fixes to docstrings
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 17 Aug 2009 08:16:30 +0000
parents 7ddec4ce99b3
children b64ce990abb1
rev   line source
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # coding: utf-8
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 # ###################################################
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # Copyright (C) 2008 The Zero-Projekt team
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 # http://zero-projekt.net
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # info@zero-projekt.net
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of Zero "Was vom Morgen blieb"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # The Zero-Projekt codebase is free software; you can redistribute it and/or modify
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # the Free Software Foundation; either version 2 of the License, or
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # (at your option) any later version.
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # GNU General Public License for more details.
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # along with this program; if not, write to the
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ###################################################
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
24 """ A layertool plugin for FIFedit """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 import fife
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 import scripts.plugin as plugin
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 import scripts.editor
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 from scripts.events import *
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 from scripts.gui.action import Action
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 import pychan
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 import pychan.widgets as widgets
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 from pychan.tools import callbackWithArguments as cbwa
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 # default should be pychan default, highlight can be choosen (format: r,g,b)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 _DEFAULT_BACKGROUND_COLOR = pychan.internal.DEFAULT_STYLE['default']['base_color']
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 _HIGHLIGHT_BACKGROUND_COLOR = pychan.internal.DEFAULT_STYLE['default']['selection_color']
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 # the dynamicly created widgets have the name scheme prefix + layerid
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 _LABEL_NAME_PREFIX = "select_"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 class LayerTool(plugin.Plugin):
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
43 """ The B{LayerTool} allows to select and show / hide layers of a loaded
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
44 map as well as creating new layers or edit layer properties
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 def __init__(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 self._editor = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 self._enabled = False
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 self._mapview = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 self._showAction = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self.subwrappers = []
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
54
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
55 self._layer_wizard = None
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 #--- Plugin function ---#
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 def enable(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
59 """ """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 if self._enabled is True:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 # Fifedit plugin data
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 self._editor = scripts.editor.getEditor()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 self._showAction = Action(u"LayerTool", checkable=True)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 scripts.gui.action.activated.connect(self.toggle, sender=self._showAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 self._editor._toolsMenu.addAction(self._showAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 self.__create_gui()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 self.toggle()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 events.postMapShown.connect(self.update)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 def disable(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
76 """ """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 if self._enabled is False:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self.container.setDocked(False)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 self.container.hide()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 events.postMapShown.disconnect(self.update)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 self._editor._toolsMenu.removeAction(self._showAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 def isEnabled(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
87 """ """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 return self._enabled;
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 def getName(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
91 """ """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 return u"Layertool"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 #--- End plugin functions ---#
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 def __create_gui(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 """ create the basic gui container """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 self.container = pychan.loadXML('gui/layertool.xml')
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 self.wrapper = self.container.findChild(name="layers_wrapper")
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
100 self.removeLayerButton = self.container.findChild(name="remove_layer_button")
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
101 self.createLayerButton = self.container.findChild(name="add_layer_button")
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
102 self.editLayerButton = self.container.findChild(name="edit_layer_button")
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
103 self.removeLayerButton.capture(self.removeSelectedLayer)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
104 self.createLayerButton.capture(self.showLayerWizard)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
105 self.editLayerButton.capture(self.showEditDialog)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 self.update(None)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 def _adjust_position(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 """ adjusts the position of the container - we don't want to
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 let the window appear at the center of the screen.
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 (new default position: left, beneath the tools window)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 self.container.position = (50, 200)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
115 def removeSelectedLayer(self):
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
116 """
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
117
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
118 """
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
119 if not self._mapview: return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
120
321
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
121 if self._mapview.getMap().getNumLayers() <= 1:
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
122 print "Can't remove the last layer"
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
123 return
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
124
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
125 layer = self.getActiveLayer()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
126 if not layer: return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
127
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
128 self.select_no_layer()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
129
321
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
130 map = self._mapview.getMap()
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
131
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
132 # FIFE will crash if we try to delete the layer which is in use by a camera
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
133 # so we will set the camera to another layer instead
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
134 for cam in self._editor.getEngine().getView().getCameras():
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
135 if cam.getLocationRef().getMap().getId() != map.getId():
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
136 continue
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
137
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
138 if cam.getLocation().getLayer().getId() != layer.getId():
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
139 continue
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
140
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
141 for l in map.getLayers():
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
142 if l.getId() == layer.getId():
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
143 continue
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
144
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
145 cam.getLocationRef().setLayer(l)
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
146 break
321
7ddec4ce99b3 Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 319
diff changeset
147
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
148 map.deleteLayer(layer)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
149 self.update(self._mapview)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
150
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
151 def showLayerWizard(self):
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
152 if not self._mapview: return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
153
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
154 if self._layer_wizard: self._layer_wizard._widget.hide()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
155 self._layer_wizard = LayerEditor(self._editor.getEngine(), self._mapview.getMap(), callback=cbwa(self.update, self._mapview))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
156
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
157 def showEditDialog(self):
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
158 if not self._mapview: return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
159 layer = self.getActiveLayer()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
160 if not layer: return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
161
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
162 if self._layer_wizard: self._layer_wizard._widget.hide()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
163 self._layer_wizard = LayerEditor(self._editor.getEngine(), self._mapview.getMap(), layer=layer, callback=cbwa(self.update, self._mapview))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
164
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 def clear(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 """ remove all subwrappers """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 if self.subwrappers is []: return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 for subwrapper in self.subwrappers:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 self.wrapper.removeChild(subwrapper)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 self.subwrappers = []
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 def update(self, mapview):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 """ Dump new layer informations into the wrapper
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 We group one ToggleButton and one Label into a HBox, the main wrapper
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 itself is a VBox and we also capture both the Button and the Label to listen
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 for mouse actions
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 layers = []
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 self._mapview = mapview
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 if self._mapview is not None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 layers = self._mapview.getMap().getLayers()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 self.clear()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 if len(layers) <= 0:
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
189 if not self._mapview:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
190 layerid = "No map is open"
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
191 else:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
192 layerid = "No layers"
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 subwrapper = pychan.widgets.HBox()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
195 layerLabel = pychan.widgets.Label()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
196 layerLabel.text = unicode(layerid)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
197 layerLabel.name = _LABEL_NAME_PREFIX + layerid
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
198 subwrapper.addChild(layerLabel)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 self.wrapper.addChild(subwrapper)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 self.subwrappers.append(subwrapper)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203 active_layer = self.getActiveLayer()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 if active_layer:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 active_layer = active_layer.getId()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 for layer in reversed(layers):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 layerid = layer.getId()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 subwrapper = pychan.widgets.HBox()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
210 toggleVisibleButton = pychan.widgets.ToggleButton(hexpand=0, up_image="gui/icons/is_visible.png", down_image="gui/icons/is_visible.png", hover_image="gui/icons/is_visible.png")
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
211 toggleVisibleButton.name = "toggle_" + layerid
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 if layer.areInstancesVisible():
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
213 toggleVisibleButton.toggled = True
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
214 toggleVisibleButton.capture(self.toggle_layer_visibility)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
216 layerLabel = pychan.widgets.Label()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
217 layerLabel.text = unicode(layerid)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
218 layerLabel.name = _LABEL_NAME_PREFIX + layerid
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
219 layerLabel.capture(self.select_active_layer,"mousePressed")
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 if active_layer == layerid:
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
222 layerLabel.background_color = _HIGHLIGHT_BACKGROUND_COLOR
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
223 layerLabel.foreground_color = _HIGHLIGHT_BACKGROUND_COLOR
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
224 layerLabel.base_color = _HIGHLIGHT_BACKGROUND_COLOR
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
226 subwrapper.addChild(toggleVisibleButton)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
227 subwrapper.addChild(layerLabel)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 self.wrapper.addChild(subwrapper)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 self.subwrappers.append(subwrapper)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231
316
6add14ebe9f5 Disabled recursing for some adaptLayout calls. This will make the editor more responsive
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 303
diff changeset
232 self.container.adaptLayout(False)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 def toggle_layer_visibility(self, event, widget):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 """ Callback for ToggleButtons
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
237 Toggle the chosen layer visible / invisible
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 NOTE:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240 - if a layer is set to invisible, it also shouldn't be the active layer anymore
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
242 @type event: object
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243 @param event: pychan mouse event
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244 @type widget: object
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 @param widget: the pychan widget where the event occurs, transports the layer id in it's name
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
246 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 layerid = widget.name[len(_LABEL_NAME_PREFIX):]
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
249
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250 layer = self._mapview.getMap().getLayer(layerid)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 active_layer = self.getActiveLayer()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 if active_layer:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253 active_layer = active_layer.getId()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255 if layer.areInstancesVisible():
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 layer.setInstancesVisible(False)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257 else:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 layer.setInstancesVisible(True)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
259
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 if active_layer == layerid:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 self.select_no_layer()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 def select_no_layer(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
265 """ Resets the current active layer (widget + editor) """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266 previous_active_layer = self.getActiveLayer()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 if previous_active_layer is not None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 previous_layer_id = previous_active_layer.getId()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 previous_active_widget = self.container.findChild(name=_LABEL_NAME_PREFIX + previous_layer_id)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270 previous_active_widget.background_color = _DEFAULT_BACKGROUND_COLOR
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 previous_active_widget.foreground_color = _DEFAULT_BACKGROUND_COLOR
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 previous_active_widget.base_color = _DEFAULT_BACKGROUND_COLOR
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 previous_active_widget.text = unicode(previous_layer_id)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275 self._mapview.getController().selectLayer(None)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 def getActiveLayer(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278 """ Returns the active layer """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
279 if self._mapview:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
280 return self._mapview.getController()._layer
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
281
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
282 def select_active_layer(self, event, widget):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
283 """ callback for Labels
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
284
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
285 We hand the layerid over to the mapeditor module to select a
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
286 new active layer
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288 Additionally, we mark the active layer widget (changing base color) and reseting the previous one
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
289
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
290 @type event: object
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 @param event: pychan mouse event
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292 @type widget: object
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
293 @param widget: the pychan widget where the event occurs, transports the layer id in it's name
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
294 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
295
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
296 self.select_no_layer()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
297
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
298 layerid = widget.name[len(_LABEL_NAME_PREFIX):]
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
299
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
300 widget.background_color = _HIGHLIGHT_BACKGROUND_COLOR
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
301 widget.foreground_color = _HIGHLIGHT_BACKGROUND_COLOR
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
302 widget.base_color = _HIGHLIGHT_BACKGROUND_COLOR
316
6add14ebe9f5 Disabled recursing for some adaptLayout calls. This will make the editor more responsive
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 303
diff changeset
303 self.container.adaptLayout(False)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
304
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
305 self._mapview.getController().selectLayer(layerid)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
306
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
307 def toggle(self):
303
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
308 """ toggles the layertool visible / invisible and sets
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
309 dock status
a33576d94f32 - eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 298
diff changeset
310 """
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
311 if self.container.isVisible() or self.container.isDocked():
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
312 self.container.setDocked(False)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
313 self.container.hide()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
314
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
315 self._showAction.setChecked(False)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
316 else:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
317 self.container.show()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
318 self._showAction.setChecked(True)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
319 self._adjust_position()
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
320
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
321
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
322 class LayerEditor(object):
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
323 """ The B{LayerEditor} provides a gui dialog for creating and editing layers.
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
324
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
325 FIXME:
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
326 - gridtypes can only be square for now
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
327 - pathing strategy
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
328 """
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
329 def __init__(self, engine, map, callback=None, onCancel=None, layer=None):
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
330 self.engine = engine
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
331 self.model = engine.getModel()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
332 self.map = map
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
333 self.layer = layer
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
334 self.callback = callback
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
335 self.onCancel = onCancel
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
336 self._widget = pychan.loadXML('gui/layereditor.xml')
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
337
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
338 # TODO: Add access method for adopted grid types?
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
339 self._widget.findChild(name="gridBox").items = ['square']#, 'hex'] # Hex does not work?
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
340
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
341 # TODO: Ditto for pather?
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
342 self._widget.findChild(name="pathingBox").items = ['cell_edges_only', 'cell_edges_and_diagonals', 'freeform']
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
343
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
344 if layer:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
345 cg = layer.getCellGrid()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
346 cgtype = 0
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
347 if cg.getType() == 'hex':
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
348 cgtype = 1
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
349
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
350 self._widget.distributeData({
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
351 "layerBox" : unicode(layer.getId()),
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
352 "xScaleBox" : unicode(cg.getXScale()),
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
353 "yScaleBox" : unicode(cg.getYScale()),
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
354 "rotBox" : unicode(cg.getRotation()),
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
355 "xOffsetBox" : unicode(cg.getXShift()),
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
356 "yOffsetBox" : unicode(cg.getYShift())
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
357 })
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
358
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
359 self._widget.findChild(name="pathingBox").selected = int(layer.getPathingStrategy())
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
360 self._widget.findChild(name="gridBox").selected = int(cgtype)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
361 else:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
362 self._widget.findChild(name="pathingBox").selected = 0
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
363 self._widget.findChild(name="gridBox").selected = 0
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
364
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
365 self._widget.mapEvents({
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
366 'okButton' : self._finished,
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
367 'cancelButton' : self._cancelled
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
368 })
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
369
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
370 self._widget.show()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
371
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
372 def _cancelled(self):
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
373 """ """
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
374 if self.onCancel:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
375 self.onCancel()
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
376 self._widget.hide()
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
377
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
378 def _finished(self):
322
3853f8659598 - small changes to code layout to make it more readable
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 321
diff changeset
379 """ """
319
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
380 # Collect and validate data
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
381 layerId = self._widget.collectData('layerBox')
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
382 if layerId == '':
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
383 print 'Please enter a layer id.'
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
384 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
385
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
386 try:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
387 x_offset = float(self._widget.collectData('xOffsetBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
388 y_offset = float(self._widget.collectData('yOffsetBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
389 except ValueError:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
390 print 'Please enter integer or decimal values for offset.'
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
391 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
392
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
393 try:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
394 x_scale = float(self._widget.collectData('xScaleBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
395 y_scale = float(self._widget.collectData('yScaleBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
396 except ValueError:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
397 print 'Please enter integer or decimal values for scale.'
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
398 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
399
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
400 try:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
401 rotation = float(self._widget.collectData('rotBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
402 except ValueError:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
403 print 'Please enter integer or decimal value for rotation.'
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
404 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
405
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
406 grid_type = int(self._widget.collectData('gridBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
407 pathing = int(self._widget.collectData('pathingBox'))
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
408
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
409 if grid_type == 0:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
410 grid_type = "square"
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
411 else:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
412 grid_type = "hex"
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
413
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
414 # Set up layer
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
415 layer = self.layer
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
416 cellgrid = None
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
417 if not self.layer:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
418 # TODO: FIFE currently does not support setting layer ID and cellgrid after the layer has been created
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
419 cellgrid = self.model.getCellGrid(grid_type)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
420 if not cellgrid:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
421 print "Invalid grid type"
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
422 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
423
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
424 cellgrid.setRotation(rotation)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
425 cellgrid.setXScale(x_scale)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
426 cellgrid.setYScale(y_scale)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
427 cellgrid.setXShift(x_offset)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
428 cellgrid.setYShift(y_offset)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
429
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
430 try:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
431 layer = self.map.createLayer(str(layerId), cellgrid)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
432 except:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
433 print 'The layer ' + str(layerId) + ' already exists!'
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
434 return
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
435 else:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
436 cellgrid = layer.getCellGrid()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
437 cellgrid.setRotation(rotation)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
438 cellgrid.setXScale(x_scale)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
439 cellgrid.setYScale(y_scale)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
440 cellgrid.setXShift(x_offset)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
441 cellgrid.setYShift(y_offset)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
442
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
443 layer.setPathingStrategy(pathing)
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
444
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
445 # Hide dialog and call back
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
446 self._widget.hide()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
447
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
448 if self.callback:
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
449 self.callback()
62ec3b530cc6 * Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 316
diff changeset
450