<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="post-text" itemprop="text">
      <p>Dear list,</p>
      <p>I'm writing a plugin, I want to change the content of a
        comboBox (fields) depending of the content of another comboBox
        (layers). </p>
      <p>My plugin is a dockwidget. I can populate the fields comboBox
        just starting the plugin in the <em>def run(self):</em>
        function, and it's working fine:</p>
      <pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">        layerNom </span><span class="pun">=</span><span class="pln"> self</span><span class="pun">.</span><span class="pln">dockwidget</span><span class="pun">.</span><span class="pln">comboBoxErrores</span><span class="pun">.</span><span class="pln">currentText</span><span class="pun">() #</span><span class="typ">Get</span><span class="pln"> the text value of the comboBox
        </span><span class="kwd">for</span><span class="pln"> lyr </span><span class="kwd">in</span><span class="pln"> </span><span class="typ">QgsMapLayerRegistry</span><span class="pun">.</span><span class="pln">instance</span><span class="pun">().</span><span class="pln">mapLayers</span><span class="pun">().</span><span class="pln">values</span><span class="pun">():</span><span class="pln">    </span><span class="com">#Get layers        </span><span class="pln">
            </span><span class="kwd">if</span><span class="pln"> lyr</span><span class="pun">.</span><span class="pln">name</span><span class="pun">()==</span><span class="pln">str</span><span class="pun">(</span><span class="pln">layerNom</span><span class="pun">):</span><span class="pln"> 
                fields </span><span class="pun">=</span><span class="pln"> lyr</span><span class="pun">.</span><span class="pln">pendingFields</span><span class="pun">()</span><span class="pln"> </span><span class="com">#Get Fiels</span><span class="pln">
                field_names </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">field</span><span class="pun">.</span><span class="pln">name</span><span class="pun">()</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> field </span><span class="kwd">in</span><span class="pln"> fields</span><span class="pun">]</span><span class="pln"> </span><span class="com">#Field List</span><span class="pln">
                self</span><span class="pun">.</span><span class="pln">dockwidget</span><span class="pun">.</span><span class="pln">comboCampos</span><span class="pun">.</span><span class="pln">addItems</span><span class="pun">(</span><span class="pln">field_names</span><span class="pun">)</span><span class="pln"> </span><span class="com">#Add to the comboBox</span></code></pre>
      <p>But when I try to update the content of the fields comboBox I
        really don't know how to do it.</p>
      <p>In my "pluginName_dockwidget.py" file, in the <strong>init</strong>
        function I have created the connection with the function that
        will repopulate the comboBox with the new content:</p>
      <pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">self</span><span class="pun">.</span><span class="pln">comboBoxErrores</span><span class="pun">.</span><span class="pln">currentIndexChanged</span><span class="pun">[</span><span class="str">'QString'</span><span class="pun">].</span><span class="pln">connect</span><span class="pun">(</span><span class="pln">self</span><span class="pun">.</span><span class="pln">pueblaCampos</span><span class="pun">)</span></code></pre>
      <p>In the same file I have a function that get the value of the
        layer name of the comboBox and emit it with the signal created
        previously:</p>
      <pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">sennalComboIndex </span><span class="pun">=</span><span class="pln"> pyqtSignal</span><span class="pun">(</span><span class="pln">str</span><span class="pun">)</span><span class="pln">
</span><span class="pun">.</span><span class="pln">
</span><span class="pun">.</span><span class="pln">
</span><span class="pun">.</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> pueblaCampos</span><span class="pun">(</span><span class="pln">self</span><span class="pun">):</span><span class="pln">      

    layerName </span><span class="pun">=</span><span class="pln"> self</span><span class="pun">.</span><span class="pln">comboBoxErrores</span><span class="pun">.</span><span class="pln">currentText</span><span class="pun">()</span><span class="pln">
    self</span><span class="pun">.</span><span class="pln">sennalComboIndex</span><span class="pun">.</span><span class="pln">emit</span><span class="pun">(</span><span class="pln">layerName</span><span class="pun">)</span></code></pre>
      <p>In my main file, I have the rest of the function:</p>
      <pre style="" class="lang-py prettyprint prettyprinted"><code><span class="kwd">def</span><span class="pln"> pueblaCampos</span><span class="pun">(</span><span class="pln">self</span><span class="pun">,</span><span class="pln"> layerName</span><span class="pun">):</span><span class="pln">        

    </span><span class="kwd">for</span><span class="pln"> lyr </span><span class="kwd">in</span><span class="pln"> </span><span class="typ">QgsMapLayerRegistry</span><span class="pun">.</span><span class="pln">instance</span><span class="pun">().</span><span class="pln">mapLayers</span><span class="pun">().</span><span class="pln">values</span><span class="pun">():</span><span class="pln">
        </span><span class="kwd">if</span><span class="pln"> lyr</span><span class="pun">.</span><span class="pln">name</span><span class="pun">()==</span><span class="pln">str</span><span class="pun">(</span><span class="pln">layerName</span><span class="pun">):</span><span class="pln">
            fields </span><span class="pun">=</span><span class="pln"> lyr</span><span class="pun">.</span><span class="pln">pendingFields</span><span class="pun">()</span><span class="pln">
            field_names </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">field</span><span class="pun">.</span><span class="pln">name</span><span class="pun">()</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> field </span><span class="kwd">in</span><span class="pln"> fields</span><span class="pun">]</span><span class="pln">             
            self</span><span class="pun">.</span><span class="pln">dockwidget</span><span class="pun">.</span><span class="pln">comboCampos</span><span class="pun">.</span><span class="pln">clear</span><span class="pun">()</span><span class="pln">
            self</span><span class="pun">.</span><span class="pln">dockwidget</span><span class="pun">.</span><span class="pln">comboCampos</span><span class="pun">.</span><span class="pln">addItems</span><span class="pun">(</span><span class="pln">field_names</span><span class="pun">)</span></code></pre>
      <p>When I change the slected item in the layers comboBox, nothing
        happens. What Am I missing?</p>
      <p>Ask for more detail info if you think it's needed. Thank you
        very much!!</p>
    </div>
  </body>
</html>