[GRASS-SVN] r61178 - sandbox/krejcmat/src

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 7 15:33:28 PDT 2014


Author: krejcmat
Date: 2014-07-07 15:33:28 -0700 (Mon, 07 Jul 2014)
New Revision: 61178

Modified:
   sandbox/krejcmat/src/editor2.py
   sandbox/krejcmat/src/jinjainfo.py
Log:
commented editor2.py 

Modified: sandbox/krejcmat/src/editor2.py
===================================================================
--- sandbox/krejcmat/src/editor2.py	2014-07-07 22:17:36 UTC (rev 61177)
+++ sandbox/krejcmat/src/editor2.py	2014-07-07 22:33:28 UTC (rev 61178)
@@ -5,6 +5,7 @@
 
 from owslib.iso import *
 from jinjainfo  import JinjaTemplateInfo as jt
+from jinjainfo import MdDescription
 
 from lxml import etree as ET
 
@@ -46,25 +47,29 @@
               
         self.wxIdTag={} #dict with id and tag from ows lib
         mdo=MD()
-        self.md=mdo.md
+        self.md=mdo.md  #instance of 
         
-        self.comboItems=[]
+        self.comboItems=[]  #list in combobox
         
         self._layout()    
+        
         self.templatePath='data/grassInspireTemplate01.xml'
         #self.templatePath='data/jinjatest.xml'
-        
         jinj=jt(self.templatePath)
-        self.mdDescription=jinj.mdDescription   #list of object MdDescription
-        self.mdOWSTagStr=jinj.mdOWSTagStr
+        self.mdDescription=jinj.mdDescription     #list of object MdDescription
         
-        self.MDinfoDictNum=jinj.cretemdDescriptionDict('num')
-        self.MDinfoDictGroup=jinj.cretemdDescriptionDict('group')
-        self.MDinfoDictBox=jinj.cretemdDescriptionDict('inbox')
-        self.mdOWSTagStrList=jinj.mdOWSTagStrList
+        self.mdOWSTagStr=jinj.mdOWSTagStr         #string of tags from jinja template (loops and OWSLib objects)   
+        self.mdOWSTagStrList=jinj.mdOWSTagStrList #
+        self.valueStorageWxID={}
+        
+        #self.mdDescriptionVAL=MdDescription()
+        self.mdDescriptionList=[]
+        
+        #self.MDinfoDictNum=jinj.cretemdDescriptionDict('num')
+        #self.MDinfoDictGroup=jinj.cretemdDescriptionDict('group')
+        #self.MDinfoDictBox=jinj.cretemdDescriptionDict('inbox')
+        
         #self.initCreatorEmpty()
-        self.FILLER=''
-        self.idDict={}
         self.initCreatorMD()
         
         self.currWXid=None
@@ -141,14 +146,36 @@
                 self.valueCtrl = wx.TextCtrl(self.place, id=wx.ID_ANY,  
                                        style=wx.VSCROLL |  wx.TE_DONTWRAP | 
                                        wx.TAB_TRAVERSAL|wx.RAISED_BORDER|wx.HSCROLL)  
+                
+                
+#------------------------------------------------------------------------------ 
         #register tag to created wx.id
-        self.currWXid= self.valueCtrl.GetId()        
-        val=self.mdDescription[self.cTmp].value
-        val=self.valueCtrl.SetValue(str(val))
-       
-        #self.MD.valueStorageByID[self.valueCtrl.GetId()]=MdInfo(tag,val)
+        self.currWXid= self.valueCtrl.GetId()
+        val=self.mdDescription[self.cTmp].value   
+  
+        mdVal=MdDescription()
+        self.valueCtrl.SetValue(str(val))
+        self.valueStorageWxID[self.currWXid]=val
+#------------------------------------------------------------------------------ 
+         
+         
+        try:
+            mdVal=self.mdDescription[self.c]
+        except:
+            mdVal=self.mdDescription[self.c]
+        # print mdVal
+        mdVal.value=str(val)
+        mdVal.id=str(self.currWXid)
+        self.mdDescriptionList.append(mdVal)
+
+        #=======================================================================
+        # print '='*50
+        # print self.currWXid
+        # print val
+        # print mdVal.value
+        # print '='*50
+        #=======================================================================
         
-        
         if multiple:
             self.addItemButt=wx.Button(self.place,-1,size=(20,20),label='+')
             #self.addInfoButt=wx.Button(self,-1,size=(20,20),label='I')
@@ -205,31 +232,54 @@
     def _addComboBoxLay(self):
          self.nbPanelSizer.Add(self.comboboxSizer,proportion=0,flag=wx.EXPAND)
 #----------------------------------------------------------------------- CREATOR        
-    def initCreatorMD1(self):        
-        self.addNotebook() 
-        c=0
-        markgroup=[]    #notebok panel marker
-        markbox=[]      # box panel marker
-        markitem=[]     #item panel marker
-        for lstruct, linfo in zip(self.struct.splitlines(),self.mdDescription):
-            c+=1
-            
-            group=linfo.group
-            if group not in markgroup:          #if group is not created
-                markgroup.append(group)
-                self.addNotebookPage(linfo.group)
-                for item in self.MDinfoDictGroup[group]:        
-                    box=item.inbox
-                    if box not in markbox and box!=None:    #if box is not created or item is not in box
-                        markbox.append(box)
-                        self.addBox(item.inbox)             #mark box
-                        for boxite in self.MDinfoDictBox[box]:
-                            markitem.append(boxite.num)
-                            self.addItem(boxite, True)
-                    else:
-                        if item.num not in markitem:        #if item is not created
-                            self.addItem(item)
- #----------------------------------------------------------------------- CREATOR        
+    #===========================================================================
+    # def initCreatorMD1(self):        
+    #     self.addNotebook() 
+    #     c=0
+    #     markgroup=[]    #notebok panel marker
+    #     markbox=[]      # box panel marker
+    #     markitem=[]     #item panel marker
+    #     for lstruct, linfo in zip(self.struct.splitlines(),self.mdDescription):
+    #         c+=1
+    #         
+    #         group=linfo.group
+    #         if group not in markgroup:          #if group is not created
+    #             markgroup.append(group)
+    #             self.addNotebookPage(linfo.group)
+    #             for item in self.MDinfoDictGroup[group]:        
+    #                 box=item.inbox
+    #                 if box not in markbox and box!=None:    #if box is not created or item is not in box
+    #                     markbox.append(box)
+    #                     self.addBox(item.inbox)             #mark box
+    #                     for boxite in self.MDinfoDictBox[box]:
+    #                         markitem.append(boxite.num)
+    #                         self.addItem(boxite, True)
+    #                 else:
+    #                     if item.num not in markitem:        #if item is not created
+    #                         self.addItem(item)
+    #===========================================================================
+
+                
+
+#------------------------------------------------------------- MAIN PANEL LAYOUT
+    def _layout(self):
+        #main sizer in frame
+        self.mainSizer=wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(self.mainSizer)
+        
+#-------------------------------------------------------------------------- INFO
+    def createInfo(self,item):
+        string=''
+        if item.name !=None:
+            string+='name: '+ item.name + '\n' 
+        if item.desc !=None:
+            string+='description: ' + item.desc + '\n'
+        if item.example  !=None:
+            string+='example: ' + item.example + '\n'   
+        return string
+#------------------------------------------------------------------------------ 
+#----------------------------------------------------------------------- CREATOR
+#------------------------------------------------------------------------------ 
     def executeStr(self,stri,linfo):
         print stri
         exec stri
@@ -240,95 +290,126 @@
             self.c-=1
             self.stop=True    
                                             
-    def initCreatorMD(self):        
+    def initCreatorMD(self):  
+        '''
+             @var var:   self.c        index of lstruct and self.mdDescription
+                        lstruct        lstruct is self.mdOWSTagStr in list. Item=line from jinja template(only lines with owslib objects and loops)
+                        linfo          list of MdDescription() objects inicialized by information from jinja t.
+                        markgroup       markers of created list in GUI notebook
+                        self.max        length of lstruct and linfo
+                        self.stop       index self.c is increasing  by function plusC(), that care about  not exceeding the index
+        '''                  
         self.addNotebook() 
-        c=0
         markgroup=[]    #notebok panel marker
-        markbox=[]      # box panel marker
-        markitem=[]     #item panel marker
-        
-        lstruct=self.mdOWSTagStrList
-        linfo=self.mdDescription
-        
-        self.c=0
+        lstruct=self.mdOWSTagStrList   
+        linfo=self.mdDescription        #from jinja
+
+        self.c=0        #this valus is the index of self.mdOWSTagStrList and also in self.mdDescription
         self.stop=False
-        self.max=len(linfo)      ##TODO why -1? :-(
+        self.max=len(linfo)      
         
-        def inBox2():
+        def chckLen():
+            '''
+            @note: -length of list in jinja template is provided by |length.
+                    -need to convert to python len() 
+            '''
+            try:
+                    if '|length' in str(lstruct[self.c-1])and self.stop is False:
+                         a=lstruct[self.c-1]
+                         a=a.replace('|length',')').replace('if ','if len(self.')
+                         lstruct[self.c-1]=a
+            except:   
+                 self.stop=True
+                 #print '='*60
+                 
+        def inBox2(): #function in def initCreatorMD(self):   !!!
+            '''
+            @note: 
+            '''
             self.k=0
             loop = lstruct[self.c-1]
             str2=loop.replace(' md.',' self.md.')+':\n'
             str2+='\t' +'self.addBox(linfo[' + str(self.c) + '].inbox)\n'
-
             str1=str2
+            
             while '\t' in lstruct[self.c] and self.stop is False:
                 if not 'for' in str(lstruct[self.c]).split() or 'if' in str(lstruct[self.c]).split(): 
                     value= str(self.mdOWSTagStrList[self.c])
+                    #print value
                     str1+= '\t' +'self.mdDescription['+str(self.c)+'].value='+str(value)+'\n'
-                    str1+= '\t' +'self.idDict[self.currWXid]=' + 'linfo[' + str(self.c) + ']\n'
                     str1+= '\t' +'self.cTmp='+str(self.c)+'\n'                         #save wx id
                     str1+= '\t' +'self.addItem(linfo[' + str(self.c) + '], True)\n'
-                else:
+                    tab='\t'
+                else:#if loop in loop
                     loop = lstruct[self.c]
                     str2=loop.replace(' md.',' self.md.')+':\n'
                     self.plusC()
                     str1+=str2
                     while '\t\t' in lstruct[self.c] and self.stop is False:
+
                         value= str(self.mdOWSTagStrList[self.c])
                         str1+= '\t\t' +'self.mdDescription['+str(self.c)+'].value='+str(value)+'\n'
-                        str1+= '\t\t' +'self.idDict[self.currWXid]=' + 'linfo[' + str(self.c) + ']\n'
                         str1+= '\t\t' +'self.cTmp='+str(self.c)+'\n'                         #save wx id
                         str1+= '\t\t' +'self.addItem(linfo[' + str(self.c) + '], True)\n'
-                            
-                        print str1        
+                        tab='\t\t'   
+      
                         self.plusC()
-                        
+                    
                 self.plusC()
-            print '--'*80    
-            str1+= '\tself.k+=1\n'
+            ##print '--'*80
+            self.c-=1    
+            str1+= tab+'self.c+=1\n'
             self.executeStr(str1,linfo)
-            self.c+=self.k - 1
 
-        while self.stop is False:
+            
+
+   
+        #START of the looop of genereator
+        while self.stop is False: #self.stop is managed by   def plusC(self):
             group=linfo[self.c].group
             if group not in markgroup:          #if group is not created
-                markgroup.append(group)
-                self.addNotebookPage(linfo[self.c].group)
+                markgroup.append(group)         #mark group
+                self.addNotebookPage(linfo[self.c].group)   #crate notebog page in gui
+            
 
-            if '\t' in lstruct[self.c]and self.stop is False:
+            if '\t' in lstruct[self.c]and self.stop is False: #if starting the loop
+                    
                     inBox2()
-
-            elif not 'for' in str(lstruct[self.c]).split() or 'if' in str(lstruct[self.c]).split():
+                    chckLen()
+            elif not 'for' in str(lstruct[self.c]).split() or 'if' in str(lstruct[self.c]).split(): # if just singe item without loop
                     value= 'self.'+str(self.mdOWSTagStrList[self.c]).replace('\n','')
                     addStr='self.mdDescription['+str(self.c)+'].value='+str(value)
-                    print '--'*80
-                    print addStr
+                    ##print '--'*80
+                    ##print addStr
                     self.executeStr(addStr,False)
-                    self.cTmp=self.c
+                    self.cTmp=self.c                
                     self.addItem(linfo[self.c], False)
                     self.plusC()
             else:
+                #if lstruct[self.c] is "FOR", "IF" "WHILE"
+                #print str(lstruct[self.c])
                 self.plusC()
+                #print str(lstruct[self.c])
                 
 
-        #print self.FILLER
-#------------------------------------------------------------- MAIN PANEL LAYOUT
-    def _layout(self):
-        #main sizer in frame
-        self.mainSizer=wx.BoxSizer(wx.VERTICAL)
-        self.SetSizer(self.mainSizer)
+#===============================================================================
+#         print '========================================'    
+#         for keys,values in self.valueStorageWxID.items():
+#             print(keys)
+#             #print values
+# 
+#             print values
+#             print '------------'
+#===============================================================================
         
-#-------------------------------------------------------------------------- INFO
-    def createInfo(self,item):
-        string=''
-        if item.name !=None:
-            string+='name: '+ item.name + '\n' 
-        if item.desc !=None:
-            string+='description: ' + item.desc + '\n'
-        if item.example  !=None:
-            string+='example: ' + item.example + '\n'   
-        return string
-
+        #=======================================================================
+        # for values in self.mdDescriptionList:
+        #         print values.id
+        #         print values.name
+        #         print values.value
+        #         print '------------'
+        # #print self.mdDescriptionList[9].id
+        #=======================================================================
 #===============================================================================
 # MAIN FRAME
 #===============================================================================

Modified: sandbox/krejcmat/src/jinjainfo.py
===================================================================
--- sandbox/krejcmat/src/jinjainfo.py	2014-07-07 22:17:36 UTC (rev 61177)
+++ sandbox/krejcmat/src/jinjainfo.py	2014-07-07 22:33:28 UTC (rev 61178)
@@ -20,7 +20,7 @@
 from jinja2 import Environment, FileSystemLoader
 
 class MdDescription():
-     def __init__(self,tag, name = None, desc = None, example = None, type = None, multi = 0, inboxmulti=None, group = None, inbox = None, multiline = None, value=None,id=None,num=None ):
+     def __init__(self,tag= None, name = None, desc = None, example = None, type = None, multi = 0, inboxmulti=None, group = None, inbox = None, multiline = None, value=None,id=None,num=None ):
          
          self.tag=tag
          self.name = name
@@ -34,6 +34,7 @@
          self.multiline=multiline       #type of ctrl text
          self.num=num
          self.value=value
+         self.id=id
          
 class JinjaTemplateInfo():
     def __init__(self,template):
@@ -137,7 +138,7 @@
                 continue
             
             tabstr='\t'*tab
-            str1=tabstr + item[1:] + '\n'         
+            str1=tabstr + item[1:] + '\n' 
             self.mdOWSTagStr+=str1
             self.mdOWSTagStrList.append(tabstr + item[1:])
             



More information about the grass-commit mailing list