Hi Giuseppe and Alexander<div><br></div><div>Thank you for the help - both of you. I followed your instructions and can now pick file names of loaded layers.</div><div><br></div><div>Also, as you suggested, I realised that I needed to study the Qt4 interface and have gone through most of the tutorials (<a href="http://zetcode.com/tutorials/pyqt4" target="_blank">http://zetcode.com/tutorials/pyqt4</a>)</div>
<div><br></div><div>The only things I had to change was </div><div><ul><li>that the layerCombo lives in 'dlg.ui' and not 'self' since I am using a skeleton generated by the plugin generator. Is that OK?</li>
<li>that the method in layerCombo to add layers is 'addItem' and not 'append' :-)</li></ul></div><div>With that loaded layer names show up in the combo and after selection the fully qualified filename is returned by layer.source()</div>
<div><br></div><div>However, if I want a handle to an active layer, like I got with self.iface.mapCanvas().currentLayer() is there any way that could be obtained from the layer object?</div><div><br></div><div><br></div><div>
Grateful for your advice.</div><div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Cheers and thanks</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">
Ole </p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">
<br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">
<br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p></div><div><br></div><div><br><div class="gmail_quote">On Thu, Dec 8, 2011 at 7:46 PM, Giuseppe Sucameli <span dir="ltr"><<a href="mailto:sucameli@faunalia.it" target="_blank">sucameli@faunalia.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ole,<br>
<div><br>
On Thu, Dec 8, 2011 at 3:54 AM, Ole Nielsen<br>
<<a href="mailto:ole.moller.nielsen@gmail.com" target="_blank">ole.moller.nielsen@gmail.com</a>> wrote:<br>
> I am maybe looking for a file or layer selection combo and<br>
> a hint on how to make it work.<br>
<br>
</div>First create a combo in your UI named "layerCombo"<br>
<br>
Then populate the combo running:<br>
<br>
self.layers = self.iface.legendInterface().layers() # store the layer list<br>
self.layerCombo.clear() # clear the combo<br>
for layer in self.layers: # foreach layer in legend<br>
self.layerCombo.append( <a href="http://layer.name" target="_blank">layer.name</a>() ) # add it to the combo<br>
<br>
<br>
When you have to get the layer selected in the combo,<br>
just us the following snippet:<br>
<br>
index = self.layerCombo.currentIndex()<br>
if index < 0:<br>
# it may occur if there's no layer in the combo/legend<br>
else:<br>
layer = self.layers[ index ] # get the layer by index from the<br>
previous stored list<br>
source = layer.source() # get the layer source<br>
<br>
<br>
I haven't tried the previous code, so it could contains errors.<br>
<div><br>
> I have very limited experience with UIs so please forgive me my basic<br>
> questions.<br>
<br>
</div>Look at QT tutorials, they contain everything you need<br>
to know about UI creation.<br>
<br>
Cheers.<br>
<div><div><br>
><br>
> Cheers and thanks<br>
> Ole<br>
><br>
> On Wed, Dec 7, 2011 at 8:57 PM, Alexander Bruy <<a href="mailto:alexander.bruy@gmail.com" target="_blank">alexander.bruy@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hi Ole,<br>
>><br>
>> 2011/12/7 Ole Nielsen <<a href="mailto:ole.moller.nielsen@gmail.com" target="_blank">ole.moller.nielsen@gmail.com</a>>:<br>
>> > Sorry, I was perhaps not as clear as I could have been. I have already<br>
>> > written plugins using the currentLayer option. What I need now is to<br>
>> > combine<br>
>> > two layers for a specific analysis. So I imagine being able to select<br>
>> > them<br>
>> > through the plugin GUI selection combos and return the two layer handles<br>
>> > to<br>
>> > the Python code in the same format as what is provided by current layer.<br>
>> > However, I have no idea how to start doing this.<br>
>><br>
>> Ah, understand. That's not so difficult. You need to get layer name<br>
>> from combobox,<br>
>> then find layer by name. Here is small function that did this work for you<br>
>><br>
>> def getVectorLayerByName( layerName ):<br>
>> layerMap = QgsMapLayerRegistry.instance().mapLayers()<br>
>> for name, layer in layerMap.iteritems():<br>
>> if layer.type() == QgsMapLayer.VectorLayer and <a href="http://layer.name" target="_blank">layer.name</a>() ==<br>
>> layerName:<br>
>> if layer.isValid():<br>
>> return layer<br>
>> else:<br>
>> return None<br>
>><br>
>> So in your code you can simply do something like this<br>
>><br>
>> layerA = getVectorLayerByName( self.cmbLayerA.currentText() )<br>
>> layerB = getVectorLayerByName( self.cmbLayerB.currentText() )<br>
>><br>
>> Hope this helps<br>
>><br>
>> --<br>
>> Alexander Bruy<br>
>> NextGIS<br>
><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Qgis-developer mailing list<br>
> <a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
><br>
<span><font color="#888888"><br>
<br>
<br>
--<br>
Giuseppe Sucameli<br>
</font></span></blockquote></div><br></div>