2 @package module.ogc_services
4 @brief Dialogs for OGC services
6 Currently only implemeted WMS.
9 - ogc_services::WMSDialog
10 - ogc_services::LayersList
12 (C) 2009-2011 by the GRASS Development Team
14 This program is free software under the GNU General Public License
15 (>=v2). Read the file COPYING that comes with GRASS for details.
17 @author Martin Landa <landa.martin gmail.com>
21 from wx.gizmos
import TreeListCtrl
22 import wx.lib.mixins.listctrl
as listmix
29 def __init__(self, parent, service = 'wms',
31 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
32 """!Dialog to import data from WMS server"""
36 wx.Dialog.__init__(self, parent, id, style=style)
38 self.SetTitle(_(
"Import data from WMS server"))
40 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
46 self.SetMinSize((550, 400))
48 def __createWidgets(self):
49 """!Create dialog widgets"""
54 label = _(
" Server settings "))
56 self.
serverText = wx.StaticText(parent = self.
panel, id = wx.ID_ANY, label = _(
"Server:"))
57 self.
server = wx.TextCtrl(parent = self.
panel, id = wx.ID_ANY)
63 label=_(
" List of layers "))
68 self.
add = wx.CheckBox(parent=self.
panel, id=wx.ID_ANY,
69 label=_(
"Add imported layers into layer tree"))
70 self.add.SetValue(UserSettings.Get(group=
'cmd', key=
'addNewLayer', subkey=
'enabled'))
77 self.btn_cancel.SetToolTipString(_(
"Close dialog"))
79 self.
btn_connect = wx.Button(parent = self.
panel, id = wx.ID_ANY, label = _(
"&Connect"))
80 self.btn_connect.SetToolTipString(_(
"Connect to the server"))
81 self.btn_connect.SetDefault()
82 if not self.server.GetValue():
83 self.btn_connect.Enable(
False)
85 self.
btn_import = wx.Button(parent = self.
panel, id = wx.ID_OK, label = _(
"&Import"))
86 self.btn_import.SetToolTipString(_(
"Import selected layers"))
87 self.btn_import.Enable(
False)
92 self.btn_cancel.Bind(wx.EVT_BUTTON, self.
OnCancel)
93 self.btn_connect.Bind(wx.EVT_BUTTON, self.
OnConnect)
94 self.server.Bind(wx.EVT_TEXT, self.
OnServer)
97 """!Do dialog layout"""
98 dialogSizer = wx.BoxSizer(wx.VERTICAL)
103 settingsSizer = wx.StaticBoxSizer(self.
settingsBox, wx.HORIZONTAL)
105 gridSizer = wx.FlexGridSizer(cols=2, vgap=5, hgap=5)
108 flag=wx.ALIGN_CENTER_VERTICAL)
109 gridSizer.AddGrowableCol(1)
110 gridSizer.Add(item=self.
server,
111 flag=wx.EXPAND | wx.ALL)
113 settingsSizer.Add(item=gridSizer, proportion=1,
114 flag=wx.EXPAND | wx.ALL)
116 dialogSizer.Add(item=settingsSizer, proportion=0,
117 flag=wx.ALL | wx.EXPAND, border=5)
122 layersSizer = wx.StaticBoxSizer(self.
layersBox, wx.HORIZONTAL)
124 layersSizer.Add(item=self.
list, proportion=1,
125 flag=wx.ALL | wx.EXPAND, border=5)
127 dialogSizer.Add(item=layersSizer, proportion=1,
128 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
130 dialogSizer.Add(item=self.
add, proportion=0,
131 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
136 btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
138 btnsizer.Add(item=self.
btn_cancel, proportion=0,
139 flag=wx.ALL | wx.ALIGN_CENTER,
143 flag=wx.ALL | wx.ALIGN_CENTER,
146 btnsizer.Add(item=self.
btn_import, proportion=0,
147 flag=wx.ALL | wx.ALIGN_CENTER,
150 dialogSizer.Add(item=btnsizer, proportion=0,
151 flag=wx.ALIGN_CENTER)
153 self.panel.SetAutoLayout(
True)
154 self.panel.SetSizer(dialogSizer)
155 dialogSizer.Fit(self.
panel)
159 """!Button 'Cancel' pressed -> close the dialog"""
163 """!Button 'Connect' pressed"""
167 GError(_(
"The 'xml2' parser is required, please install it "
168 "first. You may also try running r.in.wms directly "
169 "from the command line."))
172 server = self.server.GetValue()
174 self.btn_import.Enable(
False)
187 self.btn_import.Enable(
False)
190 lastLayer = lastStyle =
''
191 for line
in ret.splitlines():
193 key, value = line.split(
':', 1)
196 key = key.strip().lower()
197 value = value.strip()
203 if lastLayer
and 'title' not in layers[lastLayer]:
204 layers[lastLayer][key] = value.decode(
'utf8')
207 if 'style' not in layers[lastLayer]:
208 layers[lastLayer][
'style'] = {}
209 layers[lastLayer][
'style'][value] =
''
211 elif key ==
'style title':
213 layers[lastLayer][
'style'][lastStyle] = value
216 self.list.LoadData(layers)
218 if len(layers.keys()) > 0:
219 self.btn_import.Enable(
True)
221 self.btn_import.Enable(
False)
224 """!Server settings changed"""
225 value = event.GetString()
227 self.btn_connect.Enable(
True)
229 self.btn_connect.Enable(
False)
232 """!Get list of selected layers/styles to be imported"""
233 return self.list.GetSelectedLayers()
236 """!Get connection settings"""
237 return {
'server' : self.server.GetValue() }
239 class LayersList(TreeListCtrl, listmix.ListCtrlAutoWidthMixin):
240 def __init__(self, parent, pos=wx.DefaultPosition):
241 """!List of layers to be imported (dxf, shp...)"""
244 TreeListCtrl.__init__(self, parent, wx.ID_ANY,
245 style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT |
246 wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_MULTIPLE)
249 listmix.ListCtrlAutoWidthMixin.__init__(self)
251 self.AddColumn(_(
'Layer / Style'))
252 self.AddColumn(_(
'Title'))
253 self.SetMainColumn(0)
254 self.SetColumnWidth(0, 175)
259 """!Load data into list"""
261 self.DeleteAllItems()
262 self.
root = self.AddRoot(_(
"Layers"))
271 title = data[layer][
'title']
272 lchild = self.AppendItem(self.
root, layer)
273 self.SetItemText(lchild, title, 1)
274 if 'style' in data[layer]:
275 styles = data[layer][
'style'].keys()
280 title = data[layer][
'style'][style]
281 schild = self.AppendItem(lchild, style)
282 self.SetItemText(schild, title, 1)
284 self.Expand(self.
root)
287 """!Required for listmix.ListCtrlAutoWidthMixin"""
291 """!Required for listmix.ListCtrlAutoWidthMixin"""
295 """!Get selected layers/styles"""
298 for item
in self.GetSelections():
299 parent = self.GetItemParent(item)
300 if parent == self.
root:
301 layer = self.GetItemText(item, 0)
302 layers[layer] = list()
303 sitem, cookie = self.GetFirstChild(item)
305 layers[layer].append(self.GetItemText(sitem, 0))
306 sitem, cookie = self.GetNextChild(item, cookie)
308 layer = self.GetItemText(parent, 0)
309 layers[layer] = list()
310 layers[layer].append(self.GetItemText(item, 0))
def GetSelectedLayers
Get selected layers/styles.
def find_program
Attempt to run a program, with optional arguments.
def GetLayers
Get list of selected layers/styles to be imported.
def OnServer
Server settings changed.
GRASS Python scripting module (core functions)
def GetCountPerPage
Required for listmix.ListCtrlAutoWidthMixin.
def __createWidgets
Create dialog widgets.
def GetSettings
Get connection settings.
def LoadData
Load data into list.
def GetItemCount
Required for listmix.ListCtrlAutoWidthMixin.
def OnCancel
Button 'Cancel' pressed -> close the dialog.
def __doLayout
Do dialog layout.
def OnConnect
Button 'Connect' pressed.
def __init__
Dialog to import data from WMS server.
def RunCommand
Run GRASS command.
def __init__
List of layers to be imported (dxf, shp...)