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

cvs@intevation.de cvs at intevation.de
Wed Jul 28 14:37:30 CEST 2004


Author: jschuengel

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

Modified Files:
	mf_handle.py 
Log Message:
Added a dialog to handle metadata. Yet only mapfile metadata are supported. Layer and class supported are not implemented.
Added a dialog to handle layer informations. The dialog only shows the selected layer at the moment.


Index: mf_handle.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_handle.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mf_handle.py	14 Jul 2004 10:35:51 -0000	1.5
+++ mf_handle.py	28 Jul 2004 12:37:28 -0000	1.6
@@ -30,6 +30,7 @@
 # wxPython support
 # TODO: explicitly use from .. import
 from wxPython.wx import *  
+from wxPython.grid import *
 
 # Thuban
 # use _() already now for all strings that may later be translated
@@ -315,6 +316,86 @@
     def OnCancel(self, event):
         self.end_dialog(None)
 
+ID_METADATA_CHANGE = 8020
+
+from Extensions.umn_mapserver.mapfile import MF_Layer
+
+class Layer_Dialog(wxDialog):
+        
+    def __init__(self, parent, ID, title,
+                 pos=wxDefaultPosition, size=wxDefaultSize,
+                 style=wxDEFAULT_DIALOG_STYLE):
+                     
+        # initialize the Dialog
+        wxDialog.__init__(self, parent, ID, title, pos, size, style)
+
+        #  get the web object
+        self.tb_layer = parent.current_layer()
+        
+        # create name
+        layer_name = wxBoxSizer(wxHORIZONTAL)
+        layer_name.Add(wxStaticText(self, -1, _("Layer-Name:")), 0,
+                     wxALL|wxALIGN_CENTER_VERTICAL, 4)
+        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)
+        
+        # buttons
+        box_buttons = wxBoxSizer(wxHORIZONTAL)
+        button = wxButton(self, wxID_OK, _("OK"))
+        box_buttons.Add(button, 0, wxALL, 5)
+        button = wxButton(self, wxID_CANCEL, _("Cancel"))
+        box_buttons.Add(button, 0, wxALL, 5)
+        #set the button funcitons
+        EVT_BUTTON(self, wxID_OK, self.OnOK)
+        EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)      
+      
+        # 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(box_buttons, 0, wxALIGN_RIGHT)
+        
+        # final layout settings
+        self.SetSizer(top)
+        top.Fit(self)
+
+    def OnChangeMetadata(self, event):
+        # 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),
+                 style = wxDEFAULT_DIALOG_STYLE
+                 )
+        dialog.CenterOnScreen()
+        if dialog.ShowModal() == wxID_OK:
+            return
+        dialog.Destroy()
+        
+    
+    def RunDialog(self):
+        self.ShowModal()
+        self.Destroy()
+
+    def end_dialog(self, result):
+        self.result = result
+        if self.result is not None:
+            self.EndModal(wxID_OK)
+        else:
+            self.EndModal(wxID_CANCEL)
+        self.Show(False)
+
+    def OnOK(self, event):
+        self.result ="OK"
+        self.end_dialog(self.result)
+
+    def OnCancel(self, event):
+        self.end_dialog(None)
+
 
 ID_LABEL_CHANGE = 8011
 
@@ -974,6 +1055,183 @@
         self.end_dialog(None)
 
 
+class Metadata_CustomDataTable(wxPyGridTableBase):
+    """
+    """
+    def __init__(self, data):
+        wxPyGridTableBase.__init__(self)
+
+        self.colLabels = ['ID', 'Description']
+        self.dataTypes = [wxGRID_VALUE_STRING,
+                          wxGRID_VALUE_STRING
+                          ]
+
+        if data:
+            self.data = data
+        else:
+            self.data = [["",""]]    #--------------------------------------------------
+    # required methods for the wxPyGridTableBase interface
+
+    def GetNumberRows(self):
+        return len(self.data) + 1
+
+    def GetNumberCols(self):
+        if self.data[0]:
+            return len(self.data[0])
+        else:
+            return None
+
+    def IsEmptyCell(self, row, col):
+        try:
+            return not self.data[row][col]
+        except IndexError:
+            return true
+
+    # Get/Set values in the table.  The Python version of these
+    # methods can handle any data-type, (as long as the Editor and
+    # Renderer understands the type too,) not just strings as in the
+    # C++ version.
+    def GetValue(self, row, col):
+        try:
+            return self.data[row][col]
+        except IndexError:
+            return ''
+
+    def SetValue(self, row, col, value):
+        try:
+            self.data[row][col] = value
+        except IndexError:
+            # add a new row
+            self.data.append([''] * self.GetNumberCols())
+            self.SetValue(row, col, value)
+
+            # tell the grid we've added a row
+            msg = wxGridTableMessage(self,                             # The table
+                                     wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
+                                     1)                                # how many
+
+            self.GetView().ProcessTableMessage(msg)
+
+
+class Metadata_TableGrid(wxGrid):
+    def __init__(self, parent, data):
+        wxGrid.__init__(self, parent, -1, size=(600,400))
+
+        self.table = Metadata_CustomDataTable(data)
+
+        # The second parameter means that the grid is to take ownership of the
+        # table and will destroy it when done.  Otherwise you would need to keep
+        # a reference to it and call it's Destroy method later.
+        self.SetTable(self.table, true)
+
+        self.SetRowLabelSize(0)
+        self.SetMargins(0,0)
+        self.AutoSizeColumns(False)
+
+        EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
+
+    def get_table(self):
+        return self.table
+
+    # I do this because I don't like the default behaviour of not starting the
+    # cell editor on double clicks, but only a second click.
+    def OnLeftDClick(self, evt):
+        if self.CanEnableCellControl():
+            self.EnableCellEditControl()
+
+
+class Metadata_Dialog(wxDialog):
+    
+    def __init__(self, parent, ID, title,
+                 pos=wxDefaultPosition, size=wxDefaultSize,
+                 style=wxDEFAULT_DIALOG_STYLE):
+                     
+        # initialize the Dialog
+        wxDialog.__init__(self, parent, ID, title, pos, size, style)
+        
+        #  get the web object
+        if hasattr(parent,"umn_metadata"):
+            self.umn_metadata = parent.umn_metadata
+        else:
+            self.tb_map = parent.canvas.Map()
+            self.umn_metadata = self.tb_map.extension_umn_mapobj.get_metadata()
+        
+        
+        # at all items to the dataset
+        self.grid = Metadata_TableGrid(self, self.umn_metadata.get_metadata())
+        
+        #buttons
+        box_buttons = wxBoxSizer(wxHORIZONTAL)
+        button = wxButton(self, wxID_OK, _("OK"))
+        box_buttons.Add(button, 0, wxALL, 5)
+        button = wxButton(self, wxID_CANCEL, _("Cancel"))
+        button.SetFocus()
+        box_buttons.Add(button, 0, wxALL, 5)
+        #set the button funcitons
+        EVT_BUTTON(self, wxID_OK, self.OnOK)
+        EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)      
+        
+        # compose the dialog
+        top = wxBoxSizer(wxVERTICAL)
+        top.Add(self.grid, 1, wxGROW|wxALL, 5)
+        top.Add(box_buttons, 0, wxALIGN_RIGHT)
+        
+        # final layout settings
+        self.SetSizer(top)
+        #top.Fit(self)
+        
+    def OnItemActivated(self, event):
+        self.currentItem = event.m_itemIndex
+
+    def OnDoubleClick(self, event):
+        print "OnDoubleClick" +self.list.GetItemText(self.currentItem)
+        event.Skip()
+        
+    def OnSize(self, event):
+        w,h = self.GetClientSizeTuple()
+        self.list.SetDimensions(0, 0, w, h)
+        
+    def RunDialog(self):
+        self.ShowModal()
+        self.Destroy()
+
+    def end_dialog(self, result):
+        self.result = result
+        if self.result is not None:
+            self.EndModal(wxID_OK)
+        else:
+            self.EndModal(wxID_CANCEL)
+        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):
+            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)
+
+    def OnCancel(self, event):
+        self.end_dialog(None)
+        
+        
+        
+
+def metadatasettings(context):
+    win = Metadata_Dialog(context.mainwindow, -1, "Metadata Settings",
+                          size=wxSize(350, 200),
+                          style = wxDEFAULT_DIALOG_STYLE)
+    win.CenterOnScreen()
+    val = win.ShowModal()    
+    
+
 def scalebarsettings(context):
     win = Scalebar_Dialog(context.mainwindow, -1, "Scalebar Settings",
                           size=wxSize(350, 200),
@@ -1002,6 +1260,13 @@
     win.CenterOnScreen()
     val = win.ShowModal()
 
+def layersettings(context):
+    win = Layer_Dialog(context.mainwindow, -1, "Layer Settings",
+                     size=wxSize(350, 200),
+                     style = wxDEFAULT_DIALOG_STYLE)
+    win.CenterOnScreen()
+    val = win.ShowModal()
+
 def legendsettings(context):
     win = Legend_Dialog(context.mainwindow, -1, "Legend Settings",
                         size=wxSize(350, 200),
@@ -1021,6 +1286,12 @@
     """Return true if a umn_mapobj exists"""
     return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj")
 
+def _has_umn_mapobj_and_selectedlayer(context):
+    """Return true if a umn_mapobj exists"""
+    if context.mainwindow.has_selected_layer():
+        return hasattr(context.mainwindow.canvas.Map(), "extension_umn_mapobj")
+    else:
+        return False
 
 # ###################################
 #
@@ -1063,6 +1334,14 @@
 # finally add the new entry to the extensions menu
 mapserver_edit_menu.InsertItem("Web Settings")
 
+# register the new command (Layer Settings Dialog)
+registry.Add(Command("Layer Settings", _("Layer"),
+                     layersettings,
+                     helptext = _("Edit the Layer Setting of the aktive Layer"), \
+                     sensitive = _has_umn_mapobj_and_selectedlayer))
+# finally add the new entry to the extensions menu
+mapserver_edit_menu.InsertItem("Layer Settings")
+
 # register the new command (Legend Settings Dialog)
 registry.Add(Command("Legend Settings", _("Legend"),
                      legendsettings,
@@ -1078,5 +1357,13 @@
                      sensitive = _has_umn_mapobj))
 # finally add the new entry to the extensions menu
 mapserver_edit_menu.InsertItem("Scalebar Settings")
+
+# register the new command (Scalebar Settings Dialog)
+registry.Add(Command("Metadata Settings", _("Metadata"),
+                     metadatasettings,
+                     helptext = _("Edit the Metadata Setting"), \
+                     sensitive = _has_umn_mapobj))
+# finally add the new entry to the extensions menu
+mapserver_edit_menu.InsertItem("Metadata Settings")
 
 





More information about the Thuban-devel mailing list

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