[GRASS-SVN] r41866 - in grass/trunk/gui/wxpython: gui_modules icons xml

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 14 16:52:22 EDT 2010


Author: martinl
Date: 2010-04-14 16:52:22 -0400 (Wed, 14 Apr 2010)
New Revision: 41866

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/gmodeler.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/icons/icon.py
   grass/trunk/gui/wxpython/xml/menudata_modeler.xml
Log:
wxGUI/modeler: export to image


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-04-14 20:52:22 UTC (rev 41866)
@@ -1502,4 +1502,49 @@
         opacity = float(self.value.GetValue()) / 100
         return opacity
 
+def GetImageHandlers(image):
+    """!Get list of supported image handlers"""
+    lext = list()
+    ltype = list()
+    for h in image.GetHandlers():
+        lext.append(h.GetExtension())
+        
+    filetype = ''
+    if 'png' in lext:
+        filetype += "PNG file (*.png)|*.png|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_PNG,
+                       'ext'  : 'png' })
+    filetype +=  "BMP file (*.bmp)|*.bmp|"
+    ltype.append({ 'type' : wx.BITMAP_TYPE_BMP,
+                   'ext'  : 'bmp' })
+    if 'gif' in lext:
+        filetype += "GIF file (*.gif)|*.gif|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_GIF,
+                       'ext'  : 'gif' })
+        
+    if 'jpg' in lext:
+        filetype += "JPG file (*.jpg)|*.jpg|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_JPEG,
+                       'ext'  : 'jpg' })
 
+    if 'pcx' in lext:
+        filetype += "PCX file (*.pcx)|*.pcx|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_PCX,
+                       'ext'  : 'pcx' })
+        
+    if 'pnm' in lext:
+        filetype += "PNM file (*.pnm)|*.pnm|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_PNM,
+                       'ext'  : 'pnm' })
+
+    if 'tif' in lext:
+        filetype += "TIF file (*.tif)|*.tif|"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_TIF,
+                       'ext'  : 'tif' })
+
+    if 'xpm' in lext:
+        filetype += "XPM file (*.xpm)|*.xpm"
+        ltype.append({ 'type' : wx.BITMAP_TYPE_XPM,
+                       'ext'  : 'xpm' })
+    
+    return filetype, ltype

Modified: grass/trunk/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-14 20:52:22 UTC (rev 41866)
@@ -52,6 +52,7 @@
 from   debug import Debug
 from   gcmd import GMessage
 from   gdialogs import ElementDialog
+from   gdialogs import GetImageHandlers
 from grass.script import core as grass
 
 class ModelFrame(wx.Frame):
@@ -164,6 +165,9 @@
         """!Close window"""
         self.Destroy()
 
+    def OnDeleteData(self, event):
+        """!Delete intermediate data"""
+        
     def OnModelNew(self, event):
         """!Create new model"""
         Debug.msg(4, "ModelFrame.OnModelNew():")
@@ -355,7 +359,47 @@
             GMessage(parent = self,
                      message = _('Model is valid.'),
                      msgType = 'info')
-
+    
+    def OnExportImage(self, event):
+        """!Export model to image (default image)"""
+        size = self.canvas.GetSize()
+        bitmap = wx.EmptyBitmap(width = size.width, height = size.height)
+        
+        filetype, ltype = GetImageHandlers(wx.ImageFromBitmap(bitmap))
+        
+        dlg = wx.FileDialog(parent = self,
+                            message = _("Choose a file name to save the image (no need to add extension)"),
+                            defaultDir = "",
+                            defaultFile = "",
+                            wildcard = filetype,
+                            style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
+        
+        if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+            if not path:
+                dlg.Destroy()
+                return
+            
+            base, ext = os.path.splitext(path)
+            fileType = ltype[dlg.GetFilterIndex()]['type']
+            extType  = ltype[dlg.GetFilterIndex()]['ext']
+            if ext != extType:
+                path = base + '.' + extType
+                
+            dc = wx.MemoryDC(bitmap)
+            dc.SetBackground(wx.WHITE_BRUSH)
+            dc.SetBackgroundMode(wx.SOLID)
+            
+            dc.BeginDrawing()
+            self.canvas.GetDiagram().Clear(dc)
+            self.canvas.GetDiagram().Redraw(dc)
+            dc.EndDrawing()
+            
+            bitmap.SaveFile(path, fileType)
+            self.SetStatusText(_("Model exported to <%s>") % path)
+            
+        dlg.Destroy()
+        
     def OnExportPython(self, event):
         """!Export model to Python script"""
         filename = ''
@@ -1492,6 +1536,7 @@
         
 def main():
     app = wx.PySimpleApp()
+    wx.InitAllImageHandlers()
     frame = ModelFrame(parent = None)
     if len(sys.argv) > 1:
         frame.LoadModelFile(sys.argv[1])

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2010-04-14 20:52:22 UTC (rev 41866)
@@ -1172,63 +1172,29 @@
             win.SetSize((w, h))
 
     def SaveToFile(self, event):
+        """!Save map to image
         """
-        Save image to file
-        """
-        lext = []
-        for h in self.MapWindow.img.GetHandlers():
-            lext.append(h.GetExtension())
+        filetype, ltype = gdialogs.GetImageHandlers(self.MapWindow.img)
         
-        filetype =  "BMP file (*.bmp)|*.bmp|"
-        if 'gif' in lext:
-            filetype += "GIF file (*.gif)|*.gif|"
-        if 'jpg' in lext:
-            filetype += "JPG file (*.jpg)|*.jpg|"
-        if 'pcx' in lext:
-            filetype += "PCX file (*.pcx)|*.pcx|"
-        if 'png' in lext:
-            filetype += "PNG file (*.png)|*.png|"
-        if 'pnm' in lext:
-            filetype += "PNM file (*.pnm)|*.pnm|"
-        if 'tif' in lext:
-            filetype += "TIF file (*.tif)|*.tif|"
-        if 'xpm' in lext:
-            filetype += "XPM file (*.xpm)|*.xpm"
-
-        dlg = wx.FileDialog(self, _("Choose a file name to save the image (no need to add extension)"),
+        dlg = wx.FileDialog(parent = self,
+                            message = _("Choose a file name to save the image (no need to add extension)"),
                             defaultDir = "",
                             defaultFile = "",
                             wildcard = filetype,
-                            style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
+                            style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
+        
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
-            if path == None: return
-            base = os.path.splitext(dlg.GetPath())[0]
-            ext = os.path.splitext(dlg.GetPath())[1]
-            if dlg.GetFilterIndex() == 0:
-                type = wx.BITMAP_TYPE_BMP
-                if ext != '.bmp': path = base+'.bmp'
-            if dlg.GetFilterIndex() == 1:
-                type = wx.BITMAP_TYPE_GIF
-                if ext != '.gif': path = base+'.gif'
-            elif dlg.GetFilterIndex() == 2:
-                type = wx.BITMAP_TYPE_JPEG
-                if ext != '.jpg': path = base+'.jpg'
-            elif dlg.GetFilterIndex() == 3:
-                type = wx.BITMAP_TYPE_GIF
-                if ext != '.pcx': path = base+'.pcx'
-            elif dlg.GetFilterIndex() == 4:
-                type = wx.BITMAP_TYPE_PNG
-                if ext != '.png': path = base+'.png'
-            elif dlg.GetFilterIndex() == 5:
-                type = wx.BITMAP_TYPE_PNM
-                if ext != '.pnm': path = base+'.pnm'
-            elif dlg.GetFilterIndex() == 6:
-                type = wx.BITMAP_TYPE_TIF
-                if ext != '.tif': path = base+'.tif'
-            elif dlg.GetFilterIndex() == 7:
-                type = wx.BITMAP_TYPE_XPM
-                if ext != '.xpm': path = base+'.xpm'
+            if not path:
+                dlg.Destroy()
+                return
+            
+            base, ext = os.path.splitext(path)
+            fileType = ltype[dlg.GetFilterIndex()]['type']
+            extType  = ltype[dlg.GetFilterIndex()]['ext']
+            if ext != extType:
+                path = base + '.' + extType
+            
             self.MapWindow.SaveToFile(path, type)
             
         dlg.Destroy()

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2010-04-14 20:52:22 UTC (rev 41866)
@@ -1392,6 +1392,8 @@
         self.new = wx.NewId()
         self.open = wx.NewId()
         self.save = wx.NewId()
+        self.image = wx.NewId()
+        self.python = wx.NewId()
         self.action = wx.NewId()
         self.data = wx.NewId()
         self.relation = wx.NewId()
@@ -1410,6 +1412,12 @@
             (self.save, 'save', Icons['modelSave'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
              self.parent.OnModelSave),
+            (self.image, 'image', Icons['modelToImage'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons['modelToImage'].GetLabel(), Icons['modelToImage'].GetDesc(),
+             self.parent.OnExportImage),
+            (self.python, 'python', Icons['modelToPython'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons['modelToPython'].GetLabel(), Icons['modelToPython'].GetDesc(),
+             self.parent.OnExportPython),
             ('', '', '', '', '', '', ''),
             (self.data, 'data', Icons['modelDataAdd'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelDataAdd'].GetLabel(), Icons['modelDataAdd'].GetDesc(),

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/icons/icon.py	2010-04-14 20:52:22 UTC (rev 41866)
@@ -343,6 +343,10 @@
                                 label=_("Load model from file (Ctrl+O)")),
     "modelSave" : MetaIcon (img=Icons["fileSave"],
                                 label=_("Save current model to file (Ctrl+S)")),
+    "modelToImage" : MetaIcon (img=Icons["savefile"],
+                                label=_("Export model to image")),
+    "modelToPython" : MetaIcon (img=Icons["printmap"],
+                                label=_("Export model to Python script")),
     "modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
                                  label=_("Add action (GRASS module) to model")),
     "modelDataAdd" : MetaIcon (img=Icons["modelDataAdd"],

Modified: grass/trunk/gui/wxpython/xml/menudata_modeler.xml
===================================================================
--- grass/trunk/gui/wxpython/xml/menudata_modeler.xml	2010-04-14 18:45:09 UTC (rev 41865)
+++ grass/trunk/gui/wxpython/xml/menudata_modeler.xml	2010-04-14 20:52:22 UTC (rev 41866)
@@ -33,6 +33,11 @@
 	</menuitem>
 	<separator />
 	<menuitem>
+	  <label>Export to image</label>
+	  <help>Export model to image</help>
+	  <handler>OnExportImage</handler>
+	</menuitem>
+	<menuitem>
 	  <label>Export to Python</label>
 	  <help>Export model to Python script</help>
 	  <handler>OnExportPython</handler>
@@ -73,6 +78,12 @@
 	</menuitem>
 	<separator />
 	<menuitem>
+	  <label>Delete intermediate data</label>
+	  <help>Delete intermediate data defined in the model</help>
+	  <handler>OnDeleteData</handler>
+	</menuitem>
+	<separator />
+	<menuitem>
 	  <label>Run model</label>
 	  <help>Run entire model</help>
 	  <handler>OnRunModel</handler>



More information about the grass-commit mailing list