Python get main window

15 Python code examples are found related to " get main window". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: pyqt.py    From mgear_core with MIT License 6 votes vote down vote up
def get_main_window(widget=None):
    """Get the active window

    Function borrowed from Cesar Saez QuickLauncher
    Args:
        widget (QtWidget, optional): window

    Returns:
        QtWidget: parent of the window
    """
    widget = widget or QtWidgets.QApplication.activeWindow()
    if widget is None:
        return
    parent = widget.parent()
    if parent is None:
        return widget
    return get_main_window(parent) 
Example 2
Source File: functions.py    From medic with MIT License 6 votes vote down vote up
def getMayaMainWindow():
    if hasattr(Qt, "IsPySide2"):
        if Qt.IsPySide2:
            import shiboken2 as shiboken
        else:
            import shiboken

    # Qt version less than 1.0.0
    elif hasattr(Qt, "__version_info__"):
        if Qt.__version_info__[0] >= 2:
            import shiboken2 as shiboken
        else:
            import shiboken

    else:
        try:
            import shiboken2 as shiboken
        except:
            import shiboken

    return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil_mainWindow()), QtWidgets.QMainWindow) 
Example 3
Source File: __init__.py    From anima with MIT License 6 votes vote down vote up
def get_maya_main_window():
    """Get the main Maya window as a QtGui.QMainWindow instance
    @return: QtGui.QMainWindow instance of the top level Maya windows

    ref: https://stackoverflow.com/questions/22331337/how-to-get-maya-main-window-pointer-using-pyside
    """
    from anima.ui.lib import QtWidgets, QtCore
    from maya import OpenMayaUI

    ptr = OpenMayaUI.MQtUtil.mainWindow()
    if ptr is not None:
        from anima.ui.lib import IS_PYSIDE, IS_PYSIDE2, IS_PYQT4, IS_QTPY
        if IS_PYSIDE():
            import shiboken
            return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
        elif IS_PYSIDE2():
            import shiboken2
            return shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
        elif IS_PYQT4():
            import sip
            return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example 4
Source File: pipeline.py    From core with MIT License 5 votes vote down vote up
def get_main_window():
    """Acquire Maya's main window"""
    if self._parent is None:
        self._parent = {
            widget.objectName(): widget
            for widget in QtWidgets.QApplication.topLevelWidgets()
        }["MayaWindow"]
    return self._parent 
Example 5
Source File: SurfaceEdit.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def getMainWindow():
   "returns the main window"
   # using QtGui.qApp.activeWindow() isn't very reliable because if another
   # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
   # returned
   toplevel = QtGui.qApp.topLevelWidgets()
   for i in toplevel:
       if i.metaObject().className() == "Gui::MainWindow":
           return i
   raise Exception("No main window found") 
Example 6
Source File: maya_.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def getMayaMainWindow():
    """
    Get Maya's main window.

    :rtype: QMainWindow
    """
    window = OpenMayaUI.MQtUtil.mainWindow()
    window = Qt.shiboken.wrapInstance(long(window), Qt.QMainWindow)

    return window 
Example 7
Source File: applications.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def get_main_window():
        import maya.OpenMayaUI as omui
        import shiboken2
        main_window = omui.MQtUtil.mainWindow()
        if main_window is not None:
            return shiboken2.wrapInstance(long(main_window), QtWidgets.QWidget) 
Example 8
Source File: lib.py    From MayaDev with MIT License 5 votes vote down vote up
def getMayaMainWindow():
    from PySide2 import QtWidgets
    from maya import OpenMayaUI
    from shiboken2 import wrapInstance
    mayaMainWindow = OpenMayaUI.MQtUtil.mainWindow()
    return wrapInstance(long(mayaMainWindow), QtWidgets.QMainWindow) 
Example 9
Source File: lib.py    From MayaDev with MIT License 5 votes vote down vote up
def getHoudiniMainWindow():
    from PySide import QtGui
    app = QtGui.QApplication.instance()
    if app:
        parent = app.topLevelAt(QtGui.QCursor().pos())
        if parent:
            return parent
        else:
            # root = app.desktop()
            ws = [w for w in app.topLevelWidgets() if w.windowTitle().count('Houdini') and w.windowType().name == 'Window']
            if ws:
                return ws[0] 
Example 10
Source File: parsec_application.py    From parsec-cloud with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_main_window(cls):
        # Avoid recursive imports
        from .main_window import MainWindow

        for win in cls.topLevelWidgets():
            if isinstance(win, MainWindow):
                return win
        return None 
Example 11
Source File: lightManager2016Below.py    From PythonForMayaSamples with GNU General Public License v3.0 5 votes vote down vote up
def getMayaMainWindow():
    """
    Since Maya is Qt, we can parent our UIs to it.
    This means that we don't have to manage our UI and can leave it to Maya.

    Returns:
        QtWidgets.QMainWindow: The Maya MainWindow
    """
    # We use the OpenMayaUI API to get a reference to Maya's MainWindow
    win = omui.MQtUtil_mainWindow()
    # Then we can use the wrapInstance method to convert it to something python can understand
    # In this case, we're converting it to a QMainWindow
    ptr = wrapInstance(long(win), QtWidgets.QMainWindow)
    # Finally we return this to whoever wants it
    return ptr 
Example 12
Source File: applogic.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getMainWindow():

    global _mainWindow
    if _mainWindow is None:
        for widget in QtGui.QApplication.topLevelWidgets():
            if isinstance(widget, PythonQt.QtGui.QMainWindow):
                _mainWindow = widget
                break

    return _mainWindow 
Example 13
Source File: __init__.py    From SiShelf with MIT License 5 votes vote down vote up
def GetMayaMainWindow():
    from ..vendor import Qt
    from ..vendor.Qt import QtWidgets

    if Qt.IsPySide2:
        import shiboken2 as shiboken
    else:
        import shiboken

    return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil_mainWindow()), QtWidgets.QMainWindow) 
Example 14
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def get_maya_main_window():
    """
    Get the main Maya window as a QtGui.QMainWindow instance
    :return: QtGui.QMainWindow instance of the top level Maya windows
    """
    ptr = omui.MQtUtil.mainWindow()
    if ptr is not None:
        return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget) 
Example 15
Source File: reaper.py    From reapy with MIT License 5 votes vote down vote up
def get_main_window():
    """
    Return main window.

    Returns
    -------
    window : Window
        Main window.
    """
    window = reapy.Window(RPR.GetMainHwnd())
    return window