Arh, OK, then use a factory function to build the QWidget class.  Something
like this.
If you need the class name to be different each time, and I don't think you
do as it's overkill then you want to a metaclass.  But you don't :) so it's
all ok.  But if you're interested here's a link.

http://jasonmbaker.com/python-metaclasses-in-depth?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+posterous%2FNmsE+%28Jason+in+a+Nutshell%29&utm_content=Google+Reader



def FactoryTab(TabName):
    '''
    Creates a QWidget via loadUiType and returns the
    new class
    '''
    dynamicUI = ThisDir + "/" + TabName + ".ui"
    if os.path.exists(dynamicUI):
        UIForn, UIBase = uic.loadUiType(dynamicUI)
        class Tab(UIBase, UIForn):
            def __init__(self, parent = None):
                super(Tab, self).__init__(parent)
                self.setupUi(self)
        return Tab


On Mon, Aug 9, 2010 at 7:56 PM, <br...@meljunky.com> wrote:

> If I print the results from the loadUiType I get the following results:
> <class 'Ui_Form'> <class 'PyQt4.QtGui.QWidget'>
>
> The addTab method wants a QWidget. The method describe under the Ui_Form
> are retranslateUi and setupUi. I even tried passing the methods as both
> bound and unbound.
>
> Thanks,
> -brian
>
>  -------- Original Message --------
> Subject: Re: [Maya-Python] Calling a compiled QT file in Maya
> From: David Moulder <da...@thirstydevil.co.uk>
> Date: Mon, August 09, 2010 1:15 am
> To: python_inside_maya@googlegroups.com
>
> Hi Brain,
>
> I believe loadUiType returns a tuple where the 1st Widget is your compiled
> UI Widget and the second Widget is it's base class.  So you need to do...
>
> self.MainTab.addTab(tabForm (), "FooTab")
>
> not...
>
>  self.MainTab.addTab(tabBase(), "FooTab")
>
> It does take a while to get used to Qt but the advantages are such that
> it's worth keeping at it.  At the end you'll know a GUI API that is cross
> platform and Maya independent.
>
> - Dave
>
>
> On Sun, Aug 8, 2010 at 4:19 AM, <br...@meljunky.com> wrote:
>
>>  Using the pastebin example I changed the AddTab method too:
>>
>> def AddTab(self, item):
>> if item.text() == "Foo":
>>    # Add a QWidget to your tab.... self.TabWidget
>>    # use any method here.. uic.loadUiType() or just define your own
>> class's in this file for each tab.
>>    tabForm ,tabBase = uic.loadUiType(thisDir + "/tab.ui")
>>    self.MainTab.addTab(tabBase(), "FooTab")
>>
>> tab.ui is a QWidget based ui. MainTab is the named QTabWidget created in
>> the uiMain.ui. (I commented that section out). Anyway, when I clicked on
>> "Foo" it creates the "FooTab", but it does NOT contain any of the widgets
>> that I created tab.ui.
>>
>> Thanks,
>> -brian
>>
>> -------- Original Message --------
>> Subject: Re: [Maya-Python] Calling a compiled QT file in Maya
>> From: David Moulder <da...@thirstydevil.co.uk>
>> Date: Fri, August 06, 2010 7:23 am
>> To: python_inside_maya@googlegroups.com
>>
>> Yes totally,
>>
>> Just add a signal that calls a method to add a QWidget to a QTabWidget
>>
>> How you create the QWidget would be up to you.  You could just create a
>> QWidget class for each tab, or use loadUiType with a factory function.
>>
>> Form, Base = uic.loadUiType(uifile)
>>
>> <script src="http://pastebin.com/embed_js.php?i=We9uVQWU";></
>> script>
>>
>> You should see the pastbin file above.
>> The ui file I can't upload but you should be able to create your main UI
>> with Designer...
>>
>> -Dave
>>
>> On Fri, Aug 6, 2010 at 8:24 AM, John Creson <johncre...@gmail.com> wrote:
>>
>>> You could also parent it into a layout in a standard maya window, that
>>> should act in Maya like a std maya window.
>>>
>>> On Thu, Aug 5, 2010 at 6:44 PM, David Moulder <da...@thirstydevil.co.uk>
>>> wrote:
>>> > Arh, had that a few times in the past.  From what I remember it was due
>>> to
>>> > bad inheritance (Try a QDialog).  I think I had it when I was using
>>> > QTabWidget and I hadn't set the allowed area's correctly.
>>> >
>>> > -Dave
>>> >
>>> >
>>> >
>>> > On Thu, Aug 5, 2010 at 10:06 PM, <br...@meljunky.com> wrote:
>>> >>
>>> >>  Figured out the "_" thing, guess I should grab working code
>>> >> online. Appears uic.compileUI does use pyuic4
>>> >>
>>> >> No, it doesnt run everytime an instance is made. Well, plan on
>>> >> making compile Ui files when a py is not found.
>>> >>
>>> >> Now, the window (partically displayed) is literaly embeded in the top
>>> left
>>> >> corner of Maya making it unuseable.
>>> >>
>>> >> Thanks,
>>> >> -brian
>>> >>
>>> >>
>>> >> -------- Original Message --------
>>> >> Subject: Re: [Maya-Python] Calling a compiled QT file in Maya
>>> >> From: David Moulder <da...@thirstydevil.co.uk>
>>> >> Date: Thu, August 05, 2010 10:55 am
>>> >> To: python_inside_maya@googlegroups.com
>>> >>
>>> >> To parent your window you well need to get the Maya main window and
>>> pass
>>> >> that in as the parent widget
>>> >>
>>> >> > 2011
>>> >>
>>> >> def GetMayaMainWindow():
>>> >>     '''
>>> >>     :returns: The QtWidget that pertains to the Maya Main Window
>>> >>     '''
>>> >>     import maya.OpenMayaUI as mui
>>> >>     import sip
>>> >>     ptr = mui.MQtUtil.mainWindow()
>>> >>     if ptr:
>>> >>         return sip.wrapinstance(long(ptr), QtCore.QObject)
>>> >>
>>> >> Then pass the resulting QWidget into your class
>>> >>
>>> >> eg
>>> >> a = Browser(GetMayaMainWindow())
>>> >>
>>> >> I don't know about uic.compileUI as I pre compile all my ui files with
>>> the
>>> >> pyuic4.exe from the command line.
>>> >>
>>> >> Well, not exactly.  I wrote a PyQt ui to browser and convert them on
>>> >> double click using os.system
>>> >>
>>> >> cmd = 'pyuic4 %s > %s' % (DesignFile, OutPutFile)
>>> >> os.system(cmd)
>>> >>
>>> >> To be honest, it was on of the 1st things I did so I've never looked
>>> at
>>> >> another way to convert files.  Does your method convert each and every
>>> time
>>> >> you make an instance?
>>> >>
>>> >> -Dave
>>> >>
>>> >>
>>> >> On Thu, Aug 5, 2010 at 5:18 PM, <br...@meljunky.com> wrote:
>>> >>>
>>> >>> I edited the class below to reference the class for my browser using
>>> the
>>> >>> following lines of code to show the window:
>>> >>>
>>> >>> a = Browser()
>>> >>> a.show()
>>> >>>
>>> >>> Two things happen.. first the window does not stay "parented" to the
>>> main
>>> >>> Maya window and will disappear under Maya.
>>> >>>
>>> >>> Second... using the compiled version of calculatorform that comes
>>> with Qt
>>> >>> works fine. However, when I used uic.compileUi to complile the
>>> >>> calculatorform.ui. I get the following error:
>>> >>>
>>> >>> # Error: ... global name '_' is not defined #
>>> >>>
>>> >>> The compiler added a '_' that doesn't belong. For example:
>>> >>>
>>> >>> CalculatorForm.setWindowTitle(_( u"Calculator Form"))
>>> >>>
>>> >>> If I removed the '_', it will open.
>>> >>>
>>> >>> Also, on a ui that I created I had to comment out the following lines
>>> >>> because:
>>> >>> test.setCentralWidget(self.centralwidget)
>>> >>> test.setMenuBar(self.menubar)
>>> >>> test.setStatusBar(self.statusbar)
>>> >>>
>>> >>> They cause a Attribute Error such as:
>>> >>> # Error: AttributeError ... 'Browser' object has no attribute
>>> >>> 'setCentralWidget' #
>>> >>>
>>> >>> Is there a way to get a compiled version of a Ui to open without
>>> having
>>> >>> to edit the file?
>>> >>>
>>> >>> Thanks,
>>> >>> -brian
>>> >>>
>>> >>>
>>> >>> -------- Original Message --------
>>> >>> Subject: Re: [Maya-Python] Calling a compiled QT file in Maya
>>> >>> From: David Moulder <da...@thirstydevil.co.uk>
>>> >>> Date: Thu, August 05, 2010 8:09 am
>>> >>> To: python_inside_maya@googlegroups.com
>>> >>>
>>> >>> I use multiple inheritance...
>>> >>>
>>> >>> import ui_Browser
>>> >>> class Browser(QtGui.QWidget, ui_Browser.Ui_Form):
>>> >>>     def __init__(self, parent=None):
>>> >>>         super(Browser, self).__init__(parent)
>>> >>>         self.setupUi(self)
>>> >>>         self.setObjectName('Browser')
>>> >>>         self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
>>> >>>
>>> >>> -Dave
>>> >>>
>>> >>> On Thu, Aug 5, 2010 at 2:39 PM, meljunky <br...@meljunky.com> wrote:
>>> >>>>
>>> >>>> Trying to get QT Ui file to work in Maya I could use the loadUI
>>> >>>> command for example:
>>> >>>>
>>> >>>> import maya.cmds as cmds
>>> >>>> dialog =
>>> cmds.loadUI(f=r'C:/Python26/Lib/site-packages/PyQt4/examples/
>>> >>>> designer/calculatorform/calculatorform.ui')
>>> >>>> cmds.showWindow(dialog)
>>> >>>>
>>> >>>> Don't expect the calculator to actually work but the UI opens in
>>> Maya.
>>> >>>> But, I want to be able to edit UI elements so I used uic.compileUi
>>> to
>>> >>>> convert the file into a Python file in hopes to make method calls to
>>> >>>> add and remove UI elements while the window is open.
>>> >>>>
>>> >>>> The first four lines are:
>>> >>>> from PyQt4 import QtCore, QtGui
>>> >>>>
>>> >>>> class Ui_CalculatorForm(object):
>>> >>>>    def setupUi(self, CalculatorForm):
>>> >>>>        ...
>>> >>>>
>>> >>>> At this point I don't know how to call the Ui_CalculatorForm class
>>> >>>> method setupUi since it needs a different class called
>>> CalculatorForm.
>>> >>>>
>>> >>>> Thanks in advance.
>>> >>>>
>>> >>>> --
>>> >>>> http://groups.google.com/group/python_inside_maya
>>> >>>
>>> >>>
>>> >>>
>>> >>> --
>>> >>> David Moulder
>>> >>> http://www.google.com/profiles/squish3d
>>> >>> --
>>> >>> http://groups.google.com/group/python_inside_maya
>>> >>>
>>> >>> --
>>> >>> http://groups.google.com/group/python_inside_maya
>>> >>
>>> >>
>>> >> --
>>> >> David Moulder
>>> >> http://www.google.com/profiles/squish3d
>>> >> --
>>> >> http://groups.google.com/group/python_inside_maya
>>> >>
>>> >> --
>>> >> http://groups.google.com/group/python_inside_maya
>>> >
>>> >
>>> > --
>>> > David Moulder
>>> > http://www.google.com/profiles/squish3d
>>> >
>>> > --
>>>  > http://groups.google.com/group/python_inside_maya
>>>
>>> --
>>> http://groups.google.com/group/python_inside_maya
>>>
>>
>>
>>
>> --
>> David Moulder
>> http://www.google.com/profiles/squish3d
>> --
>> http://groups.google.com/group/python_inside_maya
>>
>>  --
>> http://groups.google.com/group/python_inside_maya
>>
>
>
>
> --
> David Moulder
> http://www.google.com/profiles/squish3d
>  --
> http://groups.google.com/group/python_inside_maya
>
>  --
> http://groups.google.com/group/python_inside_maya
>



-- 
David Moulder
http://www.google.com/profiles/squish3d

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to