[Thuban-devel] Re: RfD: Support for layer specific resources
Martin Schulze
joey at infodrom.org
Wed Jun 9 17:39:05 CEST 2004
Bernhard Herzog wrote:
> >> The logic that determines whether the dialog is already shown and either
> >> raises the existing one or creates a new one should be left in the
> >> mainwindow. Actually, it should be moved into its own mainwindow method
> >> as this logic has already been duplicated at least seven times in
> >> mainwindow.py, but that's for another patch.
> >
> > That would require a global logic for naming windows/dialogs.
>
> It would be local to the mainwindow.
Hmm, possibly.
> > We may also need some sort of registration for calculation functions.
>
> What exactly do you mean? The Panels in Thuban/UI/classgen.py?
If dialogs should not be opened multiple times, they need to be named
and inserted into the dialog list. My idea is that when dialog
creation is handled globally there needs to be a global logic for
naming dialogs.
I'm not yet able to oversee the global picture yet, so my ideas may not
always make too much sense. In such cases, feel free to ignore them.
> > Something like
> >
> > def OpenOrRaiseDialog(self, type, layer, group=None):
> > # type one of [layer,properties,information]
> > name = self.calculate_dialog_name(...)
> >
> > dialog = self.get_open_dialog(name)
> >
> > if dialog is None:
> > open_func = get_layer_properties_dialog(layer)
> > if open_func is None:
> > return None
> > dialog = open_func(self, layer, group)
> > parent.add_dialog(name, dialog)
> > dialog.Show(True)
> > else:
> > dialog.Raise()
>
> Well, it's still too get_layer_properties_dialog specific. I was
> thinking about something more like this:
>
> def OpenOrRaiseDialog(self, name, dialog_class, *args, *kw):
> dialog = self.get_open_dialog(name)
>
> if dialog is None:
> dialog = dialog_class(self, name, *args, **kw)
> parent.add_dialog(name, dialog)
> dialog.Show(True)
> else:
> dialog.Raise()
>
> The raise-or-open logic should be completely separate from the logic
> that determines which dialog to open.
>
>
> > we will probably handle show_table
> > and information similar to the properties dialog.
>
> Why do we need layer specific dialogs for show table? It may be
> necessary to make the existing code more flexible, so that it works for
> layers that are not sub-classes of Layer among others, but that
> shouldn't require different dialogs.
Maybe there is no need for different show table dialogs at the
moment. I can't guarantee that there won't be one in the future.
Hence, I would rather like to implement a general solution which could
be used for other instances of the same problem class as well.
> > Apart from that, this method is executed quite often. We would
> > probably create a reasonable delay if it would be implemented that
> > way. In order to avoid this, I propose a hierarchical data structure
> > for layer_dialogs.py (attached).
>
> Well, the way you wrote the function, it returns the wrong results (see
> below) in some cases and probably isn't all that much faster. Anyway, I
> don't think we need the hierarchical approach yet. If the lookup is too
> slow there are lots of ways in can be made faster. E.g. instead of
> doing a linear search each time, we could build a dictionary on demand
> mapping layer classes to the appropriate dialog classes.
ok.
Is the attached patch better?
Regards,
Joey
--
Whenever you meet yourself you're in a time loop or in front of a mirror.
-------------- 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 9 Jun 2004 15:30:45 -0000
@@ -72,7 +72,7 @@
Representation for the WMS properties dialog
"""
- def __init__(self, parent, name, layer):
+ def __init__(self, parent, name, layer, group = None):
"""
Build the properties dialog
"""
Index: Extensions/wms/wms.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/wms/wms.py,v
retrieving revision 1.9
diff -u -r1.9 wms.py
--- Extensions/wms/wms.py 11 May 2004 22:34:49 -0000 1.9
+++ Extensions/wms/wms.py 9 Jun 2004 15:30:46 -0000
@@ -33,6 +33,7 @@
import Thuban.UI.baserenderer
from layer import WMSLayer
+from properties import wmsProperties
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, wmsProperties)
class SelectWMSServer(wxDialog):
Index: Thuban/UI/classifier.py
===================================================================
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 9 Jun 2004 15:30:50 -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
@@ -685,7 +687,7 @@
FIELDTYPE_INT: _("Integer"),
FIELDTYPE_DOUBLE: _("Decimal")}
- def __init__(self, parent, name, map, layer, group = None):
+ def __init__(self, parent, name, layer, group = None):
"""Create a Properties/Classification dialog for a layer.
The layer is part of map. If group is not None, select that
group in the classification table.
@@ -697,7 +699,7 @@
self.parent.Subscribe(MAP_REPLACED, self.map_replaced)
self.layer = layer
- self.map = map
+ self.map = parent.Map()
self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED,
@@ -1510,3 +1512,6 @@
def _OnLeftDClick(self, event):
self.DoEdit()
+
+add_layer_dialog('properties', Layer, Classifier)
+add_layer_dialog('properties', RasterLayer, Classifier)
Index: Thuban/UI/mainwindow.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/mainwindow.py,v
retrieving revision 1.132
diff -u -r1.132 mainwindow.py
--- Thuban/UI/mainwindow.py 18 Apr 2004 20:37:01 -0000 1.132
+++ Thuban/UI/mainwindow.py 9 Jun 2004 15:30:54 -0000
@@ -53,6 +53,9 @@
import projdialog
+from Extensions.wms.infodialog import wmsInfoDialog
+
+from Thuban.UI.layer_dialogs import get_layer_properties_class
class MainWindow(DockFrame):
@@ -349,6 +352,23 @@
"""
self.SetStatusText(text)
+ def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
+ """
+ Open or raise a dialog.
+
+ If a dialog with the denoted name does already exist it is
+ raised. Otherwise a new dialog, an instance of dialog_class,
+ is created, inserted into the main list and displayed.
+ """
+ dialog = self.get_open_dialog(name)
+
+ if dialog is None:
+ dialog = dialog_class(self, name, *args, **kw)
+ self.add_dialog(name, dialog)
+ dialog.Show(True)
+ else:
+ dialog.Raise()
+
def save_modified_session(self, can_veto = 1):
"""If the current session has been modified, ask the user
whether to save it and do so if requested. Return the outcome of
@@ -705,14 +742,18 @@
self.OpenLayerProperties(layer)
def OpenLayerProperties(self, layer, group = None):
- name = "layer_properties" + str(id(layer))
- dialog = self.get_open_dialog(name)
+ """
+ Open or raise the properties dialog.
- if dialog is None:
- dialog = Classifier(self, name, self.Map(), layer, group)
- self.add_dialog(name, dialog)
- dialog.Show()
- dialog.Raise()
+ This method opens or raises the properties dialog for the
+ currently selected layer if one is defined for this layer
+ type.
+ """
+ dialog_class = get_layer_properties_class(layer)
+
+ if dialog_class is not None:
+ name = "layer_properties" + str(id(layer))
+ self.OpenOrRaiseDialog(name, dialog_class, layer, group = group)
def LayerJoinTable(self):
layer = self.canvas.SelectedLayer()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: layer_dialogs.py
Type: text/x-python
Size: 811 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20040609/f467246b/layer_dialogs.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_layer_dialogs.py
Type: text/x-python
Size: 643 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20040609/f467246b/test_layer_dialogs.py
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)