[Thuban-devel] Re: RfD: Support for layer specific resources

Martin Schulze joey at infodrom.org
Mon May 24 18:26:41 CEST 2004


Bernhard Herzog wrote:
> > BaseLayer.propertiesDialog of class PropertiesDialog, or rather one
> > of the specialisations of it (i.e. Classifier or wmsPropertiesDialog).
> >
> > MainWindow.OpenLayerProperties would then contain code like
> >
> >   if current_layer.has_properties():
> >     name = ...
> >     dialog = self.get_open_dialog(name)
> >     if dialog is None:
> >         dialog = current_layer.properties_dialog(..)
> >         self.add_dialog(name, dialog)
> >         dialog.Show()
> >     else
> >         dialog.Raise()
> 
> No.  The code outside of Thuban.UI should not depend on the GUI.

Hm, that means that we'll have to move the properties and information
dialogs from Extensions/wms into Thuban/UI in the long-term.

> I'd prefer a solution like the one used for the renderer extensions in
> baserenderer.py.  It basically means that there's a mapping between
> layer classes and property dialog classes.  This mapping should be in a
> new module, I think, together with the GeneralPropertiesDialog class.
> The OpenLayerProperties method would call a function in that module
> which returns the dialog class for a given layer.

Understood.

Is the patch below and the two new files (test/test_layer_dialogs.py
and Thuban/UI/layer_dialogs.py) what you want?  Documentation will
follow, of course.

I've decided to implement layer_dialogs.py a bit more generic, so it
can be used for show-table and information in addition to properties.
Hope that's ok with you.

Regards,

	Joey

-- 
Ten years and still binary compatible.  -- XFree86
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_layer_dialogs.py
Type: text/x-python
Size: 742 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20040524/75333a45/test_layer_dialogs.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: layer_dialogs.py
Type: text/x-python
Size: 575 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20040524/75333a45/layer_dialogs.py
-------------- next part --------------
Index: Extensions/wms/properties.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/wms/properties.py,v
retrieving revision 1.1
diff -u -r1.1 properties.py
--- Extensions/wms/properties.py	15 Apr 2004 16:14:51 -0000	1.1
+++ Extensions/wms/properties.py	24 May 2004 15:54:14 -0000
@@ -192,7 +192,7 @@
         self.Close()
 
 
-def OpenWMSProperties(parent, layer):
+def OpenWMSProperties(parent, layer, group = None):
     """
     Open or raise the WMS properties dialog
     """
Index: wms.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/wms/wms.py,v
retrieving revision 1.9
diff -u -r1.9 wms.py
--- wms.py	11 May 2004 22:34:49 -0000	1.9
+++ wms.py	24 May 2004 16:01:14 -0000
@@ -33,6 +33,7 @@
 import Thuban.UI.baserenderer
 
 from layer import WMSLayer
+from properties import OpenWMSProperties
 
 
 class WMSExtension(Extension):
@@ -57,6 +58,7 @@
     return ()
 
 Thuban.UI.baserenderer.add_renderer_extension(WMSLayer, render_wms_layer)
+Thuban.UI.layer_dialogs.add_layer_dialog('properties', WMSLayer, OpenWMSProperties)
 
 
 class SelectWMSServer(wxDialog):
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/classifier.py,v
retrieving revision 1.65
diff -u -r1.65 classifier.py
--- Thuban/UI/classifier.py	7 May 2004 20:20:43 -0000	1.65
+++ Thuban/UI/classifier.py	24 May 2004 15:54:47 -0000
@@ -38,6 +38,8 @@
 from dialogs import NonModalNonParentDialog
 from messages import MAP_REPLACED
 
+from Thuban.UI.layer_dialogs import add_layer_dialog
+
 ID_CLASS_TABLE = 40011
 
 
@@ -1510,3 +1512,17 @@
 
     def _OnLeftDClick(self, event):
         self.DoEdit()
+
+def OpenClassifier(parent, layer, group):
+    name = "layer_properties" + str(id(layer))
+    dialog = parent.get_open_dialog(name)
+
+    if dialog is None:
+        dialog = Classifier(parent, name, parent.Map(), layer, group)
+        parent.add_dialog(name, dialog)
+        dialog.Show(True)
+    else:
+        dialog.Raise()
+
+add_layer_dialog('properties', Layer, OpenClassifier)
+add_layer_dialog('properties', RasterLayer, OpenClassifier)
Index: mainwindow.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/mainwindow.py,v
retrieving revision 1.132
diff -u -r1.132 mainwindow.py
--- mainwindow.py	18 Apr 2004 20:37:01 -0000	1.132
+++ mainwindow.py	24 May 2004 16:09:52 -0000
@@ -53,6 +53,9 @@
 
 import projdialog
 
+from Extensions.wms.infodialog import wmsInfoDialog
+
+from Thuban.UI.layer_dialogs import open_properties_dialog
 
 class MainWindow(DockFrame):
 
@@ -607,6 +610,10 @@
         """Return true if a shape layer is currently selected"""
         return isinstance(self.current_layer(), Layer)
 
+    def has_selected_wms_layer(self):
+        """Return true if a WMS layer is currently selected"""
+        return 'capabilities' in dir(self.current_layer())
+
     def has_selected_shapes(self):
         """Return true if a shape is currently selected"""
         return self.canvas.HasSelectedShapes()
@@ -705,14 +712,7 @@
         self.OpenLayerProperties(layer)
 
     def OpenLayerProperties(self, layer, group = None):
-        name = "layer_properties" + str(id(layer))
-        dialog = self.get_open_dialog(name)
-
-        if dialog is None:
-            dialog = Classifier(self, name, self.Map(), layer, group)
-            self.add_dialog(name, dialog)
-            dialog.Show()
-        dialog.Raise()
+        open_properties_dialog (self, layer, group)
 
     def LayerJoinTable(self):
         layer = self.canvas.SelectedLayer()
@@ -1020,6 +1020,11 @@
     """Return true if a shape layer is selected in the context"""
     return context.mainwindow.has_selected_shape_layer()
 
+def _has_selected_wms_or_shape_layer(context):
+    """Return true if a WMS layer is selected in the context"""
+    return (context.mainwindow.has_selected_shape_layer()
+            or context.mainwindow.has_selected_wms_layer())
+
 def _has_selected_shapes(context):
     """Return true if a layer is selected in the context"""
     return context.mainwindow.has_selected_shapes()
@@ -1156,7 +1161,7 @@
                 sensitive = _has_selected_layer)
 _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
                 helptext = _("Show the selected layer's table"),
-                sensitive = _has_selected_shape_layer)
+                sensitive = _has_selected_wms_or_shape_layer)
 _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
                 sensitive = _has_selected_layer,
                 helptext = _("Edit the properties of the selected layer"))



More information about the Thuban-devel mailing list

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