comparison clients/editor/plugins/layertool.py @ 182:bcc93e17f978

- added new plugin to FIFedit (Layertool) FEATURES: - layers now can be toogled visible / invisible - tool also allows layer selection (better workflow IMO) - just click on the layer name - demo screencapture can be found here: http://zero-projekt.net/files/screencaptures/1280x_zero_fifedit_layertool.ogg Please let me know if this plugin causes any trouble for you.
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 11 Feb 2009 19:27:18 +0000
parents
children 5f5f8ca6db93
comparison
equal deleted inserted replaced
181:56ac89189bc4 182:bcc93e17f978
1 #!/usr/bin/env python
2 # coding: utf-8
3 # ###################################################
4 # Copyright (C) 2008 The Zero-Projekt team
5 # http://zero-projekt.net
6 # info@zero-projekt.net
7 # This file is part of Zero "Was vom Morgen blieb"
8 #
9 # The Zero-Projekt codebase is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the
21 # Free Software Foundation, Inc.,
22 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 # ###################################################
24
25 """ an advanced layer tool for FIFedit """
26
27 import fife
28 import plugin
29 import pychan
30 import pychan.widgets as widgets
31 from pychan.tools import callbackWithArguments as cbwa
32
33 import settings as Settings
34
35 class LayerTool(plugin.Plugin):
36 """ The B{LayerTool} is an advanced method to view
37 and change layer informations.
38
39 While the original FIFedit tool only allows to select
40 layers, this one will provide the following functionality:
41
42 - toggle layer visibility
43 - select layer
44 - list layers
45
46 The plugin has to register itself in the mapeditor module
47 to get actual content when a new map is loaded.
48 """
49 def __init__(self, engine, mapedit):
50 # Fifedit plugin data
51 self.menu_items = { 'LayerTool' : self.toggle }
52 self._mapedit = mapedit
53 self.data = False
54
55 # "register" at mapeditor module
56 self._mapedit.layertool = self
57
58 self.subwrappers = []
59 self.__create_gui()
60
61 def __create_gui(self):
62 """ create the basic gui container """
63 self.container = pychan.loadXML('gui/layertool.xml')
64 self.wrapper = self.container.findChild(name="layers_wrapper")
65
66 def _adjust_position(self):
67 """ adjusts the position of the container - we don't want to
68 let the window appear at the center of the screen.
69 (new default position: left, beneath the tools window)
70 """
71 self.container.position = (10, 200)
72
73 def clear(self):
74 """ remove all subwrappers """
75 if self.subwrappers is []: return
76
77 for subwrapper in self.subwrappers:
78 self.wrapper.removeChild(subwrapper)
79
80 self.subwrappers = []
81
82 def update(self):
83 """ dump new layer informations into the wrapper
84
85 We group one ToggleButton and one Lable into a HBox, the main wrapper
86 itself is a VBox and we also capture both the Button and the Label to listen
87 for mouse actions
88 """
89 layers = self._mapedit._map.getLayers()
90
91 self.clear()
92
93 for layer in layers:
94 layerid = layer.getId()
95 subwrapper = pychan.widgets.HBox()
96
97 visibility_widget = pychan.widgets.ToggleButton(up_image="icons/is_visible.png",down_image="icons/quit.png")
98 visibility_widget.name = "toggle_" + layerid
99 visibility_widget.capture(self.toggle_layer_visibility,"mousePressed")
100
101 layer_name_widget = pychan.widgets.Label()
102 layer_name_widget.text = layerid
103 layer_name_widget.name = "select_" + layerid
104 layer_name_widget.capture(self.select_active_layer,"mousePressed")
105
106 subwrapper.addChild(visibility_widget)
107 subwrapper.addChild(layer_name_widget)
108
109 self.wrapper.addChild(subwrapper)
110 self.subwrappers.append(subwrapper)
111
112 self.container.adaptLayout()
113 self.data = True
114
115 def toggle(self):
116 """ toggle visibility of the main gui container """
117 if self.container.isVisible():
118 self.container.hide()
119 else:
120 self.container.show()
121 self._adjust_position()
122
123 def toggle_layer_visibility(self, event, widget):
124 """ callback for ToggleButtons
125
126 @type event: object
127 @param event: pychan mouse event
128 @type widget: object
129 @param widget: the pychan widget where the event occurs, transports the layer id in it's name
130 """
131 if not self.data: return
132
133 layerid = widget.name[7:]
134
135 layer = self._mapedit._map.getLayer(layerid)
136 if layer.areInstancesVisible():
137 layer.setInstancesVisible(False)
138 else:
139 layer.setInstancesVisible(True)
140
141
142 def select_active_layer(self, event, widget):
143 """ callback for Labels
144
145 We hand the layerid over to the mapeditor module to select a
146 new active layer
147
148 @type event: object
149 @param event: pychan mouse event
150 @type widget: object
151 @param widget: the pychan widget where the event occurs, transports the layer id in it's name
152 """
153 if not self.data: return
154
155 layerid = widget.name[7:]
156 self._mapedit._editLayer(layerid)