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

Martin Schulze joey at infodrom.org
Sun May 30 18:26:36 CEST 2004


Moin!

Bernhard Herzog wrote:
> [2. text/x-python; test_layer_dialogs.py]
> [...]
> > class TestLayerDialogs(unittest.TestCase):
> >
> >     def test_layer_dialogs(self):
> >
> >         class MyLayer(BaseLayer):
> >             pass
> >
> >         my_class = MyLayer("test")
> 
> Why "my_class"?  It's not a class.

Whoops, corrected to my_instance.

> [3. text/x-python; layer_dialogs.py]
> > def open_properties_dialog(parent, layer, group):
> >     for cls, func in _layer_dialogs['properties']:
> >         if isinstance(layer, cls):
> >             func(parent, layer, group)
> >             return
> >     raise NotImplementedError
> 
> This function should return the class, not the already instantiated
> dialog.  More precisely, the return value should be an object that when
> called with name, parent and layer creates the dialog and returns it.
> If there is not dialog class available for a given layer, the function
> should return None.
> 
> Also, the function shouldn't be called open_properties_dialog then, but
> perhaps get_layer_properties_dialog instead.

What about this one instead?

def get_layer_properties_dialog(layer):
    for cls, func in _layer_dialogs['properties']:
        if isinstance(layer, cls):
            return func
    return None
    

> 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.  We may
also need some sort of registration for calculation functions.

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()

Since add_dialog/get_open_dialog are only used in mainwindow (and in
the WMS extension), this should not be too difficult, I guess.

> > Index: mainwindow.py
> > ===================================================================
> > RCS file: /thubanrepository/thuban/Thuban/UI/mainwindow.py,v
> > retrieving revision 1.132
> > diff -u -r1.132 mainwindow.py
> [...]
> > @@ -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())
> 
> This is specific for one extension.  Such code should not be in the
> Thuban core, i.e. the code in Thuban/.  Also, you use it to determine
> whether the sensitivity of the layer_show_table command, which AFAICT
> doesn't make sense for WMS layers.  If that's a bug and you wanted to
> use it for the sensitivity of the layer_properties command, then it's
> better to have a method that returns whether a dialog can be opened for
> the currently selected layer, i.e. whether get_layer_properties_dialog
> returns None or not.

Whoops, too much information for you... I should have removed that
part as well, but forgot it apparently.  I had hooked the wms
information dialog to the "Show Table" menu item.

Please ignore it for the moment, we will probably handle show_table
and information similar to the properties dialog.

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).

I've also added a simple function has_layer_dialog() that can be
called from the menu support functions.

Regards,

	Joey

-- 
Of course, I didn't mean that, which is why I didn't say it.
What I meant to say, I said.              -- Thomas Bushnell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: layer_dialogs.py
Type: text/x-python
Size: 675 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20040530/eec30e05/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)