[GRASS-SVN] r66461 - grass-addons/grass7/gui/wxpython/wx.mwprecip

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 10 07:02:38 PDT 2015


Author: krejcmat
Date: 2015-10-10 07:02:38 -0700 (Sat, 10 Oct 2015)
New Revision: 66461

Modified:
   grass-addons/grass7/gui/wxpython/wx.mwprecip/g.gui.mwprecip.py
   grass-addons/grass7/gui/wxpython/wx.mwprecip/mw3.py
   grass-addons/grass7/gui/wxpython/wx.mwprecip/mw_util.py
Log:
wx.mwprecip addons: fix colors, fix db port

Modified: grass-addons/grass7/gui/wxpython/wx.mwprecip/g.gui.mwprecip.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.mwprecip/g.gui.mwprecip.py	2015-10-10 00:02:55 UTC (rev 66460)
+++ grass-addons/grass7/gui/wxpython/wx.mwprecip/g.gui.mwprecip.py	2015-10-10 14:02:38 UTC (rev 66461)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-VERSION = 1.1
+VERSION = 1.2
 import sys,os
 sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'g.gui.mwprecip'))
 import grass.script as grass
@@ -134,7 +134,7 @@
 
 
 class BaselinePanel(wx.ScrolledWindow):
-    def __init__(self, parent, settings={}):
+    def __init__(self, parent, settings=dict()):
         wx.ScrolledWindow.__init__(self, parent,  wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL)
         self.SetScrollRate( 5, 5 )
         self.settings = settings
@@ -160,7 +160,7 @@
         self.dryWin.Bind(wx.EVT_RADIOBUTTON, self.onChangeMethod)
         self.noDryWin.Bind(wx.EVT_RADIOBUTTON, self.onChangeMethod)
         if len(settings) > 0:
-            self.loadSettings(None)
+            self.loadSettings()
 
         self._layout()
 
@@ -540,7 +540,8 @@
 class MWMainFrame(wx.Frame):
     def __init__(self, parent, id, title):
         wx.Frame.__init__(self, parent, id, title,style=wx.DEFAULT_FRAME_STYLE )
-        self.workPath = os.path.join(pathToMapset(), "temp")
+        context=StaticContext()
+        self.workPath = context.getTmpPath()
         self.initWorkingFoldrs()
         self.settings = {}
         self.settingsLst = []
@@ -610,7 +611,7 @@
 
     def onAbout(self,evt):
         dir=os.path.dirname(os.path.realpath(__file__))
-        GMessage( "ver: %s \n %s"%(VERSION,dir))
+        GMessage( "ver: %s \n %s"%(VERSION,dir),self)
 
 
     def getMinTime(self, evt=None):
@@ -697,7 +698,6 @@
             self.findProject()
 
     def initWorkingFoldrs(self):
-
         savePath = os.path.join(self.workPath, 'save')
         if not os.path.exists(savePath):
             os.makedirs(savePath)
@@ -710,7 +710,7 @@
         try:
             projectDir = os.path.join(self.workPath, "save")
         except:
-            GMessage('Cannot find "save" folder')
+            GMessage('Cannot find "save" folder',self)
             return
         filePathList = getFilesInFoldr(projectDir, True)
         print filePathList
@@ -749,7 +749,7 @@
     def _onSetGeomDLG(self, evt):
         type, name = self.geometryPnl.GetOptions()
         if name == '':
-            GMessage('Please set name of map')
+            GMessage('Please set name of map',self)
         else:
             self.createGeometry(type, name)
             # self.addMapToLay()#TODO giface
@@ -781,7 +781,7 @@
             self.settingsLst=[]
             self.findProject()
 
-        GMessage('Working path destination: %s' % self.workPath)
+        GMessage('Working path destination: %s' % self.workPath,self)
 
     def onSetDatabase(self, evt):
         self.dbDialog = wx.Dialog(self, id=wx.ID_ANY,
@@ -887,7 +887,7 @@
             io0 = open(path, "w+")
             io0.writelines(lines)
             io0.close()
-            GMessage('Data exported<%s>' % path)
+            GMessage('Data exported<%s>' % path,self)
 
         else:
             exportData = {'getData': True, 'dataOnly': False}
@@ -920,7 +920,7 @@
             io0.writelines(lines)
             io0.close()
             os.remove(os.path.join(interface.dbConn.pathworkSchemaDir, "precip"))
-            GMessage('Data exported<%s>' % path)
+            GMessage('Data exported<%s>' % path,self)
 
         self.exportDialog.Destroy()
 
@@ -928,6 +928,7 @@
         self.thread=gThread()
         self.thread.Run(callable=self.runComp,
                         ondone=self.onFinish)
+        self.computeBtt.Enable()
 
     def runComp(self, evt=None):
         self.computeBtt.Disable()
@@ -958,7 +959,7 @@
     def onFinish(self,evt):
         #self.computeBtt.SetLabel('Compute')
         self.computeBtt.Enable()
-        GMessage('Finish')
+        GMessage('Finish',self)
 
     def layout(self):
         self.panelSizer.Add(self.loadScheme, flag=wx.EXPAND)

Modified: grass-addons/grass7/gui/wxpython/wx.mwprecip/mw3.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.mwprecip/mw3.py	2015-10-10 00:02:55 UTC (rev 66460)
+++ grass-addons/grass7/gui/wxpython/wx.mwprecip/mw3.py	2015-10-10 14:02:38 UTC (rev 66461)
@@ -906,11 +906,14 @@
                 return True
             else:
                 return False
-    def logMsg(self, msg):
+    def logMsg(self, msg,err=False):
         if self.status.get('msg') == 'Done':
             self.status['msg'] = ''
         self.status['msg'] += msg + '\n'
-        grass.warning(msg)
+        if not err:
+            grass.warning(msg)
+        else:
+            grass.fatal(msg)
 
     def computePrecip(self, getData=False, dataOnly=False):
         def checkValidity(freq, polarization):
@@ -929,7 +932,7 @@
         compPrecTab = "%s.%s" % (self.database.schema, self.database.computedPrecip)
         # self.timeWin.sumValues()
         if not self.timeWin.setTimestamp():
-            self.logMsg("Out of available time interval")
+            self.logMsg("Out of available time interval",1)
             return False
         grass.message("Quering data")
 
@@ -997,10 +1000,10 @@
         # choose baseline source (quantile, user values, ) get dict linkid, baseline
         grass.message("Computing baseline")
         if not self.getBaselDict():
-            self.logMsg('Dry interval is out of defined time interval(from,to)')
+            self.logMsg('Dry interval is out of defined time interval(from,to)',1)
             return False
         if len(self.baselineDict) == 0:
-            self.logMsg('Baselines coputation faild. Check dry windows')
+            self.logMsg('Baselines coputation faild. Check dry windows',1)
             return False
         grass.message("Computing baseline-done")
 
@@ -1168,30 +1171,34 @@
 
     def makeRGB(self, map):
         grass.message('Creating RGB column in database')
+        try:
+            if self.rules not in [None,""]:
+                for lay in range(1, self.getNumLayer(self.database.linkVecMapName), 1):
+                    Module('v.colors',
+                           map=map,
+                           use='attr',
+                           column=self.database.precipColName,
+                           rules=self.rules,
+                           rgb_column=self.database.colorCol,
+                           quiet=True,
+                           layer=lay)
 
-        if self.color is not None:
+            if self.color not in [None,""]:
+                for lay in range(1, self.getNumLayer(self.database.linkVecMapName), 1):
+                    Module('v.colors',
+                           map=map,
+                           use='attr',
+                           column=self.database.precipColName,
+                           color=self.color,
+                           rgb_column=self.database.colorCol,
+                           quiet=True,
+                           layer=lay)
 
-            for lay in range(1, self.getNumLayer(self.database.linkVecMapName), 1):
-                Module('v.colors',
-                       map=map,
-                       use='attr',
-                       column=self.database.precipColName,
-                       color=self.color,
-                       rgb_column=self.database.colorCol,
-                       layer=lay)
+            grass.message('Creating RGB column in database-done')
+        except Exception, e:
+            grass.warning("v.color error < %s>"%e)
 
-        if self.rules is not None:
-            for lay in range(1, self.getNumLayer(self.database.linkVecMapName), 1):
-                Module('v.colors',
-                       map=map,
-                       use='attr',
-                       column=self.database.precipColName,
-                       rules=self.rules,
-                       rgb_column=self.database.colorCol,
-                       layer=lay)
 
-        grass.message('Creating RGB column in database-done')
-
     def getNumLayer(self, map):
         numLay = Module('v.category',
                         input=map,
@@ -1452,6 +1459,15 @@
                                   port=self.port,
                                   overwrite=True
                                   )
+            elif self.host:
+                grass.run_command('db.login',
+                                  driver="pg",
+                                  database=self.dbName,
+                                  user=self.user,
+                                  password=self.password,
+                                  host=self.host,
+                                  overwrite=True
+                                  )
             else:
                 grass.run_command('db.login',
                                   driver="pg",

Modified: grass-addons/grass7/gui/wxpython/wx.mwprecip/mw_util.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.mwprecip/mw_util.py	2015-10-10 00:02:55 UTC (rev 66460)
+++ grass-addons/grass7/gui/wxpython/wx.mwprecip/mw_util.py	2015-10-10 14:02:38 UTC (rev 66461)
@@ -12,6 +12,15 @@
 from core.gcmd          import GMessage, GError
 from grass.script       import core as grass
 
+class StaticContext():
+    def __init__(self):
+        gisenvDict = grass.gisenv()
+        pathToMapset = os.path.join(gisenvDict['GISDBASE'], gisenvDict['LOCATION_NAME'], gisenvDict['MAPSET'])
+        self.tmp_mapset_path = os.path.join(pathToMapset, "temp")
+
+    def getTmpPath(self):
+        return self.tmp_mapset_path
+
 class SaveLoad(wx.Panel):
     def __init__(self, parent):
         wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
@@ -244,9 +253,11 @@
         event.Skip()
 '''
 class TextInput(wx.Panel):
-    def __init__(self, parent, label, tmpPath=None):
+    def __init__(self, parent, label ):
         wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
-        self.tmpPath = tmpPath
+        self.context=StaticContext()
+
+        self.tmpPath = None
         statText = wx.StaticText(self, id=wx.ID_ANY, label=label)
         statText2 = wx.StaticText(self, id=wx.ID_ANY, label='or enter values interactively')
 
@@ -273,11 +284,11 @@
         self.firstDirInp = False
 
     def setTmpPath(self, event):
-        if self.firstDirInp is False:
+        if self.firstDirInp is False: #intitialization
             self.firstDirInp = True
             if self.tmpPath is None:
-                self.tmpPath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tmp%s' % randomWord(3))
-                self.pathInput.SetValue(str(self.tmpPath))
+                self.tmpPath = os.path.join(self.context.getTmpPath(), 'tmp%s'%randomWord(3))
+                self.pathInput.SetValue(self.tmpPath)
 
         io=open(self.tmpPath,'w')
         io.writelines(self.directInp.GetValue())
@@ -444,10 +455,8 @@
     output_stream = (saveFileDialog.GetPath())
     return output_stream
 
-def pathToMapset():
-    gisenvDict = grass.gisenv()
-    return os.path.join(gisenvDict['GISDBASE'], gisenvDict['LOCATION_NAME'], gisenvDict['MAPSET'])
 
+
 def saveDict(fn, dict_rap):
     f = open(fn, "wb")
     w = csv.writer(f)
@@ -474,8 +483,6 @@
         print "I/O error({0}): {1}".format(e.errno, e.strerror)
 
 
-
-
 def randomWord(length):
     return ''.join(random.choice(string.lowercase) for i in range(length))
 



More information about the grass-commit mailing list