1 |
jschuengel |
2257 |
# -*- coding:latin1 -*- |
2 |
|
|
# Copyright (C) 2004 by Intevation GmbH |
3 |
|
|
# Authors: |
4 |
|
|
# Jan Schüngel <[email protected]> |
5 |
|
|
# |
6 |
|
|
# This program is free software under the GPL (>=v2) |
7 |
|
|
# Read the file COPYING coming with Thuban for details. |
8 |
|
|
|
9 |
|
|
""" |
10 |
|
|
This modul extend Thuban with the possibility to handle |
11 |
|
|
UMN MapServer mapfiles. |
12 |
|
|
""" |
13 |
|
|
|
14 |
|
|
__version__ = "$Revision$" |
15 |
|
|
# $Source$ |
16 |
|
|
# $Id$ |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
# ################################### |
20 |
|
|
# |
21 |
|
|
# import necessary modules |
22 |
|
|
# |
23 |
|
|
# ################################### |
24 |
|
|
|
25 |
|
|
import os, sys |
26 |
|
|
|
27 |
|
|
# mapscript |
28 |
jschuengel |
2318 |
from mapscript import mapObj, layerObj |
29 |
jschuengel |
2257 |
|
30 |
|
|
# wxPython support |
31 |
|
|
# TODO: explicitly use from .. import |
32 |
|
|
from wxPython.wx import * |
33 |
jschuengel |
2303 |
from wxPython.grid import * |
34 |
jschuengel |
2257 |
|
35 |
|
|
# Thuban |
36 |
|
|
# use _() already now for all strings that may later be translated |
37 |
|
|
from Thuban import _ |
38 |
|
|
|
39 |
|
|
# Thuban has named commands which can be registered in the central |
40 |
|
|
# instance registry. |
41 |
|
|
from Thuban.UI.command import registry, Command |
42 |
|
|
|
43 |
|
|
# needed to add the new menu |
44 |
|
|
from Thuban.UI.mainwindow import main_menu |
45 |
|
|
|
46 |
|
|
# import Map Object for the Mapfile |
47 |
|
|
from mapfile import MF_Map |
48 |
|
|
|
49 |
|
|
from Thuban.UI.colordialog import ColorDialog |
50 |
|
|
|
51 |
|
|
from mapfile import unit_type, legend_status_type, legend_position_type, \ |
52 |
jschuengel |
2267 |
label_font_type, scalebar_status_type, scalebar_style_type, \ |
53 |
jschuengel |
2274 |
scalebar_position_type, label_position_type |
54 |
jschuengel |
2257 |
|
55 |
|
|
# ################################### |
56 |
|
|
# |
57 |
|
|
# Mainpart of the Extension |
58 |
|
|
# |
59 |
|
|
# ################################### |
60 |
|
|
|
61 |
|
|
ID_COLOR_CHANGE= 8001 |
62 |
jschuengel |
2267 |
ID_IMGCOLOR_CHANGE = 8002 |
63 |
jschuengel |
2257 |
|
64 |
|
|
class Map_Dialog(wxDialog): |
65 |
|
|
|
66 |
|
|
def __init__(self, parent, ID, title, |
67 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
68 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
69 |
|
|
|
70 |
|
|
# initialize the Dialog |
71 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
72 |
|
|
|
73 |
|
|
# parent.canvas.Map() |
74 |
|
|
self.tb_map = parent.canvas.Map() |
75 |
|
|
self.tb_map_umn = self.tb_map.extension_umn_mapobj |
76 |
|
|
|
77 |
|
|
# create name |
78 |
|
|
box_name = wxBoxSizer(wxHORIZONTAL) |
79 |
|
|
box_name.Add(wxStaticText(self, -1, _("Map-Name:")), 0, |
80 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
81 |
|
|
box_name.Add(wxStaticText(self, -1, self.tb_map.Title()), 0, |
82 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
83 |
|
|
|
84 |
|
|
#create size settings |
85 |
jschuengel |
2271 |
insidetxt = self.tb_map_umn.get_size() |
86 |
jschuengel |
2274 |
staticSize = wxStaticBox(self, 1010, _("Size"), style = 0, |
87 |
|
|
name = "staticBox", ) |
88 |
jschuengel |
2257 |
box_size = wxStaticBoxSizer(staticSize, wxVERTICAL) |
89 |
|
|
|
90 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
91 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 4) |
92 |
|
|
self.text_width = wxTextCtrl(self, -1, str(insidetxt[0])) |
93 |
|
|
box_sizepartWidth.Add(self.text_width, 2, wxALL, 4) |
94 |
|
|
box_size.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 5) |
95 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
96 |
jschuengel |
2274 |
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, |
97 |
|
|
wxALL, 4) |
98 |
jschuengel |
2257 |
self.text_height = wxTextCtrl(self, -1, str(insidetxt[1])) |
99 |
|
|
box_sizepartHeight.Add(self.text_height, 2, wxALL, 4) |
100 |
|
|
box_size.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 5) |
101 |
|
|
|
102 |
jschuengel |
2282 |
# get the web object |
103 |
|
|
self.tb_map = parent.canvas.Map() |
104 |
|
|
self.tb_map_umn = self.tb_map.extension_umn_mapobj |
105 |
|
|
|
106 |
|
|
#get the imagetype |
107 |
|
|
umn_imagetype = self.tb_map_umn.get_imagetype() |
108 |
|
|
# create a list with the outputformat names |
109 |
|
|
umn_outputformats = [] |
110 |
|
|
for format in self.tb_map_umn.get_alloutputformats(): |
111 |
|
|
umn_outputformats.append(format.get_name()) |
112 |
|
|
#Imagetype selector |
113 |
|
|
box_imagetypeStatic = wxStaticBox(self, -1, _("Image Type"), |
114 |
|
|
style = 0, name = "imagetype") |
115 |
|
|
box_imagetype = wxStaticBoxSizer(box_imagetypeStatic, wxVERTICAL) |
116 |
|
|
self.choice_imgtype = wxChoice(self, 8060, (80, 50), |
117 |
|
|
choices = umn_outputformats) |
118 |
|
|
EVT_CHOICE(self, 8060, self.EvtChoiceBox) |
119 |
|
|
self.choice_imgtype.SetStringSelection(umn_imagetype) |
120 |
|
|
box_imagetype.Add(self.choice_imgtype,0, wxEXPAND, wxALL, 5) |
121 |
|
|
|
122 |
jschuengel |
2274 |
#unittype |
123 |
jschuengel |
2257 |
insideunit = self.tb_map_umn.get_units() |
124 |
jschuengel |
2274 |
#Unittype selector |
125 |
|
|
box_unitsStatic = wxStaticBox(self, 1011, _("Unit Type"), |
126 |
|
|
style = 0, name = "imagecolor") |
127 |
jschuengel |
2257 |
box_units = wxStaticBoxSizer(box_unitsStatic, wxVERTICAL) |
128 |
|
|
sam = [] |
129 |
|
|
for key in unit_type: |
130 |
|
|
sam.append(unit_type[key]) |
131 |
|
|
self.choice_units = wxChoice(self, 40, (80, 50), choices = sam) |
132 |
|
|
self.choice_units.SetStringSelection(insideunit) |
133 |
|
|
box_units.Add(self.choice_units,0, wxEXPAND, wxALL, 5) |
134 |
|
|
|
135 |
|
|
# color chouser |
136 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("ImageColor"), |
137 |
|
|
style = 0, name = "imagecolor") |
138 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
139 |
|
|
|
140 |
|
|
# preview box |
141 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self,99, name = 'backgroundPanel', |
142 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
143 |
jschuengel |
2257 |
imagecolor = self.tb_map_umn.get_imagecolor() |
144 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(imagecolor.get_red(), |
145 |
|
|
imagecolor.get_green(), imagecolor.get_blue())) |
146 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
147 |
|
|
# color change button, opens a new color dialog |
148 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
149 |
|
|
button.SetFocus() |
150 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
151 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
152 |
|
|
|
153 |
jschuengel |
2271 |
# status |
154 |
|
|
umn_status = self.tb_map_umn.get_status() |
155 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=["True","False"], |
156 |
|
|
label='status', majorDimension=1, |
157 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
158 |
|
|
self.choice_status.SetStringSelection(str(umn_status)) |
159 |
|
|
|
160 |
jschuengel |
2257 |
#buttons |
161 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
162 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
163 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
164 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
165 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
166 |
jschuengel |
2274 |
#button functions |
167 |
jschuengel |
2257 |
EVT_BUTTON(self, wxID_OK, self.OnOK) |
168 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
169 |
|
|
|
170 |
|
|
#add all boxes to the box top |
171 |
|
|
top = wxBoxSizer(wxVERTICAL) |
172 |
|
|
top.Add(box_name, 0, wxEXPAND |wxALL, 5) |
173 |
|
|
top.Add(box_size, 0, wxEXPAND |wxALL, 5) |
174 |
jschuengel |
2282 |
top.Add(box_imagetype,0, wxEXPAND |wxALL, 5) |
175 |
jschuengel |
2257 |
top.Add(box_units,0, wxEXPAND |wxALL, 5) |
176 |
jschuengel |
2271 |
top.Add(box_color,0, wxEXPAND |wxALL, 5) |
177 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
178 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
179 |
|
|
|
180 |
|
|
# final layout settings |
181 |
|
|
self.SetSizer(top) |
182 |
|
|
top.Fit(self) |
183 |
|
|
|
184 |
|
|
def OnChangeColor(self, event): |
185 |
|
|
cur = self.tb_map_umn.get_imagecolor().get_thubancolor() |
186 |
|
|
dialog = ColorDialog(self) |
187 |
|
|
dialog.SetColor(cur) |
188 |
|
|
self.retcolor = None |
189 |
|
|
if dialog.ShowModal() == wxID_OK: |
190 |
|
|
self.retcolor = dialog.GetColor() |
191 |
|
|
dialog.Destroy() |
192 |
|
|
if self.retcolor: |
193 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
194 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
195 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
196 |
|
|
self.previewcolor.SetBackgroundColour(wxColour((self.redcolor), |
197 |
|
|
int(self.greencolor), int(self.bluecolor))) |
198 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
199 |
|
|
self.previewcolor.Refresh() |
200 |
|
|
|
201 |
|
|
def EvtChoiceBox(self, event): |
202 |
|
|
outformat = self.tb_map_umn.get_outputformat().get_name() |
203 |
jschuengel |
2257 |
|
204 |
|
|
def RunDialog(self): |
205 |
|
|
self.ShowModal() |
206 |
|
|
self.Destroy() |
207 |
|
|
|
208 |
|
|
def end_dialog(self, result): |
209 |
|
|
self.result = result |
210 |
|
|
if self.result is not None: |
211 |
|
|
self.EndModal(wxID_OK) |
212 |
|
|
else: |
213 |
|
|
self.EndModal(wxID_CANCEL) |
214 |
|
|
self.Show(False) |
215 |
|
|
|
216 |
|
|
def OnOK(self, event): |
217 |
jschuengel |
2271 |
self.tb_map_umn.set_size(int(self.text_width.GetValue()), |
218 |
|
|
int(self.text_height.GetValue())) |
219 |
jschuengel |
2257 |
self.tb_map_umn.set_units(self.choice_units.GetStringSelection()) |
220 |
jschuengel |
2271 |
if self.choice_status.GetStringSelection() == "True": |
221 |
|
|
self.tb_map_umn.set_status(True) |
222 |
|
|
else: |
223 |
|
|
self.tb_map_umn.set_status(False) |
224 |
jschuengel |
2267 |
previewcolor = self.previewcolor.GetBackgroundColour() |
225 |
|
|
self.tb_map_umn.get_imagecolor().set_rgbcolor(previewcolor.Red(), |
226 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
227 |
jschuengel |
2271 |
self.tb_map_umn.set_imagetype(self.choice_imgtype.GetStringSelection()) |
228 |
|
|
self.result ="OK" |
229 |
|
|
self.end_dialog(self.result) |
230 |
|
|
|
231 |
|
|
def OnCancel(self, event): |
232 |
|
|
self.end_dialog(None) |
233 |
|
|
|
234 |
|
|
|
235 |
jschuengel |
2257 |
class Web_Dialog(wxDialog): |
236 |
|
|
|
237 |
|
|
def __init__(self, parent, ID, title, |
238 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
239 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
240 |
|
|
|
241 |
|
|
# initialize the Dialog |
242 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
243 |
|
|
|
244 |
|
|
# get the web object |
245 |
|
|
self.tb_map = parent.canvas.Map() |
246 |
|
|
self.umn_web = self.tb_map.extension_umn_mapobj.get_web() |
247 |
jschuengel |
2282 |
|
248 |
|
|
# Template |
249 |
|
|
box_template = wxBoxSizer(wxHORIZONTAL) |
250 |
|
|
box_template.Add(wxStaticText(self, -1, _("Template:")), 0, |
251 |
|
|
wxALL|wxALIGN_LEFT, 4) |
252 |
|
|
self.text_template = wxTextCtrl(self, -1, |
253 |
|
|
str(self.umn_web.get_template())) |
254 |
|
|
self.text_template.SetSize((250,self.text_template.GetSize()[1])) |
255 |
|
|
box_template.Add(self.text_template, 0, |
256 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
257 |
|
|
|
258 |
jschuengel |
2257 |
# Imagepath |
259 |
|
|
box_imagepath = wxBoxSizer(wxHORIZONTAL) |
260 |
|
|
box_imagepath.Add(wxStaticText(self, -1, _("Imagepath:")), 0, |
261 |
|
|
wxALL|wxALIGN_LEFT, 4) |
262 |
jschuengel |
2274 |
self.text_imagepath = wxTextCtrl(self, -1, |
263 |
|
|
str(self.umn_web.get_imagepath())) |
264 |
jschuengel |
2257 |
box_imagepath.Add(self.text_imagepath, 0, |
265 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
266 |
|
|
|
267 |
|
|
# Imageurl |
268 |
|
|
box_imageurl = wxBoxSizer(wxHORIZONTAL) |
269 |
|
|
box_imageurl.Add(wxStaticText(self, -1, _("Imageurl:")), 0, |
270 |
|
|
wxALL|wxALIGN_LEFT, 4) |
271 |
jschuengel |
2274 |
self.text_imageurl = wxTextCtrl(self, -1, |
272 |
|
|
str(self.umn_web.get_imageurl())) |
273 |
jschuengel |
2257 |
box_imageurl.Add(self.text_imageurl, 0, |
274 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
275 |
|
|
|
276 |
|
|
#buttons |
277 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
278 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
279 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
280 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
281 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
282 |
|
|
#set the button funcitons |
283 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
284 |
jschuengel |
2271 |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
285 |
|
|
|
286 |
|
|
# compose the final dialog |
287 |
|
|
top = wxBoxSizer(wxVERTICAL) |
288 |
jschuengel |
2282 |
top.Add(box_template, 0, wxEXPAND |wxALL, 5) |
289 |
jschuengel |
2271 |
top.Add(box_imagepath, 0, wxEXPAND |wxALL, 5) |
290 |
|
|
top.Add(box_imageurl, 0, wxEXPAND |wxALL, 5) |
291 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
292 |
|
|
|
293 |
|
|
# final layout settings |
294 |
|
|
self.SetSizer(top) |
295 |
|
|
top.Fit(self) |
296 |
|
|
|
297 |
|
|
def RunDialog(self): |
298 |
|
|
self.ShowModal() |
299 |
|
|
self.Destroy() |
300 |
|
|
|
301 |
|
|
def end_dialog(self, result): |
302 |
|
|
self.result = result |
303 |
|
|
if self.result is not None: |
304 |
|
|
self.EndModal(wxID_OK) |
305 |
|
|
else: |
306 |
|
|
self.EndModal(wxID_CANCEL) |
307 |
|
|
self.Show(False) |
308 |
|
|
|
309 |
|
|
def OnOK(self, event): |
310 |
jschuengel |
2282 |
self.umn_web.set_template(self.text_template.GetValue()) |
311 |
jschuengel |
2257 |
self.umn_web.set_imagepath(self.text_imagepath.GetValue()) |
312 |
|
|
self.umn_web.set_imageurl(self.text_imageurl.GetValue()) |
313 |
|
|
self.result ="OK" |
314 |
|
|
self.end_dialog(self.result) |
315 |
|
|
|
316 |
|
|
def OnCancel(self, event): |
317 |
|
|
self.end_dialog(None) |
318 |
|
|
|
319 |
jschuengel |
2303 |
ID_METADATA_CHANGE = 8020 |
320 |
jschuengel |
2257 |
|
321 |
jschuengel |
2303 |
from Extensions.umn_mapserver.mapfile import MF_Layer |
322 |
|
|
|
323 |
|
|
class Layer_Dialog(wxDialog): |
324 |
|
|
|
325 |
|
|
def __init__(self, parent, ID, title, |
326 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
327 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
328 |
|
|
|
329 |
|
|
# initialize the Dialog |
330 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
331 |
|
|
|
332 |
|
|
# get the web object |
333 |
|
|
self.tb_layer = parent.current_layer() |
334 |
jschuengel |
2318 |
if hasattr(self.tb_layer,"extension_umn_layerobj"): |
335 |
|
|
self.umn_layer = self.tb_layer.extension_umn_layerobj |
336 |
|
|
else: |
337 |
|
|
newlayerobj = parent.canvas.Map().extension_umn_mapobj.create_new_layer() |
338 |
|
|
self.tb_layer.extension_umn_layerobj = newlayerobj |
339 |
|
|
self.umn_layer = self.tb_layer.extension_umn_layerobj |
340 |
jschuengel |
2303 |
|
341 |
|
|
# create name |
342 |
|
|
layer_name = wxBoxSizer(wxHORIZONTAL) |
343 |
|
|
layer_name.Add(wxStaticText(self, -1, _("Layer-Name:")), 0, |
344 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
345 |
|
|
layer_name.Add(wxStaticText(self, -1, self.tb_layer.Title()), 0, |
346 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
347 |
|
|
|
348 |
jschuengel |
2318 |
# metadata button |
349 |
|
|
metadata_button = wxButton(self, ID_METADATA_CHANGE, _("Edit Metadata")) |
350 |
|
|
EVT_BUTTON(self, ID_METADATA_CHANGE, self.OnChangeMetadata) |
351 |
jschuengel |
2303 |
|
352 |
jschuengel |
2318 |
# Group |
353 |
|
|
box_group = wxBoxSizer(wxHORIZONTAL) |
354 |
|
|
if self.umn_layer.get_group(): |
355 |
|
|
umn_layer_group = self.umn_layer.get_group() |
356 |
|
|
else: |
357 |
|
|
umn_layer_group = "" |
358 |
|
|
box_group.Add(wxStaticText(self, -1, _("Group:")), 0, |
359 |
|
|
wxALL|wxALIGN_LEFT, 4) |
360 |
|
|
self.text_group = wxTextCtrl(self, -1, |
361 |
|
|
str(umn_layer_group)) |
362 |
|
|
self.text_group.SetSize((250,self.text_group.GetSize()[1])) |
363 |
|
|
box_group.Add(self.text_group, 0, |
364 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
365 |
|
|
|
366 |
jschuengel |
2303 |
# buttons |
367 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
368 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
369 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
370 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
371 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
372 |
|
|
#set the button funcitons |
373 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
374 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
375 |
|
|
|
376 |
|
|
# compose the final dialog |
377 |
|
|
top = wxBoxSizer(wxVERTICAL) |
378 |
|
|
#top.Add(box_template, 0, wxEXPAND |wxALL, 5) |
379 |
jschuengel |
2318 |
top.Add(layer_name, 0, wxEXPAND|wxALL, 5) |
380 |
|
|
top.Add(box_group, 0, wxEXPAND|wxALL, 5) |
381 |
|
|
top.Add(metadata_button, 0, wxEXPAND|wxALL, 5) |
382 |
jschuengel |
2303 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
383 |
|
|
|
384 |
|
|
# final layout settings |
385 |
|
|
self.SetSizer(top) |
386 |
|
|
top.Fit(self) |
387 |
|
|
|
388 |
|
|
def OnChangeMetadata(self, event): |
389 |
|
|
# set the umn_label for scalebar so the Label_Dialog can be used |
390 |
|
|
self.umn_metadata= self.umn_layer.get_metadata() |
391 |
|
|
dialog = Metadata_Dialog(self, -1, "Layer Metadata Settings", |
392 |
jschuengel |
2318 |
size=wxSize(450, 200), |
393 |
jschuengel |
2303 |
style = wxDEFAULT_DIALOG_STYLE |
394 |
|
|
) |
395 |
|
|
dialog.CenterOnScreen() |
396 |
|
|
if dialog.ShowModal() == wxID_OK: |
397 |
|
|
return |
398 |
|
|
dialog.Destroy() |
399 |
|
|
|
400 |
|
|
|
401 |
|
|
def RunDialog(self): |
402 |
|
|
self.ShowModal() |
403 |
|
|
self.Destroy() |
404 |
|
|
|
405 |
|
|
def end_dialog(self, result): |
406 |
|
|
self.result = result |
407 |
|
|
if self.result is not None: |
408 |
|
|
self.EndModal(wxID_OK) |
409 |
|
|
else: |
410 |
|
|
self.EndModal(wxID_CANCEL) |
411 |
|
|
self.Show(False) |
412 |
|
|
|
413 |
|
|
def OnOK(self, event): |
414 |
jschuengel |
2318 |
if self.text_group.GetValue() == "": |
415 |
|
|
self.umn_layer.set_group(None) |
416 |
|
|
else: |
417 |
|
|
self.umn_layer.set_group(self.text_group.GetValue()) |
418 |
jschuengel |
2303 |
self.result ="OK" |
419 |
|
|
self.end_dialog(self.result) |
420 |
|
|
|
421 |
|
|
def OnCancel(self, event): |
422 |
|
|
self.end_dialog(None) |
423 |
|
|
|
424 |
|
|
|
425 |
jschuengel |
2257 |
ID_LABEL_CHANGE = 8011 |
426 |
|
|
|
427 |
|
|
class Legend_Dialog(wxDialog): |
428 |
|
|
|
429 |
|
|
def __init__(self, parent, ID, title, |
430 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
431 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
432 |
|
|
|
433 |
|
|
# initialize the Dialog |
434 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
435 |
|
|
|
436 |
|
|
# get the web object |
437 |
|
|
self.tb_map = parent.canvas.Map() |
438 |
|
|
self.umn_legend = self.tb_map.extension_umn_mapobj.get_legend() |
439 |
|
|
|
440 |
|
|
# create the Keysize |
441 |
jschuengel |
2274 |
keySize = wxStaticBox(self, 1010, _("KeySize"), style = 0, |
442 |
|
|
name = "KeySize Box", ) |
443 |
jschuengel |
2257 |
box_keysize = wxStaticBoxSizer(keySize, wxVERTICAL) |
444 |
|
|
umn_legend_keysize = self.umn_legend.get_keysize() |
445 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
446 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2) |
447 |
|
|
self.text_keysize_width = wxSpinCtrl(self, -1, |
448 |
|
|
value=str(umn_legend_keysize[0]), max=100, min=0, |
449 |
|
|
name='keywidth', style=wxSP_ARROW_KEYS) |
450 |
|
|
box_sizepartWidth.Add(self.text_keysize_width, 2, wxALL, 2) |
451 |
|
|
box_keysize.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2) |
452 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
453 |
|
|
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2), |
454 |
|
|
self.text_keysize_height = wxSpinCtrl(self, -1, |
455 |
|
|
value=str(umn_legend_keysize[1]), max=100, min=0, |
456 |
|
|
name='keyheight', style=wxSP_ARROW_KEYS) |
457 |
|
|
box_sizepartHeight.Add(self.text_keysize_height, 2, wxALL, 2) |
458 |
|
|
box_keysize.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2) |
459 |
|
|
|
460 |
|
|
# create the Keyspacing |
461 |
jschuengel |
2274 |
keySpacing= wxStaticBox(self, 1010, _("KeySpacing"), style = 0, |
462 |
|
|
name = "KeySpacing Box", ) |
463 |
jschuengel |
2257 |
box_keyspacing = wxStaticBoxSizer(keySpacing, wxVERTICAL) |
464 |
|
|
umn_legend_keyspacing = self.umn_legend.get_keyspacing() |
465 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
466 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2) |
467 |
|
|
self.text_keyspacing_width = wxSpinCtrl(self, -1, |
468 |
jschuengel |
2274 |
value=str(umn_legend_keyspacing[0]), max=100, |
469 |
|
|
min=0, name='spacingwidth', style=wxSP_ARROW_KEYS) |
470 |
jschuengel |
2257 |
box_sizepartWidth.Add(self.text_keyspacing_width, 2, wxALL, 2) |
471 |
|
|
box_keyspacing.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2) |
472 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
473 |
|
|
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2), |
474 |
|
|
self.text_keyspacing_height = wxSpinCtrl(self, -1, |
475 |
jschuengel |
2274 |
value=str(umn_legend_keyspacing[1]), max=100, |
476 |
|
|
min=0,name='spacingheight', style=wxSP_ARROW_KEYS) |
477 |
jschuengel |
2257 |
box_sizepartHeight.Add(self.text_keyspacing_height, 2, wxALL, 2) |
478 |
|
|
box_keyspacing.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2) |
479 |
|
|
|
480 |
|
|
# color chooser |
481 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("ImageColor"), style = 0, |
482 |
|
|
name = "imagecolor") |
483 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
484 |
|
|
# preview box |
485 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'imagecolorPanel', |
486 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
487 |
jschuengel |
2257 |
imagecolor = self.umn_legend.get_imagecolor() |
488 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(imagecolor.get_red(), |
489 |
|
|
imagecolor.get_green(), imagecolor.get_blue())) |
490 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
491 |
|
|
# color change button, opens a new color dialog |
492 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
493 |
|
|
button.SetFocus() |
494 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
495 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
496 |
|
|
|
497 |
jschuengel |
2267 |
# status |
498 |
jschuengel |
2274 |
umn_legend_status= self.umn_legend.get_status(mode="string") |
499 |
jschuengel |
2257 |
possible_choices = [] |
500 |
|
|
for key in legend_status_type: |
501 |
|
|
possible_choices.append(legend_status_type[key]) |
502 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=possible_choices, |
503 |
|
|
label='Status', majorDimension=1, |
504 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
505 |
|
|
self.choice_status.SetStringSelection(umn_legend_status) |
506 |
|
|
|
507 |
|
|
# create the positionbox |
508 |
jschuengel |
2274 |
umn_legend_position= self.umn_legend.get_position(mode="string") |
509 |
jschuengel |
2257 |
possible_choices = [] |
510 |
|
|
for key in legend_position_type: |
511 |
|
|
possible_choices.append(legend_position_type[key]) |
512 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
513 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
514 |
|
|
name='position check', |
515 |
|
|
size=wxDefaultSize, |
516 |
|
|
style=wxRA_SPECIFY_ROWS) |
517 |
jschuengel |
2257 |
self.choice_position.SetStringSelection(umn_legend_position) |
518 |
|
|
|
519 |
jschuengel |
2271 |
# button for label |
520 |
|
|
labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label")) |
521 |
jschuengel |
2257 |
EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel) |
522 |
|
|
|
523 |
|
|
#buttons |
524 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
525 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
526 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
527 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
528 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
529 |
|
|
#set the button funcitons |
530 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
531 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
532 |
jschuengel |
2271 |
|
533 |
|
|
# compose the final layout |
534 |
|
|
top = wxBoxSizer(wxVERTICAL) |
535 |
|
|
top.Add(box_keysize,0, wxEXPAND |wxALL, 5) |
536 |
|
|
top.Add(box_keyspacing,0, wxEXPAND |wxALL, 5) |
537 |
|
|
top.Add(box_color,0, wxEXPAND |wxALL, 5) |
538 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
539 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
540 |
|
|
top.Add(labelbutton, 1, wxEXPAND|wxALL, 5) |
541 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
542 |
|
|
|
543 |
|
|
# final layout settings |
544 |
|
|
self.SetSizer(top) |
545 |
|
|
top.Fit(self) |
546 |
|
|
|
547 |
|
|
def OnChangeLabel(self, event): |
548 |
jschuengel |
2267 |
self.umn_label = self.umn_legend.get_label() |
549 |
jschuengel |
2274 |
dialog = Label_Dialog(self, -1, "Legend Label Settings", |
550 |
|
|
size=wxSize(350, 200), |
551 |
jschuengel |
2257 |
style = wxDEFAULT_DIALOG_STYLE |
552 |
|
|
) |
553 |
|
|
dialog.CenterOnScreen() |
554 |
|
|
if dialog.ShowModal() == wxID_OK: |
555 |
|
|
return |
556 |
|
|
dialog.Destroy() |
557 |
|
|
|
558 |
|
|
def OnChangeColor(self, event): |
559 |
|
|
cur = self.umn_legend.get_imagecolor().get_thubancolor() |
560 |
|
|
dialog = ColorDialog(self) |
561 |
|
|
dialog.SetColor(cur) |
562 |
|
|
self.retcolor = None |
563 |
|
|
if dialog.ShowModal() == wxID_OK: |
564 |
|
|
self.retcolor = dialog.GetColor() |
565 |
|
|
dialog.Destroy() |
566 |
|
|
if self.retcolor: |
567 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
568 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
569 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
570 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
571 |
|
|
int(self.greencolor), |
572 |
|
|
int(self.bluecolor))) |
573 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
574 |
|
|
self.previewcolor.Refresh() |
575 |
jschuengel |
2257 |
|
576 |
|
|
def RunDialog(self): |
577 |
|
|
self.ShowModal() |
578 |
|
|
self.Destroy() |
579 |
|
|
|
580 |
|
|
def end_dialog(self, result): |
581 |
|
|
self.result = result |
582 |
|
|
if self.result is not None: |
583 |
|
|
self.EndModal(wxID_OK) |
584 |
|
|
else: |
585 |
|
|
self.EndModal(wxID_CANCEL) |
586 |
|
|
self.Show(False) |
587 |
|
|
|
588 |
|
|
def OnOK(self, event): |
589 |
jschuengel |
2271 |
self.umn_legend.set_keysize(self.text_keysize_width.GetValue(), |
590 |
|
|
self.text_keysize_height.GetValue()) |
591 |
|
|
self.umn_legend.set_keyspacing(self.text_keyspacing_width.GetValue(), |
592 |
|
|
self.text_keyspacing_height.GetValue()) |
593 |
jschuengel |
2257 |
self.umn_legend.set_status(self.choice_status.GetStringSelection()) |
594 |
|
|
self.umn_legend.set_position(self.choice_position.GetStringSelection()) |
595 |
jschuengel |
2267 |
previewcolor = self.previewcolor.GetBackgroundColour() |
596 |
|
|
self.umn_legend.get_imagecolor().set_rgbcolor(previewcolor.Red(), |
597 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
598 |
jschuengel |
2257 |
self.result ="OK" |
599 |
|
|
self.end_dialog(self.result) |
600 |
|
|
|
601 |
|
|
def OnCancel(self, event): |
602 |
|
|
self.end_dialog(None) |
603 |
|
|
|
604 |
|
|
class Label_Dialog(wxDialog): |
605 |
|
|
|
606 |
|
|
def __init__(self, parent, ID, title, |
607 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
608 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
609 |
|
|
|
610 |
|
|
# initialize the Dialog |
611 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
612 |
|
|
|
613 |
|
|
# get the web object |
614 |
jschuengel |
2267 |
self.umn_label = parent.umn_label |
615 |
jschuengel |
2257 |
|
616 |
|
|
# size |
617 |
jschuengel |
2274 |
labelsize= wxStaticBox(self, 1010, _("Size"), style = 0, |
618 |
|
|
name = "Size Box", ) |
619 |
jschuengel |
2257 |
box_labelsize = wxStaticBoxSizer(labelsize, wxVERTICAL) |
620 |
|
|
umn_label_size= self.umn_label.get_size() |
621 |
|
|
box_size = wxBoxSizer(wxHORIZONTAL) |
622 |
|
|
self.text_labelsize = wxSpinCtrl(self, -1, |
623 |
|
|
value=str(umn_label_size), max=10, min=0, |
624 |
|
|
name='size', style=wxSP_ARROW_KEYS) |
625 |
|
|
box_size.Add(self.text_labelsize, 2, wxALL, 2) |
626 |
|
|
box_labelsize.Add(box_size, 0, wxALIGN_RIGHT | wxALL, 2) |
627 |
|
|
|
628 |
|
|
# color chooser |
629 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0, |
630 |
|
|
name = "color") |
631 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
632 |
|
|
# preview box |
633 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'colorPanel', |
634 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
635 |
jschuengel |
2257 |
color = self.umn_label.get_color() |
636 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(color.get_red(), |
637 |
|
|
color.get_green(), color.get_blue())) |
638 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
639 |
|
|
# color change button, opens a new color dialog |
640 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
641 |
|
|
button.SetFocus() |
642 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
643 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
644 |
|
|
|
645 |
|
|
#get the set type |
646 |
|
|
insidetype = self.umn_label.get_type() |
647 |
|
|
#create the type selector for fonttype (Bitmap, TrueType) |
648 |
|
|
# TODO: Truetype is not supported yet |
649 |
jschuengel |
2274 |
box_typeStatic = wxStaticBox(self, 1011, _("Type"), style = 0, |
650 |
|
|
name = "type") |
651 |
jschuengel |
2257 |
box_type = wxStaticBoxSizer(box_typeStatic, wxVERTICAL) |
652 |
|
|
sam = [] |
653 |
|
|
for key in label_font_type: |
654 |
|
|
# dont add truetype |
655 |
|
|
#if key != 0: |
656 |
|
|
sam.append(label_font_type[key]) |
657 |
|
|
self.choice_type = wxChoice(self, 40, (80, 50), choices = sam) |
658 |
|
|
self.choice_type.SetStringSelection(insidetype) |
659 |
|
|
box_type.Add(self.choice_type,0, wxEXPAND, wxALL, 5) |
660 |
jschuengel |
2271 |
|
661 |
jschuengel |
2257 |
# Offset |
662 |
jschuengel |
2274 |
offset= wxStaticBox(self, 1010, _("Offset"), style = 0, |
663 |
|
|
name = "Offset Box", ) |
664 |
jschuengel |
2257 |
box_offset = wxStaticBoxSizer(offset, wxVERTICAL) |
665 |
|
|
umn_label_offset = self.umn_label.get_offset() |
666 |
|
|
box_offsetX = wxBoxSizer(wxHORIZONTAL) |
667 |
|
|
box_offsetX.Add(wxStaticText(self, -1, _("X: ")), 0, wxALL, 2) |
668 |
|
|
self.text_offsetx = wxSpinCtrl(self, -1, |
669 |
|
|
value=str(umn_label_offset[0]), max=20, min=0, |
670 |
|
|
name='offsetX', style=wxSP_ARROW_KEYS) |
671 |
|
|
box_offsetX.Add(self.text_offsetx, 2, wxALL, 2) |
672 |
|
|
box_offset.Add(box_offsetX, 0, wxALIGN_RIGHT | wxALL, 2) |
673 |
|
|
box_offsetY = wxBoxSizer(wxHORIZONTAL) |
674 |
|
|
box_offsetY.Add(wxStaticText(self, -1, _("Y: ")), 0, wxALL, 2), |
675 |
|
|
self.text_offsety = wxSpinCtrl(self, -1, |
676 |
|
|
value=str(umn_label_offset[1]), max=100, min=0, |
677 |
|
|
name='offsetY', style=wxSP_ARROW_KEYS) |
678 |
|
|
box_offsetY.Add(self.text_offsety, 2, wxALL, 2) |
679 |
|
|
box_offset.Add(box_offsetY, 0, wxALIGN_RIGHT | wxALL, 2) |
680 |
|
|
|
681 |
jschuengel |
2271 |
# partials |
682 |
jschuengel |
2267 |
umn_partials = self.umn_label.get_partials() |
683 |
|
|
self.choice_partials = wxRadioBox(self, -1, choices=["True","False"], |
684 |
jschuengel |
2274 |
label='partials', majorDimension=1, |
685 |
|
|
name='partials check', |
686 |
|
|
size=wxDefaultSize, |
687 |
|
|
style=wxRA_SPECIFY_ROWS) |
688 |
jschuengel |
2267 |
self.choice_partials.SetStringSelection(str(umn_partials)) |
689 |
jschuengel |
2271 |
|
690 |
|
|
# force |
691 |
|
|
umn_force = self.umn_label.get_force() |
692 |
|
|
self.choice_force = wxRadioBox(self, -1, choices=["True","False"], |
693 |
|
|
label='force', majorDimension=1, |
694 |
|
|
name='force check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
695 |
|
|
self.choice_force.SetStringSelection(str(umn_force)) |
696 |
|
|
|
697 |
|
|
# buffer |
698 |
jschuengel |
2274 |
buffer = wxStaticBox(self, 1010, _("Buffer"), style = 0, |
699 |
|
|
name = "Buffer Box", ) |
700 |
jschuengel |
2271 |
box_buffer = wxStaticBoxSizer(buffer, wxVERTICAL) |
701 |
|
|
umn_buffer= self.umn_label.get_buffer() |
702 |
|
|
box_buffertext = wxBoxSizer(wxHORIZONTAL) |
703 |
|
|
self.text_buffer = wxSpinCtrl(self, -1, |
704 |
|
|
value=str(umn_buffer), max=10, min=0, |
705 |
|
|
name='size', style=wxSP_ARROW_KEYS) |
706 |
|
|
box_buffertext.Add(self.text_buffer, 2, wxALL, 2) |
707 |
|
|
box_buffer.Add(box_buffertext, 0, wxALIGN_RIGHT | wxALL, 2) |
708 |
|
|
|
709 |
|
|
# minfeaturesize |
710 |
jschuengel |
2274 |
minfeaturesize = wxStaticBox(self, 1010, _("Minfeaturesize"), |
711 |
|
|
style = 0, name = "Minfeaturesize Box") |
712 |
jschuengel |
2271 |
box_minfeaturesize = wxStaticBoxSizer(minfeaturesize, wxVERTICAL) |
713 |
|
|
umn_minfeaturesize= self.umn_label.get_minfeaturesize() |
714 |
|
|
box_minfeaturesizetext = wxBoxSizer(wxHORIZONTAL) |
715 |
|
|
self.text_minfeaturesize = wxSpinCtrl(self, -1, |
716 |
|
|
value=str(umn_minfeaturesize), max=10, min=-1, |
717 |
|
|
name='minfeaturesize', style=wxSP_ARROW_KEYS) |
718 |
|
|
box_minfeaturesizetext.Add(self.text_minfeaturesize, 2, wxALL, 2) |
719 |
|
|
box_minfeaturesize.Add(box_minfeaturesizetext, 0, |
720 |
|
|
wxALIGN_RIGHT | wxALL, 2) |
721 |
|
|
|
722 |
|
|
# mindistance |
723 |
|
|
mindistance = wxStaticBox(self, 1010, _("Mindistance"), style = 0, |
724 |
|
|
name = "Mindistance Box", ) |
725 |
|
|
box_mindistance = wxStaticBoxSizer(mindistance, wxVERTICAL) |
726 |
|
|
umn_mindistance= self.umn_label.get_mindistance() |
727 |
|
|
box_mindistancetext = wxBoxSizer(wxHORIZONTAL) |
728 |
|
|
self.text_mindistance = wxSpinCtrl(self, -1, |
729 |
|
|
value=str(umn_mindistance), max=10, min=-1, |
730 |
|
|
name='mindistance', style=wxSP_ARROW_KEYS) |
731 |
|
|
box_mindistancetext.Add(self.text_mindistance, 2, wxALL, 2) |
732 |
|
|
box_mindistance.Add(box_mindistancetext, 0, |
733 |
|
|
wxALIGN_RIGHT | wxALL, 2) |
734 |
jschuengel |
2257 |
|
735 |
jschuengel |
2271 |
# position |
736 |
jschuengel |
2274 |
umn_label_position= self.umn_label.get_position(mode="string") |
737 |
jschuengel |
2271 |
possible_choices = [] |
738 |
|
|
for key in label_position_type: |
739 |
|
|
possible_choices.append(label_position_type[key]) |
740 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
741 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
742 |
|
|
name='position check', |
743 |
|
|
size=wxDefaultSize, |
744 |
|
|
style=wxRA_SPECIFY_ROWS) |
745 |
jschuengel |
2271 |
self.choice_position.SetStringSelection(umn_label_position) |
746 |
|
|
|
747 |
jschuengel |
2257 |
#buttons |
748 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
749 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
750 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
751 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
752 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
753 |
|
|
#set the button funcitons |
754 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
755 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
756 |
jschuengel |
2271 |
|
757 |
|
|
# compose the Dialog |
758 |
|
|
top = wxBoxSizer(wxVERTICAL) |
759 |
|
|
|
760 |
|
|
top1 = wxBoxSizer(wxHORIZONTAL) |
761 |
|
|
top1.Add(box_labelsize,0, wxEXPAND |wxALL, 5) |
762 |
|
|
top1.Add(box_color,0, wxEXPAND |wxALL, 5) |
763 |
|
|
top1.Add(box_minfeaturesize,0, wxEXPAND |wxALL, 5) |
764 |
|
|
|
765 |
|
|
top2 = wxBoxSizer(wxHORIZONTAL) |
766 |
|
|
top2.Add(box_type,0,wxEXPAND |wxALL, 5) |
767 |
|
|
top2.Add(box_offset,0, wxEXPAND |wxALL, 5) |
768 |
|
|
top2.Add(box_mindistance,0, wxEXPAND |wxALL, 5) |
769 |
|
|
|
770 |
|
|
top3 = wxBoxSizer(wxHORIZONTAL) |
771 |
|
|
top3.Add(self.choice_partials,0, wxEXPAND |wxALL, 5) |
772 |
|
|
top3.Add(box_buffer,0, wxEXPAND |wxALL, 5) |
773 |
|
|
top3.Add(self.choice_force,0, wxEXPAND |wxALL, 5) |
774 |
|
|
|
775 |
|
|
top.Add(top1, 0, wxEXPAND) |
776 |
|
|
top.Add(top2, 0, wxEXPAND) |
777 |
|
|
top.Add(top3, 0, wxEXPAND) |
778 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
779 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
780 |
jschuengel |
2271 |
|
781 |
jschuengel |
2257 |
# final layout settings |
782 |
|
|
self.SetSizer(top) |
783 |
|
|
top.Fit(self) |
784 |
|
|
|
785 |
|
|
def OnChangeColor(self, event): |
786 |
|
|
cur = self.umn_label.get_color().get_thubancolor() |
787 |
|
|
dialog = ColorDialog(self) |
788 |
|
|
dialog.SetColor(cur) |
789 |
|
|
self.retcolor = None |
790 |
|
|
if dialog.ShowModal() == wxID_OK: |
791 |
|
|
self.retcolor = dialog.GetColor() |
792 |
|
|
dialog.Destroy() |
793 |
|
|
if self.retcolor: |
794 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
795 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
796 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
797 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
798 |
|
|
int(self.greencolor), |
799 |
|
|
int(self.bluecolor))) |
800 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
801 |
|
|
self.previewcolor.Refresh() |
802 |
jschuengel |
2257 |
|
803 |
|
|
def RunDialog(self): |
804 |
|
|
self.ShowModal() |
805 |
|
|
self.Destroy() |
806 |
|
|
|
807 |
|
|
def end_dialog(self, result): |
808 |
|
|
self.result = result |
809 |
|
|
if self.result is not None: |
810 |
|
|
self.EndModal(wxID_OK) |
811 |
|
|
else: |
812 |
|
|
self.EndModal(wxID_CANCEL) |
813 |
|
|
self.Show(False) |
814 |
|
|
|
815 |
|
|
def OnOK(self, event): |
816 |
|
|
self.umn_label.set_size(self.text_labelsize.GetValue()) |
817 |
jschuengel |
2274 |
self.umn_label.set_offset(self.text_offsetx.GetValue(), |
818 |
|
|
self.text_offsety.GetValue()) |
819 |
jschuengel |
2257 |
self.umn_label.set_type(self.choice_type.GetStringSelection()) |
820 |
jschuengel |
2267 |
if self.choice_partials.GetStringSelection() == "True": |
821 |
|
|
self.umn_label.set_partials(True) |
822 |
|
|
else: |
823 |
|
|
self.umn_label.set_partials(False) |
824 |
|
|
previewcolor = self.previewcolor.GetBackgroundColour() |
825 |
|
|
self.umn_label.get_color().set_rgbcolor(previewcolor.Red(), |
826 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
827 |
jschuengel |
2271 |
self.umn_label.set_mindistance(self.text_mindistance.GetValue()) |
828 |
|
|
self.umn_label.set_minfeaturesize(self.text_minfeaturesize.GetValue()) |
829 |
|
|
self.umn_label.set_position(self.choice_position.GetStringSelection()) |
830 |
|
|
self.umn_label.set_buffer(self.text_buffer.GetValue()) |
831 |
|
|
if self.choice_force.GetStringSelection() == "True": |
832 |
|
|
self.umn_label.set_force(True) |
833 |
|
|
else: |
834 |
|
|
self.umn_label.set_force(False) |
835 |
jschuengel |
2257 |
self.result ="OK" |
836 |
|
|
self.end_dialog(self.result) |
837 |
|
|
|
838 |
|
|
def OnCancel(self, event): |
839 |
|
|
self.end_dialog(None) |
840 |
|
|
|
841 |
jschuengel |
2267 |
class Scalebar_Dialog(wxDialog): |
842 |
|
|
|
843 |
|
|
def __init__(self, parent, ID, title, |
844 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
845 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
846 |
|
|
|
847 |
|
|
# initialize the Dialog |
848 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
849 |
jschuengel |
2257 |
|
850 |
jschuengel |
2267 |
# get the web object |
851 |
|
|
self.tb_map = parent.canvas.Map() |
852 |
|
|
self.umn_scalebar = self.tb_map.extension_umn_mapobj.get_scalebar() |
853 |
|
|
|
854 |
|
|
# color chooser |
855 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0, |
856 |
|
|
name = "color") |
857 |
jschuengel |
2267 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
858 |
|
|
# preview box |
859 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'colorPanel', |
860 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
861 |
jschuengel |
2267 |
color = self.umn_scalebar.get_color() |
862 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(color.get_red(), |
863 |
|
|
color.get_green(), color.get_blue())) |
864 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
865 |
|
|
# color change button, opens a new color dialog |
866 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
867 |
|
|
button.SetFocus() |
868 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
869 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
870 |
|
|
# show the two color chooser horizontal |
871 |
|
|
colorHor = wxBoxSizer(wxHORIZONTAL) |
872 |
|
|
colorHor.Add(box_color,0, wxEXPAND |wxALL, 5) |
873 |
|
|
|
874 |
|
|
# imagecolor chooser |
875 |
jschuengel |
2274 |
box_imgcolorStatic = wxStaticBox(self, 1011, _("Image Color"), |
876 |
|
|
style = 0, name = "imgcolor") |
877 |
jschuengel |
2267 |
box_imgcolor = wxStaticBoxSizer(box_imgcolorStatic, wxVERTICAL) |
878 |
|
|
# preview box |
879 |
jschuengel |
2274 |
self.previewimgcolor = wxPanel(self, 99, name = 'colorPanel', |
880 |
|
|
style = wxSIMPLE_BORDER|wxCLIP_CHILDREN) |
881 |
jschuengel |
2267 |
color = self.umn_scalebar.get_imagecolor() |
882 |
|
|
self.previewimgcolor.SetBackgroundColour(wxColour(color.get_red(), |
883 |
|
|
color.get_green(), color.get_blue())) |
884 |
|
|
box_imgcolor.Add(self.previewimgcolor, 1, wxGROW | wxALL, 5) |
885 |
|
|
# color change button, opens a new color dialog |
886 |
|
|
button = wxButton(self, ID_IMGCOLOR_CHANGE, _("Change ImageColor")) |
887 |
|
|
button.SetFocus() |
888 |
|
|
EVT_BUTTON(self, ID_IMGCOLOR_CHANGE, self.OnChangeImageColor) |
889 |
|
|
box_imgcolor.Add(button, 1, wxEXPAND|wxALL, 5) |
890 |
|
|
colorHor.Add(box_imgcolor,0, wxEXPAND |wxALL, 5) |
891 |
|
|
|
892 |
|
|
# create the intervals |
893 |
jschuengel |
2274 |
intervalsStatic = wxStaticBox(self, 1010, _("Intervals"), style = 0, |
894 |
|
|
name = "Intervals Box", ) |
895 |
jschuengel |
2267 |
box_intervals = wxStaticBoxSizer(intervalsStatic, wxVERTICAL) |
896 |
|
|
umn_scalebar_intervals = self.umn_scalebar.get_intervals() |
897 |
|
|
self.text_intervals = wxSpinCtrl(self, -1, |
898 |
|
|
value=str(umn_scalebar_intervals), max=100, min=0, |
899 |
|
|
name='intervals', style=wxSP_ARROW_KEYS) |
900 |
|
|
box_intervals.Add(self.text_intervals, 0, wxALIGN_RIGHT | wxALL, 2) |
901 |
|
|
hori2 = wxBoxSizer(wxHORIZONTAL) |
902 |
|
|
hori2.Add(box_intervals,0, wxEXPAND |wxALL, 5) |
903 |
|
|
|
904 |
|
|
#style |
905 |
|
|
umn_scalebar_style= self.umn_scalebar.get_style() |
906 |
|
|
possible_choices = [] |
907 |
|
|
for key in scalebar_style_type: |
908 |
|
|
possible_choices.append(scalebar_style_type[key]) |
909 |
|
|
self.choice_style = wxRadioBox(self, -1, choices=possible_choices, |
910 |
|
|
label='Style', majorDimension=1, |
911 |
|
|
name='style check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
912 |
|
|
self.choice_style.SetSelection(umn_scalebar_style) |
913 |
|
|
hori2.Add(self.choice_style, 1, wxEXPAND|wxALL, 5) |
914 |
|
|
|
915 |
|
|
#create size settings |
916 |
|
|
try: |
917 |
|
|
insidetxt = self.umn_scalebar.get_size() |
918 |
|
|
except: |
919 |
|
|
insidetxt = (0,0) |
920 |
|
|
# create the Size Box |
921 |
jschuengel |
2274 |
staticSize = wxStaticBox(self, -1, _("Size"), style = 0, |
922 |
|
|
name="sizeBox") |
923 |
jschuengel |
2267 |
box_size = wxStaticBoxSizer(staticSize, wxHORIZONTAL) |
924 |
|
|
|
925 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
926 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 4) |
927 |
|
|
self.text_width = wxTextCtrl(self, -1, str(insidetxt[0])) |
928 |
|
|
box_sizepartWidth.Add(self.text_width, 2, wxALL, 4) |
929 |
|
|
box_size.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 5) |
930 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
931 |
jschuengel |
2274 |
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, |
932 |
|
|
wxALL, 4) |
933 |
jschuengel |
2267 |
self.text_height = wxTextCtrl(self, -1, str(insidetxt[1])) |
934 |
|
|
box_sizepartHeight.Add(self.text_height, 2, wxALL, 4) |
935 |
|
|
box_size.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 5) |
936 |
|
|
|
937 |
|
|
# status |
938 |
jschuengel |
2274 |
umn_scalebar_status= self.umn_scalebar.get_status(mode="string") |
939 |
jschuengel |
2267 |
possible_choices = [] |
940 |
|
|
for key in legend_status_type: |
941 |
|
|
possible_choices.append(scalebar_status_type[key]) |
942 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=possible_choices, |
943 |
|
|
label='Status', majorDimension=1, |
944 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
945 |
|
|
self.choice_status.SetStringSelection(umn_scalebar_status) |
946 |
|
|
|
947 |
|
|
# position |
948 |
jschuengel |
2274 |
umn_scalebar_position= self.umn_scalebar.get_position(mode="string") |
949 |
jschuengel |
2267 |
possible_choices = [] |
950 |
|
|
for key in scalebar_position_type: |
951 |
|
|
possible_choices.append(scalebar_position_type[key]) |
952 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
953 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
954 |
|
|
name='position check', size=wxDefaultSize, |
955 |
|
|
style=wxRA_SPECIFY_ROWS) |
956 |
jschuengel |
2267 |
self.choice_position.SetStringSelection(umn_scalebar_position) |
957 |
|
|
|
958 |
|
|
#get the set unittype |
959 |
|
|
insideunit = self.umn_scalebar .get_units() |
960 |
|
|
#create the Unittype selector |
961 |
jschuengel |
2274 |
box_unitsStatic = wxStaticBox(self, -1, _("Unit Type"), style = 0, |
962 |
|
|
name = "unittype") |
963 |
jschuengel |
2267 |
box_units = wxStaticBoxSizer(box_unitsStatic, wxVERTICAL) |
964 |
|
|
sam = [] |
965 |
|
|
for key in unit_type: |
966 |
|
|
sam.append(unit_type[key]) |
967 |
|
|
self.choice_units = wxChoice(self, 40, (80, 50), choices = sam) |
968 |
|
|
self.choice_units.SetStringSelection(insideunit) |
969 |
jschuengel |
2271 |
box_units.Add(self.choice_units,0, wxEXPAND, wxALL, 5) |
970 |
jschuengel |
2267 |
|
971 |
jschuengel |
2271 |
# button for label |
972 |
|
|
labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label")) |
973 |
jschuengel |
2267 |
EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel) |
974 |
|
|
|
975 |
|
|
#buttons |
976 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
977 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
978 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
979 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
980 |
|
|
button.SetFocus() |
981 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
982 |
|
|
#set the button funcitons |
983 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
984 |
jschuengel |
2271 |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
985 |
|
|
|
986 |
|
|
# compose the dialog |
987 |
|
|
top = wxBoxSizer(wxVERTICAL) |
988 |
|
|
top.Add(colorHor,0, wxEXPAND |wxALL, 5) |
989 |
|
|
top.Add(hori2, 1, wxEXPAND|wxALL, 5) |
990 |
|
|
top.Add(box_size, 1, wxEXPAND|wxALL, 5) |
991 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
992 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
993 |
|
|
top.Add(box_units, 1, wxEXPAND|wxALL, 5) |
994 |
|
|
top.Add(labelbutton, 0, wxEXPAND|wxALL, 5) |
995 |
jschuengel |
2267 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
996 |
|
|
|
997 |
|
|
# final layout settings |
998 |
|
|
self.SetSizer(top) |
999 |
|
|
top.Fit(self) |
1000 |
|
|
|
1001 |
|
|
def OnChangeLabel(self, event): |
1002 |
|
|
# set the umn_label for scalebar so the Label_Dialog can be used |
1003 |
|
|
self.umn_label = self.umn_scalebar.get_label() |
1004 |
jschuengel |
2274 |
dialog = Label_Dialog(self, -1, "Scalbar Label Settings", |
1005 |
|
|
size=wxSize(350, 200), |
1006 |
jschuengel |
2267 |
style = wxDEFAULT_DIALOG_STYLE |
1007 |
|
|
) |
1008 |
|
|
dialog.CenterOnScreen() |
1009 |
|
|
if dialog.ShowModal() == wxID_OK: |
1010 |
|
|
return |
1011 |
|
|
dialog.Destroy() |
1012 |
|
|
|
1013 |
|
|
def OnChangeImageColor(self, event): |
1014 |
|
|
cur = self.umn_scalebar.get_imagecolor().get_thubancolor() |
1015 |
|
|
dialog = ColorDialog(self) |
1016 |
|
|
dialog.SetColor(cur) |
1017 |
|
|
self.retcolor = None |
1018 |
|
|
if dialog.ShowModal() == wxID_OK: |
1019 |
|
|
self.retcolor = dialog.GetColor() |
1020 |
|
|
dialog.Destroy() |
1021 |
|
|
if self.retcolor: |
1022 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
1023 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
1024 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
1025 |
jschuengel |
2274 |
self.previewimgcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
1026 |
|
|
int(self.greencolor), |
1027 |
|
|
int(self.bluecolor))) |
1028 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
1029 |
|
|
self.previewimgcolor.Refresh() |
1030 |
jschuengel |
2267 |
|
1031 |
|
|
def OnChangeColor(self, event): |
1032 |
|
|
cur = self.umn_scalebar.get_color().get_thubancolor() |
1033 |
|
|
dialog = ColorDialog(self) |
1034 |
|
|
dialog.SetColor(cur) |
1035 |
|
|
self.retcolor = None |
1036 |
|
|
if dialog.ShowModal() == wxID_OK: |
1037 |
|
|
self.retcolor = dialog.GetColor() |
1038 |
|
|
dialog.Destroy() |
1039 |
|
|
if self.retcolor: |
1040 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
1041 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
1042 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
1043 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
1044 |
|
|
int(self.greencolor), |
1045 |
|
|
int(self.bluecolor))) |
1046 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
1047 |
|
|
self.previewcolor.Refresh() |
1048 |
jschuengel |
2267 |
|
1049 |
|
|
def RunDialog(self): |
1050 |
|
|
self.ShowModal() |
1051 |
|
|
self.Destroy() |
1052 |
|
|
|
1053 |
|
|
def end_dialog(self, result): |
1054 |
|
|
self.result = result |
1055 |
|
|
if self.result is not None: |
1056 |
|
|
self.EndModal(wxID_OK) |
1057 |
|
|
else: |
1058 |
|
|
self.EndModal(wxID_CANCEL) |
1059 |
|
|
self.Show(False) |
1060 |
|
|
|
1061 |
|
|
def OnOK(self, event): |
1062 |
|
|
self.umn_scalebar.set_status(self.choice_status.GetStringSelection()) |
1063 |
|
|
self.umn_scalebar.set_units(self.choice_units.GetStringSelection()) |
1064 |
|
|
self.umn_scalebar.set_intervals(self.text_intervals.GetValue()) |
1065 |
|
|
self.umn_scalebar.set_style(self.choice_style.GetSelection()) |
1066 |
|
|
self.umn_scalebar.set_position(self.choice_position.GetStringSelection()) |
1067 |
jschuengel |
2274 |
self.umn_scalebar.set_size(int(self.text_width.GetValue()), |
1068 |
|
|
int(self.text_height.GetValue())) |
1069 |
jschuengel |
2267 |
|
1070 |
|
|
previewcolor = self.previewcolor.GetBackgroundColour() |
1071 |
|
|
self.umn_scalebar.get_color().set_rgbcolor(previewcolor.Red(), |
1072 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
1073 |
|
|
previewimgcolor = self.previewimgcolor.GetBackgroundColour() |
1074 |
|
|
self.umn_scalebar.get_imagecolor().set_rgbcolor(previewimgcolor.Red(), |
1075 |
|
|
previewimgcolor.Green(), previewimgcolor.Blue()) |
1076 |
|
|
self.result ="OK" |
1077 |
|
|
self.end_dialog(self.result) |
1078 |
|
|
|
1079 |
|
|
def OnCancel(self, event): |
1080 |
|
|
self.end_dialog(None) |
1081 |
|
|
|
1082 |
|
|
|
1083 |
jschuengel |
2303 |
class Metadata_CustomDataTable(wxPyGridTableBase): |
1084 |
|
|
""" |
1085 |
jschuengel |
2318 |
creates a custum Grid. |
1086 |
|
|
|
1087 |
|
|
copied from the wx demo. |
1088 |
jschuengel |
2303 |
""" |
1089 |
|
|
def __init__(self, data): |
1090 |
|
|
wxPyGridTableBase.__init__(self) |
1091 |
|
|
|
1092 |
|
|
self.colLabels = ['ID', 'Description'] |
1093 |
|
|
self.dataTypes = [wxGRID_VALUE_STRING, |
1094 |
|
|
wxGRID_VALUE_STRING |
1095 |
|
|
] |
1096 |
jschuengel |
2318 |
|
1097 |
jschuengel |
2303 |
if data: |
1098 |
|
|
self.data = data |
1099 |
|
|
else: |
1100 |
|
|
self.data = [["",""]] #-------------------------------------------------- |
1101 |
|
|
# required methods for the wxPyGridTableBase interface |
1102 |
|
|
|
1103 |
|
|
def GetNumberRows(self): |
1104 |
|
|
return len(self.data) + 1 |
1105 |
|
|
|
1106 |
|
|
def GetNumberCols(self): |
1107 |
jschuengel |
2318 |
return len(self.data[0]) |
1108 |
jschuengel |
2303 |
|
1109 |
|
|
def IsEmptyCell(self, row, col): |
1110 |
|
|
try: |
1111 |
|
|
return not self.data[row][col] |
1112 |
|
|
except IndexError: |
1113 |
|
|
return true |
1114 |
|
|
|
1115 |
|
|
# Get/Set values in the table. The Python version of these |
1116 |
|
|
# methods can handle any data-type, (as long as the Editor and |
1117 |
|
|
# Renderer understands the type too,) not just strings as in the |
1118 |
|
|
# C++ version. |
1119 |
|
|
def GetValue(self, row, col): |
1120 |
|
|
try: |
1121 |
|
|
return self.data[row][col] |
1122 |
|
|
except IndexError: |
1123 |
|
|
return '' |
1124 |
|
|
|
1125 |
|
|
def SetValue(self, row, col, value): |
1126 |
|
|
try: |
1127 |
|
|
self.data[row][col] = value |
1128 |
|
|
except IndexError: |
1129 |
|
|
# add a new row |
1130 |
jschuengel |
2318 |
|
1131 |
jschuengel |
2303 |
self.data.append([''] * self.GetNumberCols()) |
1132 |
|
|
self.SetValue(row, col, value) |
1133 |
|
|
|
1134 |
|
|
# tell the grid we've added a row |
1135 |
|
|
msg = wxGridTableMessage(self, # The table |
1136 |
|
|
wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it |
1137 |
|
|
1) # how many |
1138 |
|
|
|
1139 |
|
|
self.GetView().ProcessTableMessage(msg) |
1140 |
|
|
|
1141 |
jschuengel |
2318 |
#-------------------------------------------------- |
1142 |
|
|
# Some optional methods |
1143 |
jschuengel |
2303 |
|
1144 |
jschuengel |
2318 |
# Called when the grid needs to display labels |
1145 |
|
|
def GetColLabelValue(self, col): |
1146 |
|
|
return self.colLabels[col] |
1147 |
|
|
|
1148 |
|
|
# Called to determine the kind of editor/renderer to use by |
1149 |
|
|
# default, doesn't necessarily have to be the same type used |
1150 |
|
|
# natively by the editor/renderer if they know how to convert. |
1151 |
|
|
def GetTypeName(self, row, col): |
1152 |
|
|
return self.dataTypes[col] |
1153 |
|
|
|
1154 |
|
|
# Called to determine how the data can be fetched and stored by the |
1155 |
|
|
# editor and renderer. This allows you to enforce some type-safety |
1156 |
|
|
# in the grid. |
1157 |
|
|
def CanGetValueAs(self, row, col, typeName): |
1158 |
|
|
colType = self.dataTypes[col].split(':')[0] |
1159 |
|
|
if typeName == colType: |
1160 |
|
|
return true |
1161 |
|
|
else: |
1162 |
|
|
return False |
1163 |
|
|
|
1164 |
|
|
def CanSetValueAs(self, row, col, typeName): |
1165 |
|
|
return self.CanGetValueAs(row, col, typeName) |
1166 |
|
|
|
1167 |
|
|
|
1168 |
jschuengel |
2303 |
class Metadata_TableGrid(wxGrid): |
1169 |
|
|
def __init__(self, parent, data): |
1170 |
jschuengel |
2318 |
wxGrid.__init__(self, parent, -1) |
1171 |
jschuengel |
2303 |
|
1172 |
|
|
self.table = Metadata_CustomDataTable(data) |
1173 |
|
|
|
1174 |
|
|
# The second parameter means that the grid is to take ownership of the |
1175 |
|
|
# table and will destroy it when done. Otherwise you would need to keep |
1176 |
|
|
# a reference to it and call it's Destroy method later. |
1177 |
|
|
self.SetTable(self.table, true) |
1178 |
|
|
|
1179 |
|
|
self.SetRowLabelSize(0) |
1180 |
jschuengel |
2318 |
self.SetColMinimalWidth(0,180) |
1181 |
|
|
self.SetColSize(0,180) |
1182 |
|
|
self.SetColMinimalWidth(1,250) |
1183 |
|
|
self.SetColSize(1,250) |
1184 |
jschuengel |
2303 |
self.SetMargins(0,0) |
1185 |
|
|
EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick) |
1186 |
|
|
|
1187 |
|
|
def get_table(self): |
1188 |
|
|
return self.table |
1189 |
|
|
|
1190 |
|
|
# I do this because I don't like the default behaviour of not starting the |
1191 |
|
|
# cell editor on double clicks, but only a second click. |
1192 |
|
|
def OnLeftDClick(self, evt): |
1193 |
|
|
if self.CanEnableCellControl(): |
1194 |
|
|
self.EnableCellEditControl() |
1195 |
|
|
|
1196 |
|
|
|
1197 |
|
|
class Metadata_Dialog(wxDialog): |
1198 |
|
|
|
1199 |
|
|
def __init__(self, parent, ID, title, |
1200 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
1201 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
1202 |
|
|
|
1203 |
|
|
# initialize the Dialog |
1204 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
1205 |
|
|
|
1206 |
|
|
# get the web object |
1207 |
|
|
if hasattr(parent,"umn_metadata"): |
1208 |
|
|
self.umn_metadata = parent.umn_metadata |
1209 |
|
|
else: |
1210 |
|
|
self.tb_map = parent.canvas.Map() |
1211 |
|
|
self.umn_metadata = self.tb_map.extension_umn_mapobj.get_metadata() |
1212 |
|
|
|
1213 |
|
|
|
1214 |
|
|
# at all items to the dataset |
1215 |
|
|
self.grid = Metadata_TableGrid(self, self.umn_metadata.get_metadata()) |
1216 |
|
|
|
1217 |
|
|
#buttons |
1218 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
1219 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
1220 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
1221 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
1222 |
|
|
button.SetFocus() |
1223 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
1224 |
|
|
#set the button funcitons |
1225 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
1226 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
1227 |
|
|
|
1228 |
|
|
# compose the dialog |
1229 |
|
|
top = wxBoxSizer(wxVERTICAL) |
1230 |
|
|
top.Add(self.grid, 1, wxGROW|wxALL, 5) |
1231 |
|
|
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
1232 |
|
|
|
1233 |
|
|
# final layout settings |
1234 |
|
|
self.SetSizer(top) |
1235 |
|
|
#top.Fit(self) |
1236 |
|
|
|
1237 |
|
|
def OnItemActivated(self, event): |
1238 |
|
|
self.currentItem = event.m_itemIndex |
1239 |
|
|
|
1240 |
|
|
def OnDoubleClick(self, event): |
1241 |
|
|
print "OnDoubleClick" +self.list.GetItemText(self.currentItem) |
1242 |
|
|
event.Skip() |
1243 |
|
|
|
1244 |
|
|
def OnSize(self, event): |
1245 |
|
|
w,h = self.GetClientSizeTuple() |
1246 |
|
|
self.list.SetDimensions(0, 0, w, h) |
1247 |
|
|
|
1248 |
|
|
def RunDialog(self): |
1249 |
|
|
self.ShowModal() |
1250 |
|
|
self.Destroy() |
1251 |
|
|
|
1252 |
|
|
def end_dialog(self, result): |
1253 |
|
|
self.result = result |
1254 |
|
|
if self.result is not None: |
1255 |
|
|
self.EndModal(wxID_OK) |
1256 |
|
|
else: |
1257 |
|
|
self.EndModal(wxID_CANCEL) |
1258 |
|
|
self.Show(False) |
1259 |
|
|
|
1260 |
|
|
def OnOK(self, event): |
1261 |
jschuengel |
2318 |
# added all metadatas to the mapobj, |
1262 |
|
|
# first remove the old ones |
1263 |
|
|
self.umn_metadata.remove_allmetadata() |
1264 |
|
|
for x in range(self.grid.get_table().GetNumberRows()-2,-1, -1): |
1265 |
jschuengel |
2303 |
if self.grid.get_table().GetValue(x,0): |
1266 |
|
|
self.umn_metadata.add_metadata(str(self.grid.get_table().GetValue(x,0)),\ |
1267 |
|
|
str(self.grid.get_table().GetValue(x,1))) |
1268 |
jschuengel |
2318 |
|
1269 |
jschuengel |
2303 |
self.result ="OK" |
1270 |
|
|
self.end_dialog(self.result) |
1271 |
|
|
|
1272 |
|
|
def OnCancel(self, event): |
1273 |
|
|
self.end_dialog(None) |
1274 |
|
|
|
1275 |
|
|
|
1276 |
|
|
|
1277 |
|
|
|
1278 |
|
|
def metadatasettings(context): |
1279 |
|
|
win = Metadata_Dialog(context.mainwindow, -1, "Metadata Settings", |
1280 |
jschuengel |
2318 |
size=wxSize(450, 250), |
1281 |
jschuengel |
2303 |
style = wxDEFAULT_DIALOG_STYLE) |
1282 |
|
|
win.CenterOnScreen() |
1283 |
|
|
val = win.ShowModal() |
1284 |
|
|
|
1285 |
|
|
|
1286 |
jschuengel |
2267 |
def scalebarsettings(context): |
1287 |
jschuengel |
2274 |
win = Scalebar_Dialog(context.mainwindow, -1, "Scalebar Settings", |
1288 |
|
|
size=wxSize(350, 200), |
1289 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1290 |
jschuengel |
2267 |
win.CenterOnScreen() |
1291 |
|
|
val = win.ShowModal() |
1292 |
|
|
|
1293 |
jschuengel |
2257 |
def mapsettings(context): |
1294 |
jschuengel |
2274 |
win = Map_Dialog(context.mainwindow, -1, "Map Settings", |
1295 |
|
|
size=wxSize(350, 200), |
1296 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1297 |
jschuengel |
2257 |
win.CenterOnScreen() |
1298 |
|
|
val = win.ShowModal() |
1299 |
|
|
|
1300 |
jschuengel |
2271 |
def outputformatsettings(context): |
1301 |
|
|
win = OutputFormat_Dialog(context.mainwindow, -1, "OutputFormat Settings", |
1302 |
jschuengel |
2274 |
size=wxSize(350, 200), |
1303 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1304 |
jschuengel |
2271 |
win.CenterOnScreen() |
1305 |
|
|
val = win.ShowModal() |
1306 |
|
|
|
1307 |
jschuengel |
2257 |
def websettings(context): |
1308 |
jschuengel |
2274 |
win = Web_Dialog(context.mainwindow, -1, "Web Settings", |
1309 |
|
|
size=wxSize(350, 200), |
1310 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1311 |
jschuengel |
2257 |
win.CenterOnScreen() |
1312 |
|
|
val = win.ShowModal() |
1313 |
|
|
|
1314 |
jschuengel |
2303 |
def layersettings(context): |
1315 |
|
|
win = Layer_Dialog(context.mainwindow, -1, "Layer Settings", |
1316 |
|
|
size=wxSize(350, 200), |
1317 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1318 |
|
|
win.CenterOnScreen() |
1319 |
|
|
val = win.ShowModal() |
1320 |
|
|
|
1321 |
jschuengel |
2257 |
def legendsettings(context): |
1322 |
jschuengel |
2274 |
win = Legend_Dialog(context.mainwindow, -1, "Legend Settings", |
1323 |
|
|
size=wxSize(350, 200), |
1324 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1325 |
jschuengel |
2257 |
win.CenterOnScreen() |
1326 |
|
|
val = win.ShowModal() |
1327 |
|
|
|
1328 |
jschuengel |
2282 |
# TODO: Maybe can be imported from another class |
1329 |
|
|
# check if an mapobj exists, to control the menuitem is available or not |
1330 |
|
|
def _has_umn_mapobj(context): |
1331 |
|
|
"""Return true if a umn_mapobj exists""" |
1332 |
|
|
return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj") |
1333 |
|
|
|
1334 |
jschuengel |
2303 |
def _has_umn_mapobj_and_selectedlayer(context): |
1335 |
|
|
"""Return true if a umn_mapobj exists""" |
1336 |
jschuengel |
2318 |
# temporary disabled |
1337 |
|
|
return False |
1338 |
jschuengel |
2303 |
if context.mainwindow.has_selected_layer(): |
1339 |
|
|
return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj") |
1340 |
|
|
else: |
1341 |
|
|
return False |
1342 |
jschuengel |
2282 |
|
1343 |
jschuengel |
2257 |
# ################################### |
1344 |
|
|
# |
1345 |
|
|
# Hook in MapServer Extension into Thuban |
1346 |
|
|
# |
1347 |
|
|
# ################################### |
1348 |
|
|
|
1349 |
|
|
# find the extensions menu (create it anew if not found) |
1350 |
jschuengel |
2274 |
experimental_menu = main_menu.FindOrInsertMenu("experimental", |
1351 |
|
|
_("Experimenta&l")) |
1352 |
jschuengel |
2257 |
# find the extension menu and add a new submenu if found |
1353 |
jschuengel |
2274 |
mapserver_menu = experimental_menu.FindOrInsertMenu("mapserver", |
1354 |
|
|
_("&MapServer")) |
1355 |
jschuengel |
2257 |
|
1356 |
jschuengel |
2282 |
# find the MapServer menu and add a new submenu if found |
1357 |
|
|
mapserver_edit_menu = mapserver_menu.FindOrInsertMenu("edit_mapfile", |
1358 |
|
|
_("&Edit mapfile"), \ |
1359 |
jschuengel |
2318 |
after = "import_layer_from_mapfile") |
1360 |
jschuengel |
2257 |
|
1361 |
|
|
# register the new command (Map Settings Dialog) |
1362 |
jschuengel |
2282 |
registry.Add(Command("Map Settings", _("Map"), mapsettings, |
1363 |
|
|
helptext = _("Edit the Map Setting"), \ |
1364 |
|
|
sensitive = _has_umn_mapobj)) |
1365 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1366 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Map Settings") |
1367 |
jschuengel |
2257 |
|
1368 |
jschuengel |
2271 |
|
1369 |
jschuengel |
2257 |
# register the new command (Map Settings Dialog) |
1370 |
jschuengel |
2282 |
registry.Add(Command("Web Settings", _("Web"), |
1371 |
jschuengel |
2274 |
websettings, |
1372 |
jschuengel |
2282 |
helptext = _("Edit the Web Setting"), \ |
1373 |
|
|
sensitive = _has_umn_mapobj)) |
1374 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1375 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Web Settings") |
1376 |
jschuengel |
2257 |
|
1377 |
jschuengel |
2303 |
# register the new command (Layer Settings Dialog) |
1378 |
|
|
registry.Add(Command("Layer Settings", _("Layer"), |
1379 |
|
|
layersettings, |
1380 |
|
|
helptext = _("Edit the Layer Setting of the aktive Layer"), \ |
1381 |
|
|
sensitive = _has_umn_mapobj_and_selectedlayer)) |
1382 |
|
|
# finally add the new entry to the extensions menu |
1383 |
|
|
mapserver_edit_menu.InsertItem("Layer Settings") |
1384 |
|
|
|
1385 |
jschuengel |
2257 |
# register the new command (Legend Settings Dialog) |
1386 |
jschuengel |
2282 |
registry.Add(Command("Legend Settings", _("Legend"), |
1387 |
jschuengel |
2274 |
legendsettings, |
1388 |
jschuengel |
2282 |
helptext = _("Edit the Legend Setting"), \ |
1389 |
|
|
sensitive = _has_umn_mapobj)) |
1390 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1391 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Legend Settings") |
1392 |
jschuengel |
2257 |
|
1393 |
jschuengel |
2267 |
# register the new command (Scalebar Settings Dialog) |
1394 |
jschuengel |
2282 |
registry.Add(Command("Scalebar Settings", _("Scalebar"), |
1395 |
jschuengel |
2274 |
scalebarsettings, |
1396 |
jschuengel |
2282 |
helptext = _("Edit the Scalebar Setting"), \ |
1397 |
|
|
sensitive = _has_umn_mapobj)) |
1398 |
jschuengel |
2267 |
# finally add the new entry to the extensions menu |
1399 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Scalebar Settings") |
1400 |
jschuengel |
2257 |
|
1401 |
jschuengel |
2303 |
# register the new command (Scalebar Settings Dialog) |
1402 |
|
|
registry.Add(Command("Metadata Settings", _("Metadata"), |
1403 |
|
|
metadatasettings, |
1404 |
|
|
helptext = _("Edit the Metadata Setting"), \ |
1405 |
|
|
sensitive = _has_umn_mapobj)) |
1406 |
|
|
# finally add the new entry to the extensions menu |
1407 |
|
|
mapserver_edit_menu.InsertItem("Metadata Settings") |
1408 |
jschuengel |
2267 |
|
1409 |
jschuengel |
2303 |
|