Calling UI objects



I am currently writing a ui script for Maya in python.

It goes something like this

def loadUI():
    #loads UI

def getMayaWindow():
    #gets the maya main window

class MainClass():
    def __init__ (self, parent = getMayaWindow()):
        super(MainClass, self).__init__(parent)

    #create connections to ui            

def delete(self):
    self.deselect = self.QListWidget.selectedItems()
    for j in self.deselect:

so, I have ui that has different tabs at the top and I do not want to put every single piece of code in the MainClass because that would be too messy and long. For every tab, I want to write its script in a different .py file. I want to create the connections under the init function, at the same time, load functions from another script into this MainClass to be used.

Question is, how should I go about calling objectName from the ui in a new file? I tried to import the MainClass code but that didn’t work and I don’t want the initialize the ui window in the new .py file. What’s a good way to go about this?



So I’m not sure exactly what you’re asking. But I think you’re hoping to have a window/dialog with a tabbed layout, and you want each tab to be defined in it’s own separate python file?

So this example show just how to setup some basic QWidgets in a tabbed layout.

If you replace those widgets with you’re own custom widgets, you should be able to do what you’re looking for.
Unless I’ve misunderstood completely.


Your question is not very clear.

What I understand here is that you want to separate each tab content in a different .py file.

In your MainClass you can create your UI, and then create a TabLayout as @R.White said.
Then you can import all those UI .py files, calling a function on each of them that receives the tabLayout and add a tab with contents to it.

   import uiTab1
   import uiTab2
   import uiTab3

        //Create Ui stuff...
        //Create a tab layout

Each file would be:

 def create(QTabLayout lyt):   
       ///create other UI related to this tab.

Hopefully you meant that. I can fix my answer if it wasn’t what you were asking!