/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/umn_mapserver/mf_handle.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/umn_mapserver/mf_handle.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2303 - (hide annotations)
Wed Jul 28 12:37:28 2004 UTC (20 years, 7 months ago) by jschuengel
Original Path: trunk/thuban/Extensions/umn_mapserver/mf_handle.py
File MIME type: text/x-python
File size: 56607 byte(s)
Added a dialog to handle metadata. Yet only mapfile metadata are supported. Layer and class supported are not implemented.
Added a dialog to handle layer informations. The dialog only shows the selected layer at the moment.

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 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    
335     # create name
336     layer_name = wxBoxSizer(wxHORIZONTAL)
337     layer_name.Add(wxStaticText(self, -1, _("Layer-Name:")), 0,
338     wxALL|wxALIGN_CENTER_VERTICAL, 4)
339     layer_name.Add(wxStaticText(self, -1, self.tb_layer.Title()), 0,
340     wxALL|wxALIGN_CENTER_VERTICAL, 4)
341    
342     ##~ # metadata button
343     ##~ metadata_button = wxButton(self, ID_METADATA_CHANGE, _("Edit Metadata"))
344     ##~ EVT_BUTTON(self, ID_METADATA_CHANGE, self.OnChangeMetadata)
345    
346     # buttons
347     box_buttons = wxBoxSizer(wxHORIZONTAL)
348     button = wxButton(self, wxID_OK, _("OK"))
349     box_buttons.Add(button, 0, wxALL, 5)
350     button = wxButton(self, wxID_CANCEL, _("Cancel"))
351     box_buttons.Add(button, 0, wxALL, 5)
352     #set the button funcitons
353     EVT_BUTTON(self, wxID_OK, self.OnOK)
354     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
355    
356     # compose the final dialog
357     top = wxBoxSizer(wxVERTICAL)
358     #top.Add(box_template, 0, wxEXPAND |wxALL, 5)
359     top.Add(layer_name, 0)
360     ##~ top.Add(metadata_button, 0, wxEXPAND)
361     top.Add(box_buttons, 0, wxALIGN_RIGHT)
362    
363     # final layout settings
364     self.SetSizer(top)
365     top.Fit(self)
366    
367     def OnChangeMetadata(self, event):
368     # set the umn_label for scalebar so the Label_Dialog can be used
369     self.umn_metadata= self.umn_layer.get_metadata()
370     dialog = Metadata_Dialog(self, -1, "Layer Metadata Settings",
371     size=wxSize(350, 200),
372     style = wxDEFAULT_DIALOG_STYLE
373     )
374     dialog.CenterOnScreen()
375     if dialog.ShowModal() == wxID_OK:
376     return
377     dialog.Destroy()
378    
379    
380     def RunDialog(self):
381     self.ShowModal()
382     self.Destroy()
383    
384     def end_dialog(self, result):
385     self.result = result
386     if self.result is not None:
387     self.EndModal(wxID_OK)
388     else:
389     self.EndModal(wxID_CANCEL)
390     self.Show(False)
391    
392     def OnOK(self, event):
393     self.result ="OK"
394     self.end_dialog(self.result)
395    
396     def OnCancel(self, event):
397     self.end_dialog(None)
398    
399    
400 jschuengel 2257 ID_LABEL_CHANGE = 8011
401    
402     class Legend_Dialog(wxDialog):
403    
404     def __init__(self, parent, ID, title,
405     pos=wxDefaultPosition, size=wxDefaultSize,
406     style=wxDEFAULT_DIALOG_STYLE):
407    
408     # initialize the Dialog
409     wxDialog.__init__(self, parent, ID, title, pos, size, style)
410    
411     # get the web object
412     self.tb_map = parent.canvas.Map()
413     self.umn_legend = self.tb_map.extension_umn_mapobj.get_legend()
414    
415     # create the Keysize
416 jschuengel 2274 keySize = wxStaticBox(self, 1010, _("KeySize"), style = 0,
417     name = "KeySize Box", )
418 jschuengel 2257 box_keysize = wxStaticBoxSizer(keySize, wxVERTICAL)
419     umn_legend_keysize = self.umn_legend.get_keysize()
420     box_sizepartWidth = wxBoxSizer(wxHORIZONTAL)
421     box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2)
422     self.text_keysize_width = wxSpinCtrl(self, -1,
423     value=str(umn_legend_keysize[0]), max=100, min=0,
424     name='keywidth', style=wxSP_ARROW_KEYS)
425     box_sizepartWidth.Add(self.text_keysize_width, 2, wxALL, 2)
426     box_keysize.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2)
427     box_sizepartHeight = wxBoxSizer(wxHORIZONTAL)
428     box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2),
429     self.text_keysize_height = wxSpinCtrl(self, -1,
430     value=str(umn_legend_keysize[1]), max=100, min=0,
431     name='keyheight', style=wxSP_ARROW_KEYS)
432     box_sizepartHeight.Add(self.text_keysize_height, 2, wxALL, 2)
433     box_keysize.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2)
434    
435     # create the Keyspacing
436 jschuengel 2274 keySpacing= wxStaticBox(self, 1010, _("KeySpacing"), style = 0,
437     name = "KeySpacing Box", )
438 jschuengel 2257 box_keyspacing = wxStaticBoxSizer(keySpacing, wxVERTICAL)
439     umn_legend_keyspacing = self.umn_legend.get_keyspacing()
440     box_sizepartWidth = wxBoxSizer(wxHORIZONTAL)
441     box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 2)
442     self.text_keyspacing_width = wxSpinCtrl(self, -1,
443 jschuengel 2274 value=str(umn_legend_keyspacing[0]), max=100,
444     min=0, name='spacingwidth', style=wxSP_ARROW_KEYS)
445 jschuengel 2257 box_sizepartWidth.Add(self.text_keyspacing_width, 2, wxALL, 2)
446     box_keyspacing.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 2)
447     box_sizepartHeight = wxBoxSizer(wxHORIZONTAL)
448     box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0, wxALL, 2),
449     self.text_keyspacing_height = wxSpinCtrl(self, -1,
450 jschuengel 2274 value=str(umn_legend_keyspacing[1]), max=100,
451     min=0,name='spacingheight', style=wxSP_ARROW_KEYS)
452 jschuengel 2257 box_sizepartHeight.Add(self.text_keyspacing_height, 2, wxALL, 2)
453     box_keyspacing.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 2)
454    
455     # color chooser
456 jschuengel 2274 box_colorStatic = wxStaticBox(self, 1011, _("ImageColor"), style = 0,
457     name = "imagecolor")
458 jschuengel 2257 box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL)
459     # preview box
460 jschuengel 2274 self.previewcolor = wxPanel(self, 99, name = 'imagecolorPanel',
461     style = wxSIMPLE_BORDER | wxCLIP_CHILDREN)
462 jschuengel 2257 imagecolor = self.umn_legend.get_imagecolor()
463     self.previewcolor.SetBackgroundColour(wxColour(imagecolor.get_red(),
464     imagecolor.get_green(), imagecolor.get_blue()))
465     box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5)
466     # color change button, opens a new color dialog
467     button = wxButton(self, ID_COLOR_CHANGE, _("Change Color"))
468     button.SetFocus()
469     EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor)
470     box_color.Add(button, 1, wxEXPAND|wxALL, 5)
471    
472 jschuengel 2267 # status
473 jschuengel 2274 umn_legend_status= self.umn_legend.get_status(mode="string")
474 jschuengel 2257 possible_choices = []
475     for key in legend_status_type:
476     possible_choices.append(legend_status_type[key])
477     self.choice_status = wxRadioBox(self, -1, choices=possible_choices,
478     label='Status', majorDimension=1,
479     name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS)
480     self.choice_status.SetStringSelection(umn_legend_status)
481    
482     # create the positionbox
483 jschuengel 2274 umn_legend_position= self.umn_legend.get_position(mode="string")
484 jschuengel 2257 possible_choices = []
485     for key in legend_position_type:
486     possible_choices.append(legend_position_type[key])
487     self.choice_position = wxRadioBox(self, -1, choices=possible_choices,
488 jschuengel 2274 label='Position', majorDimension=1,
489     name='position check',
490     size=wxDefaultSize,
491     style=wxRA_SPECIFY_ROWS)
492 jschuengel 2257 self.choice_position.SetStringSelection(umn_legend_position)
493    
494 jschuengel 2271 # button for label
495     labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label"))
496 jschuengel 2257 EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel)
497    
498     #buttons
499     box_buttons = wxBoxSizer(wxHORIZONTAL)
500     button = wxButton(self, wxID_OK, _("OK"))
501     box_buttons.Add(button, 0, wxALL, 5)
502     button = wxButton(self, wxID_CANCEL, _("Cancel"))
503     box_buttons.Add(button, 0, wxALL, 5)
504     #set the button funcitons
505     EVT_BUTTON(self, wxID_OK, self.OnOK)
506     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
507 jschuengel 2271
508     # compose the final layout
509     top = wxBoxSizer(wxVERTICAL)
510     top.Add(box_keysize,0, wxEXPAND |wxALL, 5)
511     top.Add(box_keyspacing,0, wxEXPAND |wxALL, 5)
512     top.Add(box_color,0, wxEXPAND |wxALL, 5)
513     top.Add(self.choice_status,0, wxEXPAND |wxALL, 5)
514     top.Add(self.choice_position,0, wxEXPAND |wxALL, 5)
515     top.Add(labelbutton, 1, wxEXPAND|wxALL, 5)
516 jschuengel 2257 top.Add(box_buttons, 0, wxALIGN_RIGHT)
517    
518     # final layout settings
519     self.SetSizer(top)
520     top.Fit(self)
521    
522     def OnChangeLabel(self, event):
523 jschuengel 2267 self.umn_label = self.umn_legend.get_label()
524 jschuengel 2274 dialog = Label_Dialog(self, -1, "Legend Label Settings",
525     size=wxSize(350, 200),
526 jschuengel 2257 style = wxDEFAULT_DIALOG_STYLE
527     )
528     dialog.CenterOnScreen()
529     if dialog.ShowModal() == wxID_OK:
530     return
531     dialog.Destroy()
532    
533     def OnChangeColor(self, event):
534     cur = self.umn_legend.get_imagecolor().get_thubancolor()
535     dialog = ColorDialog(self)
536     dialog.SetColor(cur)
537     self.retcolor = None
538     if dialog.ShowModal() == wxID_OK:
539     self.retcolor = dialog.GetColor()
540     dialog.Destroy()
541     if self.retcolor:
542     self.redcolor = int(round(self.retcolor.red*255))
543     self.greencolor = int(round(self.retcolor.green*255))
544     self.bluecolor = int(round(self.retcolor.blue*255))
545 jschuengel 2274 self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor),
546     int(self.greencolor),
547     int(self.bluecolor)))
548 jschuengel 2282 # refresh the colorbox to show the new color
549     self.previewcolor.Refresh()
550 jschuengel 2257
551     def RunDialog(self):
552     self.ShowModal()
553     self.Destroy()
554    
555     def end_dialog(self, result):
556     self.result = result
557     if self.result is not None:
558     self.EndModal(wxID_OK)
559     else:
560     self.EndModal(wxID_CANCEL)
561     self.Show(False)
562    
563     def OnOK(self, event):
564 jschuengel 2271 self.umn_legend.set_keysize(self.text_keysize_width.GetValue(),
565     self.text_keysize_height.GetValue())
566     self.umn_legend.set_keyspacing(self.text_keyspacing_width.GetValue(),
567     self.text_keyspacing_height.GetValue())
568 jschuengel 2257 self.umn_legend.set_status(self.choice_status.GetStringSelection())
569     self.umn_legend.set_position(self.choice_position.GetStringSelection())
570 jschuengel 2267 previewcolor = self.previewcolor.GetBackgroundColour()
571     self.umn_legend.get_imagecolor().set_rgbcolor(previewcolor.Red(),
572     previewcolor.Green(), previewcolor.Blue())
573 jschuengel 2257 self.result ="OK"
574     self.end_dialog(self.result)
575    
576     def OnCancel(self, event):
577     self.end_dialog(None)
578    
579     class Label_Dialog(wxDialog):
580    
581     def __init__(self, parent, ID, title,
582     pos=wxDefaultPosition, size=wxDefaultSize,
583     style=wxDEFAULT_DIALOG_STYLE):
584    
585     # initialize the Dialog
586     wxDialog.__init__(self, parent, ID, title, pos, size, style)
587    
588     # get the web object
589 jschuengel 2267 self.umn_label = parent.umn_label
590 jschuengel 2257
591     # size
592 jschuengel 2274 labelsize= wxStaticBox(self, 1010, _("Size"), style = 0,
593     name = "Size Box", )
594 jschuengel 2257 box_labelsize = wxStaticBoxSizer(labelsize, wxVERTICAL)
595     umn_label_size= self.umn_label.get_size()
596     box_size = wxBoxSizer(wxHORIZONTAL)
597     self.text_labelsize = wxSpinCtrl(self, -1,
598     value=str(umn_label_size), max=10, min=0,
599     name='size', style=wxSP_ARROW_KEYS)
600     box_size.Add(self.text_labelsize, 2, wxALL, 2)
601     box_labelsize.Add(box_size, 0, wxALIGN_RIGHT | wxALL, 2)
602    
603     # color chooser
604 jschuengel 2274 box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0,
605     name = "color")
606 jschuengel 2257 box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL)
607     # preview box
608 jschuengel 2274 self.previewcolor = wxPanel(self, 99, name = 'colorPanel',
609     style = wxSIMPLE_BORDER | wxCLIP_CHILDREN)
610 jschuengel 2257 color = self.umn_label.get_color()
611     self.previewcolor.SetBackgroundColour(wxColour(color.get_red(),
612     color.get_green(), color.get_blue()))
613     box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5)
614     # color change button, opens a new color dialog
615     button = wxButton(self, ID_COLOR_CHANGE, _("Change Color"))
616     button.SetFocus()
617     EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor)
618     box_color.Add(button, 1, wxEXPAND|wxALL, 5)
619    
620     #get the set type
621     insidetype = self.umn_label.get_type()
622     #create the type selector for fonttype (Bitmap, TrueType)
623     # TODO: Truetype is not supported yet
624 jschuengel 2274 box_typeStatic = wxStaticBox(self, 1011, _("Type"), style = 0,
625     name = "type")
626 jschuengel 2257 box_type = wxStaticBoxSizer(box_typeStatic, wxVERTICAL)
627     sam = []
628     for key in label_font_type:
629     # dont add truetype
630     #if key != 0:
631     sam.append(label_font_type[key])
632     self.choice_type = wxChoice(self, 40, (80, 50), choices = sam)
633     self.choice_type.SetStringSelection(insidetype)
634     box_type.Add(self.choice_type,0, wxEXPAND, wxALL, 5)
635 jschuengel 2271
636 jschuengel 2257 # Offset
637 jschuengel 2274 offset= wxStaticBox(self, 1010, _("Offset"), style = 0,
638     name = "Offset Box", )
639 jschuengel 2257 box_offset = wxStaticBoxSizer(offset, wxVERTICAL)
640     umn_label_offset = self.umn_label.get_offset()
641     box_offsetX = wxBoxSizer(wxHORIZONTAL)
642     box_offsetX.Add(wxStaticText(self, -1, _("X: ")), 0, wxALL, 2)
643     self.text_offsetx = wxSpinCtrl(self, -1,
644     value=str(umn_label_offset[0]), max=20, min=0,
645     name='offsetX', style=wxSP_ARROW_KEYS)
646     box_offsetX.Add(self.text_offsetx, 2, wxALL, 2)
647     box_offset.Add(box_offsetX, 0, wxALIGN_RIGHT | wxALL, 2)
648     box_offsetY = wxBoxSizer(wxHORIZONTAL)
649     box_offsetY.Add(wxStaticText(self, -1, _("Y: ")), 0, wxALL, 2),
650     self.text_offsety = wxSpinCtrl(self, -1,
651     value=str(umn_label_offset[1]), max=100, min=0,
652     name='offsetY', style=wxSP_ARROW_KEYS)
653     box_offsetY.Add(self.text_offsety, 2, wxALL, 2)
654     box_offset.Add(box_offsetY, 0, wxALIGN_RIGHT | wxALL, 2)
655    
656 jschuengel 2271 # partials
657 jschuengel 2267 umn_partials = self.umn_label.get_partials()
658     self.choice_partials = wxRadioBox(self, -1, choices=["True","False"],
659 jschuengel 2274 label='partials', majorDimension=1,
660     name='partials check',
661     size=wxDefaultSize,
662     style=wxRA_SPECIFY_ROWS)
663 jschuengel 2267 self.choice_partials.SetStringSelection(str(umn_partials))
664 jschuengel 2271
665     # force
666     umn_force = self.umn_label.get_force()
667     self.choice_force = wxRadioBox(self, -1, choices=["True","False"],
668     label='force', majorDimension=1,
669     name='force check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS)
670     self.choice_force.SetStringSelection(str(umn_force))
671    
672     # buffer
673 jschuengel 2274 buffer = wxStaticBox(self, 1010, _("Buffer"), style = 0,
674     name = "Buffer Box", )
675 jschuengel 2271 box_buffer = wxStaticBoxSizer(buffer, wxVERTICAL)
676     umn_buffer= self.umn_label.get_buffer()
677     box_buffertext = wxBoxSizer(wxHORIZONTAL)
678     self.text_buffer = wxSpinCtrl(self, -1,
679     value=str(umn_buffer), max=10, min=0,
680     name='size', style=wxSP_ARROW_KEYS)
681     box_buffertext.Add(self.text_buffer, 2, wxALL, 2)
682     box_buffer.Add(box_buffertext, 0, wxALIGN_RIGHT | wxALL, 2)
683    
684     # minfeaturesize
685 jschuengel 2274 minfeaturesize = wxStaticBox(self, 1010, _("Minfeaturesize"),
686     style = 0, name = "Minfeaturesize Box")
687 jschuengel 2271 box_minfeaturesize = wxStaticBoxSizer(minfeaturesize, wxVERTICAL)
688     umn_minfeaturesize= self.umn_label.get_minfeaturesize()
689     box_minfeaturesizetext = wxBoxSizer(wxHORIZONTAL)
690     self.text_minfeaturesize = wxSpinCtrl(self, -1,
691     value=str(umn_minfeaturesize), max=10, min=-1,
692     name='minfeaturesize', style=wxSP_ARROW_KEYS)
693     box_minfeaturesizetext.Add(self.text_minfeaturesize, 2, wxALL, 2)
694     box_minfeaturesize.Add(box_minfeaturesizetext, 0,
695     wxALIGN_RIGHT | wxALL, 2)
696    
697     # mindistance
698     mindistance = wxStaticBox(self, 1010, _("Mindistance"), style = 0,
699     name = "Mindistance Box", )
700     box_mindistance = wxStaticBoxSizer(mindistance, wxVERTICAL)
701     umn_mindistance= self.umn_label.get_mindistance()
702     box_mindistancetext = wxBoxSizer(wxHORIZONTAL)
703     self.text_mindistance = wxSpinCtrl(self, -1,
704     value=str(umn_mindistance), max=10, min=-1,
705     name='mindistance', style=wxSP_ARROW_KEYS)
706     box_mindistancetext.Add(self.text_mindistance, 2, wxALL, 2)
707     box_mindistance.Add(box_mindistancetext, 0,
708     wxALIGN_RIGHT | wxALL, 2)
709 jschuengel 2257
710 jschuengel 2271 # position
711 jschuengel 2274 umn_label_position= self.umn_label.get_position(mode="string")
712 jschuengel 2271 possible_choices = []
713     for key in label_position_type:
714     possible_choices.append(label_position_type[key])
715     self.choice_position = wxRadioBox(self, -1, choices=possible_choices,
716 jschuengel 2274 label='Position', majorDimension=1,
717     name='position check',
718     size=wxDefaultSize,
719     style=wxRA_SPECIFY_ROWS)
720 jschuengel 2271 self.choice_position.SetStringSelection(umn_label_position)
721    
722 jschuengel 2257 #buttons
723     box_buttons = wxBoxSizer(wxHORIZONTAL)
724     button = wxButton(self, wxID_OK, _("OK"))
725     box_buttons.Add(button, 0, wxALL, 5)
726     button = wxButton(self, wxID_CANCEL, _("Cancel"))
727     box_buttons.Add(button, 0, wxALL, 5)
728     #set the button funcitons
729     EVT_BUTTON(self, wxID_OK, self.OnOK)
730     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
731 jschuengel 2271
732     # compose the Dialog
733     top = wxBoxSizer(wxVERTICAL)
734    
735     top1 = wxBoxSizer(wxHORIZONTAL)
736     top1.Add(box_labelsize,0, wxEXPAND |wxALL, 5)
737     top1.Add(box_color,0, wxEXPAND |wxALL, 5)
738     top1.Add(box_minfeaturesize,0, wxEXPAND |wxALL, 5)
739    
740     top2 = wxBoxSizer(wxHORIZONTAL)
741     top2.Add(box_type,0,wxEXPAND |wxALL, 5)
742     top2.Add(box_offset,0, wxEXPAND |wxALL, 5)
743     top2.Add(box_mindistance,0, wxEXPAND |wxALL, 5)
744    
745     top3 = wxBoxSizer(wxHORIZONTAL)
746     top3.Add(self.choice_partials,0, wxEXPAND |wxALL, 5)
747     top3.Add(box_buffer,0, wxEXPAND |wxALL, 5)
748     top3.Add(self.choice_force,0, wxEXPAND |wxALL, 5)
749    
750     top.Add(top1, 0, wxEXPAND)
751     top.Add(top2, 0, wxEXPAND)
752     top.Add(top3, 0, wxEXPAND)
753     top.Add(self.choice_position,0, wxEXPAND |wxALL, 5)
754 jschuengel 2257 top.Add(box_buttons, 0, wxALIGN_RIGHT)
755 jschuengel 2271
756 jschuengel 2257 # final layout settings
757     self.SetSizer(top)
758     top.Fit(self)
759    
760     def OnChangeColor(self, event):
761     cur = self.umn_label.get_color().get_thubancolor()
762     dialog = ColorDialog(self)
763     dialog.SetColor(cur)
764     self.retcolor = None
765     if dialog.ShowModal() == wxID_OK:
766     self.retcolor = dialog.GetColor()
767     dialog.Destroy()
768     if self.retcolor:
769     self.redcolor = int(round(self.retcolor.red*255))
770     self.greencolor = int(round(self.retcolor.green*255))
771     self.bluecolor = int(round(self.retcolor.blue*255))
772 jschuengel 2274 self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor),
773     int(self.greencolor),
774     int(self.bluecolor)))
775 jschuengel 2282 # refresh the colorbox to show the new color
776     self.previewcolor.Refresh()
777 jschuengel 2257
778     def RunDialog(self):
779     self.ShowModal()
780     self.Destroy()
781    
782     def end_dialog(self, result):
783     self.result = result
784     if self.result is not None:
785     self.EndModal(wxID_OK)
786     else:
787     self.EndModal(wxID_CANCEL)
788     self.Show(False)
789    
790     def OnOK(self, event):
791     self.umn_label.set_size(self.text_labelsize.GetValue())
792 jschuengel 2274 self.umn_label.set_offset(self.text_offsetx.GetValue(),
793     self.text_offsety.GetValue())
794 jschuengel 2257 self.umn_label.set_type(self.choice_type.GetStringSelection())
795 jschuengel 2267 if self.choice_partials.GetStringSelection() == "True":
796     self.umn_label.set_partials(True)
797     else:
798     self.umn_label.set_partials(False)
799     previewcolor = self.previewcolor.GetBackgroundColour()
800     self.umn_label.get_color().set_rgbcolor(previewcolor.Red(),
801     previewcolor.Green(), previewcolor.Blue())
802 jschuengel 2271 self.umn_label.set_mindistance(self.text_mindistance.GetValue())
803     self.umn_label.set_minfeaturesize(self.text_minfeaturesize.GetValue())
804     self.umn_label.set_position(self.choice_position.GetStringSelection())
805     self.umn_label.set_buffer(self.text_buffer.GetValue())
806     if self.choice_force.GetStringSelection() == "True":
807     self.umn_label.set_force(True)
808     else:
809     self.umn_label.set_force(False)
810 jschuengel 2257 self.result ="OK"
811     self.end_dialog(self.result)
812    
813     def OnCancel(self, event):
814     self.end_dialog(None)
815    
816 jschuengel 2267 class Scalebar_Dialog(wxDialog):
817    
818     def __init__(self, parent, ID, title,
819     pos=wxDefaultPosition, size=wxDefaultSize,
820     style=wxDEFAULT_DIALOG_STYLE):
821    
822     # initialize the Dialog
823     wxDialog.__init__(self, parent, ID, title, pos, size, style)
824 jschuengel 2257
825 jschuengel 2267 # get the web object
826     self.tb_map = parent.canvas.Map()
827     self.umn_scalebar = self.tb_map.extension_umn_mapobj.get_scalebar()
828    
829     # color chooser
830 jschuengel 2274 box_colorStatic = wxStaticBox(self, 1011, _("Color"), style = 0,
831     name = "color")
832 jschuengel 2267 box_color = wxStaticBoxSizer(box_colorStatic, wxVERTICAL)
833     # preview box
834 jschuengel 2274 self.previewcolor = wxPanel(self, 99, name = 'colorPanel',
835     style = wxSIMPLE_BORDER | wxCLIP_CHILDREN)
836 jschuengel 2267 color = self.umn_scalebar.get_color()
837     self.previewcolor.SetBackgroundColour(wxColour(color.get_red(),
838     color.get_green(), color.get_blue()))
839     box_color.Add(self.previewcolor, 1, wxGROW | wxALL, 5)
840     # color change button, opens a new color dialog
841     button = wxButton(self, ID_COLOR_CHANGE, _("Change Color"))
842     button.SetFocus()
843     EVT_BUTTON(self, ID_COLOR_CHANGE, self.OnChangeColor)
844     box_color.Add(button, 1, wxEXPAND|wxALL, 5)
845     # show the two color chooser horizontal
846     colorHor = wxBoxSizer(wxHORIZONTAL)
847     colorHor.Add(box_color,0, wxEXPAND |wxALL, 5)
848    
849     # imagecolor chooser
850 jschuengel 2274 box_imgcolorStatic = wxStaticBox(self, 1011, _("Image Color"),
851     style = 0, name = "imgcolor")
852 jschuengel 2267 box_imgcolor = wxStaticBoxSizer(box_imgcolorStatic, wxVERTICAL)
853     # preview box
854 jschuengel 2274 self.previewimgcolor = wxPanel(self, 99, name = 'colorPanel',
855     style = wxSIMPLE_BORDER|wxCLIP_CHILDREN)
856 jschuengel 2267 color = self.umn_scalebar.get_imagecolor()
857     self.previewimgcolor.SetBackgroundColour(wxColour(color.get_red(),
858     color.get_green(), color.get_blue()))
859     box_imgcolor.Add(self.previewimgcolor, 1, wxGROW | wxALL, 5)
860     # color change button, opens a new color dialog
861     button = wxButton(self, ID_IMGCOLOR_CHANGE, _("Change ImageColor"))
862     button.SetFocus()
863     EVT_BUTTON(self, ID_IMGCOLOR_CHANGE, self.OnChangeImageColor)
864     box_imgcolor.Add(button, 1, wxEXPAND|wxALL, 5)
865     colorHor.Add(box_imgcolor,0, wxEXPAND |wxALL, 5)
866    
867     # create the intervals
868 jschuengel 2274 intervalsStatic = wxStaticBox(self, 1010, _("Intervals"), style = 0,
869     name = "Intervals Box", )
870 jschuengel 2267 box_intervals = wxStaticBoxSizer(intervalsStatic, wxVERTICAL)
871     umn_scalebar_intervals = self.umn_scalebar.get_intervals()
872     self.text_intervals = wxSpinCtrl(self, -1,
873     value=str(umn_scalebar_intervals), max=100, min=0,
874     name='intervals', style=wxSP_ARROW_KEYS)
875     box_intervals.Add(self.text_intervals, 0, wxALIGN_RIGHT | wxALL, 2)
876     hori2 = wxBoxSizer(wxHORIZONTAL)
877     hori2.Add(box_intervals,0, wxEXPAND |wxALL, 5)
878    
879     #style
880     umn_scalebar_style= self.umn_scalebar.get_style()
881     possible_choices = []
882     for key in scalebar_style_type:
883     possible_choices.append(scalebar_style_type[key])
884     self.choice_style = wxRadioBox(self, -1, choices=possible_choices,
885     label='Style', majorDimension=1,
886     name='style check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS)
887     self.choice_style.SetSelection(umn_scalebar_style)
888     hori2.Add(self.choice_style, 1, wxEXPAND|wxALL, 5)
889    
890     #create size settings
891     try:
892     insidetxt = self.umn_scalebar.get_size()
893     except:
894     insidetxt = (0,0)
895     # create the Size Box
896 jschuengel 2274 staticSize = wxStaticBox(self, -1, _("Size"), style = 0,
897     name="sizeBox")
898 jschuengel 2267 box_size = wxStaticBoxSizer(staticSize, wxHORIZONTAL)
899    
900     box_sizepartWidth = wxBoxSizer(wxHORIZONTAL)
901     box_sizepartWidth.Add(wxStaticText(self, -1, _("Width: ")), 0, wxALL, 4)
902     self.text_width = wxTextCtrl(self, -1, str(insidetxt[0]))
903     box_sizepartWidth.Add(self.text_width, 2, wxALL, 4)
904     box_size.Add(box_sizepartWidth, 0, wxALIGN_RIGHT | wxALL, 5)
905     box_sizepartHeight = wxBoxSizer(wxHORIZONTAL)
906 jschuengel 2274 box_sizepartHeight.Add(wxStaticText(self, -1, _("Height: ")), 0,
907     wxALL, 4)
908 jschuengel 2267 self.text_height = wxTextCtrl(self, -1, str(insidetxt[1]))
909     box_sizepartHeight.Add(self.text_height, 2, wxALL, 4)
910     box_size.Add(box_sizepartHeight, 0, wxALIGN_RIGHT | wxALL, 5)
911    
912     # status
913 jschuengel 2274 umn_scalebar_status= self.umn_scalebar.get_status(mode="string")
914 jschuengel 2267 possible_choices = []
915     for key in legend_status_type:
916     possible_choices.append(scalebar_status_type[key])
917     self.choice_status = wxRadioBox(self, -1, choices=possible_choices,
918     label='Status', majorDimension=1,
919     name='status check', size=wxDefaultSize, style=wxRA_SPECIFY_ROWS)
920     self.choice_status.SetStringSelection(umn_scalebar_status)
921    
922     # position
923 jschuengel 2274 umn_scalebar_position= self.umn_scalebar.get_position(mode="string")
924 jschuengel 2267 possible_choices = []
925     for key in scalebar_position_type:
926     possible_choices.append(scalebar_position_type[key])
927     self.choice_position = wxRadioBox(self, -1, choices=possible_choices,
928 jschuengel 2274 label='Position', majorDimension=1,
929     name='position check', size=wxDefaultSize,
930     style=wxRA_SPECIFY_ROWS)
931 jschuengel 2267 self.choice_position.SetStringSelection(umn_scalebar_position)
932    
933     #get the set unittype
934     insideunit = self.umn_scalebar .get_units()
935     #create the Unittype selector
936 jschuengel 2274 box_unitsStatic = wxStaticBox(self, -1, _("Unit Type"), style = 0,
937     name = "unittype")
938 jschuengel 2267 box_units = wxStaticBoxSizer(box_unitsStatic, wxVERTICAL)
939     sam = []
940     for key in unit_type:
941     sam.append(unit_type[key])
942     self.choice_units = wxChoice(self, 40, (80, 50), choices = sam)
943     self.choice_units.SetStringSelection(insideunit)
944 jschuengel 2271 box_units.Add(self.choice_units,0, wxEXPAND, wxALL, 5)
945 jschuengel 2267
946 jschuengel 2271 # button for label
947     labelbutton = wxButton(self, ID_LABEL_CHANGE, _("Change Label"))
948 jschuengel 2267 EVT_BUTTON(self, ID_LABEL_CHANGE, self.OnChangeLabel)
949    
950     #buttons
951     box_buttons = wxBoxSizer(wxHORIZONTAL)
952     button = wxButton(self, wxID_OK, _("OK"))
953     box_buttons.Add(button, 0, wxALL, 5)
954     button = wxButton(self, wxID_CANCEL, _("Cancel"))
955     button.SetFocus()
956     box_buttons.Add(button, 0, wxALL, 5)
957     #set the button funcitons
958     EVT_BUTTON(self, wxID_OK, self.OnOK)
959 jschuengel 2271 EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
960    
961     # compose the dialog
962     top = wxBoxSizer(wxVERTICAL)
963     top.Add(colorHor,0, wxEXPAND |wxALL, 5)
964     top.Add(hori2, 1, wxEXPAND|wxALL, 5)
965     top.Add(box_size, 1, wxEXPAND|wxALL, 5)
966     top.Add(self.choice_status,0, wxEXPAND |wxALL, 5)
967     top.Add(self.choice_position,0, wxEXPAND |wxALL, 5)
968     top.Add(box_units, 1, wxEXPAND|wxALL, 5)
969     top.Add(labelbutton, 0, wxEXPAND|wxALL, 5)
970 jschuengel 2267 top.Add(box_buttons, 0, wxALIGN_RIGHT)
971    
972     # final layout settings
973     self.SetSizer(top)
974     top.Fit(self)
975    
976     def OnChangeLabel(self, event):
977     # set the umn_label for scalebar so the Label_Dialog can be used
978     self.umn_label = self.umn_scalebar.get_label()
979 jschuengel 2274 dialog = Label_Dialog(self, -1, "Scalbar Label Settings",
980     size=wxSize(350, 200),
981 jschuengel 2267 style = wxDEFAULT_DIALOG_STYLE
982     )
983     dialog.CenterOnScreen()
984     if dialog.ShowModal() == wxID_OK:
985     return
986     dialog.Destroy()
987    
988     def OnChangeImageColor(self, event):
989     cur = self.umn_scalebar.get_imagecolor().get_thubancolor()
990     dialog = ColorDialog(self)
991     dialog.SetColor(cur)
992     self.retcolor = None
993     if dialog.ShowModal() == wxID_OK:
994     self.retcolor = dialog.GetColor()
995     dialog.Destroy()
996     if self.retcolor:
997     self.redcolor = int(round(self.retcolor.red*255))
998     self.greencolor = int(round(self.retcolor.green*255))
999     self.bluecolor = int(round(self.retcolor.blue*255))
1000 jschuengel 2274 self.previewimgcolor.SetBackgroundColour(wxColour(int(self.redcolor),
1001     int(self.greencolor),
1002     int(self.bluecolor)))
1003 jschuengel 2282 # refresh the colorbox to show the new color
1004     self.previewimgcolor.Refresh()
1005 jschuengel 2267
1006     def OnChangeColor(self, event):
1007     cur = self.umn_scalebar.get_color().get_thubancolor()
1008     dialog = ColorDialog(self)
1009     dialog.SetColor(cur)
1010     self.retcolor = None
1011     if dialog.ShowModal() == wxID_OK:
1012     self.retcolor = dialog.GetColor()
1013     dialog.Destroy()
1014     if self.retcolor:
1015     self.redcolor = int(round(self.retcolor.red*255))
1016     self.greencolor = int(round(self.retcolor.green*255))
1017     self.bluecolor = int(round(self.retcolor.blue*255))
1018 jschuengel 2274 self.previewcolor.SetBackgroundColour(wxColour(int(self.redcolor),
1019     int(self.greencolor),
1020     int(self.bluecolor)))
1021 jschuengel 2282 # refresh the colorbox to show the new color
1022     self.previewcolor.Refresh()
1023 jschuengel 2267
1024     def RunDialog(self):
1025     self.ShowModal()
1026     self.Destroy()
1027    
1028     def end_dialog(self, result):
1029     self.result = result
1030     if self.result is not None:
1031     self.EndModal(wxID_OK)
1032     else:
1033     self.EndModal(wxID_CANCEL)
1034     self.Show(False)
1035    
1036     def OnOK(self, event):
1037     self.umn_scalebar.set_status(self.choice_status.GetStringSelection())
1038     self.umn_scalebar.set_units(self.choice_units.GetStringSelection())
1039     self.umn_scalebar.set_intervals(self.text_intervals.GetValue())
1040     self.umn_scalebar.set_style(self.choice_style.GetSelection())
1041     self.umn_scalebar.set_position(self.choice_position.GetStringSelection())
1042 jschuengel 2274 self.umn_scalebar.set_size(int(self.text_width.GetValue()),
1043     int(self.text_height.GetValue()))
1044 jschuengel 2267
1045     previewcolor = self.previewcolor.GetBackgroundColour()
1046     self.umn_scalebar.get_color().set_rgbcolor(previewcolor.Red(),
1047     previewcolor.Green(), previewcolor.Blue())
1048     previewimgcolor = self.previewimgcolor.GetBackgroundColour()
1049     self.umn_scalebar.get_imagecolor().set_rgbcolor(previewimgcolor.Red(),
1050     previewimgcolor.Green(), previewimgcolor.Blue())
1051     self.result ="OK"
1052     self.end_dialog(self.result)
1053    
1054     def OnCancel(self, event):
1055     self.end_dialog(None)
1056    
1057    
1058 jschuengel 2303 class Metadata_CustomDataTable(wxPyGridTableBase):
1059     """
1060     """
1061     def __init__(self, data):
1062     wxPyGridTableBase.__init__(self)
1063    
1064     self.colLabels = ['ID', 'Description']
1065     self.dataTypes = [wxGRID_VALUE_STRING,
1066     wxGRID_VALUE_STRING
1067     ]
1068    
1069     if data:
1070     self.data = data
1071     else:
1072     self.data = [["",""]] #--------------------------------------------------
1073     # required methods for the wxPyGridTableBase interface
1074    
1075     def GetNumberRows(self):
1076     return len(self.data) + 1
1077    
1078     def GetNumberCols(self):
1079     if self.data[0]:
1080     return len(self.data[0])
1081     else:
1082     return None
1083    
1084     def IsEmptyCell(self, row, col):
1085     try:
1086     return not self.data[row][col]
1087     except IndexError:
1088     return true
1089    
1090     # Get/Set values in the table. The Python version of these
1091     # methods can handle any data-type, (as long as the Editor and
1092     # Renderer understands the type too,) not just strings as in the
1093     # C++ version.
1094     def GetValue(self, row, col):
1095     try:
1096     return self.data[row][col]
1097     except IndexError:
1098     return ''
1099    
1100     def SetValue(self, row, col, value):
1101     try:
1102     self.data[row][col] = value
1103     except IndexError:
1104     # add a new row
1105     self.data.append([''] * self.GetNumberCols())
1106     self.SetValue(row, col, value)
1107    
1108     # tell the grid we've added a row
1109     msg = wxGridTableMessage(self, # The table
1110     wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
1111     1) # how many
1112    
1113     self.GetView().ProcessTableMessage(msg)
1114    
1115    
1116     class Metadata_TableGrid(wxGrid):
1117     def __init__(self, parent, data):
1118     wxGrid.__init__(self, parent, -1, size=(600,400))
1119    
1120     self.table = Metadata_CustomDataTable(data)
1121    
1122     # The second parameter means that the grid is to take ownership of the
1123     # table and will destroy it when done. Otherwise you would need to keep
1124     # a reference to it and call it's Destroy method later.
1125     self.SetTable(self.table, true)
1126    
1127     self.SetRowLabelSize(0)
1128     self.SetMargins(0,0)
1129     self.AutoSizeColumns(False)
1130    
1131     EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
1132    
1133     def get_table(self):
1134     return self.table
1135    
1136     # I do this because I don't like the default behaviour of not starting the
1137     # cell editor on double clicks, but only a second click.
1138     def OnLeftDClick(self, evt):
1139     if self.CanEnableCellControl():
1140     self.EnableCellEditControl()
1141    
1142    
1143     class Metadata_Dialog(wxDialog):
1144    
1145     def __init__(self, parent, ID, title,
1146     pos=wxDefaultPosition, size=wxDefaultSize,
1147     style=wxDEFAULT_DIALOG_STYLE):
1148    
1149     # initialize the Dialog
1150     wxDialog.__init__(self, parent, ID, title, pos, size, style)
1151    
1152     # get the web object
1153     if hasattr(parent,"umn_metadata"):
1154     self.umn_metadata = parent.umn_metadata
1155     else:
1156     self.tb_map = parent.canvas.Map()
1157     self.umn_metadata = self.tb_map.extension_umn_mapobj.get_metadata()
1158    
1159    
1160     # at all items to the dataset
1161     self.grid = Metadata_TableGrid(self, self.umn_metadata.get_metadata())
1162    
1163     #buttons
1164     box_buttons = wxBoxSizer(wxHORIZONTAL)
1165     button = wxButton(self, wxID_OK, _("OK"))
1166     box_buttons.Add(button, 0, wxALL, 5)
1167     button = wxButton(self, wxID_CANCEL, _("Cancel"))
1168     button.SetFocus()
1169     box_buttons.Add(button, 0, wxALL, 5)
1170     #set the button funcitons
1171     EVT_BUTTON(self, wxID_OK, self.OnOK)
1172     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
1173    
1174     # compose the dialog
1175     top = wxBoxSizer(wxVERTICAL)
1176     top.Add(self.grid, 1, wxGROW|wxALL, 5)
1177     top.Add(box_buttons, 0, wxALIGN_RIGHT)
1178    
1179     # final layout settings
1180     self.SetSizer(top)
1181     #top.Fit(self)
1182    
1183     def OnItemActivated(self, event):
1184     self.currentItem = event.m_itemIndex
1185    
1186     def OnDoubleClick(self, event):
1187     print "OnDoubleClick" +self.list.GetItemText(self.currentItem)
1188     event.Skip()
1189    
1190     def OnSize(self, event):
1191     w,h = self.GetClientSizeTuple()
1192     self.list.SetDimensions(0, 0, w, h)
1193    
1194     def RunDialog(self):
1195     self.ShowModal()
1196     self.Destroy()
1197    
1198     def end_dialog(self, result):
1199     self.result = result
1200     if self.result is not None:
1201     self.EndModal(wxID_OK)
1202     else:
1203     self.EndModal(wxID_CANCEL)
1204     self.Show(False)
1205    
1206     def OnOK(self, event):
1207     # added all metadatas to the mapobj
1208     # TODO: only add ne to the old Metadata
1209     #self.tb_map_metadata = MF_Metadata(self.tb_map.extension_umn_mapobj)
1210     for x in range(0, self.grid.get_table().GetNumberRows()-1,1):
1211     if self.grid.get_table().GetValue(x,0):
1212     self.umn_metadata.add_metadata(str(self.grid.get_table().GetValue(x,0)),\
1213     str(self.grid.get_table().GetValue(x,1)))
1214     else:
1215     delkey = self.umn_metadata.get_metadatakeys()[x]
1216     self.umn_metadata.remove_metadatabykey(delkey)
1217    
1218     self.result ="OK"
1219     self.end_dialog(self.result)
1220    
1221     def OnCancel(self, event):
1222     self.end_dialog(None)
1223    
1224    
1225    
1226    
1227     def metadatasettings(context):
1228     win = Metadata_Dialog(context.mainwindow, -1, "Metadata Settings",
1229     size=wxSize(350, 200),
1230     style = wxDEFAULT_DIALOG_STYLE)
1231     win.CenterOnScreen()
1232     val = win.ShowModal()
1233    
1234    
1235 jschuengel 2267 def scalebarsettings(context):
1236 jschuengel 2274 win = Scalebar_Dialog(context.mainwindow, -1, "Scalebar Settings",
1237     size=wxSize(350, 200),
1238     style = wxDEFAULT_DIALOG_STYLE)
1239 jschuengel 2267 win.CenterOnScreen()
1240     val = win.ShowModal()
1241    
1242 jschuengel 2257 def mapsettings(context):
1243 jschuengel 2274 win = Map_Dialog(context.mainwindow, -1, "Map Settings",
1244     size=wxSize(350, 200),
1245     style = wxDEFAULT_DIALOG_STYLE)
1246 jschuengel 2257 win.CenterOnScreen()
1247     val = win.ShowModal()
1248    
1249 jschuengel 2271 def outputformatsettings(context):
1250     win = OutputFormat_Dialog(context.mainwindow, -1, "OutputFormat Settings",
1251 jschuengel 2274 size=wxSize(350, 200),
1252     style = wxDEFAULT_DIALOG_STYLE)
1253 jschuengel 2271 win.CenterOnScreen()
1254     val = win.ShowModal()
1255    
1256 jschuengel 2257 def websettings(context):
1257 jschuengel 2274 win = Web_Dialog(context.mainwindow, -1, "Web Settings",
1258     size=wxSize(350, 200),
1259     style = wxDEFAULT_DIALOG_STYLE)
1260 jschuengel 2257 win.CenterOnScreen()
1261     val = win.ShowModal()
1262    
1263 jschuengel 2303 def layersettings(context):
1264     win = Layer_Dialog(context.mainwindow, -1, "Layer Settings",
1265     size=wxSize(350, 200),
1266     style = wxDEFAULT_DIALOG_STYLE)
1267     win.CenterOnScreen()
1268     val = win.ShowModal()
1269    
1270 jschuengel 2257 def legendsettings(context):
1271 jschuengel 2274 win = Legend_Dialog(context.mainwindow, -1, "Legend Settings",
1272     size=wxSize(350, 200),
1273     style = wxDEFAULT_DIALOG_STYLE)
1274 jschuengel 2257 win.CenterOnScreen()
1275     val = win.ShowModal()
1276    
1277     #create a new mapfile
1278     def create_new_mapfile(context):
1279     theMap = MF_Map(mapObj(""))
1280     context.mainwindow.canvas.Map().extension_umn_mapobj = theMap
1281    
1282 jschuengel 2282
1283     # TODO: Maybe can be imported from another class
1284     # check if an mapobj exists, to control the menuitem is available or not
1285     def _has_umn_mapobj(context):
1286     """Return true if a umn_mapobj exists"""
1287     return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj")
1288    
1289 jschuengel 2303 def _has_umn_mapobj_and_selectedlayer(context):
1290     """Return true if a umn_mapobj exists"""
1291     if context.mainwindow.has_selected_layer():
1292     return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj")
1293     else:
1294     return False
1295 jschuengel 2282
1296 jschuengel 2257 # ###################################
1297     #
1298     # Hook in MapServer Extension into Thuban
1299     #
1300     # ###################################
1301    
1302     # find the extensions menu (create it anew if not found)
1303 jschuengel 2274 experimental_menu = main_menu.FindOrInsertMenu("experimental",
1304     _("Experimenta&l"))
1305 jschuengel 2257 # find the extension menu and add a new submenu if found
1306 jschuengel 2274 mapserver_menu = experimental_menu.FindOrInsertMenu("mapserver",
1307     _("&MapServer"))
1308 jschuengel 2257
1309     # register the new command
1310 jschuengel 2282 registry.Add(Command("create_new_mapfile", _("Create new mapfile"), \
1311     create_new_mapfile, \
1312     helptext = _("Create a new empty mapscript MapObj")))
1313 jschuengel 2257 # finally add the new entry to the extensions menu
1314 jschuengel 2282 mapserver_menu.InsertItem("create_new_mapfile", after = "import_mapfile" )
1315 jschuengel 2257
1316 jschuengel 2282 # find the MapServer menu and add a new submenu if found
1317     mapserver_edit_menu = mapserver_menu.FindOrInsertMenu("edit_mapfile",
1318     _("&Edit mapfile"), \
1319     after = "create_new_mapfile")
1320 jschuengel 2257
1321     # register the new command (Map Settings Dialog)
1322 jschuengel 2282 registry.Add(Command("Map Settings", _("Map"), mapsettings,
1323     helptext = _("Edit the Map Setting"), \
1324     sensitive = _has_umn_mapobj))
1325 jschuengel 2257 # finally add the new entry to the extensions menu
1326 jschuengel 2282 mapserver_edit_menu.InsertItem("Map Settings")
1327 jschuengel 2257
1328 jschuengel 2271
1329 jschuengel 2257 # register the new command (Map Settings Dialog)
1330 jschuengel 2282 registry.Add(Command("Web Settings", _("Web"),
1331 jschuengel 2274 websettings,
1332 jschuengel 2282 helptext = _("Edit the Web Setting"), \
1333     sensitive = _has_umn_mapobj))
1334 jschuengel 2257 # finally add the new entry to the extensions menu
1335 jschuengel 2282 mapserver_edit_menu.InsertItem("Web Settings")
1336 jschuengel 2257
1337 jschuengel 2303 # register the new command (Layer Settings Dialog)
1338     registry.Add(Command("Layer Settings", _("Layer"),
1339     layersettings,
1340     helptext = _("Edit the Layer Setting of the aktive Layer"), \
1341     sensitive = _has_umn_mapobj_and_selectedlayer))
1342     # finally add the new entry to the extensions menu
1343     mapserver_edit_menu.InsertItem("Layer Settings")
1344    
1345 jschuengel 2257 # register the new command (Legend Settings Dialog)
1346 jschuengel 2282 registry.Add(Command("Legend Settings", _("Legend"),
1347 jschuengel 2274 legendsettings,
1348 jschuengel 2282 helptext = _("Edit the Legend Setting"), \
1349     sensitive = _has_umn_mapobj))
1350 jschuengel 2257 # finally add the new entry to the extensions menu
1351 jschuengel 2282 mapserver_edit_menu.InsertItem("Legend Settings")
1352 jschuengel 2257
1353 jschuengel 2267 # register the new command (Scalebar Settings Dialog)
1354 jschuengel 2282 registry.Add(Command("Scalebar Settings", _("Scalebar"),
1355 jschuengel 2274 scalebarsettings,
1356 jschuengel 2282 helptext = _("Edit the Scalebar Setting"), \
1357     sensitive = _has_umn_mapobj))
1358 jschuengel 2267 # finally add the new entry to the extensions menu
1359 jschuengel 2282 mapserver_edit_menu.InsertItem("Scalebar Settings")
1360 jschuengel 2257
1361 jschuengel 2303 # register the new command (Scalebar Settings Dialog)
1362     registry.Add(Command("Metadata Settings", _("Metadata"),
1363     metadatasettings,
1364     helptext = _("Edit the Metadata Setting"), \
1365     sensitive = _has_umn_mapobj))
1366     # finally add the new entry to the extensions menu
1367     mapserver_edit_menu.InsertItem("Metadata Settings")
1368 jschuengel 2267
1369 jschuengel 2303

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26