jschuengel: thuban/Extensions/umn_mapserver mf_handle.py,1.6,1.7

cvs@intevation.de cvs at intevation.de
Tue Aug 3 13:56:55 CEST 2004


Author: jschuengel

Update of /thubanrepository/thuban/Extensions/umn_mapserver
In directory doto:/tmp/cvs-serv14461

Modified Files:
	mf_handle.py 
Log Message:
Added a group option and the metadata button to the Layer dialog. The layer dialog is temporary disabled.
(Metadata_CustomDataTable): Added some funktions to show the grid correct.


Index: mf_handle.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_handle.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mf_handle.py	28 Jul 2004 12:37:28 -0000	1.6
+++ mf_handle.py	3 Aug 2004 11:56:53 -0000	1.7
@@ -25,7 +25,7 @@
 import os, sys
 
 # mapscript
-from mapscript import mapObj
+from mapscript import mapObj, layerObj
 
 # wxPython support
 # TODO: explicitly use from .. import
@@ -331,6 +331,12 @@
 
         #  get the web object
         self.tb_layer = parent.current_layer()
+        if hasattr(self.tb_layer,"extension_umn_layerobj"):
+            self.umn_layer = self.tb_layer.extension_umn_layerobj
+        else:
+            newlayerobj = parent.canvas.Map().extension_umn_mapobj.create_new_layer()
+            self.tb_layer.extension_umn_layerobj = newlayerobj
+            self.umn_layer = self.tb_layer.extension_umn_layerobj
         
         # create name
         layer_name = wxBoxSizer(wxHORIZONTAL)
@@ -339,9 +345,23 @@
         layer_name.Add(wxStaticText(self, -1, self.tb_layer.Title()), 0,
                      wxALL|wxALIGN_CENTER_VERTICAL, 4)  
  
-##~         # metadata button
-##~         metadata_button = wxButton(self, ID_METADATA_CHANGE, _("Edit Metadata"))
-##~         EVT_BUTTON(self, ID_METADATA_CHANGE, self.OnChangeMetadata)
+        # metadata button
+        metadata_button = wxButton(self, ID_METADATA_CHANGE, _("Edit Metadata"))
+        EVT_BUTTON(self, ID_METADATA_CHANGE, self.OnChangeMetadata)
+        
+        # Group 
+        box_group = wxBoxSizer(wxHORIZONTAL)
+        if self.umn_layer.get_group():
+            umn_layer_group = self.umn_layer.get_group()
+        else:
+            umn_layer_group = ""
+        box_group.Add(wxStaticText(self, -1, _("Group:")), 0,
+                     wxALL|wxALIGN_LEFT, 4)
+        self.text_group = wxTextCtrl(self, -1, 
+                                    str(umn_layer_group))
+        self.text_group.SetSize((250,self.text_group.GetSize()[1]))
+        box_group.Add(self.text_group, 0,
+                     wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         
         # buttons
         box_buttons = wxBoxSizer(wxHORIZONTAL)
@@ -356,8 +376,9 @@
         # compose the final dialog
         top = wxBoxSizer(wxVERTICAL)
         #top.Add(box_template, 0, wxEXPAND |wxALL, 5)
-        top.Add(layer_name, 0)
-##~         top.Add(metadata_button, 0, wxEXPAND)
+        top.Add(layer_name, 0, wxEXPAND|wxALL, 5)
+        top.Add(box_group, 0, wxEXPAND|wxALL, 5)
+        top.Add(metadata_button, 0, wxEXPAND|wxALL, 5)
         top.Add(box_buttons, 0, wxALIGN_RIGHT)
         
         # final layout settings
@@ -368,7 +389,7 @@
         # set the umn_label for scalebar so the Label_Dialog can be used
         self.umn_metadata= self.umn_layer.get_metadata()
         dialog = Metadata_Dialog(self, -1, "Layer Metadata Settings",
-	                      size=wxSize(350, 200),
+	                      size=wxSize(450, 200),
                  style = wxDEFAULT_DIALOG_STYLE
                  )
         dialog.CenterOnScreen()
@@ -390,6 +411,10 @@
         self.Show(False)
 
     def OnOK(self, event):
+        if self.text_group.GetValue() == "":
+            self.umn_layer.set_group(None)
+        else:
+            self.umn_layer.set_group(self.text_group.GetValue())
         self.result ="OK"
         self.end_dialog(self.result)
 
@@ -1057,6 +1082,9 @@
 
 class Metadata_CustomDataTable(wxPyGridTableBase):
     """
+    creates a custum Grid.
+    
+    copied from the wx demo.
     """
     def __init__(self, data):
         wxPyGridTableBase.__init__(self)
@@ -1065,7 +1093,7 @@
         self.dataTypes = [wxGRID_VALUE_STRING,
                           wxGRID_VALUE_STRING
                           ]
-
+        
         if data:
             self.data = data
         else:
@@ -1076,10 +1104,7 @@
         return len(self.data) + 1
 
     def GetNumberCols(self):
-        if self.data[0]:
-            return len(self.data[0])
-        else:
-            return None
+        return len(self.data[0])
 
     def IsEmptyCell(self, row, col):
         try:
@@ -1102,6 +1127,7 @@
             self.data[row][col] = value
         except IndexError:
             # add a new row
+            
             self.data.append([''] * self.GetNumberCols())
             self.SetValue(row, col, value)
 
@@ -1112,10 +1138,36 @@
 
             self.GetView().ProcessTableMessage(msg)
 
+    #--------------------------------------------------
+    # Some optional methods
+
+    # Called when the grid needs to display labels
+    def GetColLabelValue(self, col):
+        return self.colLabels[col]
+
+    # Called to determine the kind of editor/renderer to use by
+    # default, doesn't necessarily have to be the same type used
+    # natively by the editor/renderer if they know how to convert.
+    def GetTypeName(self, row, col):
+        return self.dataTypes[col]
+
+    # Called to determine how the data can be fetched and stored by the
+    # editor and renderer.  This allows you to enforce some type-safety
+    # in the grid.
+    def CanGetValueAs(self, row, col, typeName):
+        colType = self.dataTypes[col].split(':')[0]
+        if typeName == colType:
+            return true
+        else:
+            return False
+
+    def CanSetValueAs(self, row, col, typeName):
+        return self.CanGetValueAs(row, col, typeName)
+
 
 class Metadata_TableGrid(wxGrid):
     def __init__(self, parent, data):
-        wxGrid.__init__(self, parent, -1, size=(600,400))
+        wxGrid.__init__(self, parent, -1)
 
         self.table = Metadata_CustomDataTable(data)
 
@@ -1125,9 +1177,11 @@
         self.SetTable(self.table, true)
 
         self.SetRowLabelSize(0)
+        self.SetColMinimalWidth(0,180)
+        self.SetColSize(0,180)
+        self.SetColMinimalWidth(1,250)
+        self.SetColSize(1,250)
         self.SetMargins(0,0)
-        self.AutoSizeColumns(False)
-
         EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
 
     def get_table(self):
@@ -1204,17 +1258,14 @@
         self.Show(False)
 
     def OnOK(self, event):
-        # added all metadatas to the mapobj
-        # TODO: only add ne to the old Metadata
-        #self.tb_map_metadata = MF_Metadata(self.tb_map.extension_umn_mapobj)
-        for x in range(0, self.grid.get_table().GetNumberRows()-1,1):
+        # added all metadatas to the mapobj,
+        # first remove the old ones
+        self.umn_metadata.remove_allmetadata()
+        for x in range(self.grid.get_table().GetNumberRows()-2,-1, -1):
             if self.grid.get_table().GetValue(x,0):
                 self.umn_metadata.add_metadata(str(self.grid.get_table().GetValue(x,0)),\
                      str(self.grid.get_table().GetValue(x,1)))
-            else:
-                delkey = self.umn_metadata.get_metadatakeys()[x]
-                self.umn_metadata.remove_metadatabykey(delkey)
-        
+
         self.result ="OK"
         self.end_dialog(self.result)
 
@@ -1226,7 +1277,7 @@
 
 def metadatasettings(context):
     win = Metadata_Dialog(context.mainwindow, -1, "Metadata Settings",
-                          size=wxSize(350, 200),
+                          size=wxSize(450, 250),
                           style = wxDEFAULT_DIALOG_STYLE)
     win.CenterOnScreen()
     val = win.ShowModal()    
@@ -1273,12 +1324,6 @@
                         style = wxDEFAULT_DIALOG_STYLE)
     win.CenterOnScreen()
     val = win.ShowModal()
-    
-#create a new mapfile
-def  create_new_mapfile(context):
-    theMap = MF_Map(mapObj(""))
-    context.mainwindow.canvas.Map().extension_umn_mapobj = theMap
-
 
 # TODO: Maybe can be imported from another class
 # check if an mapobj exists, to control the menuitem is available or not
@@ -1288,6 +1333,8 @@
 
 def _has_umn_mapobj_and_selectedlayer(context):
     """Return true if a umn_mapobj exists"""
+    # temporary disabled
+    return False
     if context.mainwindow.has_selected_layer():
         return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj")
     else:
@@ -1306,17 +1353,10 @@
 mapserver_menu = experimental_menu.FindOrInsertMenu("mapserver",
                                                   _("&MapServer"))
 
-# register the new command
-registry.Add(Command("create_new_mapfile", _("Create new mapfile"), \
-                     create_new_mapfile, \
-		           helptext = _("Create a new empty mapscript MapObj")))
-# finally add the new entry to the extensions menu
-mapserver_menu.InsertItem("create_new_mapfile", after = "import_mapfile" )
-
 # find the MapServer menu and add a new submenu if found
 mapserver_edit_menu = mapserver_menu.FindOrInsertMenu("edit_mapfile",
                                                   _("&Edit mapfile"), \
-                                                  after = "create_new_mapfile")
+                                                  after = "import_layer_from_mapfile")
 
 # register the new command (Map Settings Dialog)
 registry.Add(Command("Map Settings", _("Map"), mapsettings,





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)