Browse Source

Fixed bug that prevented saving in formats other than png. Also added other graphic handlers to allow saving in additional formats.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@35428 15284696-431f-4ddb-bdfa-cd5b030d7da7
Michael Barton 16 years ago
parent
commit
3b583119d6
2 changed files with 37 additions and 9 deletions
  1. 30 9
      gui/wxpython/gui_modules/mapdisp.py
  2. 7 0
      gui/wxpython/gui_modules/mapdisp_window.py

+ 30 - 9
gui/wxpython/gui_modules/mapdisp.py

@@ -860,30 +860,51 @@ class MapFrame(wx.Frame):
         """
         """
         Save image to file
         Save image to file
         """
         """
-        filetype =  "PNG file (*.png)|*.png|"\
+        filetype =  "BMP file (*.bmp)|*.bmp|"\
+                    "GIF file (*.gif)|*.gif|"\
+                    "JPG file (*.jpg)|*.jpg|"\
+                    "PCX file (*.pcx)|*.pcx|"\
+                    "PNG file (*.png)|*.png|"\
+                    "PNM file (*.pnm)|*.pnm|"\
                     "TIF file (*.tif)|*.tif|"\
                     "TIF file (*.tif)|*.tif|"\
-                    "GIF file (*.gif)|*.gif"
+                    "XPM file (*.xpm)|*.xpm"
 
 
-        dlg = wx.FileDialog(self, "Choose a file name to save the image as a PNG to",
+        dlg = wx.FileDialog(self, "Choose a file name to save the image (no need to add extension)",
             defaultDir = "",
             defaultDir = "",
             defaultFile = "",
             defaultFile = "",
             wildcard = filetype,
             wildcard = filetype,
             style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
             style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
         if dlg.ShowModal() == wx.ID_OK:
         if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+            if path == None: return
             base = os.path.splitext(dlg.GetPath())[0]
             base = os.path.splitext(dlg.GetPath())[0]
             ext = os.path.splitext(dlg.GetPath())[1]
             ext = os.path.splitext(dlg.GetPath())[1]
             if dlg.GetFilterIndex() == 0:
             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
                 type = wx.BITMAP_TYPE_PNG
-                path = dlg.GetPath()
                 if ext != '.png': path = base+'.png'
                 if ext != '.png': path = base+'.png'
-            elif dlg.GetFilterIndex() == 1:
+            elif dlg.GetFilterIndex() == 5:
+                type = wx.BITMAP_TYPE_PNM
+                if ext != '.pnm': path = base+'.pnm'
+            elif dlg.GetFilterIndex() == 6:
                 type = wx.BITMAP_TYPE_TIF
                 type = wx.BITMAP_TYPE_TIF
                 if ext != '.tif': path = base+'.tif'
                 if ext != '.tif': path = base+'.tif'
-            elif dlg.GetFilterIndex() == 2:
-                type = wx.BITMAP_TYPE_TIF
-                if ext != '.gif': path = base+'.gif'
+            elif dlg.GetFilterIndex() == 7:
+                type = wx.BITMAP_TYPE_XPM
+                if ext != '.xpm': path = base+'.xpm'
             self.MapWindow.SaveToFile(path, type)
             self.MapWindow.SaveToFile(path, type)
-
+            
         dlg.Destroy()
         dlg.Destroy()
 
 
     def PrintMenu(self, event):
     def PrintMenu(self, event):

+ 7 - 0
gui/wxpython/gui_modules/mapdisp_window.py

@@ -481,6 +481,13 @@ class BufferedWindow(MapWindow, wx.Window):
 
 
         # get the image to be rendered
         # get the image to be rendered
         self.img = self.GetImage()
         self.img = self.GetImage()
+        if self.img != None:
+            self.img.AddHandler(JPEGHandler)
+            self.img.AddHandler(GIFHandler)
+            self.img.AddHandler(BMPHandler)
+            self.img.AddHandler(XPMHandler)
+            self.img.AddHandler(PNMHandler)
+            self.img.AddHandler(PCXHandler)
 
 
         # update map display
         # update map display
         if self.img and self.Map.width + self.Map.height > 0: # scale image during resize
         if self.img and self.Map.width + self.Map.height > 0: # scale image during resize