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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 10 02:35:01 PDT 2014


Author: krejcmat
Date: 2014-07-10 02:35:01 -0700 (Thu, 10 Jul 2014)
New Revision: 61230

Added:
   sandbox/krejcmat/src/editor3.py
Log:
add editor3(O-O)

Added: sandbox/krejcmat/src/editor3.py
===================================================================
--- sandbox/krejcmat/src/editor3.py	                        (rev 0)
+++ sandbox/krejcmat/src/editor3.py	2014-07-10 09:35:01 UTC (rev 61230)
@@ -0,0 +1,313 @@
+import wx 
+from wx import ID_ANY
+from wx import EVT_BUTTON
+import wx.lib.scrolledpanel as scrolled
+
+from owslib.iso import *
+from jinjainfo  import JinjaTemplateInfo as jt
+
+from lxml import etree as ET
+import contextlib
+from wxPython._core import wxBoxSizer
+
+#===============================================================================
+#EDITOR                   
+#===============================================================================
+class MD():
+    def __init__(self,pathToXml=None):
+
+        self.path=pathToXml
+        self.owslibInfo=None
+        self.initMD()
+ 
+    def initMD(self):        
+        self.path='INStest.xml'
+        tree = ET.parse(self.path)
+        root = tree.getroot()
+        self.md = MD_Metadata(root)
+        #self.md = MD_Metadata(md=None)  
+
+#-------------------------------------------------------------------- CREATE BOX
+class Box(wx.Panel):
+    def __init__(self,parent,label='label'):
+        wx.Panel.__init__(self,parent=parent,id=wx.ID_ANY) 
+
+        self.stbox= wx.StaticBox(self, label=label,id=ID_ANY, style=wx.RAISED_BORDER)
+        self.stbox.SetForegroundColour((0,0,0))
+        self.stbox.SetBackgroundColour((200,200,200))
+        self.stbox.SetFont(wx.Font(12,wx.NORMAL, wx.NORMAL, wx.NORMAL))
+
+    def addItems(self,items,multi=True):
+        self.panelSizer=wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(self.panelSizer)
+        
+        self.boxButtonSizer=wx.BoxSizer(wx.HORIZONTAL)
+        
+        self.panelSizer.AddSpacer(10 , 10, 1, wx.EXPAND) 
+        self.panelSizer.Add(self.boxButtonSizer,flag=wx.EXPAND,proportion=1)
+        self.stBoxSizer = wx.StaticBoxSizer( self.stbox, orient=wx.VERTICAL)
+        self.boxButtonSizer.Add(self.stBoxSizer,flag=wx.EXPAND,proportion=1)
+        self.stBoxSizer.AddSpacer(5 , 5, 1, wx.EXPAND)
+        
+        for item in items:
+            self.stBoxSizer.Add(item,flag=wx.EXPAND,proportion=1)
+            self.stBoxSizer.AddSpacer(5 , 5, 1, wx.EXPAND)             
+
+        if multi:
+            self.addBoxButt=wx.Button(self,id=ID_ANY,size=(20,20),label='+')
+            self.boxButtonSizer.Add(self.addBoxButt,0)
+            
+    def addItem(self,item):
+        pass
+
+#--------------------------------------------------------------------- ADD ITEM
+class MdItem(wx.BoxSizer):
+    def __init__(self,parent,item):
+        wx.BoxSizer.__init__(self,wx.VERTICAL)    
+        self.itemObject=item
+        self.multiple=item.multiplicity
+        
+        #info=self.createInfo(item)  
+            
+        self.tagText= wx.StaticText(parent=parent,id=ID_ANY,label=item.name)
+        
+        if item.multiline is True:
+            self.valueCtrl = wx.TextCtrl(parent, id=ID_ANY,  size=(0, 55),
+                       style=wx.VSCROLL | 
+                       wx.TE_MULTILINE | wx.TE_DONTWRAP | wx.ST_NO_AUTORESIZE|
+                       wx.TAB_TRAVERSAL|wx.RAISED_BORDER|wx.HSCROLL)       
+        else:
+            self.valueCtrl = wx.TextCtrl(parent, id=wx.ID_ANY,  
+                       style=wx.VSCROLL |  wx.TE_DONTWRAP | 
+                       wx.TAB_TRAVERSAL|wx.RAISED_BORDER|wx.HSCROLL)  
+
+        if self.multiple:
+            self.addItemButt=wx.Button(parent,-1,size=(20,20),label='+')
+            #self.addInfoButt=wx.Button(self,-1,size=(20,20),label='I')
+            #BINDS    
+            
+        self._addItemLay(item.multiline)
+    
+    def setValue(self,value):
+        self.valueCtrl.SetValue(value)
+        
+    def getValue(self):
+        return self.valueCtrl.GetValue()
+        
+    def getCtrlID(self):
+        return self.valueCtrl.GetId()
+    
+    def getButtonID(self):  
+        if self.multiple:
+            return self.addItemButt.GetId()
+        else:
+            return None
+                 
+    def _addItemLay(self,multiline): 
+
+        if multiline is True:
+            self.textFieldSizer = wx.BoxSizer(wx.HORIZONTAL)  
+            self.textFieldSizer.Add(self.valueCtrl,proportion=1,flag=wx.EXPAND)
+            if self.multiple:
+                self.textFieldSizer.Add(self.addItemButt,0)
+            self.Add(item=self.tagText,proportion=0)
+            self.Add(item=self.textFieldSizer,proportion=0,flag=wx.EXPAND)
+        else:
+            self.textFieldSizer = wx.BoxSizer(wx.HORIZONTAL)  
+            self.textFieldSizer.Add(self.valueCtrl,proportion=1)
+            if self.multiple:
+                self.textFieldSizer.Add(self.addItemButt,0)
+            self.Add(item=self.tagText,proportion=0)
+            self.Add(item=self.textFieldSizer,proportion=0,flag=wx.EXPAND)
+
+
+class NotebookPage(scrolled.ScrolledPanel):
+    def __init__(self,parent):
+            scrolled.ScrolledPanel.__init__(self,parent=parent,id=wx.ID_ANY)
+            
+            self.SetupScrolling()       
+            self._addNotebookPageLay()
+    
+    def _addNotebookPageLay(self):   
+            self.mainSizer=wx.BoxSizer(wx.VERTICAL)
+            self.SetSizer(self.mainSizer)
+            
+    def addItem(self,item):
+        self.mainSizer.Add(item,proportion=0,flag=wx.EXPAND)
+        
+#===============================================================================
+# MAIN FRAME            
+#===============================================================================
+class MainFrame(wx.Frame):
+    def __init__(self):
+        wx.Frame.__init__(self, None, title="Metadata Editor",
+                  size=(500 ,500))
+        
+        mdo=MD()
+        self.md=mdo.md  #instance of 
+        self.comboItems=[]  #list in combobox
+        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         #string of tags from jinja template (loops and OWSLib objects)   
+        self.mdOWSTagStrList=jinj.mdOWSTagStrList #
+        self.valueStorageWxID={}
+        self.mdDescriptionList=[]
+        self.currWXid=None
+        
+        self.initCreatorMD()
+        self._layout()
+    
+
+#===============================================================================
+# GUI GENERATOR
+#===============================================================================
+    def executeStr(self,stri,linfo):
+        print stri
+        exec stri
+        
+    def plusC(self):
+        self.c+=1
+        if self.c >= self.max:
+            self.c-=1
+            self.stop=True    
+                                       
+    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.notebook=wx.Notebook(self)
+        markgroup=[]    #notebok panel marker
+        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)      
+
+        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' +'box=Box(self.nbPage,linfo[' + str(self.c) + '].inbox)\n' #add box
+            str2+='\t' +'self.boxItemList=[]\n' #initialize list
+            
+            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])
+                    str1+= '\t' + 'self.mdDescription['+str(self.c)+'].addValue('+str(value)+')\n'
+                    str1+= '\t' + 'self.cTmp='+str(self.c)+'\n'
+                    str1+= '\t' + 'it=MdItem(box,linfo[' + str(self.c) + '])\n'
+                    str1+= '\t' + 'it.setValue(' + str(value)+')\n'                         
+                    str1+= '\t' + 'self.boxItemList.append(it)\n'
+                    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)+'].addValue('+str(value)+')\n'
+                        str1+= '\t\t' +'self.cTmp='+str(self.c)+'\n'                         #save wx id
+                        str1+= '\t\t' + 'it=MdItem(box,linfo[' + str(self.c) + '])\n'
+                        str1+= '\t\t' + 'it.setValue(' + str(value)+')\n'                         
+                        str1+= '\t\t' + 'self.boxItemList.append(it)\n'
+                        tab='\t\t'   
+                        
+                        self.plusC()
+                self.plusC()
+            self.c-=1 
+            str1+= tab+'box.addItems(self.boxItemList)\n'
+            str1+= tab+'self.nbPage.addItem(box)\n'   
+            str1+= tab+'self.plusC()\n'
+            
+            self.executeStr(str1,linfo)
+   
+        #START of the looop of genereator
+        while self.stop is False: #self.stop is managed by   def plusC(self):
+#+ADD NOTEBOOK PAGE            
+            group=linfo[self.c].group
+            if group not in markgroup:          #if group is not created
+                markgroup.append(group)         #mark group
+                self.nbPage=NotebookPage(self.notebook)
+                self.notebook.AddPage(self.nbPage,linfo[self.c].group)
+#-ADD NOTEBOOK PAGE
+                 
+            if '\t' in lstruct[self.c]and self.stop is False: #if starting the loop
+                    inBox2()                
+                    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)+'].addValue('+str(value)+')'
+                    self.executeStr(addStr,False)
+                    
+                    self.cTmp=self.c        
+                    item=MdItem(self.nbPage,linfo[self.c])
+                    item.setValue(eval(value))
+                        
+                    self.nbPage.addItem(item)    
+                    self.plusC()
+            else:
+
+                self.plusC()
+
+#------------------------------------------------------------------------ LAYOUT
+    def _layout(self):
+        self.mainSizer=wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(self.mainSizer)
+        
+        noteSizer=wx.BoxSizer(wx.VERTICAL)
+        self.notebook.SetSizer(noteSizer)
+        self.mainSizer.Add(self.notebook,proportion=1,flag=wx.EXPAND)  
+        self.Show()
+ #-------------------------------------------------------------------------- INFO
+class MetadataUserInfo():
+    def __init__(self,item):
+        self.item=item
+        self.createInfo()
+    
+    def createInfo(self):
+        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   
+    
+#----------------------------------------------------------------------
+if __name__ == "__main__":
+    app = wx.App(False)
+    frame = MainFrame()
+    app.MainLoop()
+     
\ No newline at end of file



More information about the grass-commit mailing list