1 |
# Copyright (c) 2004 by Intevation GmbH |
2 |
# Authors: |
3 |
# Martin Schulze <[email protected]> |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or modify |
6 |
# it under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 2 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, |
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with this program; if not, write to the Free Software |
17 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 |
|
19 |
""" |
20 |
Edit Layer Properties |
21 |
|
22 |
class wmsProperties(NonModalNonParentDialog): |
23 |
__init__ |
24 |
|
25 |
dialog_layout(text) |
26 |
|
27 |
OnOK(event) |
28 |
OnCancel(event) |
29 |
|
30 |
Problems: |
31 |
|
32 |
1. The wxTextCtrl should fit to the right side of the horizontal |
33 |
box/sizer. It doesn't. I only found the sizer.Add() method to |
34 |
be able to take proportions but no way to tell the object to |
35 |
fill all remaining space. |
36 |
|
37 |
2. The framed box "Layers" needs to be scrollable if there are |
38 |
more than 12 items, since the dialog would probably not fit on |
39 |
people's screen anymore. |
40 |
|
41 |
Todo: This can be solved (in C it was possible at least), |
42 |
probably with wxScrolledWindow |
43 |
|
44 |
3. The button hbox is not aligned to the right side which should |
45 |
be. For some reason wxALIGN_RIGHT does not have any effect. |
46 |
Maybe I just misunderstood the documentation? |
47 |
|
48 |
""" |
49 |
|
50 |
__version__ = "$Revision$" |
51 |
# $Source$ |
52 |
# $Id$ |
53 |
|
54 |
from Thuban import _ |
55 |
from Thuban.UI.dialogs import NonModalNonParentDialog |
56 |
|
57 |
from wxPython.wx import * |
58 |
# wxBoxSizer, wxVERTICAL, wxHORIZONTAL, \ |
59 |
# wxButton, wxID_OK, wxID_CANCEL, wxALL, wxALIGN_CENTER_HORIZONTAL, \ |
60 |
# EVT_BUTTON, wxEXPAND, wxStaticBoxSizer, wxStaticBox, wxALIGN_RIGHT, \ |
61 |
# wxALIGN_BOTTOM |
62 |
|
63 |
ID_WMS_TITLE = 5001 |
64 |
ID_WMS_LAYER = 5002 |
65 |
ID_WMS_FORMATS = 5003 |
66 |
|
67 |
MAX_LAYERNAME_LENGTH = 45 |
68 |
MAX_VISIBLE_LAYERS = 12 |
69 |
|
70 |
class wmsProperties(NonModalNonParentDialog): |
71 |
""" |
72 |
Representation for the WMS properties dialog |
73 |
""" |
74 |
|
75 |
def __init__(self, parent, name, layer, *args, **kw): |
76 |
""" |
77 |
Build the properties dialog |
78 |
""" |
79 |
title = _("Edit WMS Properties") |
80 |
NonModalNonParentDialog.__init__(self, parent, name, title) |
81 |
|
82 |
self.layer = layer |
83 |
|
84 |
# Hooks for the widgets to get user data |
85 |
self.entry = None |
86 |
self.layers = {} |
87 |
self.formats = None |
88 |
|
89 |
self.dialog_layout(layer) |
90 |
|
91 |
|
92 |
def dialog_layout(self, layer): |
93 |
""" |
94 |
Set up the information dialog |
95 |
""" |
96 |
|
97 |
# main box for the entire dialog |
98 |
mainbox = wxBoxSizer(wxHORIZONTAL) |
99 |
|
100 |
# vertical box to contain the three parts |
101 |
# (title, layers, formats+buttons) |
102 |
vbox = wxBoxSizer(wxVERTICAL) |
103 |
mainbox.Add(vbox, 0, wxALL|wxEXPAND, 4) |
104 |
|
105 |
# edit the title |
106 |
hbox = wxBoxSizer(wxHORIZONTAL) |
107 |
vbox.Add(hbox, 0, wxALL, 0) |
108 |
label = wxStaticText(self, ID_WMS_TITLE, _("Title:")) |
109 |
hbox.Add(label, 1, wxALL|wxEXPAND, 4) |
110 |
self.entry = wxTextCtrl(self, ID_WMS_TITLE, layer.Title()) |
111 |
hbox.Add(self.entry, 7, wxALL|wxEXPAND|wxALIGN_RIGHT, 0) |
112 |
|
113 |
layerbox = wxStaticBox(self, ID_WMS_LAYER, _("Layers")) |
114 |
lbox = wxStaticBoxSizer(layerbox, wxVERTICAL) |
115 |
vbox.Add(lbox, 0, wxALL, 0) |
116 |
visible = layer.getVisibleLayers() |
117 |
for l in layer.getLayers(): |
118 |
checker = wxCheckBox(self, ID_WMS_LAYER, layer.getLayerTitle(l)[0:MAX_LAYERNAME_LENGTH].encode('latin1')) |
119 |
self.layers[l] = checker |
120 |
if l in visible: |
121 |
checker.SetValue(True) |
122 |
lbox.Add(checker, 0, wxALL|wxEXPAND, 0) |
123 |
|
124 |
# tiled box: |
125 |
hbox = wxBoxSizer(wxHORIZONTAL) |
126 |
vbox.Add(hbox, 0, wxALL|wxEXPAND, 0) |
127 |
|
128 |
# left part: image format selection |
129 |
formatbox = wxBoxSizer(wxHORIZONTAL) |
130 |
hbox.Add(formatbox, 1, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 0) |
131 |
label = wxStaticText(self, ID_WMS_FORMATS, _("Format:")) |
132 |
formatbox.Add(label, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
133 |
self.formats = wxChoice(self, ID_WMS_FORMATS) |
134 |
formatbox.Add(self.formats, 1, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 4) |
135 |
|
136 |
# fill the select box |
137 |
match = 0 |
138 |
count = 0 |
139 |
format = layer.getWMSFormat() |
140 |
for f in layer.getFormats(): |
141 |
self.formats.Append(f) |
142 |
if f == format: |
143 |
match = count |
144 |
count += 1 |
145 |
|
146 |
self.formats.Fit() |
147 |
self.formats.SetSelection(match) |
148 |
|
149 |
# Build the button hbox, to be added into row |
150 |
buttons = wxBoxSizer(wxHORIZONTAL) |
151 |
hbox.Add(buttons, 1, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 0) |
152 |
buttons.Add(wxButton(self, wxID_OK, _("OK")), 0, wxALL, 4) |
153 |
buttons.Add(wxButton(self, wxID_CANCEL, _("Cancel")), 0, wxALL, 4) |
154 |
EVT_BUTTON(self, wxID_OK, self.OnOK) |
155 |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
156 |
|
157 |
self.SetAutoLayout(True) |
158 |
self.SetSizer(mainbox) |
159 |
mainbox.Fit(self) |
160 |
mainbox.SetSizeHints(self) |
161 |
|
162 |
|
163 |
def OnOK(self, event): |
164 |
""" |
165 |
Handle the 'OK button pressed' event |
166 |
|
167 |
i.e. transfer user input into the layer |
168 |
""" |
169 |
|
170 |
# Set the title |
171 |
self.layer.SetTitle(self.entry.GetValue()) |
172 |
|
173 |
# Set the image format for WMS GetMap requests |
174 |
selection = self.formats.GetSelection() |
175 |
if selection > -1: |
176 |
self.layer.setWMSFormat(self.formats.GetString(self.formats.GetSelection())) |
177 |
|
178 |
# Set the list of visible layers |
179 |
visible = [] |
180 |
for l in self.layers.keys(): |
181 |
if self.layers[l].IsChecked(): |
182 |
visible.append(l) |
183 |
self.layer.setVisibleLayers(visible) |
184 |
|
185 |
self.Close() |
186 |
|
187 |
|
188 |
def OnCancel(self, event): |
189 |
""" |
190 |
Handle the 'Cancel button pressed' event |
191 |
""" |
192 |
self.Close() |