Mercurial > fife-parpg
annotate clients/editor/plugins/LayerTool.py @ 321:7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 16 Aug 2009 21:35:15 +0000 |
parents | 62ec3b530cc6 |
children | 3853f8659598 |
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 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 """ An advanced layer tool for FIFedit """ |
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): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 """ The B{LayerTool} is an advanced method to view |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 and change layer informations. |
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 While the original FIFedit tool only allows to select |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 layers, this one will provide the following functionality: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 - toggle layer visibility |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 - select layer |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 - list layers |
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 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 def __init__(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 self._editor = None |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 self._enabled = False |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 self._mapview = None |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 self._showAction = None |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 self.subwrappers = [] |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
62 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
63 self._layer_wizard = None |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 #--- Plugin function ---# |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 def enable(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
67 """ """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 if self._enabled is True: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 return |
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 # Fifedit plugin data |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 self._editor = scripts.editor.getEditor() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 self._showAction = Action(u"LayerTool", checkable=True) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 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
|
75 self._editor._toolsMenu.addAction(self._showAction) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self.__create_gui() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 self.toggle() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 events.postMapShown.connect(self.update) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 def disable(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
84 """ """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 if self._enabled is False: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 return |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 self.container.setDocked(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 self.container.hide() |
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 events.postMapShown.disconnect(self.update) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self._editor._toolsMenu.removeAction(self._showAction) |
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 def isEnabled(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
95 """ """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 return self._enabled; |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 def getName(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
99 """ """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 return u"Layertool" |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 #--- End plugin functions ---# |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 def __create_gui(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 """ create the basic gui container """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 self.container = pychan.loadXML('gui/layertool.xml') |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 self.editLayerButton.capture(self.showEditDialog) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 self.update(None) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 def _adjust_position(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 """ 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
|
118 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
|
119 (new default position: left, beneath the tools window) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 self.container.position = (50, 200) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
123 def removeSelectedLayer(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
124 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
|
125 |
321
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
126 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
|
127 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
|
128 return |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
129 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
130 layer = self.getActiveLayer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
131 if not layer: return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
132 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
133 self.select_no_layer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
134 |
321
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
135 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
|
136 |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
137 # 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
|
138 # 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
|
139 for cam in self._editor.getEngine().getView().getCameras(): |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
140 if cam.getLocationRef().getMap().getId() == map.getId(): |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
141 if cam.getLocation().getLayer().getId() == layer.getId(): |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
142 for l in map.getLayers(): |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
143 if l.getId() == layer.getId(): continue |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
144 cam.getLocationRef().setLayer(l) |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
145 break |
7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
146 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
147 map.deleteLayer(layer) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
148 self.update(self._mapview) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
149 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
150 def showLayerWizard(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
151 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
|
152 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
153 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
|
154 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
|
155 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
156 def showEditDialog(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
157 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
|
158 layer = self.getActiveLayer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
159 if not layer: return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
160 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
161 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
|
162 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
|
163 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 def clear(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 """ remove all subwrappers """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 if self.subwrappers is []: return |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 for subwrapper in self.subwrappers: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 self.wrapper.removeChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 self.subwrappers = [] |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 def update(self, mapview): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 """ Dump new layer informations into the wrapper |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 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
|
177 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
|
178 for mouse actions |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 layers = [] |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
181 self._mapview = mapview |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 if self._mapview is not None: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 layers = self._mapview.getMap().getLayers() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 self.clear() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 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
|
188 if not self._mapview: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
189 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
|
190 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
191 layerid = "No layers" |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 subwrapper = pychan.widgets.HBox() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
194 layerLabel = pychan.widgets.Label() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
195 layerLabel.text = unicode(layerid) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
196 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
|
197 subwrapper.addChild(layerLabel) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 self.wrapper.addChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 self.subwrappers.append(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
203 if active_layer: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
204 active_layer = active_layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 for layer in reversed(layers): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 layerid = layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
207 subwrapper = pychan.widgets.HBox() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
209 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
|
210 toggleVisibleButton.name = "toggle_" + layerid |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
211 if layer.areInstancesVisible(): |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
212 toggleVisibleButton.toggled = True |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
213 toggleVisibleButton.capture(self.toggle_layer_visibility) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
215 layerLabel = pychan.widgets.Label() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
216 layerLabel.text = unicode(layerid) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
217 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
|
218 layerLabel.capture(self.select_active_layer,"mousePressed") |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 layerLabel.base_color = _HIGHLIGHT_BACKGROUND_COLOR |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
225 subwrapper.addChild(toggleVisibleButton) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
226 subwrapper.addChild(layerLabel) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 self.wrapper.addChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 self.subwrappers.append(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 |
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
|
231 self.container.adaptLayout(False) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
233 def toggle_layer_visibility(self, event, widget): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
234 """ Callback for ToggleButtons |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
235 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 Toggle the chosen layer visible / invisible |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
238 NOTE: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 - 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
|
240 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
241 @type event: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
242 @param event: pychan mouse event |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
243 @type widget: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
244 @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
|
245 """ |
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 layerid = widget.name[len(_LABEL_NAME_PREFIX):] |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
248 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
249 layer = self._mapview.getMap().getLayer(layerid) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
250 active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
251 if active_layer: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
252 active_layer = active_layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
253 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
254 if layer.areInstancesVisible(): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 layer.setInstancesVisible(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
256 else: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
257 layer.setInstancesVisible(True) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
258 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
259 if active_layer == layerid: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 self.select_no_layer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
261 |
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 def select_no_layer(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
264 """ Resets the current active layer (widget + editor) """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
265 previous_active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
266 if previous_active_layer is not None: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
267 previous_layer_id = previous_active_layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
268 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
|
269 previous_active_widget.background_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
270 previous_active_widget.foreground_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
271 previous_active_widget.base_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
272 previous_active_widget.text = unicode(previous_layer_id) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
273 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
274 self._mapview.getController().selectLayer(None) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
275 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
276 def getActiveLayer(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
277 """ Returns the active layer """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
278 if self._mapview: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
279 return self._mapview.getController()._layer |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
280 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
281 def select_active_layer(self, event, widget): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
282 """ callback for Labels |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
283 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
284 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
|
285 new active layer |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
286 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
287 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
|
288 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
289 @type event: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
290 @param event: pychan mouse event |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
291 @type widget: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
292 @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
|
293 """ |
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 self.select_no_layer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
296 |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
297 layerid = widget.name[len(_LABEL_NAME_PREFIX):] |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
298 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
299 widget.background_color = _HIGHLIGHT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
300 widget.foreground_color = _HIGHLIGHT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
301 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
|
302 self.container.adaptLayout(False) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
303 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
304 self._mapview.getController().selectLayer(layerid) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
305 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
306 def toggle(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
307 """ toggles the layertool visible / invisible and sets |
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
308 dock status |
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
309 """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
310 if self.container.isVisible() or self.container.isDocked(): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
311 self.container.setDocked(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
312 self.container.hide() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
313 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
314 self._showAction.setChecked(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
315 else: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
316 self.container.show() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
317 self._showAction.setChecked(True) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
318 self._adjust_position() |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
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 class LayerEditor(object): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
322 """ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
323 LayerEditor provides a gui dialog for creating and editing layers. |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
324 """ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
325 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
|
326 self.engine = engine |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
327 self.model = engine.getModel() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
328 self.map = map |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
329 self.layer = layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
330 self.callback = callback |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
331 self.onCancel = onCancel |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
332 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
|
333 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
334 # 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
|
335 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
|
336 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
337 # TODO: Ditto for pather? |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
338 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
|
339 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
340 if layer: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
341 cg = layer.getCellGrid() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
342 cgtype = 0 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
343 if cg.getType() == 'hex': |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
344 cgtype = 1 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
345 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
346 self._widget.distributeData({ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
347 "layerBox" : unicode(layer.getId()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
348 "xScaleBox" : unicode(cg.getXScale()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
349 "yScaleBox" : unicode(cg.getYScale()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
350 "rotBox" : unicode(cg.getRotation()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
351 "xOffsetBox" : unicode(cg.getXShift()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
352 "yOffsetBox" : unicode(cg.getYShift()) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
353 }) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
354 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
355 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
|
356 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
|
357 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
358 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
|
359 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
|
360 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
361 self._widget.mapEvents({ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
362 'okButton' : self._finished, |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
363 'cancelButton' : self._cancelled |
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 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
366 self._widget.show() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
367 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
368 def _cancelled(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
369 if self.onCancel: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
370 self.onCancel() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
371 self._widget.hide() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
372 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
373 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
374 def _finished(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
375 # Collect and validate data |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
376 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
|
377 if layerId == '': |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
378 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
|
379 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
380 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
381 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
382 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
|
383 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
|
384 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
385 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
|
386 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
387 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
388 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
389 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
|
390 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
|
391 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
392 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
|
393 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
394 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
395 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
396 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
|
397 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
398 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
|
399 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
400 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
401 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
|
402 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
|
403 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
404 if grid_type == 0: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
405 grid_type = "square" |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
406 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
407 grid_type = "hex" |
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 # Set up layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
410 layer = self.layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
411 cellgrid = None |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
412 if not self.layer: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
413 # 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
|
414 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
|
415 if not cellgrid: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
416 print "Invalid grid type" |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
417 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
418 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
419 cellgrid.setRotation(rotation) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
420 cellgrid.setXScale(x_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
421 cellgrid.setYScale(y_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
422 cellgrid.setXShift(x_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
423 cellgrid.setYShift(y_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
424 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
425 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
426 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
|
427 except: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
428 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
|
429 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
430 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
431 cellgrid = layer.getCellGrid() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
432 cellgrid.setRotation(rotation) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
433 cellgrid.setXScale(x_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
434 cellgrid.setYScale(y_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
435 cellgrid.setXShift(x_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
436 cellgrid.setYShift(y_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
437 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
438 layer.setPathingStrategy(pathing) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
439 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
440 # 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
|
441 self._widget.hide() |
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 if self.callback: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
444 self.callback() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
445 |