[Thuban-commits] r2858 - in trunk/thuban/Extensions/umn_mapserver: . test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Jul 29 08:17:35 CEST 2008


Author: elachuni
Date: 2008-07-29 08:17:34 +0200 (Tue, 29 Jul 2008)
New Revision: 2858

Modified:
   trunk/thuban/Extensions/umn_mapserver/mapfile.py
   trunk/thuban/Extensions/umn_mapserver/mf_export.py
   trunk/thuban/Extensions/umn_mapserver/mf_handle.py
   trunk/thuban/Extensions/umn_mapserver/test/test_mapserver.py
Log:
Fixing a couple of uncaught exceptions when using the umn_mapserver extension.
(bug #694)


Modified: trunk/thuban/Extensions/umn_mapserver/mapfile.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/mapfile.py	2008-07-27 05:30:28 UTC (rev 2857)
+++ trunk/thuban/Extensions/umn_mapserver/mapfile.py	2008-07-29 06:17:34 UTC (rev 2858)
@@ -1012,18 +1012,17 @@
         self._mf_map.name = newname
     
     def set_extent(self, newextent):
-        # TODO: add the shown extend here instead of the total
-        # if no size is set or if it is zero, the size will set to 1.
-        if self.get_size()[0] == - 1:
-            print "define the size first to set extent"
-            print "size is now set to (1,1)"
-            self.set_size(1,1)
-        # if an empty map is export newextent will be none
+        """ Set the map's extent.  The map's size should already have been
+            set when you call this function, so this function will fail
+            if not.  Setting the size after the extent produces undesired
+            results anyway. """
+        width, height = self.get_size()
+        if width <= 0 or height <= 0:
+            raise mapscript.MapServerError, \
+                  "No size set before calling set_extent"
         if newextent:
-            self._newrect = MF_Rectangle(rectObj(newextent[0],newextent[1], \
-                                    newextent[2],newextent[3]))
-            self._mf_map.setExtent(newextent[0],newextent[1], \
-                                    newextent[2],newextent[3])    
+            self._newrect = MF_Rectangle(rectObj(*newextent))
+            self._mf_map.setExtent(*newextent)
     
     def set_size(self, newwidth, newheight):
         self._mf_map.width = newwidth

Modified: trunk/thuban/Extensions/umn_mapserver/mf_export.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/mf_export.py	2008-07-27 05:30:28 UTC (rev 2857)
+++ trunk/thuban/Extensions/umn_mapserver/mf_export.py	2008-07-29 06:17:34 UTC (rev 2858)
@@ -28,8 +28,7 @@
 from mapscript import mapObj
 
 # wxPython support
-from wx import FileDialog, \
-                        ID_OK, SAVE, OVERWRITE_PROMPT
+from wx import FileDialog, MessageDialog, OK, ID_OK, SAVE, OVERWRITE_PROMPT
 
 # Thuban
 # use _() already now for all strings that may later be translated
@@ -124,8 +123,8 @@
     that the file is generated automatic
     """
     thuban_umn_comment = "# \n" + \
-                                "# Map file generated by Thuban (umn_mapserver Extension) \n" + \
-                                "# \n \n"
+             "# Map file generated by Thuban (umn_mapserver Extension) \n" + \
+             "# \n \n"
     datafile = os.path.join(path,file)
     
     in_file = open(datafile,"r")
@@ -143,7 +142,12 @@
     the mapobj
     """
     theMap = context.mainwindow.canvas.Map().extension_umn_mapobj
-    
+    width, height = theMap.get_size() 
+    if width <= 0 or height <= 0:
+        dlg = MessageDialog (context.mainwindow,
+                 "You must set the map size before exporting", "Warning", OK)
+        dlg.ShowModal()
+        return
     dlg = FileDialog(context.mainwindow, "Save file as...", ".", "", 
                        "UMN MapServer Mapfiles (*.map)|*.map|"     \
                        "All files (*.*)|*.*",

Modified: trunk/thuban/Extensions/umn_mapserver/mf_handle.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/mf_handle.py	2008-07-27 05:30:28 UTC (rev 2857)
+++ trunk/thuban/Extensions/umn_mapserver/mf_handle.py	2008-07-29 06:17:34 UTC (rev 2858)
@@ -214,8 +214,15 @@
         self.Show(False)
 
     def OnOK(self, event):
-        self.tb_map_umn.set_size(int(self.text_width.GetValue()), 
-                                 int(self.text_height.GetValue()))
+        try:
+            width = int(self.text_width.GetValue())
+            height = int(self.text_height.GetValue())
+        except ValueError, e:
+            dlg = wx.MessageDialog (self, "Width / Height: " + str(e),
+                                    "Warning", wx.OK)
+            dlg.ShowModal()
+            return
+        self.tb_map_umn.set_size(width, height)
         self.tb_map_umn.set_units(self.choice_units.GetStringSelection())
         if self.choice_status.GetStringSelection() == "True":
             self.tb_map_umn.set_status(True)

Modified: trunk/thuban/Extensions/umn_mapserver/test/test_mapserver.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/test/test_mapserver.py	2008-07-27 05:30:28 UTC (rev 2857)
+++ trunk/thuban/Extensions/umn_mapserver/test/test_mapserver.py	2008-07-29 06:17:34 UTC (rev 2858)
@@ -54,7 +54,7 @@
         Testing Color Objects from MapServer.
         """
         # IMAGECOLOR  255 255 255
-        testcolor = MF_Color(self.testMap.imagecolor)        
+        testcolor = MF_Color(self.testMap.imagecolor)
         self.eq(testcolor.get_red(), 255)
         self.eq(testcolor.get_green(), 255)
         self.eq(testcolor.get_blue(), 255)



More information about the Thuban-commits mailing list