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 |
|
|
from mapscript import mapObj |
29 |
|
|
|
30 |
|
|
# wxPython support |
31 |
|
|
# TODO: explicitly use from .. import |
32 |
|
|
from wxPython.wx import * |
33 |
|
|
|
34 |
|
|
# Thuban |
35 |
|
|
# use _() already now for all strings that may later be translated |
36 |
|
|
from Thuban import _ |
37 |
|
|
|
38 |
|
|
# Thuban has named commands which can be registered in the central |
39 |
|
|
# instance registry. |
40 |
|
|
from Thuban.UI.command import registry, Command |
41 |
|
|
|
42 |
|
|
# needed to add the new menu |
43 |
|
|
from Thuban.UI.mainwindow import main_menu |
44 |
|
|
|
45 |
|
|
# import Map Object for the Mapfile |
46 |
|
|
from mapfile import MF_Map |
47 |
|
|
|
48 |
|
|
from Thuban.UI.colordialog import ColorDialog |
49 |
|
|
|
50 |
|
|
from mapfile import unit_type, legend_status_type, legend_position_type, \ |
51 |
jschuengel |
2267 |
label_font_type, scalebar_status_type, scalebar_style_type, \ |
52 |
jschuengel |
2274 |
scalebar_position_type, label_position_type |
53 |
jschuengel |
2257 |
|
54 |
|
|
# ################################### |
55 |
|
|
# |
56 |
|
|
# Mainpart of the Extension |
57 |
|
|
# |
58 |
|
|
# ################################### |
59 |
|
|
|
60 |
|
|
ID_COLOR_CHANGE= 8001 |
61 |
jschuengel |
2267 |
ID_IMGCOLOR_CHANGE = 8002 |
62 |
jschuengel |
2257 |
|
63 |
|
|
class Map_Dialog(wxDialog): |
64 |
|
|
|
65 |
|
|
def __init__(self, parent, ID, title, |
66 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
67 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
68 |
|
|
|
69 |
|
|
# initialize the Dialog |
70 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
71 |
|
|
|
72 |
|
|
# parent.canvas.Map() |
73 |
|
|
self.tb_map = parent.canvas.Map() |
74 |
|
|
self.tb_map_umn = self.tb_map.extension_umn_mapobj |
75 |
|
|
|
76 |
|
|
# create name |
77 |
|
|
box_name = wxBoxSizer(wxHORIZONTAL) |
78 |
|
|
box_name.Add(wxStaticText(self, -1, _("Map-Name:")), 0, |
79 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
80 |
|
|
box_name.Add(wxStaticText(self, -1, self.tb_map.Title()), 0, |
81 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
82 |
|
|
|
83 |
|
|
#create size settings |
84 |
jschuengel |
2271 |
insidetxt = self.tb_map_umn.get_size() |
85 |
jschuengel |
2274 |
staticSize = wxStaticBox(self, 1010, _("Size"), style = 0, |
86 |
|
|
name = "staticBox", ) |
87 |
jschuengel |
2257 |
box_size = wxStaticBoxSizer(staticSize, wxVERTICAL) |
88 |
|
|
|
89 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
90 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 4) |
91 |
|
|
self.text_width = wxTextCtrl(self, -1, str(insidetxt[0])) |
92 |
|
|
box_sizepartWidth.Add(self.text_width, 2, wxALL, 4) |
93 |
|
|
box_size.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 5) |
94 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
95 |
jschuengel |
2274 |
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, |
96 |
|
|
wxALL, 4) |
97 |
jschuengel |
2257 |
self.text_height = wxTextCtrl(self, -1, str(insidetxt[1])) |
98 |
|
|
box_sizepartHeight.Add(self.text_height, 2, wxALL, 4) |
99 |
|
|
box_size.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 5) |
100 |
|
|
|
101 |
jschuengel |
2282 |
# get the web object |
102 |
|
|
self.tb_map = parent.canvas.Map() |
103 |
|
|
self.tb_map_umn = self.tb_map.extension_umn_mapobj |
104 |
|
|
|
105 |
|
|
#get the imagetype |
106 |
|
|
umn_imagetype = self.tb_map_umn.get_imagetype() |
107 |
|
|
# create a list with the outputformat names |
108 |
|
|
umn_outputformats = [] |
109 |
|
|
for format in self.tb_map_umn.get_alloutputformats(): |
110 |
|
|
umn_outputformats.append(format.get_name()) |
111 |
|
|
#Imagetype selector |
112 |
|
|
box_imagetypeStatic = wxStaticBox(self, -1, _("Image Type"), |
113 |
|
|
style = 0, name = "imagetype") |
114 |
|
|
box_imagetype = wxStaticBoxSizer(box_imagetypeStatic, wxVERTICAL) |
115 |
|
|
self.choice_imgtype = wxChoice(self, 8060, (80, 50), |
116 |
|
|
choices = umn_outputformats) |
117 |
|
|
EVT_CHOICE(self, 8060, self.EvtChoiceBox) |
118 |
|
|
self.choice_imgtype.SetStringSelection(umn_imagetype) |
119 |
|
|
box_imagetype.Add(self.choice_imgtype,0, wxEXPAND, wxALL, 5) |
120 |
|
|
|
121 |
jschuengel |
2274 |
#unittype |
122 |
jschuengel |
2257 |
insideunit = self.tb_map_umn.get_units() |
123 |
jschuengel |
2274 |
#Unittype selector |
124 |
|
|
box_unitsStatic = wxStaticBox(self, 1011, _("Unit Type"), |
125 |
|
|
style = 0, name = "imagecolor") |
126 |
jschuengel |
2257 |
box_units = wxStaticBoxSizer(box_unitsStatic, wxVERTICAL) |
127 |
|
|
sam = [] |
128 |
|
|
for key in unit_type: |
129 |
|
|
sam.append(unit_type[key]) |
130 |
|
|
self.choice_units = wxChoice(self, 40, (80, 50), choices = sam) |
131 |
|
|
self.choice_units.SetStringSelection(insideunit) |
132 |
|
|
box_units.Add(self.choice_units,0, wxEXPAND, wxALL, 5) |
133 |
|
|
|
134 |
|
|
# color chouser |
135 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("ImageColor"), |
136 |
|
|
style = 0, name = "imagecolor") |
137 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
138 |
|
|
|
139 |
|
|
# preview box |
140 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self,99, name = 'backgroundPanel', |
141 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
142 |
jschuengel |
2257 |
imagecolor = self.tb_map_umn.get_imagecolor() |
143 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(imagecolor.get_red(), |
144 |
|
|
imagecolor.get_green(), imagecolor.get_blue())) |
145 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
146 |
|
|
# color change button, opens a new color dialog |
147 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
148 |
|
|
button.SetFocus() |
149 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
150 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
151 |
|
|
|
152 |
jschuengel |
2271 |
# status |
153 |
|
|
umn_status = self.tb_map_umn.get_status() |
154 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=["True","False"], |
155 |
|
|
label='status', majorDimension=1, |
156 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
157 |
|
|
self.choice_status.SetStringSelection(str(umn_status)) |
158 |
|
|
|
159 |
jschuengel |
2257 |
#buttons |
160 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
161 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
162 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
163 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
164 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
165 |
jschuengel |
2274 |
#button functions |
166 |
jschuengel |
2257 |
EVT_BUTTON(self, wxID_OK, self.OnOK) |
167 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
168 |
|
|
|
169 |
|
|
#add all boxes to the box top |
170 |
|
|
top = wxBoxSizer(wxVERTICAL) |
171 |
|
|
top.Add(box_name, 0, wxEXPAND |wxALL, 5) |
172 |
|
|
top.Add(box_size, 0, wxEXPAND |wxALL, 5) |
173 |
jschuengel |
2282 |
top.Add(box_imagetype,0, wxEXPAND |wxALL, 5) |
174 |
jschuengel |
2257 |
top.Add(box_units,0, wxEXPAND |wxALL, 5) |
175 |
jschuengel |
2271 |
top.Add(box_color,0, wxEXPAND |wxALL, 5) |
176 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
177 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
178 |
|
|
|
179 |
|
|
# final layout settings |
180 |
|
|
self.SetSizer(top) |
181 |
|
|
top.Fit(self) |
182 |
|
|
|
183 |
|
|
def OnChangeColor(self, event): |
184 |
|
|
cur = self.tb_map_umn.get_imagecolor().get_thubancolor() |
185 |
|
|
dialog = ColorDialog(self) |
186 |
|
|
dialog.SetColor(cur) |
187 |
|
|
self.retcolor = None |
188 |
|
|
if dialog.ShowModal() == wxID_OK: |
189 |
|
|
self.retcolor = dialog.GetColor() |
190 |
|
|
dialog.Destroy() |
191 |
|
|
if self.retcolor: |
192 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
193 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
194 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
195 |
|
|
self.previewcolor.SetBackgroundColour(wxColour((self.redcolor), |
196 |
|
|
int(self.greencolor), int(self.bluecolor))) |
197 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
198 |
|
|
self.previewcolor.Refresh() |
199 |
|
|
|
200 |
|
|
def EvtChoiceBox(self, event): |
201 |
|
|
outformat = self.tb_map_umn.get_outputformat().get_name() |
202 |
jschuengel |
2257 |
|
203 |
|
|
def RunDialog(self): |
204 |
|
|
self.ShowModal() |
205 |
|
|
self.Destroy() |
206 |
|
|
|
207 |
|
|
def end_dialog(self, result): |
208 |
|
|
self.result = result |
209 |
|
|
if self.result is not None: |
210 |
|
|
self.EndModal(wxID_OK) |
211 |
|
|
else: |
212 |
|
|
self.EndModal(wxID_CANCEL) |
213 |
|
|
self.Show(False) |
214 |
|
|
|
215 |
|
|
def OnOK(self, event): |
216 |
jschuengel |
2271 |
self.tb_map_umn.set_size(int(self.text_width.GetValue()), |
217 |
|
|
int(self.text_height.GetValue())) |
218 |
jschuengel |
2257 |
self.tb_map_umn.set_units(self.choice_units.GetStringSelection()) |
219 |
jschuengel |
2271 |
if self.choice_status.GetStringSelection() == "True": |
220 |
|
|
self.tb_map_umn.set_status(True) |
221 |
|
|
else: |
222 |
|
|
self.tb_map_umn.set_status(False) |
223 |
jschuengel |
2267 |
previewcolor = self.previewcolor.GetBackgroundColour() |
224 |
|
|
self.tb_map_umn.get_imagecolor().set_rgbcolor(previewcolor.Red(), |
225 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
226 |
jschuengel |
2271 |
self.tb_map_umn.set_imagetype(self.choice_imgtype.GetStringSelection()) |
227 |
|
|
self.result ="OK" |
228 |
|
|
self.end_dialog(self.result) |
229 |
|
|
|
230 |
|
|
def OnCancel(self, event): |
231 |
|
|
self.end_dialog(None) |
232 |
|
|
|
233 |
|
|
|
234 |
jschuengel |
2257 |
class Web_Dialog(wxDialog): |
235 |
|
|
|
236 |
|
|
def __init__(self, parent, ID, title, |
237 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
238 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
239 |
|
|
|
240 |
|
|
# initialize the Dialog |
241 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
242 |
|
|
|
243 |
|
|
# get the web object |
244 |
|
|
self.tb_map = parent.canvas.Map() |
245 |
|
|
self.umn_web = self.tb_map.extension_umn_mapobj.get_web() |
246 |
jschuengel |
2282 |
|
247 |
|
|
# Template |
248 |
|
|
box_template = wxBoxSizer(wxHORIZONTAL) |
249 |
|
|
box_template.Add(wxStaticText(self, -1, _("Template:")), 0, |
250 |
|
|
wxALL|wxALIGN_LEFT, 4) |
251 |
|
|
self.text_template = wxTextCtrl(self, -1, |
252 |
|
|
str(self.umn_web.get_template())) |
253 |
|
|
self.text_template.SetSize((250,self.text_template.GetSize()[1])) |
254 |
|
|
box_template.Add(self.text_template, 0, |
255 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
256 |
|
|
|
257 |
jschuengel |
2257 |
# Imagepath |
258 |
|
|
box_imagepath = wxBoxSizer(wxHORIZONTAL) |
259 |
|
|
box_imagepath.Add(wxStaticText(self, -1, _("Imagepath:")), 0, |
260 |
|
|
wxALL|wxALIGN_LEFT, 4) |
261 |
jschuengel |
2274 |
self.text_imagepath = wxTextCtrl(self, -1, |
262 |
|
|
str(self.umn_web.get_imagepath())) |
263 |
jschuengel |
2257 |
box_imagepath.Add(self.text_imagepath, 0, |
264 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
265 |
|
|
|
266 |
|
|
# Imageurl |
267 |
|
|
box_imageurl = wxBoxSizer(wxHORIZONTAL) |
268 |
|
|
box_imageurl.Add(wxStaticText(self, -1, _("Imageurl:")), 0, |
269 |
|
|
wxALL|wxALIGN_LEFT, 4) |
270 |
jschuengel |
2274 |
self.text_imageurl = wxTextCtrl(self, -1, |
271 |
|
|
str(self.umn_web.get_imageurl())) |
272 |
jschuengel |
2257 |
box_imageurl.Add(self.text_imageurl, 0, |
273 |
|
|
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
274 |
|
|
|
275 |
|
|
#buttons |
276 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
277 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
278 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
279 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
280 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
281 |
|
|
#set the button funcitons |
282 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
283 |
jschuengel |
2271 |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
284 |
|
|
|
285 |
|
|
# compose the final dialog |
286 |
|
|
top = wxBoxSizer(wxVERTICAL) |
287 |
jschuengel |
2282 |
top.Add(box_template, 0, wxEXPAND |wxALL, 5) |
288 |
jschuengel |
2271 |
top.Add(box_imagepath, 0, wxEXPAND |wxALL, 5) |
289 |
|
|
top.Add(box_imageurl, 0, wxEXPAND |wxALL, 5) |
290 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
291 |
|
|
|
292 |
|
|
# final layout settings |
293 |
|
|
self.SetSizer(top) |
294 |
|
|
top.Fit(self) |
295 |
|
|
|
296 |
|
|
def RunDialog(self): |
297 |
|
|
self.ShowModal() |
298 |
|
|
self.Destroy() |
299 |
|
|
|
300 |
|
|
def end_dialog(self, result): |
301 |
|
|
self.result = result |
302 |
|
|
if self.result is not None: |
303 |
|
|
self.EndModal(wxID_OK) |
304 |
|
|
else: |
305 |
|
|
self.EndModal(wxID_CANCEL) |
306 |
|
|
self.Show(False) |
307 |
|
|
|
308 |
|
|
def OnOK(self, event): |
309 |
jschuengel |
2282 |
self.umn_web.set_template(self.text_template.GetValue()) |
310 |
jschuengel |
2257 |
self.umn_web.set_imagepath(self.text_imagepath.GetValue()) |
311 |
|
|
self.umn_web.set_imageurl(self.text_imageurl.GetValue()) |
312 |
|
|
self.result ="OK" |
313 |
|
|
self.end_dialog(self.result) |
314 |
|
|
|
315 |
|
|
def OnCancel(self, event): |
316 |
|
|
self.end_dialog(None) |
317 |
|
|
|
318 |
|
|
|
319 |
|
|
ID_LABEL_CHANGE = 8011 |
320 |
|
|
|
321 |
|
|
class Legend_Dialog(wxDialog): |
322 |
|
|
|
323 |
|
|
def __init__(self, parent, ID, title, |
324 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
325 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
326 |
|
|
|
327 |
|
|
# initialize the Dialog |
328 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
329 |
|
|
|
330 |
|
|
# get the web object |
331 |
|
|
self.tb_map = parent.canvas.Map() |
332 |
|
|
self.umn_legend = self.tb_map.extension_umn_mapobj.get_legend() |
333 |
|
|
|
334 |
|
|
# create the Keysize |
335 |
jschuengel |
2274 |
keySize = wxStaticBox(self, 1010, _("KeySize"), style = 0, |
336 |
|
|
name = "KeySize Box", ) |
337 |
jschuengel |
2257 |
box_keysize = wxStaticBoxSizer(keySize, wxVERTICAL) |
338 |
|
|
umn_legend_keysize = self.umn_legend.get_keysize() |
339 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
340 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2) |
341 |
|
|
self.text_keysize_width = wxSpinCtrl(self, -1, |
342 |
|
|
value=str(umn_legend_keysize[0]), max=100, min=0, |
343 |
|
|
name='keywidth', style=wxSP_ARROW_KEYS) |
344 |
|
|
box_sizepartWidth.Add(self.text_keysize_width, 2, wxALL, 2) |
345 |
|
|
box_keysize.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2) |
346 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
347 |
|
|
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2), |
348 |
|
|
self.text_keysize_height = wxSpinCtrl(self, -1, |
349 |
|
|
value=str(umn_legend_keysize[1]), max=100, min=0, |
350 |
|
|
name='keyheight', style=wxSP_ARROW_KEYS) |
351 |
|
|
box_sizepartHeight.Add(self.text_keysize_height, 2, wxALL, 2) |
352 |
|
|
box_keysize.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2) |
353 |
|
|
|
354 |
|
|
# create the Keyspacing |
355 |
jschuengel |
2274 |
keySpacing= wxStaticBox(self, 1010, _("KeySpacing"), style = 0, |
356 |
|
|
name = "KeySpacing Box", ) |
357 |
jschuengel |
2257 |
box_keyspacing = wxStaticBoxSizer(keySpacing, wxVERTICAL) |
358 |
|
|
umn_legend_keyspacing = self.umn_legend.get_keyspacing() |
359 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
360 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2) |
361 |
|
|
self.text_keyspacing_width = wxSpinCtrl(self, -1, |
362 |
jschuengel |
2274 |
value=str(umn_legend_keyspacing[0]), max=100, |
363 |
|
|
min=0, name='spacingwidth', style=wxSP_ARROW_KEYS) |
364 |
jschuengel |
2257 |
box_sizepartWidth.Add(self.text_keyspacing_width, 2, wxALL, 2) |
365 |
|
|
box_keyspacing.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2) |
366 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
367 |
|
|
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2), |
368 |
|
|
self.text_keyspacing_height = wxSpinCtrl(self, -1, |
369 |
jschuengel |
2274 |
value=str(umn_legend_keyspacing[1]), max=100, |
370 |
|
|
min=0,name='spacingheight', style=wxSP_ARROW_KEYS) |
371 |
jschuengel |
2257 |
box_sizepartHeight.Add(self.text_keyspacing_height, 2, wxALL, 2) |
372 |
|
|
box_keyspacing.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2) |
373 |
|
|
|
374 |
|
|
# color chooser |
375 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("ImageColor"), style = 0, |
376 |
|
|
name = "imagecolor") |
377 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
378 |
|
|
# preview box |
379 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'imagecolorPanel', |
380 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
381 |
jschuengel |
2257 |
imagecolor = self.umn_legend.get_imagecolor() |
382 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(imagecolor.get_red(), |
383 |
|
|
imagecolor.get_green(), imagecolor.get_blue())) |
384 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
385 |
|
|
# color change button, opens a new color dialog |
386 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
387 |
|
|
button.SetFocus() |
388 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
389 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
390 |
|
|
|
391 |
jschuengel |
2267 |
# status |
392 |
jschuengel |
2274 |
umn_legend_status= self.umn_legend.get_status(mode="string") |
393 |
jschuengel |
2257 |
possible_choices = [] |
394 |
|
|
for key in legend_status_type: |
395 |
|
|
possible_choices.append(legend_status_type[key]) |
396 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=possible_choices, |
397 |
|
|
label='Status', majorDimension=1, |
398 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
399 |
|
|
self.choice_status.SetStringSelection(umn_legend_status) |
400 |
|
|
|
401 |
|
|
# create the positionbox |
402 |
jschuengel |
2274 |
umn_legend_position= self.umn_legend.get_position(mode="string") |
403 |
jschuengel |
2257 |
possible_choices = [] |
404 |
|
|
for key in legend_position_type: |
405 |
|
|
possible_choices.append(legend_position_type[key]) |
406 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
407 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
408 |
|
|
name='position check', |
409 |
|
|
size=wxDefaultSize, |
410 |
|
|
style=wxRA_SPECIFY_ROWS) |
411 |
jschuengel |
2257 |
self.choice_position.SetStringSelection(umn_legend_position) |
412 |
|
|
|
413 |
jschuengel |
2271 |
# button for label |
414 |
|
|
labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label")) |
415 |
jschuengel |
2257 |
EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel) |
416 |
|
|
|
417 |
|
|
#buttons |
418 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
419 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
420 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
421 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
422 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
423 |
|
|
#set the button funcitons |
424 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
425 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
426 |
jschuengel |
2271 |
|
427 |
|
|
# compose the final layout |
428 |
|
|
top = wxBoxSizer(wxVERTICAL) |
429 |
|
|
top.Add(box_keysize,0, wxEXPAND |wxALL, 5) |
430 |
|
|
top.Add(box_keyspacing,0, wxEXPAND |wxALL, 5) |
431 |
|
|
top.Add(box_color,0, wxEXPAND |wxALL, 5) |
432 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
433 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
434 |
|
|
top.Add(labelbutton, 1, wxEXPAND|wxALL, 5) |
435 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
436 |
|
|
|
437 |
|
|
# final layout settings |
438 |
|
|
self.SetSizer(top) |
439 |
|
|
top.Fit(self) |
440 |
|
|
|
441 |
|
|
def OnChangeLabel(self, event): |
442 |
jschuengel |
2267 |
self.umn_label = self.umn_legend.get_label() |
443 |
jschuengel |
2274 |
dialog = Label_Dialog(self, -1, "Legend Label Settings", |
444 |
|
|
size=wxSize(350, 200), |
445 |
jschuengel |
2257 |
style = wxDEFAULT_DIALOG_STYLE |
446 |
|
|
) |
447 |
|
|
dialog.CenterOnScreen() |
448 |
|
|
if dialog.ShowModal() == wxID_OK: |
449 |
|
|
return |
450 |
|
|
dialog.Destroy() |
451 |
|
|
|
452 |
|
|
def OnChangeColor(self, event): |
453 |
|
|
cur = self.umn_legend.get_imagecolor().get_thubancolor() |
454 |
|
|
dialog = ColorDialog(self) |
455 |
|
|
dialog.SetColor(cur) |
456 |
|
|
self.retcolor = None |
457 |
|
|
if dialog.ShowModal() == wxID_OK: |
458 |
|
|
self.retcolor = dialog.GetColor() |
459 |
|
|
dialog.Destroy() |
460 |
|
|
if self.retcolor: |
461 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
462 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
463 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
464 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
465 |
|
|
int(self.greencolor), |
466 |
|
|
int(self.bluecolor))) |
467 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
468 |
|
|
self.previewcolor.Refresh() |
469 |
jschuengel |
2257 |
|
470 |
|
|
def RunDialog(self): |
471 |
|
|
self.ShowModal() |
472 |
|
|
self.Destroy() |
473 |
|
|
|
474 |
|
|
def end_dialog(self, result): |
475 |
|
|
self.result = result |
476 |
|
|
if self.result is not None: |
477 |
|
|
self.EndModal(wxID_OK) |
478 |
|
|
else: |
479 |
|
|
self.EndModal(wxID_CANCEL) |
480 |
|
|
self.Show(False) |
481 |
|
|
|
482 |
|
|
def OnOK(self, event): |
483 |
jschuengel |
2271 |
self.umn_legend.set_keysize(self.text_keysize_width.GetValue(), |
484 |
|
|
self.text_keysize_height.GetValue()) |
485 |
|
|
self.umn_legend.set_keyspacing(self.text_keyspacing_width.GetValue(), |
486 |
|
|
self.text_keyspacing_height.GetValue()) |
487 |
jschuengel |
2257 |
self.umn_legend.set_status(self.choice_status.GetStringSelection()) |
488 |
|
|
self.umn_legend.set_position(self.choice_position.GetStringSelection()) |
489 |
jschuengel |
2267 |
previewcolor = self.previewcolor.GetBackgroundColour() |
490 |
|
|
self.umn_legend.get_imagecolor().set_rgbcolor(previewcolor.Red(), |
491 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
492 |
jschuengel |
2257 |
self.result ="OK" |
493 |
|
|
self.end_dialog(self.result) |
494 |
|
|
|
495 |
|
|
def OnCancel(self, event): |
496 |
|
|
self.end_dialog(None) |
497 |
|
|
|
498 |
|
|
class Label_Dialog(wxDialog): |
499 |
|
|
|
500 |
|
|
def __init__(self, parent, ID, title, |
501 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
502 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
503 |
|
|
|
504 |
|
|
# initialize the Dialog |
505 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
506 |
|
|
|
507 |
|
|
# get the web object |
508 |
jschuengel |
2267 |
self.umn_label = parent.umn_label |
509 |
jschuengel |
2257 |
|
510 |
|
|
# size |
511 |
jschuengel |
2274 |
labelsize= wxStaticBox(self, 1010, _("Size"), style = 0, |
512 |
|
|
name = "Size Box", ) |
513 |
jschuengel |
2257 |
box_labelsize = wxStaticBoxSizer(labelsize, wxVERTICAL) |
514 |
|
|
umn_label_size= self.umn_label.get_size() |
515 |
|
|
box_size = wxBoxSizer(wxHORIZONTAL) |
516 |
|
|
self.text_labelsize = wxSpinCtrl(self, -1, |
517 |
|
|
value=str(umn_label_size), max=10, min=0, |
518 |
|
|
name='size', style=wxSP_ARROW_KEYS) |
519 |
|
|
box_size.Add(self.text_labelsize, 2, wxALL, 2) |
520 |
|
|
box_labelsize.Add(box_size, 0, wxALIGN_RIGHT | wxALL, 2) |
521 |
|
|
|
522 |
|
|
# color chooser |
523 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0, |
524 |
|
|
name = "color") |
525 |
jschuengel |
2257 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
526 |
|
|
# preview box |
527 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'colorPanel', |
528 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
529 |
jschuengel |
2257 |
color = self.umn_label.get_color() |
530 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(color.get_red(), |
531 |
|
|
color.get_green(), color.get_blue())) |
532 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
533 |
|
|
# color change button, opens a new color dialog |
534 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
535 |
|
|
button.SetFocus() |
536 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
537 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
538 |
|
|
|
539 |
|
|
#get the set type |
540 |
|
|
insidetype = self.umn_label.get_type() |
541 |
|
|
#create the type selector for fonttype (Bitmap, TrueType) |
542 |
|
|
# TODO: Truetype is not supported yet |
543 |
jschuengel |
2274 |
box_typeStatic = wxStaticBox(self, 1011, _("Type"), style = 0, |
544 |
|
|
name = "type") |
545 |
jschuengel |
2257 |
box_type = wxStaticBoxSizer(box_typeStatic, wxVERTICAL) |
546 |
|
|
sam = [] |
547 |
|
|
for key in label_font_type: |
548 |
|
|
# dont add truetype |
549 |
|
|
#if key != 0: |
550 |
|
|
sam.append(label_font_type[key]) |
551 |
|
|
self.choice_type = wxChoice(self, 40, (80, 50), choices = sam) |
552 |
|
|
self.choice_type.SetStringSelection(insidetype) |
553 |
|
|
box_type.Add(self.choice_type,0, wxEXPAND, wxALL, 5) |
554 |
jschuengel |
2271 |
|
555 |
jschuengel |
2257 |
# Offset |
556 |
jschuengel |
2274 |
offset= wxStaticBox(self, 1010, _("Offset"), style = 0, |
557 |
|
|
name = "Offset Box", ) |
558 |
jschuengel |
2257 |
box_offset = wxStaticBoxSizer(offset, wxVERTICAL) |
559 |
|
|
umn_label_offset = self.umn_label.get_offset() |
560 |
|
|
box_offsetX = wxBoxSizer(wxHORIZONTAL) |
561 |
|
|
box_offsetX.Add(wxStaticText(self, -1, _("X: ")), 0, wxALL, 2) |
562 |
|
|
self.text_offsetx = wxSpinCtrl(self, -1, |
563 |
|
|
value=str(umn_label_offset[0]), max=20, min=0, |
564 |
|
|
name='offsetX', style=wxSP_ARROW_KEYS) |
565 |
|
|
box_offsetX.Add(self.text_offsetx, 2, wxALL, 2) |
566 |
|
|
box_offset.Add(box_offsetX, 0, wxALIGN_RIGHT | wxALL, 2) |
567 |
|
|
box_offsetY = wxBoxSizer(wxHORIZONTAL) |
568 |
|
|
box_offsetY.Add(wxStaticText(self, -1, _("Y: ")), 0, wxALL, 2), |
569 |
|
|
self.text_offsety = wxSpinCtrl(self, -1, |
570 |
|
|
value=str(umn_label_offset[1]), max=100, min=0, |
571 |
|
|
name='offsetY', style=wxSP_ARROW_KEYS) |
572 |
|
|
box_offsetY.Add(self.text_offsety, 2, wxALL, 2) |
573 |
|
|
box_offset.Add(box_offsetY, 0, wxALIGN_RIGHT | wxALL, 2) |
574 |
|
|
|
575 |
jschuengel |
2271 |
# partials |
576 |
jschuengel |
2267 |
umn_partials = self.umn_label.get_partials() |
577 |
|
|
self.choice_partials = wxRadioBox(self, -1, choices=["True","False"], |
578 |
jschuengel |
2274 |
label='partials', majorDimension=1, |
579 |
|
|
name='partials check', |
580 |
|
|
size=wxDefaultSize, |
581 |
|
|
style=wxRA_SPECIFY_ROWS) |
582 |
jschuengel |
2267 |
self.choice_partials.SetStringSelection(str(umn_partials)) |
583 |
jschuengel |
2271 |
|
584 |
|
|
# force |
585 |
|
|
umn_force = self.umn_label.get_force() |
586 |
|
|
self.choice_force = wxRadioBox(self, -1, choices=["True","False"], |
587 |
|
|
label='force', majorDimension=1, |
588 |
|
|
name='force check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
589 |
|
|
self.choice_force.SetStringSelection(str(umn_force)) |
590 |
|
|
|
591 |
|
|
# buffer |
592 |
jschuengel |
2274 |
buffer = wxStaticBox(self, 1010, _("Buffer"), style = 0, |
593 |
|
|
name = "Buffer Box", ) |
594 |
jschuengel |
2271 |
box_buffer = wxStaticBoxSizer(buffer, wxVERTICAL) |
595 |
|
|
umn_buffer= self.umn_label.get_buffer() |
596 |
|
|
box_buffertext = wxBoxSizer(wxHORIZONTAL) |
597 |
|
|
self.text_buffer = wxSpinCtrl(self, -1, |
598 |
|
|
value=str(umn_buffer), max=10, min=0, |
599 |
|
|
name='size', style=wxSP_ARROW_KEYS) |
600 |
|
|
box_buffertext.Add(self.text_buffer, 2, wxALL, 2) |
601 |
|
|
box_buffer.Add(box_buffertext, 0, wxALIGN_RIGHT | wxALL, 2) |
602 |
|
|
|
603 |
|
|
# minfeaturesize |
604 |
jschuengel |
2274 |
minfeaturesize = wxStaticBox(self, 1010, _("Minfeaturesize"), |
605 |
|
|
style = 0, name = "Minfeaturesize Box") |
606 |
jschuengel |
2271 |
box_minfeaturesize = wxStaticBoxSizer(minfeaturesize, wxVERTICAL) |
607 |
|
|
umn_minfeaturesize= self.umn_label.get_minfeaturesize() |
608 |
|
|
box_minfeaturesizetext = wxBoxSizer(wxHORIZONTAL) |
609 |
|
|
self.text_minfeaturesize = wxSpinCtrl(self, -1, |
610 |
|
|
value=str(umn_minfeaturesize), max=10, min=-1, |
611 |
|
|
name='minfeaturesize', style=wxSP_ARROW_KEYS) |
612 |
|
|
box_minfeaturesizetext.Add(self.text_minfeaturesize, 2, wxALL, 2) |
613 |
|
|
box_minfeaturesize.Add(box_minfeaturesizetext, 0, |
614 |
|
|
wxALIGN_RIGHT | wxALL, 2) |
615 |
|
|
|
616 |
|
|
# mindistance |
617 |
|
|
mindistance = wxStaticBox(self, 1010, _("Mindistance"), style = 0, |
618 |
|
|
name = "Mindistance Box", ) |
619 |
|
|
box_mindistance = wxStaticBoxSizer(mindistance, wxVERTICAL) |
620 |
|
|
umn_mindistance= self.umn_label.get_mindistance() |
621 |
|
|
box_mindistancetext = wxBoxSizer(wxHORIZONTAL) |
622 |
|
|
self.text_mindistance = wxSpinCtrl(self, -1, |
623 |
|
|
value=str(umn_mindistance), max=10, min=-1, |
624 |
|
|
name='mindistance', style=wxSP_ARROW_KEYS) |
625 |
|
|
box_mindistancetext.Add(self.text_mindistance, 2, wxALL, 2) |
626 |
|
|
box_mindistance.Add(box_mindistancetext, 0, |
627 |
|
|
wxALIGN_RIGHT | wxALL, 2) |
628 |
jschuengel |
2257 |
|
629 |
jschuengel |
2271 |
# position |
630 |
jschuengel |
2274 |
umn_label_position= self.umn_label.get_position(mode="string") |
631 |
jschuengel |
2271 |
possible_choices = [] |
632 |
|
|
for key in label_position_type: |
633 |
|
|
possible_choices.append(label_position_type[key]) |
634 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
635 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
636 |
|
|
name='position check', |
637 |
|
|
size=wxDefaultSize, |
638 |
|
|
style=wxRA_SPECIFY_ROWS) |
639 |
jschuengel |
2271 |
self.choice_position.SetStringSelection(umn_label_position) |
640 |
|
|
|
641 |
jschuengel |
2257 |
#buttons |
642 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
643 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
644 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
645 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
646 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
647 |
|
|
#set the button funcitons |
648 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
649 |
|
|
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
650 |
jschuengel |
2271 |
|
651 |
|
|
# compose the Dialog |
652 |
|
|
top = wxBoxSizer(wxVERTICAL) |
653 |
|
|
|
654 |
|
|
top1 = wxBoxSizer(wxHORIZONTAL) |
655 |
|
|
top1.Add(box_labelsize,0, wxEXPAND |wxALL, 5) |
656 |
|
|
top1.Add(box_color,0, wxEXPAND |wxALL, 5) |
657 |
|
|
top1.Add(box_minfeaturesize,0, wxEXPAND |wxALL, 5) |
658 |
|
|
|
659 |
|
|
top2 = wxBoxSizer(wxHORIZONTAL) |
660 |
|
|
top2.Add(box_type,0,wxEXPAND |wxALL, 5) |
661 |
|
|
top2.Add(box_offset,0, wxEXPAND |wxALL, 5) |
662 |
|
|
top2.Add(box_mindistance,0, wxEXPAND |wxALL, 5) |
663 |
|
|
|
664 |
|
|
top3 = wxBoxSizer(wxHORIZONTAL) |
665 |
|
|
top3.Add(self.choice_partials,0, wxEXPAND |wxALL, 5) |
666 |
|
|
top3.Add(box_buffer,0, wxEXPAND |wxALL, 5) |
667 |
|
|
top3.Add(self.choice_force,0, wxEXPAND |wxALL, 5) |
668 |
|
|
|
669 |
|
|
top.Add(top1, 0, wxEXPAND) |
670 |
|
|
top.Add(top2, 0, wxEXPAND) |
671 |
|
|
top.Add(top3, 0, wxEXPAND) |
672 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
673 |
jschuengel |
2257 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
674 |
jschuengel |
2271 |
|
675 |
jschuengel |
2257 |
# final layout settings |
676 |
|
|
self.SetSizer(top) |
677 |
|
|
top.Fit(self) |
678 |
|
|
|
679 |
|
|
def OnChangeColor(self, event): |
680 |
|
|
cur = self.umn_label.get_color().get_thubancolor() |
681 |
|
|
dialog = ColorDialog(self) |
682 |
|
|
dialog.SetColor(cur) |
683 |
|
|
self.retcolor = None |
684 |
|
|
if dialog.ShowModal() == wxID_OK: |
685 |
|
|
self.retcolor = dialog.GetColor() |
686 |
|
|
dialog.Destroy() |
687 |
|
|
if self.retcolor: |
688 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
689 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
690 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
691 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
692 |
|
|
int(self.greencolor), |
693 |
|
|
int(self.bluecolor))) |
694 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
695 |
|
|
self.previewcolor.Refresh() |
696 |
jschuengel |
2257 |
|
697 |
|
|
def RunDialog(self): |
698 |
|
|
self.ShowModal() |
699 |
|
|
self.Destroy() |
700 |
|
|
|
701 |
|
|
def end_dialog(self, result): |
702 |
|
|
self.result = result |
703 |
|
|
if self.result is not None: |
704 |
|
|
self.EndModal(wxID_OK) |
705 |
|
|
else: |
706 |
|
|
self.EndModal(wxID_CANCEL) |
707 |
|
|
self.Show(False) |
708 |
|
|
|
709 |
|
|
def OnOK(self, event): |
710 |
|
|
self.umn_label.set_size(self.text_labelsize.GetValue()) |
711 |
jschuengel |
2274 |
self.umn_label.set_offset(self.text_offsetx.GetValue(), |
712 |
|
|
self.text_offsety.GetValue()) |
713 |
jschuengel |
2257 |
self.umn_label.set_type(self.choice_type.GetStringSelection()) |
714 |
jschuengel |
2267 |
if self.choice_partials.GetStringSelection() == "True": |
715 |
|
|
self.umn_label.set_partials(True) |
716 |
|
|
else: |
717 |
|
|
self.umn_label.set_partials(False) |
718 |
|
|
previewcolor = self.previewcolor.GetBackgroundColour() |
719 |
|
|
self.umn_label.get_color().set_rgbcolor(previewcolor.Red(), |
720 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
721 |
jschuengel |
2271 |
self.umn_label.set_mindistance(self.text_mindistance.GetValue()) |
722 |
|
|
self.umn_label.set_minfeaturesize(self.text_minfeaturesize.GetValue()) |
723 |
|
|
self.umn_label.set_position(self.choice_position.GetStringSelection()) |
724 |
|
|
self.umn_label.set_buffer(self.text_buffer.GetValue()) |
725 |
|
|
if self.choice_force.GetStringSelection() == "True": |
726 |
|
|
self.umn_label.set_force(True) |
727 |
|
|
else: |
728 |
|
|
self.umn_label.set_force(False) |
729 |
jschuengel |
2257 |
self.result ="OK" |
730 |
|
|
self.end_dialog(self.result) |
731 |
|
|
|
732 |
|
|
def OnCancel(self, event): |
733 |
|
|
self.end_dialog(None) |
734 |
|
|
|
735 |
jschuengel |
2267 |
class Scalebar_Dialog(wxDialog): |
736 |
|
|
|
737 |
|
|
def __init__(self, parent, ID, title, |
738 |
|
|
pos=wxDefaultPosition, size=wxDefaultSize, |
739 |
|
|
style=wxDEFAULT_DIALOG_STYLE): |
740 |
|
|
|
741 |
|
|
# initialize the Dialog |
742 |
|
|
wxDialog.__init__(self, parent, ID, title, pos, size, style) |
743 |
jschuengel |
2257 |
|
744 |
jschuengel |
2267 |
# get the web object |
745 |
|
|
self.tb_map = parent.canvas.Map() |
746 |
|
|
self.umn_scalebar = self.tb_map.extension_umn_mapobj.get_scalebar() |
747 |
|
|
|
748 |
|
|
# color chooser |
749 |
jschuengel |
2274 |
box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0, |
750 |
|
|
name = "color") |
751 |
jschuengel |
2267 |
box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL) |
752 |
|
|
# preview box |
753 |
jschuengel |
2274 |
self.previewcolor = wxPanel(self, 99, name = 'colorPanel', |
754 |
|
|
style = wxSIMPLE_BORDER | wxCLIP_CHILDREN) |
755 |
jschuengel |
2267 |
color = self.umn_scalebar.get_color() |
756 |
|
|
self.previewcolor.SetBackgroundColour(wxColour(color.get_red(), |
757 |
|
|
color.get_green(), color.get_blue())) |
758 |
|
|
box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5) |
759 |
|
|
# color change button, opens a new color dialog |
760 |
|
|
button = wxButton(self, ID_COLOR_CHANGE, _("Change Color")) |
761 |
|
|
button.SetFocus() |
762 |
|
|
EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor) |
763 |
|
|
box_color.Add(button, 1, wxEXPAND|wxALL, 5) |
764 |
|
|
# show the two color chooser horizontal |
765 |
|
|
colorHor = wxBoxSizer(wxHORIZONTAL) |
766 |
|
|
colorHor.Add(box_color,0, wxEXPAND |wxALL, 5) |
767 |
|
|
|
768 |
|
|
# imagecolor chooser |
769 |
jschuengel |
2274 |
box_imgcolorStatic = wxStaticBox(self, 1011, _("Image Color"), |
770 |
|
|
style = 0, name = "imgcolor") |
771 |
jschuengel |
2267 |
box_imgcolor = wxStaticBoxSizer(box_imgcolorStatic, wxVERTICAL) |
772 |
|
|
# preview box |
773 |
jschuengel |
2274 |
self.previewimgcolor = wxPanel(self, 99, name = 'colorPanel', |
774 |
|
|
style = wxSIMPLE_BORDER|wxCLIP_CHILDREN) |
775 |
jschuengel |
2267 |
color = self.umn_scalebar.get_imagecolor() |
776 |
|
|
self.previewimgcolor.SetBackgroundColour(wxColour(color.get_red(), |
777 |
|
|
color.get_green(), color.get_blue())) |
778 |
|
|
box_imgcolor.Add(self.previewimgcolor, 1, wxGROW | wxALL, 5) |
779 |
|
|
# color change button, opens a new color dialog |
780 |
|
|
button = wxButton(self, ID_IMGCOLOR_CHANGE, _("Change ImageColor")) |
781 |
|
|
button.SetFocus() |
782 |
|
|
EVT_BUTTON(self, ID_IMGCOLOR_CHANGE, self.OnChangeImageColor) |
783 |
|
|
box_imgcolor.Add(button, 1, wxEXPAND|wxALL, 5) |
784 |
|
|
colorHor.Add(box_imgcolor,0, wxEXPAND |wxALL, 5) |
785 |
|
|
|
786 |
|
|
# create the intervals |
787 |
jschuengel |
2274 |
intervalsStatic = wxStaticBox(self, 1010, _("Intervals"), style = 0, |
788 |
|
|
name = "Intervals Box", ) |
789 |
jschuengel |
2267 |
box_intervals = wxStaticBoxSizer(intervalsStatic, wxVERTICAL) |
790 |
|
|
umn_scalebar_intervals = self.umn_scalebar.get_intervals() |
791 |
|
|
self.text_intervals = wxSpinCtrl(self, -1, |
792 |
|
|
value=str(umn_scalebar_intervals), max=100, min=0, |
793 |
|
|
name='intervals', style=wxSP_ARROW_KEYS) |
794 |
|
|
box_intervals.Add(self.text_intervals, 0, wxALIGN_RIGHT | wxALL, 2) |
795 |
|
|
hori2 = wxBoxSizer(wxHORIZONTAL) |
796 |
|
|
hori2.Add(box_intervals,0, wxEXPAND |wxALL, 5) |
797 |
|
|
|
798 |
|
|
#style |
799 |
|
|
umn_scalebar_style= self.umn_scalebar.get_style() |
800 |
|
|
possible_choices = [] |
801 |
|
|
for key in scalebar_style_type: |
802 |
|
|
possible_choices.append(scalebar_style_type[key]) |
803 |
|
|
self.choice_style = wxRadioBox(self, -1, choices=possible_choices, |
804 |
|
|
label='Style', majorDimension=1, |
805 |
|
|
name='style check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
806 |
|
|
self.choice_style.SetSelection(umn_scalebar_style) |
807 |
|
|
hori2.Add(self.choice_style, 1, wxEXPAND|wxALL, 5) |
808 |
|
|
|
809 |
|
|
#create size settings |
810 |
|
|
try: |
811 |
|
|
insidetxt = self.umn_scalebar.get_size() |
812 |
|
|
except: |
813 |
|
|
insidetxt = (0,0) |
814 |
|
|
# create the Size Box |
815 |
jschuengel |
2274 |
staticSize = wxStaticBox(self, -1, _("Size"), style = 0, |
816 |
|
|
name="sizeBox") |
817 |
jschuengel |
2267 |
box_size = wxStaticBoxSizer(staticSize, wxHORIZONTAL) |
818 |
|
|
|
819 |
|
|
box_sizepartWidth = wxBoxSizer(wxHORIZONTAL) |
820 |
|
|
box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 4) |
821 |
|
|
self.text_width = wxTextCtrl(self, -1, str(insidetxt[0])) |
822 |
|
|
box_sizepartWidth.Add(self.text_width, 2, wxALL, 4) |
823 |
|
|
box_size.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 5) |
824 |
|
|
box_sizepartHeight = wxBoxSizer(wxHORIZONTAL) |
825 |
jschuengel |
2274 |
box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, |
826 |
|
|
wxALL, 4) |
827 |
jschuengel |
2267 |
self.text_height = wxTextCtrl(self, -1, str(insidetxt[1])) |
828 |
|
|
box_sizepartHeight.Add(self.text_height, 2, wxALL, 4) |
829 |
|
|
box_size.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 5) |
830 |
|
|
|
831 |
|
|
# status |
832 |
jschuengel |
2274 |
umn_scalebar_status= self.umn_scalebar.get_status(mode="string") |
833 |
jschuengel |
2267 |
possible_choices = [] |
834 |
|
|
for key in legend_status_type: |
835 |
|
|
possible_choices.append(scalebar_status_type[key]) |
836 |
|
|
self.choice_status = wxRadioBox(self, -1, choices=possible_choices, |
837 |
|
|
label='Status', majorDimension=1, |
838 |
|
|
name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS) |
839 |
|
|
self.choice_status.SetStringSelection(umn_scalebar_status) |
840 |
|
|
|
841 |
|
|
# position |
842 |
jschuengel |
2274 |
umn_scalebar_position= self.umn_scalebar.get_position(mode="string") |
843 |
jschuengel |
2267 |
possible_choices = [] |
844 |
|
|
for key in scalebar_position_type: |
845 |
|
|
possible_choices.append(scalebar_position_type[key]) |
846 |
|
|
self.choice_position = wxRadioBox(self, -1, choices=possible_choices, |
847 |
jschuengel |
2274 |
label='Position', majorDimension=1, |
848 |
|
|
name='position check', size=wxDefaultSize, |
849 |
|
|
style=wxRA_SPECIFY_ROWS) |
850 |
jschuengel |
2267 |
self.choice_position.SetStringSelection(umn_scalebar_position) |
851 |
|
|
|
852 |
|
|
#get the set unittype |
853 |
|
|
insideunit = self.umn_scalebar .get_units() |
854 |
|
|
#create the Unittype selector |
855 |
jschuengel |
2274 |
box_unitsStatic = wxStaticBox(self, -1, _("Unit Type"), style = 0, |
856 |
|
|
name = "unittype") |
857 |
jschuengel |
2267 |
box_units = wxStaticBoxSizer(box_unitsStatic, wxVERTICAL) |
858 |
|
|
sam = [] |
859 |
|
|
for key in unit_type: |
860 |
|
|
sam.append(unit_type[key]) |
861 |
|
|
self.choice_units = wxChoice(self, 40, (80, 50), choices = sam) |
862 |
|
|
self.choice_units.SetStringSelection(insideunit) |
863 |
jschuengel |
2271 |
box_units.Add(self.choice_units,0, wxEXPAND, wxALL, 5) |
864 |
jschuengel |
2267 |
|
865 |
jschuengel |
2271 |
# button for label |
866 |
|
|
labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label")) |
867 |
jschuengel |
2267 |
EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel) |
868 |
|
|
|
869 |
|
|
#buttons |
870 |
|
|
box_buttons = wxBoxSizer(wxHORIZONTAL) |
871 |
|
|
button = wxButton(self, wxID_OK, _("OK")) |
872 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
873 |
|
|
button = wxButton(self, wxID_CANCEL, _("Cancel")) |
874 |
|
|
button.SetFocus() |
875 |
|
|
box_buttons.Add(button, 0, wxALL, 5) |
876 |
|
|
#set the button funcitons |
877 |
|
|
EVT_BUTTON(self, wxID_OK, self.OnOK) |
878 |
jschuengel |
2271 |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
879 |
|
|
|
880 |
|
|
# compose the dialog |
881 |
|
|
top = wxBoxSizer(wxVERTICAL) |
882 |
|
|
top.Add(colorHor,0, wxEXPAND |wxALL, 5) |
883 |
|
|
top.Add(hori2, 1, wxEXPAND|wxALL, 5) |
884 |
|
|
top.Add(box_size, 1, wxEXPAND|wxALL, 5) |
885 |
|
|
top.Add(self.choice_status,0, wxEXPAND |wxALL, 5) |
886 |
|
|
top.Add(self.choice_position,0, wxEXPAND |wxALL, 5) |
887 |
|
|
top.Add(box_units, 1, wxEXPAND|wxALL, 5) |
888 |
|
|
top.Add(labelbutton, 0, wxEXPAND|wxALL, 5) |
889 |
jschuengel |
2267 |
top.Add(box_buttons, 0, wxALIGN_RIGHT) |
890 |
|
|
|
891 |
|
|
# final layout settings |
892 |
|
|
self.SetSizer(top) |
893 |
|
|
top.Fit(self) |
894 |
|
|
|
895 |
|
|
def OnChangeLabel(self, event): |
896 |
|
|
# set the umn_label for scalebar so the Label_Dialog can be used |
897 |
|
|
self.umn_label = self.umn_scalebar.get_label() |
898 |
jschuengel |
2274 |
dialog = Label_Dialog(self, -1, "Scalbar Label Settings", |
899 |
|
|
size=wxSize(350, 200), |
900 |
jschuengel |
2267 |
style = wxDEFAULT_DIALOG_STYLE |
901 |
|
|
) |
902 |
|
|
dialog.CenterOnScreen() |
903 |
|
|
if dialog.ShowModal() == wxID_OK: |
904 |
|
|
return |
905 |
|
|
dialog.Destroy() |
906 |
|
|
|
907 |
|
|
def OnChangeImageColor(self, event): |
908 |
|
|
cur = self.umn_scalebar.get_imagecolor().get_thubancolor() |
909 |
|
|
dialog = ColorDialog(self) |
910 |
|
|
dialog.SetColor(cur) |
911 |
|
|
self.retcolor = None |
912 |
|
|
if dialog.ShowModal() == wxID_OK: |
913 |
|
|
self.retcolor = dialog.GetColor() |
914 |
|
|
dialog.Destroy() |
915 |
|
|
if self.retcolor: |
916 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
917 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
918 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
919 |
jschuengel |
2274 |
self.previewimgcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
920 |
|
|
int(self.greencolor), |
921 |
|
|
int(self.bluecolor))) |
922 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
923 |
|
|
self.previewimgcolor.Refresh() |
924 |
jschuengel |
2267 |
|
925 |
|
|
def OnChangeColor(self, event): |
926 |
|
|
cur = self.umn_scalebar.get_color().get_thubancolor() |
927 |
|
|
dialog = ColorDialog(self) |
928 |
|
|
dialog.SetColor(cur) |
929 |
|
|
self.retcolor = None |
930 |
|
|
if dialog.ShowModal() == wxID_OK: |
931 |
|
|
self.retcolor = dialog.GetColor() |
932 |
|
|
dialog.Destroy() |
933 |
|
|
if self.retcolor: |
934 |
|
|
self.redcolor = int(round(self.retcolor.red*255)) |
935 |
|
|
self.greencolor = int(round(self.retcolor.green*255)) |
936 |
|
|
self.bluecolor = int(round(self.retcolor.blue*255)) |
937 |
jschuengel |
2274 |
self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor), |
938 |
|
|
int(self.greencolor), |
939 |
|
|
int(self.bluecolor))) |
940 |
jschuengel |
2282 |
# refresh the colorbox to show the new color |
941 |
|
|
self.previewcolor.Refresh() |
942 |
jschuengel |
2267 |
|
943 |
|
|
def RunDialog(self): |
944 |
|
|
self.ShowModal() |
945 |
|
|
self.Destroy() |
946 |
|
|
|
947 |
|
|
def end_dialog(self, result): |
948 |
|
|
self.result = result |
949 |
|
|
if self.result is not None: |
950 |
|
|
self.EndModal(wxID_OK) |
951 |
|
|
else: |
952 |
|
|
self.EndModal(wxID_CANCEL) |
953 |
|
|
self.Show(False) |
954 |
|
|
|
955 |
|
|
def OnOK(self, event): |
956 |
|
|
self.umn_scalebar.set_status(self.choice_status.GetStringSelection()) |
957 |
|
|
self.umn_scalebar.set_units(self.choice_units.GetStringSelection()) |
958 |
|
|
self.umn_scalebar.set_intervals(self.text_intervals.GetValue()) |
959 |
|
|
self.umn_scalebar.set_style(self.choice_style.GetSelection()) |
960 |
|
|
self.umn_scalebar.set_position(self.choice_position.GetStringSelection()) |
961 |
jschuengel |
2274 |
self.umn_scalebar.set_size(int(self.text_width.GetValue()), |
962 |
|
|
int(self.text_height.GetValue())) |
963 |
jschuengel |
2267 |
|
964 |
|
|
previewcolor = self.previewcolor.GetBackgroundColour() |
965 |
|
|
self.umn_scalebar.get_color().set_rgbcolor(previewcolor.Red(), |
966 |
|
|
previewcolor.Green(), previewcolor.Blue()) |
967 |
|
|
previewimgcolor = self.previewimgcolor.GetBackgroundColour() |
968 |
|
|
self.umn_scalebar.get_imagecolor().set_rgbcolor(previewimgcolor.Red(), |
969 |
|
|
previewimgcolor.Green(), previewimgcolor.Blue()) |
970 |
|
|
self.result ="OK" |
971 |
|
|
self.end_dialog(self.result) |
972 |
|
|
|
973 |
|
|
def OnCancel(self, event): |
974 |
|
|
self.end_dialog(None) |
975 |
|
|
|
976 |
|
|
|
977 |
|
|
def scalebarsettings(context): |
978 |
jschuengel |
2274 |
win = Scalebar_Dialog(context.mainwindow, -1, "Scalebar Settings", |
979 |
|
|
size=wxSize(350, 200), |
980 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
981 |
jschuengel |
2267 |
win.CenterOnScreen() |
982 |
|
|
val = win.ShowModal() |
983 |
|
|
|
984 |
jschuengel |
2257 |
def mapsettings(context): |
985 |
jschuengel |
2274 |
win = Map_Dialog(context.mainwindow, -1, "Map Settings", |
986 |
|
|
size=wxSize(350, 200), |
987 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
988 |
jschuengel |
2257 |
win.CenterOnScreen() |
989 |
|
|
val = win.ShowModal() |
990 |
|
|
|
991 |
jschuengel |
2271 |
def outputformatsettings(context): |
992 |
|
|
win = OutputFormat_Dialog(context.mainwindow, -1, "OutputFormat Settings", |
993 |
jschuengel |
2274 |
size=wxSize(350, 200), |
994 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
995 |
jschuengel |
2271 |
win.CenterOnScreen() |
996 |
|
|
val = win.ShowModal() |
997 |
|
|
|
998 |
jschuengel |
2257 |
def websettings(context): |
999 |
jschuengel |
2274 |
win = Web_Dialog(context.mainwindow, -1, "Web Settings", |
1000 |
|
|
size=wxSize(350, 200), |
1001 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1002 |
jschuengel |
2257 |
win.CenterOnScreen() |
1003 |
|
|
val = win.ShowModal() |
1004 |
|
|
|
1005 |
|
|
def legendsettings(context): |
1006 |
jschuengel |
2274 |
win = Legend_Dialog(context.mainwindow, -1, "Legend Settings", |
1007 |
|
|
size=wxSize(350, 200), |
1008 |
|
|
style = wxDEFAULT_DIALOG_STYLE) |
1009 |
jschuengel |
2257 |
win.CenterOnScreen() |
1010 |
|
|
val = win.ShowModal() |
1011 |
|
|
|
1012 |
|
|
#create a new mapfile |
1013 |
|
|
def create_new_mapfile(context): |
1014 |
|
|
theMap = MF_Map(mapObj("")) |
1015 |
|
|
context.mainwindow.canvas.Map().extension_umn_mapobj = theMap |
1016 |
|
|
|
1017 |
jschuengel |
2282 |
|
1018 |
|
|
# TODO: Maybe can be imported from another class |
1019 |
|
|
# check if an mapobj exists, to control the menuitem is available or not |
1020 |
|
|
def _has_umn_mapobj(context): |
1021 |
|
|
"""Return true if a umn_mapobj exists""" |
1022 |
|
|
return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj") |
1023 |
|
|
|
1024 |
|
|
|
1025 |
jschuengel |
2257 |
# ################################### |
1026 |
|
|
# |
1027 |
|
|
# Hook in MapServer Extension into Thuban |
1028 |
|
|
# |
1029 |
|
|
# ################################### |
1030 |
|
|
|
1031 |
|
|
# find the extensions menu (create it anew if not found) |
1032 |
jschuengel |
2274 |
experimental_menu = main_menu.FindOrInsertMenu("experimental", |
1033 |
|
|
_("Experimenta&l")) |
1034 |
jschuengel |
2257 |
# find the extension menu and add a new submenu if found |
1035 |
jschuengel |
2274 |
mapserver_menu = experimental_menu.FindOrInsertMenu("mapserver", |
1036 |
|
|
_("&MapServer")) |
1037 |
jschuengel |
2257 |
|
1038 |
|
|
# register the new command |
1039 |
jschuengel |
2282 |
registry.Add(Command("create_new_mapfile", _("Create new mapfile"), \ |
1040 |
|
|
create_new_mapfile, \ |
1041 |
|
|
helptext = _("Create a new empty mapscript MapObj"))) |
1042 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1043 |
jschuengel |
2282 |
mapserver_menu.InsertItem("create_new_mapfile", after = "import_mapfile" ) |
1044 |
jschuengel |
2257 |
|
1045 |
jschuengel |
2282 |
# find the MapServer menu and add a new submenu if found |
1046 |
|
|
mapserver_edit_menu = mapserver_menu.FindOrInsertMenu("edit_mapfile", |
1047 |
|
|
_("&Edit mapfile"), \ |
1048 |
|
|
after = "create_new_mapfile") |
1049 |
jschuengel |
2257 |
|
1050 |
|
|
# register the new command (Map Settings Dialog) |
1051 |
jschuengel |
2282 |
registry.Add(Command("Map Settings", _("Map"), mapsettings, |
1052 |
|
|
helptext = _("Edit the Map Setting"), \ |
1053 |
|
|
sensitive = _has_umn_mapobj)) |
1054 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1055 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Map Settings") |
1056 |
jschuengel |
2257 |
|
1057 |
jschuengel |
2271 |
|
1058 |
jschuengel |
2257 |
# register the new command (Map Settings Dialog) |
1059 |
jschuengel |
2282 |
registry.Add(Command("Web Settings", _("Web"), |
1060 |
jschuengel |
2274 |
websettings, |
1061 |
jschuengel |
2282 |
helptext = _("Edit the Web Setting"), \ |
1062 |
|
|
sensitive = _has_umn_mapobj)) |
1063 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1064 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Web Settings") |
1065 |
jschuengel |
2257 |
|
1066 |
|
|
# register the new command (Legend Settings Dialog) |
1067 |
jschuengel |
2282 |
registry.Add(Command("Legend Settings", _("Legend"), |
1068 |
jschuengel |
2274 |
legendsettings, |
1069 |
jschuengel |
2282 |
helptext = _("Edit the Legend Setting"), \ |
1070 |
|
|
sensitive = _has_umn_mapobj)) |
1071 |
jschuengel |
2257 |
# finally add the new entry to the extensions menu |
1072 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Legend Settings") |
1073 |
jschuengel |
2257 |
|
1074 |
jschuengel |
2267 |
# register the new command (Scalebar Settings Dialog) |
1075 |
jschuengel |
2282 |
registry.Add(Command("Scalebar Settings", _("Scalebar"), |
1076 |
jschuengel |
2274 |
scalebarsettings, |
1077 |
jschuengel |
2282 |
helptext = _("Edit the Scalebar Setting"), \ |
1078 |
|
|
sensitive = _has_umn_mapobj)) |
1079 |
jschuengel |
2267 |
# finally add the new entry to the extensions menu |
1080 |
jschuengel |
2282 |
mapserver_edit_menu.InsertItem("Scalebar Settings") |
1081 |
jschuengel |
2257 |
|
1082 |
jschuengel |
2267 |
|