[PyQt][Maya] How to access PyQt UI within maya

Good morning,
I was wonder how I can access my pyqt ui within maya.
Basically I’ve got a window with a QTreeWidget in it. I want to be able to clear, populate and select items in that qTreeWidget from within Maya.
Using this method: My_Sweet_UI.QTreeWidget.clear()

Here’s how I’m getting the ui into Maya:
form_class, base_class = uic.loadUiType(uiFile)

def getMayaWindow():
#Get the maya main window as a QMainWindow instance
ptr = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)

class BaseClass():
def init(self):
# Find Maya Window
ptr = long(long(OpenMayaUI.MQtUtil.findWindow(newMayaWindow)))
newQtWin = sip.wrapinstance(ptr, base_class)

class UI(base_class, form_class):
def init(self, parent=getMayaWindow()):
#init our ui using the MayaWindow as parent
super(base_class, self).init(parent)
#uic adds a function to our class called setupUi, calling this creates all the widgets from the .ui file
self.setupUi(self)
self.setObjectName( ‘My_Sweet_UI’ )
#Populate the UI
self.Initialize_Acc_UI()

Thanks in advanced. I can provide more info if needed.
Best,
Adrian

Can’t you just define a global variable that contains a pointer to your UI?

is there a reason why you want to access it outside the scope of the tool?
else you could just have a button to call the method with self.myMethod.

btribblt: I’ve tried doing that… my_ui = my.ui.open()
but I get “NoneType” as my variable

tokejenson: It’s so I can create a script job that is listening to the users inputs and acts on the UI if the user does something. ie when a animator selects a control on the rig, I want the UI to select that control in the UI and build to correct lists

Did you make sure to declare it a global variable in all scopes? I don’t believe that the Maya command window is part of the global scope…

guessing your open function doesn’t return the instance of the UI?

class UI(base_class, form_class):
    def __init__(self, parent=getMayaWindow()):
        #init our ui using the MayaWindow as parent
        super(base_class, self).__init__(parent)
        #uic adds a function to our class called setupUi, calling this creates all the widgets from the .ui file
        self.setupUi(self)
        self.setObjectName( 'My_Sweet_UI' )
        #Populate the UI
        self.Initialize_Acc_UI()
    def open(self):
        self.show()
        return self

or just show the ui in init?

class UI(base_class, form_class):
    def __init__(self, parent=getMayaWindow()):
        #init our ui using the MayaWindow as parent
        super(base_class, self).__init__(parent)
        #uic adds a function to our class called setupUi, calling this creates all the widgets from the .ui file
        self.setupUi(self)
        self.setObjectName( 'My_Sweet_UI' )
        #Populate the UI
        self.Initialize_Acc_UI()
        self.show()

which then means

my_ui = UI()

will return the instance as expected.