[GRASS-SVN] r47889 - grass-addons/grass7/gui/wxpython/wx.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 26 06:47:13 EDT 2011
Author: sudeepsingh
Date: 2011-08-26 03:47:13 -0700 (Fri, 26 Aug 2011)
New Revision: 47889
Modified:
grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py
grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py
grass-addons/grass7/gui/wxpython/wx.wms/addserver.py
grass-addons/grass7/gui/wxpython/wx.wms/parse.py
grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
Log:
Debug messages removed
Modified: grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/LoadConfig.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -17,6 +17,7 @@
"""
import os
+import grass
def loadConfigFile(self):
try:
f=open('config','r')
@@ -26,24 +27,17 @@
#patch4s
try:
if(len(lines)!=3):
- print 'Insufficient number of arguments,3 paramters required name_url_delimiter, timeoutValueSeconds, urlLength'
+ message = 'Insufficient number of arguments,3 paramters required name_url_delimiter, timeoutValueSeconds, urlLength'
+ grass.fatal_error(message)
raise Exception
self.name_url_delimiter = lines[0].split(':')[1]
self.timeoutValueSeconds = int(lines[1].split(':')[1])
self.urlLength = int(lines[2].split(':')[1])
- #self.name_url_delimiter = '\n'
- print self.timeoutValueSeconds
except Exception, e:
- print e
- print 'Internal exception, config file format error, using default values'
self.name_url_delimiter = '#'
self.timeoutValueSeconds = 5
self.urlLength = 50
- #patch4e
- print "config file loaded successfully"
- print self.name_url_delimiter
+
return True
except:
- os.system("find ./ -name config")
- print "Unable to load config file"
return False
Modified: grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/ServerInfoAPIs.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -32,20 +32,13 @@
if(os.path.exists(fileName)):
try:
f = open(fileName,'r')
- print 'ServersList.xml found, loading ... '
except:
- print 'Unable to open File '+fileName
- print 'exiting application...'
return None, False
xml = f.read()
f.close()
soup = BeautifulStoneSoup(xml)
serverinfolist = soup.findAll('serverinfo')
- #print 'serverinfolisthere'
- #print serverinfolist
- #print len(serverinfolist)
else:
- print 'ServersList.xml not found, creating a new file'
serverinfolist = []
soup = BeautifulSoup()
xml = "null"
@@ -74,23 +67,18 @@
else:
server = Tag(soup, "server")
serverinfo.insert(0,server)
-
#Creating server info tags
servername = Tag(soup, "servername")
serverurl = Tag(soup, "serverurl")
username = Tag(soup, "username")
password = Tag(soup, "password")
-
#Inserting server info fields
server.insert(0, servername)
server.insert(1, serverurl)
server.insert(2, username)
server.insert(3, password)
-
#Adding attribute to server tag
-
server['id'] = uid
-
#Adding text values to the server info fields
servername.insert(0,snamevalue)
serverurl.insert(0, urlvalue)
Modified: grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/WMSMapDisplay.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -33,7 +33,8 @@
png = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self, -1, png, (10 + png.GetWidth(), 5), (png.GetWidth(), png.GetHeight()))
except IOError:
- print "Image file %s not found" % imageFile
+ message = "Image file %s not found" % imageFile
+ grass.warning(message)
raise SystemExit
def NewImageFrame(tempFile):
Modified: grass-addons/grass7/gui/wxpython/wx.wms/addserver.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/addserver.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/addserver.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -35,8 +35,6 @@
-# begin wxGlade: extracode
-# end wxGlade
class ServerData():
pass
@@ -85,7 +83,6 @@
#sudeep code starts
if( not loadConfigFile(self)):
- print 'Config File Error, Unable to start application...'
grass.fatal_error('Config File Error, Unable to start application...')
self.Close()
@@ -158,22 +155,15 @@
self.Layout()
# end wxGlade
def valueExists(self,dict, newServerName):
- print 'Enter here'
- print newServerName
try:
for key, value in dict.items():
- #print key, value.servername
if(value.servername == newServerName):
- print 'returning true'
return True
- print 'returning False'
return False
except:
- print 'Exception while iterating dictionary elements'
return False
+
def OnSave(self, event): # wxGlade: ServerAdd.<event_handler>
- #print "Event handler `OnSave' not implemented"
- print '-------------------------------------------------------------------> OnSave'
newServerName = unicode(self.ServerNameText.GetValue())
newUrl = self.URLText.GetValue()
newUserName = self.UsernameText.GetValue()
@@ -181,43 +171,14 @@
if(not self.allFieldsValid(newServerName, newUrl, newUserName, newPassword)):
return
-
-
-
-
-
- print newServerName
- print 'check12'
-
+
if(self.selectedUid == None):
update = False
else:
update = True
- '''print newServerName
- print self.map_servernameTouid
- if(self.map_servernameTouid.has_key(newServerName)):
- CurrentUid = self.map_servernameTouid[newServerName]
- update = True
- print 'key present'
- else:
- print 'key not present'
- CurrentUid = None
- update = False
- if(self.servers.has_key(Uid)):StatusBar_fields = [character+' is not allowed in a Field']
- self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- update = True
- #print 'Server Name already exists'
- #return
- else:
- update = False'''
-
-
-
+
serverData = ServerData()
- #self.ServerList.Append(newServerName+" "+newUrl)
-
- #url = newUrl.split()
- #if(len(newUrl) != 0 and len(newServerName) != 0 and len(newUserName) !=0 and len(newPassword) != 0 ):
+
if(len(newUrl) != 0 and len(newServerName) != 0):
if(self.selectedServer is not None):
if(not self.selectedServer.servername == newServerName):
@@ -227,9 +188,8 @@
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return
- #del self.servers[self.selectedUid]
+
if(not newUrl.startswith('http://')):
newUrl = 'http://'+newUrl
@@ -244,140 +204,89 @@
StatusBar_fields = [message]
- self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-
- print message
-
+ self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
serverData.servername = newServerName
serverData.url = newUrl
serverData.username = newUserName
serverData.password = newPassword
-
if(update):
if(updateServerInfo(self.soup, self.soup.serverinfo, self.selectedUid, newServerName, newUrl, newUserName, newPassword)):
-
- #patch7s
if(not self.saveXMLData()):
oldInfo = self.servers[self.selectedUid]
if(updateServerInfo(self.soup, self.soup.serverinfo, self.selectedUid, oldInfo.servername, oldInfo.url, oldInfo.username, oldInfo.password)):
message = 'Unable to SaveXML, changes reverted back'
- print message
grass.warning(message)
return
else:
message = 'Unable to SaveXML, changes will be reverted back on restart'
- print message
grass.warning(message)
return
- #patch7e
- #self.StatusBar.setStatusText("Information Updated")
message = 'update save successful'
- print message
grass.message(message)
self.servers[self.selectedUid] = serverData
del self.map_servernameTouid[self.selectedServer.servername]
self.selectedServer = serverData
self.map_servernameTouid[newServerName] = self.selectedUid
-
- #patch5s
+
msg = self.servers
- print 'sending serverlist as message'
Publisher().sendMessage(("update.serverList"), msg)
- print 'message sent'
msg = self.map_servernameTouid
- print 'sending map_servernameTouid as a message'
Publisher().sendMessage(("update.map_servernameTouid"), msg)
- print 'message sent'
- #patch5e
message = "Server Info Updated"
- print message
grass.message(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- self.setModified(False)
-
+ self.setModified(False)
else:
message = "Update not Successful"
self.ShowMessage(message, 'Warning')
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
else:
uid = str(uuid.uuid4())
-
if(addServerInfo(self.soup, self.soup.serverinfo, uid, newServerName, newUrl, newUserName, newPassword)):
- #patch7s
if(not self.saveXMLData()):
- #oldInfo = self.servers[uid]
if(removeServerInfo(self.soup, uid)):
message = 'Unable to SaveXML, Info not saved'
- print message
grass.warning(message)
return
else:
message = 'Unable to SaveXML, changes will be reverted back on restart'
grass.warning(message)
- print message
return
- #patch7e
message = 'soup save successfully'
- print message
grass.message(message)
self.selectedUid = uid
self.servers[self.selectedUid] = serverData
self.selectedServer = serverData
self.map_servernameTouid[newServerName] = uid
- print 'Onsave(): printing the self.map_servernameTouid'
- print self.map_servernameTouid
- print '--------------------------'
- #self.saveXMLData()
- #patch5s
msg = self.servers
- print 'sending serverlist as message'
Publisher().sendMessage(("update.serverList"), msg)
- print 'message sent'
-
msg = self.map_servernameTouid
- print 'sending map_servernameTouid as a message'
Publisher().sendMessage(("update.map_servernameTouid"), msg)
- print 'message sent'
- #patch5e
- #msg = self.servers
message = "Server Info Saved Successfully"
grass.message(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
self.setModified(False)
- #Publisher().sendMessage(("update.serverList"), msg)
else:
message = "Save not successful"
self.ShowMessage(message, 'Warning')
"Server Info Saved Successfully"
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
-
- '''
- f = open('serverList.txt','a')
- f.write(newServerName+" "+newUrl+ " "+newUserName+" "+newPassword+"\n")
- f.close()
- '''
self.selectedURL = newUrl
- print self.selectedURL
- #print self.servers
self.__update_URL_List()
- #Update_Url_List(newServerName+" "+newUrl)
else:
message = "Please fill servername and url fields"
self.ShowMessage(message, 'Warning')
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
self.editOn = False
@@ -385,14 +294,12 @@
event.Skip()
def OnRemove(self, event): # wxGlade: ServerAdd.<event_handler>
- print '-------------------------------------------------------------------> OnRemove'
if(self.selectedUid == None):
message = "No Server selected....Remove Unsuccessful"
self.ShowMessage(message, 'Warning')
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return
else:
if(removeServerInfo(self.soup, self.selectedUid)):
@@ -419,7 +326,6 @@
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
grass.message(message)
- print message
del self.map_servernameTouid[self.selectedServer.servername]
if(len(self.servers) > 0):
self.ServerList.SetSelection(0)
@@ -434,8 +340,6 @@
self.PasswordText.Clear()
self.URLText.Clear()
self.UsernameText.Clear()
- #print self.servers
-
msg = self.servers
Publisher().sendMessage(("update.serverList"), msg)
else:
@@ -444,22 +348,13 @@
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return
- #print self.servers
-
-
- #print "Event handler `OnRemove' not implemented"
self.editOn = False
event.Skip()
def OnAddNew(self, event): # wxGlade: ServerAdd.<event_handler>
- #patch1s
self.checkIfModified(event)
- #patch1e
- print '-------------------------------------------------------------------> OnAddNew'
- #print "Event handler `OnAddNew' not implemented"
self.selectedUid = None
self.ServerNameText.Clear()
self.PasswordText.Clear()
@@ -467,59 +362,34 @@
self.UsernameText.Clear()
self.editOn = False
self.selectedServer=None
- #patch3s
StatusBar_fields = ["Fill in the Info fields"]
- #patch3e
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
event.Skip()
def OnQuit(self, event): # wxGlade: ServerAdd.<event_handler>
- print '-------------------------------------------------------------------> OnQuit'
- print 'onQuit pressed'
- #patch1s
if(self.checkIfModified(event) == wx.ID_CANCEL):
return
- #patch1e
if(not self.saveXMLData()):
message = 'Unable to write in file, Exiting Application'
grass.message(message)
- print message
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-
msg = self.servers
Publisher().sendMessage(("Add_Server_Frame_Closed"), msg)
self.Destroy()
- #exit()
- #self.Close()
- '''out = open('serverList.txt','w')
- for k,v in self.servers.iteritems():
- out.write(v.servername+" "+v.url+" "+v.username+" "+v.password+"\n")
- exit()'''
- #ServerAdd.Close()
- #print "Event handler `OnQuit' not implemented"
event.Skip()
def OnServerList(self, event): # wxGlade: ServerAdd.<event_handler>
- #patch1s
self.checkIfModified(event)
- #patch1e
- print '-------------------------------------------------------------------> OnServerList'
- #print self.ServerList.CurrentSelection
info = self.ServerList.GetValue()
if(len(info) == 0):
return
- print 'here'
- print info
urlarr = info.split(self.name_url_delimiter)
- print urlarr
- #print self.servers
if(len(urlarr)==2):
uid = self.map_servernameTouid[urlarr[0]]
self.selectedUid = uid
self.selectedServer = self.servers[uid]
- print self.selectedServer
self.ServerNameText.SetValue(self.selectedServer.servername)
self.URLText.SetValue(self.selectedServer.url)
self.UsernameText.SetValue(self.selectedServer.username)
@@ -528,19 +398,15 @@
message = "Wrong format of URL selected"
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
grass.fatal_error(message)
- #self.ServerNameText.SetValue(self.servers)
event.Skip()
def OnText(self, event): # wxGlade: ServerAdd.<event_handler>
self.editOn = True
event.Skip()
#wxGlade methods ends
-
- #Sudeeps methods start
- #patch1s
+
def setModified(self, booleanValue):
self.ServerNameText.SetModified(booleanValue)
self.URLText.SetModified(booleanValue)
@@ -550,15 +416,13 @@
def checkIfModified(self, event):
if(self.URLText.IsModified() or self.ServerNameText.IsModified() or self.UsernameText.IsModified() or self.PasswordText.IsModified()):
dial = wx.MessageDialog(None, 'You have unsaved changes.\n Do you want to save them ?', 'Quit',
- wx.STAY_ON_TOP | wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
-
+ wx.STAY_ON_TOP | wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
val = dial.ShowModal()
if val == wx.ID_CANCEL:
return val
if val == wx.ID_YES:
- self.OnSave(event) #well, the parameter is unused
+ self.OnSave(event)
return val
- #patch1e
def ShowMessage(self, message, type = 'Warning'):
wx.MessageBox(message, type)
@@ -567,11 +431,7 @@
self.servers, self.map_servernameTouid = getAllRows(self.soup)
ComboBox.Append("")
for key, value in self.servers.items():
- #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
- #ComboBox.Append(string)
ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
- #ComboBox.Append(value.servername+" "+value.url)
- #print self.servers
return
def __update_URL_List(self):
@@ -579,30 +439,22 @@
ComboBox = self.ServerList
ComboBox.Append("")
for key,value in self.servers.iteritems():
- #name = v.servername+" "+v.url
- #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
- #ComboBox.Append(string)
ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
- #self.ServerList.Append(name)
def saveXMLData(self):
- xml = self.soup.prettify()
-
+ xml = self.soup.prettify()
try:
TMP = grass.tempfile()
if TMP is None:
grass.fatal_error("Unable to create temporary files")
- print TMP
f = open(TMP,'w')
f.write(xml)
f.close()
except:
message = 'Unable to write in '+TMP+' file, Save not successful'
- print message
grass.warning(message)
return False
try:
- #os.system('chmod 777 ServersList.xml')
copyCommand = "cp "+TMP+" ServersList.xml"
r, w, e = popen2.popen3(copyCommand)
if(len(e.readlines())!=0):
@@ -615,14 +467,9 @@
r.close()
w.close()
e.close()
-
- #os.system("cp templist.xml ServersList.xml")
- #f = open('ServersList.xml','w')
except:
- #print 'cant open file in write mode'
- print 'cp templist.xml ServersList.xml failed'
- print 'Save not successful'
return False
+
return True
def allFieldsValid(self, newServerName, newUrl, newUserName, newPassword):
@@ -632,8 +479,6 @@
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
self.ShowMessage(message, 'Warning')
grass.warning(message)
- print "Warning: UserName cannot consist of "+self.name_url_delimiter
- print "Please give another username, save failed..."
return False
if(newUrl.count(self.name_url_delimiter)>0):
@@ -642,8 +487,6 @@
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
self.ShowMessage(message, 'Warning')
grass.warning(message)
- print "Warning: URL cannot consist of "+self.name_url_delimiter
- print "Change in config file required to use different character as delimeter which doesnot appears in url"
return False
character = '>'
@@ -653,7 +496,6 @@
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return False
character = '<'
@@ -663,20 +505,15 @@
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return False
character = '&'
- #patch2s
- #or newUrl.count(character) > 0
- #patch2e
if(newServerName.count(character) > 0 or newUserName.count(character) > 0 or newPassword.count(character) > 0):
message = character+' is not allowed in a Field'
self.ShowMessage(message, 'Warning')
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- print message
return False
return True
@@ -713,26 +550,6 @@
self.Close()
self.Destroy()
return
- '''
- def OnPopupSaveRequest(self, msg):
- self.OnSave(None)
- self.saveXMLData()
- msg = self.servers
- Publisher().sendMessage(("Add_Server_Frame_Closed"), msg)
- self.Quit
- self.Close()
- #self.Destroy()
-
- def OnPopupNotSaveRequest(self, msg):
- self.saveXMLData()
- msg = self.servers
- Publisher().sendMessage(("Add_Server_Frame_Closed"), msg)
- self.Close()
- self.Destroy()
-
- def OnPopupCancelRequest(self, msg):
- return
- '''
# end of class ServerAdd
def AddServerFrame(parentWMS):
Modified: grass-addons/grass7/gui/wxpython/wx.wms/parse.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/parse.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/parse.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -60,9 +60,7 @@
soup = BeautifulSoup(xmltext)
#layers = soup.findAll('layer', queryable="1")
layers = soup.findAll('layer')
- '''
- for attr, value in soup.find('layer').attrs:
- print attr, " = ", value '''
+
namelist = []
for layer in layers:
soupname = BeautifulSoup(str(layer))
@@ -70,15 +68,9 @@
if len(names) > 0:
namelist += names[0]
return namelist
-'''
-f = open('wmsmaris.xml','r')
-a=f.read()
-print a
-#parsexml(a) '''
def parsexml2(xml):
- print 'c1'
layerDataDict={}
count = -1
xmltext = xml
@@ -86,46 +78,33 @@
layers = soup.findAll('layer')
namelist = []
for layer in layers:
-
soupname = BeautifulSoup(str(layer))
names = soupname.findAll('name')
titles = soupname.findAll('title')
abstracts = soupname.findAll('abstract')
srs = soupname.findAll('srs')
- print 'c2'
- print names
- print titles
- print abstracts
- print srs
- print 'a1'
if(len(names)>0):
count = count + 1
layerDataDict[count] = LayerData()
layerDataDict[count].name = unicode(names[0].string)
- print layerDataDict[count].name
else:
continue
- print 'a2'
if(len(titles)>0):
- print 'b1'
layerDataDict[count].title = unicode(titles[0].string)
- print 'b2'
else:
- print 'b3'
layerDataDict[count].title = ''
- print 'b4'
- print 'a3'
+
if(len(abstracts)>0):
layerDataDict[count].abstract = unicode(abstracts[0].string)
else:
layerDataDict[count].abstract = ''
- print 'a4'
+
if(len(srs)>0):
layerDataDict[count].srs = srs
else:
layerDataDict[count].srs = ''
- print 'c3'
+
return layerDataDict
@@ -133,45 +112,29 @@
def isValidResponse(xml):
soup = BeautifulSoup(xml)
getCapabilities = soup.findAll('wmt_ms_capabilities')
- print 'heeeeeeeeereeeeee'
- print len(getCapabilities)
if(len(getCapabilities)==0):
- print 'False'
return False
else:
- print 'True'
return True
def isServiceException(xml):
- print 'here'
- #print xml
soup = BeautifulSoup(xml)
- #print soup
exceptions = soup.findAll('ServiceException')
- #print exceptions
exceptionList = []
xmltext = str(xml)
if(xmltext.count('ServiceException') > 0):
return True
else:
return False
- print 'done'
-
-
def populateLayerTree(xml,LayerTree, layerTreeRoot):
TMP = grass.tempfile()
if TMP is None:
grass.fatal("Unable to create temporary files")
- print '########################'
- print TMP
- print '########################'
f = open(TMP,'w')
f.write(xml)
f.close()
-
f = open(TMP,'r')
xml = f.read()
- #print xml
soup = BeautifulSoup(xml)
dfs(soup,LayerTree, layerTreeRoot)
@@ -200,5 +163,4 @@
g = grassRegion[s:]
g = g.split()
g = g[1].strip(';')
- print g
return float(g)
Modified: grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py 2011-08-25 16:58:39 UTC (rev 47888)
+++ grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py 2011-08-26 10:47:13 UTC (rev 47889)
@@ -35,9 +35,6 @@
from LoadConfig import loadConfigFile
-# begin wxGlade: extracode
-# end wxGlade
-
class LayerData():
name = None
title = None
@@ -74,19 +71,7 @@
a = srs.string
a = a.split(':')
l = l+[a[1]]
- print 'here'
- print 'key = ' + str(key)
- print l
- print 'now'
keytoepsgcodes[str(key)] = l
-
- print 'dict value now is '
- print keytoepsgcodes
- print 'dict printed'
-
- print 'final dict'
- print keytoepsgcodes
- print 'final dcit printed'
return keytoepsgcodes
class Message():
@@ -123,14 +108,10 @@
self.Bind(wx.EVT_BUTTON, self.OnGetMaps, self.GetMaps)
self.Bind(wx.EVT_BUTTON, self.OnAddServer, self.addServer)
# end wxGlade
-
- #Sudeep's Code Starts
- #self.urlInput.SetValue('http://www.gisnet.lv/cgi-bin/topo')
+
self.usernameInput.Disable()
self.passwordInput.Disable()
- print 'new version'
if( not loadConfigFile(self)):
- print 'Config File Error, Unable to start application...'
grass.fatal_error('Config File Error, Unable to start application...')
self.Close()
return
@@ -152,10 +133,6 @@
self.layerName = ""
self.selectedEPSG = None
- #items = ["a", "b", "c"]
- #itemId = self.LayerTree.AppendItem(self.layerTreeRoot, "item")
- #self.LayerTree.AppendItem(itemId, "inside")
- #Sudeep's Code Ends
def __set_properties(self):
# begin wxGlade: wmsFrame.__set_properties
self.SetTitle("wmsFrame")
@@ -199,36 +176,23 @@
def OnGetCapabilities(self, event): # wxGlade: wmsFrame.<event_handler>
- ''''f=open('check.xml','r')
- xml=f.read()
- f.close()
- layerDataDict = parsexml2(xml)
- ld = LayerData()
- #ld.printLayerData(layerDataDict)
- ld.appendLayerTree(layerDataDict, self.LayerTree, self.layerTreeRoot)
- self.LayerTree.Expand(self.layerTreeRoot)
- return'''
if(self.selectedURL == "No server selected"):
message = 'No Server selected'
self.ShowMessage(message, 'Warning')
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
grass.warning(message)
- print message
return
try:
self.epsgList.SetSelection(0)
except:
- print 'epsg list is empty'
+ message = 'epsg list is empty'
+ grass.warning(message)
self.usernameInput.Enable()
self.passwordInput.Enable()
- #Sudeep's Code Starts
- #url = 'http://www.gisnet.lv/cgi-bin/topo?request=GetCapabilities&service=wms&version=1.1.1'
- self.LayerTree.CollapseAndReset(self.layerTreeRoot)
- #url = self.urlInput.GetValue()
+ self.LayerTree.CollapseAndReset(self.layerTreeRoot)
url = self.selectedURL
url = url + '?request=GetCapabilities&service=wms&version=1.1.1'
- print url
StatusBar_fields = ["GetCapabilities Request Sent..."]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
req = Request(url)
@@ -241,61 +205,35 @@
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
grass.warning(message)
- print message
return
if(isServiceException(xml)):
message = 'Service Exception in Get Capabilities'
self.ShowMessage(message, 'Warning')
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
- grass.warning(message)
- print message
+ grass.warning(message)
return
- #for testing pruposes
- #f=open('in1.xml','r')
- #xml=f.read()
- #f.close()
- #self.statusbar.SetStatusText(xml)
- #reslist = parsexml(xml)
- #populateLayerTree(xml,self.LayerTree, self.layerTreeRoot)
- print 'check1'
layerDataDict = parsexml2(xml)
- print 'check2'
ld = LayerData()
- print 'check3'
- #ld.printLayerData(layerDataDict)
ld.appendLayerTree(layerDataDict, self.LayerTree, self.layerTreeRoot)
self.keyToEPSGCodes = ld.setKeyToEPSGCodes(layerDataDict)
- print self.keyToEPSGCodes
self.selectedEPSG = None
- print 'check4'
- #for res in reslist:
- # self.LayerTree.AppendItem(self.layerTreeRoot, res)
- #self.Layers.SetValue(st)
- #print xml
self.LayerTree.Expand(self.layerTreeRoot)
except HTTPError, e:
message = 'The server couldn\'t fulfill the request.'
- print message
- #print 'Error code: ', e.code
+ message = str(e)
except URLError, e:
message = 'Failed to reach a server.'
- print message
- #print 'Reason: ', e.reason
+ message = str(e)
except ValueError, e:
message = 'Value error'
- print message
- #print 'Reason: ', e.reason
+ message = str(e)
except Exception, e:
message = 'urlopen exception, unable to fetch data for getcapabilities'
message = str(e)
- print 'printing exception here'
- print message
- print 'done'
else:
message = 'Successful'
- print message
-
+
if(not message=='Successful'):
self.ShowMessage(message, 'Warning')
StatusBar_fields = [message]
@@ -310,13 +248,8 @@
def OnGetMaps(self, event): # wxGlade: wmsFrame.<event_handler>
- #Sudeep's Code Starts
- #self.layerName = self.layerSelected.GetValue()
- #url = self.urlInput.GetValue()
- print self.selectedURL
if(self.selectedURL == "No server selected"):
message = 'No server selected'
- print message
grass.warning(message)
self.ShowMessage(message, 'Warning')
StatusBar_fields = [message]
@@ -325,7 +258,6 @@
if(self.selectedEPSG == None):
message = 'No EPSG code selected'
- print message
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
@@ -333,12 +265,10 @@
return
if(not self.selectedEPSG.isdigit()):
message = 'EPSG code selected is not a number'
- print message
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
self.ShowMessage(message, 'Warning')
-
return
bbox = self.getBBOXParameters()
@@ -347,24 +277,18 @@
getMap_request_url = self.url_in
getMap_request_url += '?service=WMS&request=GetMap&version=1.1.1&format=image/png&width=800&height=600&srs=EPSG:'+self.selectedEPSG+'&layers='
getMap_request_url += self.layerName+'&bbox='+bbox
- #'584344,397868,585500,398500'
- print bbox
- print getMap_request_url
req = Request(getMap_request_url)
try:
-
message = 'GetMaps request sent. Waiting for response...'
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
response = urlopen(req, None, self.timeoutValueSeconds)
image = response.read()
- #print image
if(isServiceException(image)):
message = 'Service Exception has occured'
self.ShowMessage(message, 'Warning')
- print message
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
@@ -372,17 +296,12 @@
TMP = grass.tempfile()
if TMP is None:
grass.fatal("Unable to create temporary files")
- print TMP
-
outfile = open(TMP,'wb')
outfile.write(image)
outfile.close()
if(imghdr.what(TMP) != 'png'):
- #print 'uiui'
- #print imghdr.what('./map.png')
message = 'Not a valid PNG Image, Unable to display Map'
self.ShowMessage(message, 'Warning')
- print message
grass.warning(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
@@ -396,24 +315,19 @@
except HTTPError, e:
message = 'The server couldn\'t fulfill the request.'
- print message
- #print 'Error code: ', e.code
+ message = str(e)
except URLError, e:
message = 'Failed to reach a server.'
- print message
- #print 'Reason: ', e.reason
+ message = str(e)
except ValueError, e:
message = 'Value error'
- print message
- #print 'Reason: ', e.reason
- except:
+ message = str(e)
+ except Exception, e:
message = 'urlopen exception, unable to fetch data for getcapabilities'
- print message
+ message = str(e)
else:
message = 'Successful'
- print message
-
- print message
+
if(message != 'Successful'):
self.ShowMessage(message, 'Warning')
grass.warning(message)
@@ -423,103 +337,53 @@
grass.message(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
-
- #Sudeep's Code Ends
+
event.Skip()
-
-
- def OnServerListEnter(self, event): # wxGlade: wmsFrame.<event_handler>
- return
- '''
- print "Event handler `OnServerListEnter' not implemented"
- #Sudeep's Code Starts
- print self.ServerList.CurrentSelection
- newUrl = self.ServerList.GetValue()
- self.ServerList.Append(newUrl)
- url = newUrl.split()
- if(len(url)==2):
- self.servers[url[0]] = url[1]
- f = open('serverList.txt','a')
- f.write(newUrl+"\n")
- f.close()
- self.selectedURL = url[1]
- print self.selectedURL
- print self.servers
-
- else:
- print "Format not recognized, Format: Severname URL"
- #Sudeep's Code Ends
- event.Skip()
- '''
def OnEPSGList(self,event):
info = self.epsgList.GetValue()
if(not info.isdigit()):
message = 'Please select an EPSG Code'
- print message
grass.warning(message)
seld.show_message(message)
StatusBar_fields = [message]
self.StatusBar.SetStatusText(StatusBar_fields[0], 0)
return
self.selectedEPSG = info
- print 'epsg = '+info
def OnServerList(self, event): # wxGlade: wmsFrame.<event_handler>
- print "Event handler `OnServerList' not implemented"
- #Sudeep's Code Starts
- print self.ServerList.CurrentSelection
info = self.ServerList.GetValue()
if(len(info) == 0):
return
urlarr = info.split(self.name_url_delimiter)
- print "OnServerList:printing urlarr"
- print urlarr
- print urlarr[0]
- #print urlarr[0].encode()
- #self.printDict(self.servers)
- print "OnServerList: done"
if(len(urlarr)==2):
try:
uid = self.map_servernameTouid[urlarr[0]]
self.selectedURL = self.servers[uid].url
- print self.selectedURL
except KeyError,e:
- print e
message = 'key error reported'
- print message
- print self.map_servernameTouid
grass.warning(message)
else:
message = "Wrong format of URL selected"
- print message
grass.warning(message)
- #Sudeep's Code Ends
+
event.Skip()
def OnLayerTreeActivated(self, event): # wxGlade: wmsFrame.<event_handler>
- #Sudeep's Code Starts
- print "OnLayerTreeActivated: ", self.LayerTree.GetItemText(event.GetItem())
- #Sudeep's Code Ends
- print "Event handler `OnLayerTreeActivated' not implemented"
event.Skip()
+
+ def OnServerListEnter(self, event): # wxGlade: wmsFrame.<event_handler>
+ event.Skip()
- def OnLayerTreeSelChanged(self, event): # wxGlade: wmsFrame.<event_handler>
- #self.layerName = self.LayerTree.GetItemText(event.GetItem())
- #print "Event handler `OnLayerTreeSelChanged' not implemented"
+ def OnLayerTreeSelChanged(self, event): # wxGlade: wmsFrame.<event_handler>"
self.epsgList.Clear()
self.epsgList.Append('')
self.selectedLayerList = []
keys =[]
self.layerName = ""
- print "Selected layers:"
for sellayer in self.LayerTree.GetSelections():
layerNameString = self.LayerTree.GetItemText(sellayer)
- print 'here'
- print layerNameString
layerNameStringList = layerNameString.split(':')
- print layerNameStringList
- print len(layerNameStringList)
if(len(layerNameStringList)==0):
message = 'Unable to select layers'
self.ShowMessage(message, 'Warning')
@@ -529,65 +393,41 @@
return
layerName = layerNameStringList[0].split('-')[1]
key = layerNameStringList[0].split('-')[0]
- print layerName
- print 'done'
self.selectedLayerList += [layerName]
self.layerName += ","+layerName
keys += [key]
-
lEPSG = self.keyToEPSGCodes[key]
self.epsgList.Append('<'+layerName+'>')
self.epsgList.AppendItems(lEPSG)
self.layerName = self.layerName[1:]
- print self.layerName
self.selectedEPSG = None
- print self.keyToEPSGCodes
- #for key in keys:
- # lEPSG = self.keyToEPSGCodes[key]
- # self.epsgList.AppendItems(lEPSG)
-
- #print "Event handler `OnLayerTreeSelChanged' not implemented"
+
event.Skip()
def OnAddServer(self, event): # wxGlade: wmsFrame.<event_handler>
- print 'before add server call'
self.AddServerisClosed = False
self.addServer.Disable()
AddServerFrame(self)
- #print 'after add server call'
- #print "Event handler `OnAddServer' not implemented"
- #event.Skip()
return
-
def onAddServerFrameClose(self, msg):
self.AddServerisClosed = True
self.addServer.Enable()
- #frame = self.GetParent()
- #frame.Show()
-
+
def onUpdateServerListmessage(self, msg):
- #patch5s
self.servers = msg.data
- print 'in update serverlistmessage()'
- print 'printing serverlist'
- self.printDict(self.servers)
- #patch5e
+ #self.printDict(self.servers)
self.__update_Url_List(self.ServerList)
- #patch5s
- def onUpdateMapListmessage(self, msg):
- print 'in update maplistmessage()'
+ def onUpdateMapListmessage(self, msg):
self.map_servernameTouid = msg.data
- print 'printing map_servernametouid'
- self.printDict(self.map_servernameTouid)
- #patch5e
+ #self.printDict(self.map_servernameTouid)
def OnQuit(self, event):
msg = ""
- print 'in quit'
+
if(not self.AddServerisClosed):
Publisher().sendMessage(("WMS_Menu_Close"), msg)
self.Destroy()
@@ -600,22 +440,15 @@
ComboBox.Clear()
ComboBox.Append("")
for key, value in self.servers.items():
- #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
- #ComboBox.Append(string)
ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
- #ComboBox.Append(value.servername+" "+self.name_url_delimiter+" "+value.url)
- #print self.servers
return
def __populate_Url_List(self, ComboBox):
self.servers, self.map_servernameTouid = getAllRows(self.soup)
ComboBox.Append("")
for key, value in self.servers.items():
- #string = '{0}{1}{2}'.format(value.servername,self.name_url_delimiter,value.url[0:self.urlLength])
- #ComboBox.Append(string)
ComboBox.Append(value.servername+self.name_url_delimiter+value.url[0:self.urlLength])
- #ComboBox.Append(value.servername+" "+self.name_url_delimiter+" "+value.url)
- #print self.servers
+
return
def getBBOXParameters(self):
@@ -641,17 +474,6 @@
res = str(minx)+','+str(miny)+','+str(maxx)+','+str(maxy)
return res
- '''f = open('serverList.txt','r')
- lines = f.readlines()
- self.servers = {}
- for line in lines:
- row = line.split()
- print row
- if(len(row) == 4) :
- self.servers[row[0]] = row[1]
- name = row[0]+" "+row[1][7:45]
- ComboBox.Append(name)
- f.close()'''
def printDict(self,dict):
for key in dict.keys():
@@ -660,16 +482,13 @@
# end of class wmsFrame
-#Sudeep's Code Starts
def DisplayWMSMenu():
- print 'DisplayWMSMenu loaded...'
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
wms_Frame = wmsFrame(None, -1, "")
app.SetTopWindow(wms_Frame)
wms_Frame.Show()
app.MainLoop()
-#Sudeep's Code Ends
if __name__ == "__main__":
app = wx.PySimpleApp(0)
More information about the grass-commit
mailing list