Python FreeCADGui.getMainWindow() Examples

The following are 30 code examples of FreeCADGui.getMainWindow(). 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. You may also want to check out all available functions/classes of the module FreeCADGui , or try the search function .
Example #1
Source File: property_editor.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def setEdit(self):
        """ViewProvider setEdit example"""
        self.ed = VPEditor()
        self.group1 = self.ed.add_layout("Face 1")
        proped_11 = VectorListWidget() # PropEditor() #self.Object,"ScaleList1")
        proped_12 = VectorListWidget() #self.Object,"Continuity1")
        #proped_11.fillTable(((0.0,1.0),(0.4,1.5),(1.0,0.8)))
        proped_12.fillTable()
        self.ed.add_propeditor(proped_11, self.group1)
        #ed.add_propeditor(proped_12, self.group1)
        self.group2 = self.ed.add_layout("Face 2")
        proped_21 = VectorListWidget() #self.Object,"ScaleList2")
        #proped_22 = VectorListWidget() #self.Object,"Continuity2")
        self.ed.add_propeditor(proped_21, self.group2)
        #ed.add_propeditor(proped_22, self.group2)
        self.ed.add_close_button()

        self.mw = FreeCADGui.getMainWindow()
        self.ed.comboview = getComboView(self.mw)
        self.ed.tabIndex = self.ed.comboview.addTab(self.ed.widget,"Table")
        self.ed.comboview.setCurrentIndex(self.ed.tabIndex)
        self.ed.widget.show() 
Example #2
Source File: cq_cad_tools.py    From kicad-3d-models-in-freecad with GNU General Public License v2.0 6 votes vote down vote up
def restore_Main_Tools():

    #Getting the main window will allow us to start setting things up the way we want
    mw = FreeCADGui.getMainWindow()

    #Adjust the docks as usual
    dockWidgets = mw.findChildren(QtGui.QDockWidget)
    for widget in dockWidgets:
        if (widget.objectName() == "Report view") or (widget.objectName() == "Python console") or (widget.objectName() == "Combo View"):
            widget.setVisible(True)
        if (widget.objectName()=="cqCodeView"):
            widget.setVisible(False)

    return 0


###################################################################
# z_RotateObject()  maui
#   Function to z-rotate an object
#
################################################################### 
Example #3
Source File: Shared.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def closeActiveCodeWindow():
    mw = FreeCADGui.getMainWindow()
    mdi = mw.findChild(QtGui.QMdiArea)

    # We cannot trust the current subwindow to be a script window, it may be the associated 3D view
    mdiWin = mdi.currentSubWindow()

    # We have a 3D view selected so we need to find the corresponding script window
    if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
        subList = mdi.subWindowList()

        for sub in subList:
            if sub.windowTitle() == mdiWin.windowTitle().split(" ")[0] + ".py":
                sub.close()
                return

    mdiWin.close() 
Example #4
Source File: Shared.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def clearActiveDocument():
    """Clears the currently active 3D view so that we can re-render"""

    # Grab our code editor so we can interact with it
    mw = FreeCADGui.getMainWindow()
    mdi = mw.findChild(QtGui.QMdiArea)
    currentWin = mdi.currentSubWindow()
    if currentWin == None:
        return
    winName = currentWin.windowTitle().split(" ")[0].split('.')[0]

    # Translate dashes so that they can be safetly used since theyare common
    if '-' in winName:
        winName= winName.replace('-', "__")

    try:
        doc = FreeCAD.getDocument(winName)

        # Make sure we have an active document to work with
        if doc is not None:
            for obj in doc.Objects:
                doc.removeObject(obj.Name)
    except:
        pass 
Example #5
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def Activated(self):
        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            # Start off defaulting to the Examples directory
            module_base_path = module_locator.module_path()
            exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')

            self.previousPath = exs_dir_path

        filename = QtGui.QFileDialog.getOpenFileName(mw, mw.tr("Open CadQuery Script"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        # Make sure the user didn't click cancel
        if filename[0]:
            self.previousPath = filename[0]

            # Append this script's directory to sys.path
            sys.path.append(os.path.dirname(filename[0]))

            # We've created a library that FreeCAD can use as well to open CQ files
            ImportCQ.open(filename[0]) 
Example #6
Source File: a2p_constraintDialog.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self):
        super(a2p_ConstraintPanel,self).__init__()
        self.resize(200,250)
        cc = a2p_ConstraintCollection(None)
        self.setWidget(cc)
        self.setWindowTitle("Constraint Tools")
        #
        mw = FreeCADGui.getMainWindow()
        mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,self)
        #
        self.setFloating(True)
        self.activateWindow()
        self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea)
        self.move(getMoveDistToStoredPosition(self))

        a2plib.setConstraintDialogRef(self)
        #
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.onTimer)
        self.timer.start(100) 
Example #7
Source File: a2p_constraintDialog.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def getMoveDistToStoredPosition(widg):
    if CONSTRAINT_DIALOG_STORED_POSITION == QtCore.QPoint(-1,-1):
        mw = FreeCADGui.getMainWindow()
        fcFrame = QtGui.QDesktopWidget.geometry(mw)
        x = fcFrame.x()
        y = fcFrame.y()
        width = fcFrame.width()
        height = fcFrame.height()

        centerX = x + width/2
        centerY = y + height/2
        fcCenter = QtCore.QPoint(centerX,centerY)

        return fcCenter- widg.rect().center()
    else:
        widgetFrame = widg.frameGeometry()
        x = widgetFrame.x()
        y = widgetFrame.y()
        widgetCorner = QtCore.QPoint(x,y)

        return CONSTRAINT_DIALOG_STORED_POSITION - widgetCorner
#============================================================================== 
Example #8
Source File: blendSurfaceFP.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def setEdit(self,vobj,mode=0):
        if mode == 0:
            debug("Start Edit")
            self.ed = property_editor.VPEditor()
            self.group1 = self.ed.add_layout("Face 1")
            proped_11 = property_editor.VectorListWidget(self.Object,"ScaleList1")
            #proped_12 = property_editor.VectorListWidget() #self.Object,"Continuity1")
            #proped_11.fillTable(((0.0,1.0),(0.4,1.5),(1.0,0.8)))
            #proped_12.fillTable()
            self.ed.add_propeditor(proped_11, self.group1)
            #ed.add_propeditor(proped_12, self.group1)
            self.group2 = self.ed.add_layout("Face 2")
            proped_21 = property_editor.VectorListWidget(self.Object,"ScaleList2")
            #proped_22 = VectorListWidget() #self.Object,"Continuity2")
            self.ed.add_propeditor(proped_21, self.group2)
            #ed.add_propeditor(proped_22, self.group2)
            self.ed.add_close_button()

            self.mw = FreeCADGui.getMainWindow()
            self.ed.comboview = property_editor.getComboView(self.mw)
            self.ed.tabIndex = self.ed.comboview.addTab(self.ed.widget,"Table")
            self.ed.comboview.setCurrentIndex(self.ed.tabIndex)
            self.ed.widget.show()
            return True
        return False 
Example #9
Source File: sublink_edit.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, obj):
        self.obj = obj
        self.main_win = FreeCADGui.getMainWindow()
        self.widget = QtGui.QDockWidget()
        self.widget.ui = myWidget_Ui(obj)
        self.widget.ui.setupUi(self.widget)
        
        self.widget.ui.pushButton_7.clicked.connect(self.accept)
        
        self.main_win.addDockWidget(QtCore.Qt.RightDockWidgetArea,self.widget)
        self.widget.setFloating(True)
        
        self.initial_visibility = self.obj.ViewObject.Visibility
        self.obj.ViewObject.Visibility = False 
Example #10
Source File: gui.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def toggleToolbars(mcs):
        hgrp = mcs.getToolbarParams()
        show = False
        for toolbar in mcs._HiddenToolbars:
            if not hgrp.GetBool(toolbar,True):
                show = True
                break
        mw = FreeCADGui.getMainWindow()
        for toolbar in mcs._HiddenToolbars:
            if show != hgrp.GetBool(toolbar,True):
                hgrp.SetBool(toolbar,show)
                tb = mw.findChild(QtGui.QToolBar,toolbar)
                if not tb:
                    logger.error('cannot find toolbar "{}"',toolbar)
                tb.setVisible(show) 
Example #11
Source File: cq_cad_tools.py    From kicad-3d-models-in-freecad with GNU General Public License v2.0 5 votes vote down vote up
def close_CQ_Example(App, Gui):

    #close the example
    App.setActiveDocument("Ex000_Introduction")
    App.ActiveDocument=App.getDocument("Ex000_Introduction")
    Gui.ActiveDocument=Gui.getDocument("Ex000_Introduction")
    App.closeDocument("Ex000_Introduction")
    FreeCAD.Console.PrintMessage('\r\nEx000 Closed\r\n')

    #Getting the main window will allow us to start setting things up the way we want
    mw = FreeCADGui.getMainWindow()

    #Adjust the docks as usual
    dockWidgets = mw.findChildren(QtGui.QDockWidget)
    for widget in dockWidgets:
        if (widget.objectName() == "Report view") or (widget.objectName() == "Python console") or (widget.objectName() == "Combo View"):
            widget.setVisible(True)
        if (widget.objectName()=="cqCodeView"):
            widget.setVisible(False)
    FreeCAD.Console.PrintMessage('Dock adjusted\r\n')

    return 0


###################################################################
# FuseObjs_wColors()  maui
#   Function to fuse two objects together.
################################################################### 
Example #12
Source File: exportPartToVRML.py    From kicad-3d-models-in-freecad with GNU General Public License v2.0 5 votes vote down vote up
def clear_console():
    #clearing previous messages
    mw=FreeCADGui.getMainWindow()
    c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
    c.clear()
    r=mw.findChild(QtGui.QTextEdit, "Report view")
    r.clear()

#if not Mod_ENABLED: 
Example #13
Source File: exportPartToVRML.py    From kicad-3d-models-in-freecad with GNU General Public License v2.0 5 votes vote down vote up
def clear_console():
    #clearing previous messages
    mw=FreeCADGui.getMainWindow()
    c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
    c.clear()
    r=mw.findChild(QtGui.QTextEdit, "Report view")
    r.clear()

#if not Mod_ENABLED: 
Example #14
Source File: transform.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def config(self):
		self.dialog=TelescopWidget(self)
		#self.dialog.show()
		mw = FreeCADGui.getMainWindow()
		#dock = QtGui.QDockWidget("Mein Dock", mw)
		dock = QtGui.QDockWidget(self.Object.Label, mw)
		dock.setStyleSheet("background-color:yellow;color:brown;")
		mw.centralWidget = QtGui.QWidget(dock)
		mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)
		dock.setWidget(self.dialog) 
Example #15
Source File: transform.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def config(self):
		self.dialog=HingeWidget(self)
		# self.dialog.show()
		
		mw = FreeCADGui.getMainWindow()
		dock = QtGui.QDockWidget(self.Object.Label, mw)
		dock.setStyleSheet("background-color:lightblue;color:blue;")
		mw.centralWidget = QtGui.QWidget(dock)
		mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)
		dock.setWidget(self.dialog)
		say("widget set") 
Example #16
Source File: SheetMetalUnfolder.py    From FreeCAD_SheetMetal with GNU General Public License v3.0 5 votes vote down vote up
def SMErrorBox(* args):
    message = ""
    for x in args:
        message += str(x)
    # Error boxes mostly use HTML tags to format. Strip the HTML tags for 
    # better console readability. 
    stripped_message = re.sub('<[^<]+?>', '', message)
    SMError(stripped_message) 
    mw = FreeCADGui.getMainWindow()
    msg_box = QtGui.QMessageBox(mw)
    msg_box.setTextFormat(QtCore.Qt.TextFormat.RichText)
    msg_box.setText(message)
    msg_box.setWindowTitle("Error")
    msg_box.setIcon(QtGui.QMessageBox.Critical)
    msg_box.exec_() 
Example #17
Source File: Shared.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def populateParameterEditor(parameters):
    """Puts the proper controls in the script variable editor pane based on the parameters found"""

    mw = FreeCADGui.getMainWindow()

    # If the widget is open, we need to close it
    dockWidgets = mw.findChildren(QtGui.QDockWidget)
    for widget in dockWidgets:
        if widget.objectName() == "cqVarsEditor":
            gridLayout = QtGui.QGridLayout()

            line = 1

            # Add controls for all the parameters so that they can be edited from the GUI
            for pKey, pVal in list(parameters.items()):
                label = QtGui.QLabel(pKey)

                # We want to keep track of this parameter value field so that we can pull its value later when executing
                value = QtGui.QLineEdit()
                value.setText(str(pVal.default_value))
                value.setObjectName("pcontrol_" + pKey)

                # Add the parameter control sets, one set per line
                gridLayout.addWidget(label, line, 0)
                gridLayout.addWidget(value, line, 1)

                line += 1

            # Create a widget we can put the layout in and add a scrollbar
            newWidget = QtGui.QWidget()
            newWidget.setLayout(gridLayout)

            # Add a scroll bar in case there are a lot of variables in the script
            scrollArea = QtGui.QScrollArea()
            scrollArea.setBackgroundRole(QtGui.QPalette.Light)
            scrollArea.setStyleSheet("QLabel { color : black; }");
            scrollArea.setWidget(newWidget)

            widget.setWidget(scrollArea) 
Example #18
Source File: Shared.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def getActiveCodePane():
    """Gets the currently active code pane, even if its 3D view is selected."""

    # Grab our code editor so we can interact with it
    mw = FreeCADGui.getMainWindow()
    mdi = mw.findChild(QtGui.QMdiArea)

    # If our current subwindow doesn't contain a script, we need to find the one that does
    mdiWin = mdi.currentSubWindow()
    if mdiWin == None: return None # We need to warn the caller that there is no code pane

    windowTitle = mdiWin.windowTitle()

    if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
        if '__' in mdiWin.windowTitle():
            windowTitle = mdiWin.windowTitle().replace("__", '-')

        subList = mdi.subWindowList()

        for sub in subList:
            if sub.windowTitle() == windowTitle.split(" ")[0] + ".py":
                mdiWin = sub

    winName = mdiWin.windowTitle().split('.')[0]
    cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane_" + winName)

    return cqCodePane 
Example #19
Source File: sublink_edit.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 #20
Source File: InitGui.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        import os
        try:
            from . import module_locator
        except:
            import module_locator
        try:
            from CadQuery.CQGui import ImportCQ
        except:
            from CQGui import ImportCQ

        module_base_path = module_locator.module_path()

        import cadquery
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting API "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: Apache-2.0\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None)
        FreeCAD.Console.PrintMessage(msg)

        #Getting the main window will allow us to start setting things up the way we want
        mw = FreeCADGui.getMainWindow()

        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() == "Report view":
                widget.setVisible(True)

        # Set up the paths to allow us to open the template
        # template_path = os.path.join(module_base_path, 'Templates')
        # template_path = os.path.join(template_path, 'script_template.py')
        #
        # ImportCQ.open(template_path) 
Example #21
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        mw = FreeCADGui.getMainWindow()

        # Tracks whether or not we have already added the variables editor
        isPresent = False

        # If the widget is open, we need to close it
        dockWidgets = mw.findChildren(QtGui.QDockWidget)
        for widget in dockWidgets:
            if widget.objectName() == "cqVarsEditor":
                # Toggle the visibility of the widget
                if widget.visibleRegion().isEmpty():
                    widget.setVisible(True)
                else:
                    widget.setVisible(False)

                isPresent = True

        if not isPresent:
            cqVariablesEditor = QtGui.QDockWidget("CadQuery Variables Editor")
            cqVariablesEditor.setObjectName("cqVarsEditor")

            mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, cqVariablesEditor)

        # Go ahead and populate the view if there are variables in the script
        CadQueryValidateScript().Activated() 
Example #22
Source File: dev.py    From NodeEditor with MIT License 5 votes vote down vote up
def run_shelfToy(self):
    '''the implementation of the toy shelf tool'''
    
    nodes=FreeCAD.PF.graphManager.get().getAllNodes()
    nodes2 = sorted(nodes, key=lambda node: node.x)
    say("selected Nodes ...")
    for n in nodes2:
     if n.getWrapper().isSelected():
        say(n,n.x)

    mw=FreeCADGui.getMainWindow()
    say(mw)
    mw.hide()
    mw.show()
    say("!no action") 
Example #23
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        FreeCAD.Console.PrintMessage(self.exFile + "\r\n")

        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Start off defaulting to the Examples directory
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')

        # Append this script's directory to sys.path
        sys.path.append(os.path.dirname(exs_dir_path))

        # We've created a library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(exs_dir_path, self.exFile)) 
Example #24
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        mw = FreeCADGui.getMainWindow()

        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there's nothing open in the code pane, we don't need to close it
        if cqCodePane is None or len(cqCodePane.get_path()) == 0:
            return

        # Check to see if we need to save the script
        if cqCodePane.is_dirty():
            reply = QtGui.QMessageBox.question(cqCodePane, "Save CadQuery Script", "Save script before closing?",
                                               QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel)

            if reply == QtGui.QMessageBox.Cancel:
                return

            if reply == QtGui.QMessageBox.Yes:
                # If we've got a file name already save it there, otherwise give a save-as dialog
                if len(cqCodePane.get_path()) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), "/home/",
                                                                 mw.tr("CadQuery Files (*.py)"))
                else:
                    filename = cqCodePane.get_path()

                # Make sure we got a valid file name
                if filename is not None:
                    ExportCQ.save(filename)

        Shared.closeActiveCodeWindow() 
Example #25
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        # Grab our main window so we can interact with it
        mw = FreeCADGui.getMainWindow()

        reportView = mw.findChild(QtGui.QDockWidget, "Report view")

        # Clear the view because it gets overwhelmed sometimes and won't scroll to the bottom
        reportView.widget().clear() 
Example #26
Source File: Asm4_Measure.py    From FreeCAD_Assembly4 with GNU Lesser General Public License v2.1 5 votes vote down vote up
def clearConsole(self):
        #clearing previous messages
        mw = Gui.getMainWindow()
        #c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
        #c.clear()
        rv = mw.findChild(QtGui.QTextEdit, "Report view")
        rv.clear()

    # Actions
    #
    # when changing the measurement type, reset pre-existing selection 
Example #27
Source File: NiCrPath.py    From NiCr with GNU General Public License v2.0 5 votes vote down vote up
def importNiCrFile():
    FCW = FreeCADGui.getMainWindow()
    file_dir = QtGui.QFileDialog.getOpenFileName(FCW,
                                                 'Load .nicr file:',
                                                 '/home')
    readNiCrFile(file_dir[0])
    FreeCAD.Console.PrintMessage('Path succesfully imported\n') 
Example #28
Source File: NiCrPath.py    From NiCr with GNU General Public License v2.0 5 votes vote down vote up
def saveNiCrFile():
    FCW = FreeCADGui.getMainWindow()
    save_directory = QtGui.QFileDialog.getSaveFileName(FCW,
                                                       'Save Wirepath as:',
                                                       '/home',
                                                       '.nicr')
    full_path = CreateCompleteRawPath()
    writeNiCrFile(full_path, str(save_directory[0]))
    FreeCAD.Console.PrintMessage('NiCr code saved: ' + str(save_directory[0]) + '\n') 
Example #29
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        try:
            doc.save()
            FreeCAD.closeDocument(doc.Name)
        except:
            FreeCADGui.SendMsgToActiveView("Save")
            if not FreeCADGui.activeDocument().Modified: # user really saved the file           
                FreeCAD.closeDocument(doc.Name)
        #
        mw = FreeCADGui.getMainWindow()
        mdi = mw.findChild(QtGui.QMdiArea)
        sub = mdi.activeSubWindow()
        if sub != None:
            sub.showMaximized() 
Example #30
Source File: ZebraTool.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
   return(FreeCADGui.getMainWindow())
   toplevel = QtGui.qApp.topLevelWidgets()
   for i in toplevel:
       if i.metaObject().className() == "Gui::MainWindow":
           return i
   raise Exception("No main window found")