Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI: fix WMS, includes changing widget because listtreectrl didn't … #242

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions gui/wxpython/web_services/dialogs.py
Original file line number Diff line number Diff line change
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
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(_("Unabble 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