Mercurial > fife-parpg
annotate clients/editor/plugins/LayerTool.py @ 319:62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
* Removed an unused variable from XMLMapLoader
* Happy birthday Barra! =D
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 16 Aug 2009 20:29:12 +0000 |
parents | 6add14ebe9f5 |
children | 7ddec4ce99b3 |
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 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
126 layer = self.getActiveLayer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
127 if not layer: return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
128 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
129 self.select_no_layer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
130 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
131 map = self._mapview.getMap() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
132 map.deleteLayer(layer) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
133 self.update(self._mapview) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
134 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
135 def showLayerWizard(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
136 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
|
137 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
138 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
|
139 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
|
140 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
141 def showEditDialog(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
142 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
|
143 layer = self.getActiveLayer() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
144 if not layer: return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
145 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
146 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
|
147 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
|
148 |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 def clear(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 """ remove all subwrappers """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 if self.subwrappers is []: return |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 for subwrapper in self.subwrappers: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 self.wrapper.removeChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 self.subwrappers = [] |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 def update(self, mapview): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 """ Dump new layer informations into the wrapper |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 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
|
162 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
|
163 for mouse actions |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 layers = [] |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 self._mapview = mapview |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 if self._mapview is not None: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 layers = self._mapview.getMap().getLayers() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 self.clear() |
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 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
|
173 if not self._mapview: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
174 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
|
175 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
176 layerid = "No layers" |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 subwrapper = pychan.widgets.HBox() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
179 layerLabel = pychan.widgets.Label() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
180 layerLabel.text = unicode(layerid) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
181 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
|
182 subwrapper.addChild(layerLabel) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 self.wrapper.addChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 self.subwrappers.append(subwrapper) |
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 active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 if active_layer: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 active_layer = active_layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 for layer in reversed(layers): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 layerid = layer.getId() |
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 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
|
195 toggleVisibleButton.name = "toggle_" + layerid |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 if layer.areInstancesVisible(): |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
197 toggleVisibleButton.toggled = True |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
198 toggleVisibleButton.capture(self.toggle_layer_visibility) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
200 layerLabel = pychan.widgets.Label() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
201 layerLabel.text = unicode(layerid) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
202 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
|
203 layerLabel.capture(self.select_active_layer,"mousePressed") |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
204 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 layerLabel.base_color = _HIGHLIGHT_BACKGROUND_COLOR |
255
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 subwrapper.addChild(toggleVisibleButton) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
211 subwrapper.addChild(layerLabel) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
213 self.wrapper.addChild(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 self.subwrappers.append(subwrapper) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
215 |
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
|
216 self.container.adaptLayout(False) |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 def toggle_layer_visibility(self, event, widget): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 """ Callback for ToggleButtons |
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 Toggle the chosen layer visible / invisible |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 NOTE: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 - 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
|
225 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 @type event: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 @param event: pychan mouse event |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 @type widget: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 @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
|
230 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 layerid = widget.name[len(_LABEL_NAME_PREFIX):] |
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 layer = self._mapview.getMap().getLayer(layerid) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
235 active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 if active_layer: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 active_layer = active_layer.getId() |
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 if layer.areInstancesVisible(): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 layer.setInstancesVisible(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
241 else: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
242 layer.setInstancesVisible(True) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
243 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
244 if active_layer == layerid: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
245 self.select_no_layer() |
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 def select_no_layer(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
249 """ Resets the current active layer (widget + editor) """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
250 previous_active_layer = self.getActiveLayer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
251 if previous_active_layer is not None: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
252 previous_layer_id = previous_active_layer.getId() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
253 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
|
254 previous_active_widget.background_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 previous_active_widget.foreground_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
256 previous_active_widget.base_color = _DEFAULT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
257 previous_active_widget.text = unicode(previous_layer_id) |
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 self._mapview.getController().selectLayer(None) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
261 def getActiveLayer(self): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
262 """ Returns the active layer """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
263 if self._mapview: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
264 return self._mapview.getController()._layer |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
265 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
266 def select_active_layer(self, event, widget): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
267 """ callback for Labels |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
268 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
269 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
|
270 new active layer |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
271 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
272 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
|
273 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
274 @type event: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
275 @param event: pychan mouse event |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
276 @type widget: object |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
277 @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
|
278 """ |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
279 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
280 self.select_no_layer() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
281 |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
282 layerid = widget.name[len(_LABEL_NAME_PREFIX):] |
255
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 widget.background_color = _HIGHLIGHT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
285 widget.foreground_color = _HIGHLIGHT_BACKGROUND_COLOR |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
286 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
|
287 self.container.adaptLayout(False) |
255
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 self._mapview.getController().selectLayer(layerid) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
290 |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
291 def toggle(self): |
303
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
292 """ toggles the layertool visible / invisible and sets |
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
293 dock status |
a33576d94f32
- eliminated magic number
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
298
diff
changeset
|
294 """ |
255
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
295 if self.container.isVisible() or self.container.isDocked(): |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
296 self.container.setDocked(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
297 self.container.hide() |
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 self._showAction.setChecked(False) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
300 else: |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
301 self.container.show() |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
302 self._showAction.setChecked(True) |
51cc05d862f2
Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
303 self._adjust_position() |
319
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
304 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
305 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
306 class LayerEditor(object): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
307 """ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
308 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
|
309 """ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
310 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
|
311 self.engine = engine |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
312 self.model = engine.getModel() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
313 self.map = map |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
314 self.layer = layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
315 self.callback = callback |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
316 self.onCancel = onCancel |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
317 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
|
318 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
319 # 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
|
320 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
|
321 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
322 # TODO: Ditto for pather? |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
323 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
|
324 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
325 if layer: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
326 cg = layer.getCellGrid() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
327 cgtype = 0 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
328 if cg.getType() == 'hex': |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
329 cgtype = 1 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
330 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
331 self._widget.distributeData({ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
332 "layerBox" : unicode(layer.getId()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
333 "xScaleBox" : unicode(cg.getXScale()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
334 "yScaleBox" : unicode(cg.getYScale()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
335 "rotBox" : unicode(cg.getRotation()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
336 "xOffsetBox" : unicode(cg.getXShift()), |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
337 "yOffsetBox" : unicode(cg.getYShift()) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
338 }) |
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 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
|
341 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
|
342 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
343 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
|
344 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
|
345 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
346 self._widget.mapEvents({ |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
347 'okButton' : self._finished, |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
348 'cancelButton' : self._cancelled |
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 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
351 self._widget.show() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
352 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
353 def _cancelled(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
354 if self.onCancel: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
355 self.onCancel() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
356 self._widget.hide() |
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 def _finished(self): |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
360 # Collect and validate data |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
361 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
|
362 if layerId == '': |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
363 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
|
364 return |
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 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
367 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
|
368 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
|
369 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
370 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
|
371 return |
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 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
374 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
|
375 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
|
376 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
377 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
|
378 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
379 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
380 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
381 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
|
382 except ValueError: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
383 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
|
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 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
|
387 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
|
388 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
389 if grid_type == 0: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
390 grid_type = "square" |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
391 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
392 grid_type = "hex" |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
393 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
394 # Set up layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
395 layer = self.layer |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
396 cellgrid = None |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
397 if not self.layer: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
398 # 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
|
399 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
|
400 if not cellgrid: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
401 print "Invalid grid type" |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
402 return |
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 cellgrid.setRotation(rotation) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
405 cellgrid.setXScale(x_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
406 cellgrid.setYScale(y_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
407 cellgrid.setXShift(x_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
408 cellgrid.setYShift(y_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
409 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
410 try: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
411 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
|
412 except: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
413 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
|
414 return |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
415 else: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
416 cellgrid = layer.getCellGrid() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
417 cellgrid.setRotation(rotation) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
418 cellgrid.setXScale(x_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
419 cellgrid.setYScale(y_scale) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
420 cellgrid.setXShift(x_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
421 cellgrid.setYShift(y_offset) |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
422 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
423 layer.setPathingStrategy(pathing) |
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 # 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
|
426 self._widget.hide() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
427 |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
428 if self.callback: |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
429 self.callback() |
62ec3b530cc6
* Improved layertool: Ability to add, remove and edit layers
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
316
diff
changeset
|
430 |