Skip to content

Commit

Permalink
wxGUI: fix WMS (#242)
Browse files Browse the repository at this point in the history
* wxGUI: fix WMS, includes changing widget because listtreectrl didn't behave correctly when selecting layers

* avoid wx warnings about deprecated calls in wms dlg

* wms: fix returncode, py3 compatibility, typo
  • Loading branch information
petrasovaa committed Jan 30, 2020
1 parent d7397d5 commit a06295e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 68 deletions.
4 changes: 3 additions & 1 deletion gui/wxpython/core/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def Render(self, cmd, env):

def _render(self, cmd, env):
try:
return grass.run_command(cmd[0], env=env, **cmd[1])
# TODO: use errors=status when working
grass.run_command(cmd[0], env=env, **cmd[1])
return 0
except CalledModuleError as e:
grass.error(e)
return 1
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ def AddSettings(self, settings):
:param settings: - dict with all settigs {nameofsetting : settingdata, ....}
"""
self._settings = dict(self._settings.items() + settings.items())
self._settings.update(settings)
self._saveSettings()

def OnSettingsDelete(self, event):
Expand Down
16 changes: 7 additions & 9 deletions gui/wxpython/web_services/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from core.gconsole import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT

from gui_core.gselect import Select
from gui_core.wrap import Button, StaticText, StaticBox, TextCtrl
from gui_core.wrap import Button, StaticText, StaticBox, TextCtrl, RadioButton

from web_services.widgets import WSPanel, WSManageSettingsWidget

Expand Down Expand Up @@ -363,8 +363,6 @@ def OnOutputLayerName(self, event):
"""Update layer name to web service panel
"""
lname = event.GetString()
lname = lname.encode('ascii', 'replace')

for v in six.itervalues(self.ws_panels):
v['panel'].SetOutputLayerName(lname.strip())

Expand Down Expand Up @@ -869,17 +867,17 @@ def _createWidgets(self):

self.region_types_order = ['display', 'comp', 'named']
self.region_types = {}
self.region_types['display'] = wx.RadioButton(
self.region_types['display'] = RadioButton(
parent=self, label=_("Map display"), style=wx.RB_GROUP)
self.region_types['comp'] = wx.RadioButton(
self.region_types['comp'] = RadioButton(
parent=self, label=_("Computational region"))
self.region_types['named'] = wx.RadioButton(
self.region_types['named'] = RadioButton(
parent=self, label=_("Named region"))
self.region_types['display'].SetToolTipString(
self.region_types['display'].SetToolTip(
_("Extent and resolution" " are based on Map Display geometry."))
self.region_types['comp'].SetToolTipString(
self.region_types['comp'].SetToolTip(
_("Extent and resolution" " are based on computational region."))
self.region_types['named'].SetToolTipString(
self.region_types['named'].SetToolTip(
_("Extent and resolution" " are based on named region."))
self.region_types['display'].SetValue(
True) # set default as map display
Expand Down
73 changes: 23 additions & 50 deletions gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
else:
import wx.lib.flatnotebook as FN
import wx.lib.colourselect as csel
import wx.lib.mixins.listctrl as listmix
from wx.lib.newevent import NewEvent
if globalvar.wxPythonPhoenix:
try:
from agw.hypertreelist import HyperTreeList as TreeListCtrl
except ImportError: # if it's not there locally, try the wxPython lib.
from wx.lib.agw.hypertreelist import HyperTreeList as TreeListCtrl
else:
from wx.gizmos import TreeListCtrl

from core.debug import Debug
from core.gcmd import GWarning, GMessage
Expand All @@ -56,7 +47,7 @@
from gui_core.widgets import GNotebook
from gui_core.widgets import ManageSettingsWidget
from gui_core.wrap import SpinCtrl, Button, StaticText, StaticBox, \
TextCtrl
TextCtrl, TreeCtrl

import grass.script as grass

Expand Down Expand Up @@ -448,7 +439,7 @@ def OnDown(self, event):
def _updateLayerOrderList(self, selected=None):
"""Update order in list.
"""
def getlayercaption(layer):
def getlayercaption(l):
if l['title']:
cap = (l['title'])
else:
Expand Down Expand Up @@ -846,7 +837,7 @@ def _updateFormatRadioBox(self, formats_list):
choices=formats_list,
majorDimension=4,
style=wx.RA_SPECIFY_COLS)
self.source_sizer.Insert(item=self.params['format'], before=2,
self.source_sizer.Insert(2, window=self.params['format'],
flag=wx.LEFT | wx.RIGHT | wx.BOTTOM,
border=5)

Expand Down Expand Up @@ -918,27 +909,15 @@ def GetWebService(self):
"""
return self.ws


class LayersList(TreeListCtrl, listmix.ListCtrlAutoWidthMixin):
class LayersList(TreeCtrl):

def __init__(self, parent, web_service, style, pos=wx.DefaultPosition):
"""List of layers and styles available in capabilities file
"""
self.parent = parent
self.ws = web_service

TreeListCtrl.__init__(self, parent=parent, id=wx.ID_ANY, style=style)

# setup mixins
listmix.ListCtrlAutoWidthMixin.__init__(self)
if self.ws != 'OnEarth':
self.AddColumn(_('Name'))
self.AddColumn(_('Type'))
else:
self.AddColumn(_('Layer name'))

self.SetMainColumn(0) # column with the tree
self.setResizeColumn(0)
TreeCtrl.__init__(self, parent=parent, id=wx.ID_ANY, style=style)

self.root = None
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnListSelChanging)
Expand Down Expand Up @@ -970,10 +949,6 @@ def gettitle(layer):
return layer_title

def addlayer(layer, item):

if self.ws != 'OnEarth':
self.SetItemText(item, _('layer'), 1)

styles = layer.GetLayerData('styles')

def_st = None
Expand All @@ -991,14 +966,12 @@ def addlayer(layer, item):
def_st = st

style_item = self.AppendItem(item, style_name)
if self.ws != 'OnEarth':
self.SetItemText(style_item, _('style'), 1)

self.SetPyData(style_item, {'type': 'style',
self.SetItemData(style_item, {'type': 'style',
'layer': layer, # it is parent layer of style
'style': st})

self.SetPyData(item, {'type': 'layer', # is it layer or style?
self.SetItemData(item, {'type': 'layer', # is it layer or style?
'layer': layer, # Layer instance from web_services.cap_interface
'style': def_st}) # layer can have assigned default style

Expand Down Expand Up @@ -1030,13 +1003,13 @@ def GetSelectedLayers(self):
sel_layers_dict = []
for s in sel_layers:
try:
layer = self.GetPyData(s)['layer']
layer = self.GetItemData(s)['layer']
except ValueError:
continue
sel_layers_dict.append({
'name': layer.GetLayerData('name'),
'title': layer.GetLayerData('title'),
'style': self.GetPyData(s)['style'],
'style': self.GetItemData(s)['style'],
'cap_intf_l': layer
})
return sel_layers_dict
Expand All @@ -1052,23 +1025,23 @@ def _selectRequestableChildren(item, list_to_check, items_to_sel):

self.Expand(item)
child_item, cookie = self.GetFirstChild(item)
while child_item.IsOk():
if self.GetPyData(child_item)['layer'].IsRequestable() \
while child_item and child_item.IsOk():
if self.GetItemData(child_item)['layer'].IsRequestable() \
and not self.IsSelected(child_item):
items_to_sel.append(child_item)
elif not self.GetPyData(child_item)['layer'].IsRequestable():
elif not self.GetItemData(child_item)['layer'].IsRequestable():
list_to_check.append(child_item)

child_item, cookie = self.GetNextChild(item, cookie)

cur_item = event.GetItem()
if not self.GetPyData(cur_item)['layer'].IsRequestable():
if not self.GetItemData(cur_item)['layer'].IsRequestable():
event.Veto()

if not self.HasFlag(wx.TR_MULTIPLE):
return

_emitSelected(self.GetPyData(cur_item)['layer'])
_emitSelected(self.GetItemData(cur_item)['layer'])

items_to_chck = []
items_to_sel = []
Expand All @@ -1083,9 +1056,9 @@ def _selectRequestableChildren(item, list_to_check, items_to_sel):
break

while items_to_sel:
self.SelectItem(items_to_sel.pop(), unselect_others=False)
self.SelectItem(items_to_sel.pop(), select=True)
else:
_emitSelected(self.GetPyData(cur_item)['layer'])
_emitSelected(self.GetItemData(cur_item)['layer'])

def GetItemCount(self):
"""Required for listmix.ListCtrlAutoWidthMixin
Expand All @@ -1105,9 +1078,9 @@ def SelectLayers(self, l_st_list):
"""
def checknext(item, l_st_list, items_to_sel):
def compare(item, l_name, st_name):
it_l_name = self.GetPyData(item)['layer'].GetLayerData('name')
it_st = self.GetPyData(item)['style']
it_type = self.GetPyData(item)['type']
it_l_name = self.GetItemData(item)['layer'].GetLayerData('name')
it_st = self.GetItemData(item)['style']
it_type = self.GetItemData(item)['type']

if it_l_name == l_name and ((not it_st and not st_name) or (
it_st and it_st['name'] == st_name and it_type == 'style')):
Expand All @@ -1125,7 +1098,7 @@ def compare(item, l_name, st_name):
break

if len(items_to_sel) == len(l_st_list):
item = self.GetNext(item)
item = self.GetNextVisible(item)
if not item.IsOk():
return
checknext(item, l_st_list, items_to_sel)
Expand All @@ -1145,11 +1118,11 @@ def compare(item, l_name, st_name):
continue

item, l_st = i
un_o = True
keep = False
if self.HasFlag(wx.TR_MULTIPLE):
un_o = False
keep = True

self.SelectItem(item, unselect_others=un_o)
self.SelectItem(item, select=keep)
l_st_list.remove(l_st)

return l_st_list
Expand Down
10 changes: 4 additions & 6 deletions scripts/r.in.wms/wms_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _fetchCapabilities(self, options):
grass.fatal(msg)

grass.debug('Fetching capabilities OK')
return grass.decode(cap)
return grass.decode(cap.read())

def _fetchDataFromServer(self, url, username=None, password=None):
"""!Fetch data from server
Expand All @@ -286,15 +286,13 @@ def GetCapabilities(self, options):
if capfile_output:
try:
with open(capfile_output, "w") as temp:
temp.write(cap.read())
temp.write(cap)
return
except IOError as error:
grass.fatal(_("Unabble to open file '%s'.\n%s\n" % (cap_file, error)))
grass.fatal(_("Unable to open file '%s'.\n%s\n" % (capfile_output, error)))

# print to output
cap_lines = cap.readlines()
for line in cap_lines:
print(line.rstrip())
print(cap)

def _computeBbox(self):
"""!Get region extent for WMS query (bbox)
Expand Down
2 changes: 1 addition & 1 deletion scripts/r.in.wms/wms_drv.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _download(self):
flags='wf',
epsg=self.params['srs'])
projection = projection.rstrip('\n')
temp_map_dataset.SetProjection(grass.encode(projection))
temp_map_dataset.SetProjection(projection)

pixel_x_length = (map_region['maxx'] - map_region['minx']) / int(map_region['cols'])
pixel_y_length = (map_region['miny'] - map_region['maxy']) / int(map_region['rows'])
Expand Down

0 comments on commit a06295e

Please sign in to comment.