Dear all,<br><br>I create <b><i>QCompleter</i></b>s for <i><b>QLineEdit</b></i>, which work fine if there is no dynamically defined function/method in the subclasses (try to run the script with <i>./bugCompleterFilesysModel.py n</i> n in [0, 1, 2, 9], then try to bring up the completer by deleting some char in the LineEdit box). The QCompleter can work with <i><b>QStringList</b></i>, <i><b>QStringListModel</b></i>, and <i><b>QFileSystemModel</b></i>.<br>
<br>If I add some dynamically defined function/method in the subclass with QCompleter of simple <b>QStringList</b>, the instances work fine too (try to run the script with <i>./bugCompleterFilesysModel.py</i> n n in [10, 20, 30], then try to bring up the completer by deleting some char in the LineEdit box).<br>
<br>However, if I defined any function/method dynamically, the QCompleter with any kind of <b>data model</b>, will <b>raise an error</b> during closing the GUI window:<br><br><pre style class="default prettyprint prettyprinted">
<code><span class="typ">QObject</span><span class="pun">::</span><span class="pln">startTimer</span><span class="pun">:</span><span class="pln"> </span><span class="typ">QTimer</span><span class="pln"> can only be used </span><span class="kwd">with</span><span class="pln"> threads started </span><span class="kwd">with</span><span class="pln"> </span><span class="typ">QThread</span><span class="pln">
</span><span class="typ">Segmentation</span><span class="pln"> fault</span></code></pre><br>To repeat the error, try to run the script with <i>./bugCompleterFilesysModel.py mn</i> m in [1,2,3], n in [1, 2, 9], then try to bring up the completer by deleting some char in the LineEdit box, then close the window.<br>
<br>Can anyone tell my why is that and how to fix it? I have been scratching my head for hours. <br><br>Thanks ahead!<br><br>Full script of <i>bugCompleterFilesysModel.py</i>:<br><br><pre style class="default prettyprint prettyprinted">
<code><span class="com">#!/usr/bin/env python</span><span class="pln">
</span><span class="com"># -*- coding: UTF-8 -*-</span><span class="pln">
</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyBaseWidget</span><span class="pun">(</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QWidget</span><span class="pun">):</span><span class="pln">
dirChanged</span><span class="pun">=</span><span class="typ">QtCore</span><span class="pun">.</span><span class="pln">pyqtSignal</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QString</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> __init__</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">parent</span><span class="pun">=</span><span class="kwd">None</span><span class="pun">,</span><span class="pln">addfunc0</span><span class="pun">=</span><span class="kwd">False</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">super</span><span class="pun">(</span><span class="typ">MyBaseWidget</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">self</span><span class="pun">).</span><span class="pln">__init__</span><span class="pun">(</span><span class="pln">parent</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">addfunc0</span><span class="pun">=</span><span class="pln">addfunc0
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">=</span><span class="kwd">None</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">dummyWgt</span><span class="pun">=</span><span class="lit">1</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">initUI</span><span class="pun">()</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
addfunc0</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">addfunc0
</span><span class="kwd">if</span><span class="pln"> addfunc0 </span><span class="pun">==</span><span class="pln"> </span><span class="lit">1</span><span class="pun">:</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">funcFactory0</span><span class="pun">(</span><span class="str">'1'</span><span class="pun">)</span><span class="pln">
_func0str</span><span class="pun">=</span><span class="str">"self.funcFactory0('1')"</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> addfunc0 </span><span class="pun">==</span><span class="pln"> </span><span class="lit">2</span><span class="pun">:</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">funcFactory1</span><span class="pun">(</span><span class="str">'1'</span><span class="pun">)</span><span class="pln">
_func0str</span><span class="pun">=</span><span class="str">"self.funcFactory1('1')"</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> addfunc0 </span><span class="pun">==</span><span class="pln"> </span><span class="lit">3</span><span class="pun">:</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">funcFactory1b</span><span class="pun">()</span><span class="pln">
_func0str</span><span class="pun">=</span><span class="str">"self.funcFactory1b()"</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> addfunc0 </span><span class="pun">></span><span class="pln"> </span><span class="lit">0</span><span class="pun">:</span><span class="pln">
</span><span class="com">#print self.printWgt</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> </span><span class="str">'use %s as func0'</span><span class="pun">%(</span><span class="pln">_func0str</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> </span><span class="str">'self.func0 = %s'</span><span class="pun">%(</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">func0</span><span class="pun">()</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">show</span><span class="pun">()</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> printWgt</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">wgt0</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> </span><span class="str">'Input obj is:'</span><span class="pun">,</span><span class="pln"> wgt0</span><span class="pun">.</span><span class="pln">__class__</span><span class="pun">.</span><span class="pln">__name__
</span><span class="kwd">def</span><span class="pln"> funcFactory0</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">wgt0</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> _func</span><span class="pun">():</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">printWgt</span><span class="pun">(</span><span class="pln">wgt0</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">return</span><span class="pln"> _func
</span><span class="kwd">def</span><span class="pln"> funcFactory1</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">wgt0</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> types
</span><span class="kwd">def</span><span class="pln"> _func</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">printWgt</span><span class="pun">(</span><span class="pln">wgt0</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">return</span><span class="pln"> types</span><span class="pun">.</span><span class="typ">MethodType</span><span class="pun">(</span><span class="pln">_func</span><span class="pun">,</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">mainWidget</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> funcFactory1b</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> types
</span><span class="kwd">def</span><span class="pln"> _func</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">printWgt</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">dummyWgt</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">return</span><span class="pln"> types</span><span class="pun">.</span><span class="typ">MethodType</span><span class="pun">(</span><span class="pln">_func</span><span class="pun">,</span><span class="kwd">self</span><span class="pun">,</span><span class="pln">mainWidget</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">StringWidget</span><span class="pun">(</span><span class="typ">MyBaseWidget</span><span class="pun">):</span><span class="pln">
dirChanged</span><span class="pun">=</span><span class="typ">QtCore</span><span class="pun">.</span><span class="pln">pyqtSignal</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QString</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
currdir</span><span class="pun">=</span><span class="pln">r</span><span class="str">'/tmp'</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">currdir</span><span class="pun">=</span><span class="pln">currdir
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=[]</span><span class="pln">
completer</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QCompleter</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QStringList</span><span class="pun">([</span><span class="str">'/tmp/'</span><span class="pun">+</span><span class="pln">i </span><span class="kwd">for</span><span class="pln"> i </span><span class="kwd">in</span><span class="pln"> </span><span class="str">'abcdefg'</span><span class="pun">]),</span><span class="pln"> parent</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
completer</span><span class="pun">.</span><span class="pln">setMaxVisibleItems</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">completer</span><span class="pun">=</span><span class="pln">completer
_tb</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QLineEdit</span><span class="pun">(</span><span class="pln">currdir</span><span class="pun">)</span><span class="pln">
_tb</span><span class="pun">.</span><span class="pln">setCompleter</span><span class="pun">(</span><span class="pln">completer</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QHBoxLayout</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">.</span><span class="pln">addWidget</span><span class="pun">(</span><span class="pln">_tb</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=</span><span class="pln">_tb
</span><span class="typ">MyBaseWidget</span><span class="pun">.</span><span class="pln">initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">StringModelWidget</span><span class="pun">(</span><span class="typ">MyBaseWidget</span><span class="pun">):</span><span class="pln">
dirChanged</span><span class="pun">=</span><span class="typ">QtCore</span><span class="pun">.</span><span class="pln">pyqtSignal</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QString</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
currdir</span><span class="pun">=</span><span class="pln">r</span><span class="str">'/tmp'</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">currdir</span><span class="pun">=</span><span class="pln">currdir
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=[]</span><span class="pln">
fsModel</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QStringListModel</span><span class="pun">([</span><span class="str">'/tmp/'</span><span class="pun">+</span><span class="pln">i </span><span class="kwd">for</span><span class="pln"> i </span><span class="kwd">in</span><span class="pln"> </span><span class="str">'abcdefg'</span><span class="pun">])</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">fsModel</span><span class="pun">=</span><span class="pln">fsModel
</span><span class="com">#self.fsModel.setParent(self)</span><span class="pln">
completer</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QCompleter</span><span class="pun">()</span><span class="pln">
completer</span><span class="pun">.</span><span class="pln">setMaxVisibleItems</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)</span><span class="pln">
completer</span><span class="pun">.</span><span class="pln">setModel</span><span class="pun">(</span><span class="pln">fsModel</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">fsModel</span><span class="pun">.</span><span class="pln">setParent</span><span class="pun">(</span><span class="pln">completer</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">completer</span><span class="pun">=</span><span class="pln">completer
_tb</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QLineEdit</span><span class="pun">(</span><span class="pln">currdir</span><span class="pun">)</span><span class="pln">
_tb</span><span class="pun">.</span><span class="pln">setCompleter</span><span class="pun">(</span><span class="pln">completer</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QHBoxLayout</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">.</span><span class="pln">addWidget</span><span class="pun">(</span><span class="pln">_tb</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=</span><span class="pln">_tb
</span><span class="typ">MyBaseWidget</span><span class="pun">.</span><span class="pln">initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">class</span><span class="pln"> </span><span class="typ">FileModelWidget</span><span class="pun">(</span><span class="typ">MyBaseWidget</span><span class="pun">):</span><span class="pln">
dirChanged</span><span class="pun">=</span><span class="typ">QtCore</span><span class="pun">.</span><span class="pln">pyqtSignal</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QString</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
currdir</span><span class="pun">=</span><span class="pln">r</span><span class="str">'/tmp'</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">currdir</span><span class="pun">=</span><span class="pln">currdir
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=[]</span><span class="pln">
fsModel</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QFileSystemModel</span><span class="pun">(</span><span class="pln">parent</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
fsModel</span><span class="pun">.</span><span class="pln">setRootPath</span><span class="pun">(</span><span class="str">''</span><span class="pun">)</span><span class="pln">
fsModel</span><span class="pun">.</span><span class="pln">setFilter</span><span class="pun">(</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QDir</span><span class="pun">.</span><span class="typ">AllDirs</span><span class="pun">|</span><span class="typ">QtCore</span><span class="pun">.</span><span class="typ">QDir</span><span class="pun">.</span><span class="typ">Dirs</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">fsModel</span><span class="pun">=</span><span class="pln">fsModel
</span><span class="com">#self.fsModel.setParent(self)</span><span class="pln">
completer</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QCompleter</span><span class="pun">(</span><span class="pln">parent</span><span class="pun">=</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
completer</span><span class="pun">.</span><span class="pln">setMaxVisibleItems</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)</span><span class="pln">
completer</span><span class="pun">.</span><span class="pln">setModel</span><span class="pun">(</span><span class="pln">fsModel</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">fsModel</span><span class="pun">.</span><span class="pln">setParent</span><span class="pun">(</span><span class="pln">completer</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">completer</span><span class="pun">=</span><span class="pln">completer
_tb</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QLineEdit</span><span class="pun">(</span><span class="pln">currdir</span><span class="pun">)</span><span class="pln">
_tb</span><span class="pun">.</span><span class="pln">setCompleter</span><span class="pun">(</span><span class="pln">completer</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QHBoxLayout</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
theLayout</span><span class="pun">.</span><span class="pln">addWidget</span><span class="pun">(</span><span class="pln">_tb</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">_tb</span><span class="pun">=</span><span class="pln">_tb
</span><span class="typ">MyBaseWidget</span><span class="pun">.</span><span class="pln">initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">class</span><span class="pln"> mainWidget</span><span class="pun">(</span><span class="typ">MyBaseWidget</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">):</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">mainLayout</span><span class="pun">=</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QVBoxLayout</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">wgts</span><span class="pun">=[]</span><span class="pln">
_wgt0</span><span class="pun">=</span><span class="typ">StringWidget</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">wgts</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">_wgt0</span><span class="pun">)</span><span class="pln">
_wgt1</span><span class="pun">=</span><span class="typ">StringModelWidget</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">wgts</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">_wgt1</span><span class="pun">)</span><span class="pln">
_wgt2</span><span class="pun">=</span><span class="typ">FileModelWidget</span><span class="pun">()</span><span class="pln">
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">wgts</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">_wgt2</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">for</span><span class="pln"> _w </span><span class="kwd">in</span><span class="pln"> </span><span class="kwd">self</span><span class="pun">.</span><span class="pln">wgts</span><span class="pun">:</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> _w
</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">mainLayout</span><span class="pun">.</span><span class="pln">addWidget</span><span class="pun">(</span><span class="pln">_w</span><span class="pun">)</span><span class="pln">
</span><span class="typ">MyBaseWidget</span><span class="pun">.</span><span class="pln">initUI</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,*</span><span class="pln">args</span><span class="pun">,**</span><span class="pln">kwargs</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">def</span><span class="pln"> main</span><span class="pun">():</span><span class="pln">
app </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QApplication</span><span class="pun">(</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv</span><span class="pun">)</span><span class="pln">
argv</span><span class="pun">=</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv
mainWgt </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">None</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> len</span><span class="pun">(</span><span class="pln">argv</span><span class="pun">)></span><span class="lit">1</span><span class="pun">:</span><span class="pln">
nwgt </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">int</span><span class="pun">(</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv</span><span class="pun">[</span><span class="lit">1</span><span class="pun">])</span><span class="pln">
_addfunc0</span><span class="pun">=</span><span class="pln">nwgt</span><span class="pun">/</span><span class="lit">10</span><span class="pln">
_nwgt</span><span class="pun">=</span><span class="pln">nwgt</span><span class="pun">-</span><span class="pln">_addfunc0</span><span class="pun">*</span><span class="lit">10</span><span class="pln">
</span><span class="kwd">print</span><span class="pln"> _nwgt</span><span class="pun">,</span><span class="pln">_addfunc0
</span><span class="kwd">if</span><span class="pln"> _nwgt </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0</span><span class="pun">:</span><span class="pln">
</span><span class="typ">_MainWgt</span><span class="pun">=</span><span class="typ">StringWidget</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> _nwgt </span><span class="pun">==</span><span class="pln"> </span><span class="lit">1</span><span class="pun">:</span><span class="pln">
</span><span class="typ">_MainWgt</span><span class="pun">=</span><span class="typ">StringModelWidget</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> _nwgt </span><span class="pun">==</span><span class="pln"> </span><span class="lit">2</span><span class="pun">:</span><span class="pln">
</span><span class="typ">_MainWgt</span><span class="pun">=</span><span class="typ">FileModelWidget</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> _nwgt </span><span class="pun">==</span><span class="pln"> </span><span class="lit">9</span><span class="pun">:</span><span class="pln">
</span><span class="typ">_MainWgt</span><span class="pun">=</span><span class="pln">mainWidget
</span><span class="kwd">print</span><span class="pln"> </span><span class="str">'use %s as main widget'</span><span class="pun">%(</span><span class="typ">_MainWgt</span><span class="pun">.</span><span class="pln">__name__</span><span class="pun">)</span><span class="pln">
mainWgt</span><span class="pun">=</span><span class="typ">_MainWgt</span><span class="pun">(</span><span class="pln">addfunc0</span><span class="pun">=</span><span class="pln">_addfunc0</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">else</span><span class="pun">:</span><span class="pln">
mainWgt </span><span class="pun">=</span><span class="pln"> mainWidget</span><span class="pun">(</span><span class="pln">addfunc0</span><span class="pun">=</span><span class="lit">0</span><span class="pun">)</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> mainWgt</span><span class="pun">:</span><span class="pln">
sys</span><span class="pun">.</span><span class="kwd">exit</span><span class="pun">(</span><span class="pln">app</span><span class="pun">.</span><span class="pln">exec_</span><span class="pun">())</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> __name__ </span><span class="pun">==</span><span class="pln"> </span><span class="str">'__main__'</span><span class="pun">:</span><span class="pln">
main</span><span class="pun">()</span></code></pre><br>