[Qgis-developer] Is there an advantage in using pyuic on command line instead of uic.loadUi in plugin source?

Tim Sutton lists at linfiniti.com
Tue May 6 00:04:32 PDT 2014


Hi


On Tue, May 6, 2014 at 9:01 AM, Tim Sutton <lists at linfiniti.com> wrote:

> Hi
>
>
> On Tue, May 6, 2014 at 8:54 AM, Nathan Woodrow <madmanwoo at gmail.com>wrote:
>
>> I normally do it this way:
>>
>> base, widget = uic.loadUiType('myui.ui')
>>
>> class MyWidget(base, widget):
>>     def __init__(self, parent=None)
>>          super(MyWidget, self).__init__(parent)
>>
>
> According to the docs[1] you get the concrete class first, then the base
> class in the returned tuple:
>
> PyQt4.uic.loadUiType(*uifile*[, *from_imports=False*[,
> *resource_suffix='_rc'*]])<http://pyqt.sourceforge.net/Docs/PyQt4/designer.html#PyQt4.uic.loadUiType>
>
> Load a Qt Designer .ui file and return a tuple of the generated *form
> class* and the *Qt base class*. These can then be used to create any
> number of instances of the user interface without having to parse the .ui file
> more than once.
>
> [1] http://pyqt.sourceforge.net/Docs/PyQt4/designer.html#the-uic-module
>
> Regards
>
>
Ah did you mean that you save a line of code by using super?

Regards

Tim


> Tim
>
>
>> - Nathan
>>
>>
>> On Tue, May 6, 2014 at 4:52 PM, Tim Sutton <lists at linfiniti.com> wrote:
>>
>>> Hi
>>>
>>>
>>> On Sat, Apr 26, 2014 at 2:45 PM, Anita Graser <anitagraser at gmx.at>wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm wondering if there is an advantage in using pyuic to manually
>>>> compile .ui files instead of just using uic.loadUi() in the plugin
>>>> directly, e.g.
>>>>
>>>> from PyQt4 import uic
>>>> self.dock = uic.loadUi( os.path.join( path, "dockwidget2.ui" ) )
>>>>
>>>>
>>> As Martin mentioned, getting the class type back is nicer. I tested this
>>> and it works nicely:
>>>
>>>
>>> ----------------
>>>
>>> import os
>>>
>>> from PyQt4 import QtCore, QtGui, uic
>>>
>>> BASE_CLASS = uic.loadUiType(os.path.join(
>>>     os.path.dirname(__file__), 'results_dialog_base.ui'))[0]
>>>
>>>
>>> class ResultDialog(QtGui.QDialog, BASE_CLASS):
>>>     """Dialog for showing the results of the plugin creation process."""
>>>     def __init__(self):
>>>         QtGui.QDialog.__init__(self)
>>>         # Set up the user interface from Designer.
>>>         self.setupUi(self)
>>>
>>> --------------
>>>
>>> The advantage is that you can use Qt multi-inheritance which means less
>>> and cleaner code. More details in the Qt section at [1].
>>>
>>> [1] http://test.inasafe.org/en/developer-docs/coding_standards.html
>>>
>>> Regards
>>>
>>> Tim
>>>
>>>
>>>
>>>
>>>> Thanks for any insights!
>>>>
>>>> Best wishes,
>>>> Anita
>>>>
>>>>
>>>>
>>>> --
>>>> anitagraser.com
>>>> _______________________________________________
>>>> Qgis-developer mailing list
>>>> Qgis-developer at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>>
>>>
>>>
>>>
>>> --
>>> Tim Sutton - QGIS Project Steering Committee Member
>>> ==============================================
>>> Please do not email me off-list with technical
>>> support questions. Using the lists will gain
>>> more exposure for your issues and the knowledge
>>> surrounding your issue will be shared with all.
>>>
>>> Irc: timlinux on #qgis at freenode.net
>>> ==============================================
>>>
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>
>>
>
>
> --
> Tim Sutton - QGIS Project Steering Committee Member
> ==============================================
> Please do not email me off-list with technical
> support questions. Using the lists will gain
> more exposure for your issues and the knowledge
> surrounding your issue will be shared with all.
>
> Irc: timlinux on #qgis at freenode.net
> ==============================================
>



-- 
Tim Sutton - QGIS Project Steering Committee Member
==============================================
Please do not email me off-list with technical
support questions. Using the lists will gain
more exposure for your issues and the knowledge
surrounding your issue will be shared with all.

Irc: timlinux on #qgis at freenode.net
==============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140506/12a2261c/attachment-0001.html>


More information about the Qgis-developer mailing list