Example #1
0
    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.file.path) == 0:
            return

        # Check to see if we need to save the script
        if cqCodePane.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.file.path) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), "/home/",
                                                                 mw.tr("CadQuery Files (*.py)"))
                else:
                    filename = cqCodePane.file.path

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

        Shared.closeActiveCodeWindow()
    def Activated(self):
        #So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

        #Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        #Make sure the user didn't click cancel
        if filename[0]:
            #Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
                FreeCAD.closeDocument(docname)
            except:
                #Assume that there was no 3D view to close
                pass

            #Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
Example #3
0
    def Activated(self):
        # So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = Shared.getActiveCodePane()

        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        # Make sure the user didn't click cancel
        if filename[0]:
            # Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
                FreeCAD.closeDocument(docname)
            except:
                # Assume that there was no 3D view to close
                pass

            # Change the name of our script window's tab
            Shared.setActiveWindowTitle(os.path.basename(filename[0]))

            # Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
    def Activated(self):
        #So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

        #Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        #Make sure the user didn't click cancel
        if filename[0]:
            #Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
                FreeCAD.closeDocument(docname)
            except:
                #Assume that there was no 3D view to close
                pass

            #Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py' \
                or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'):
            FreeCAD.Console.PrintError(
                "You cannot save over a blank file, example file or template file.\r\n"
            )

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if Settings.execute_on_save:
            CadQueryExecuteScript().Activated()
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.get_path()) == 0 or os.path.basename(cqCodePane.get_path()) == 'script_template.py' \
                or os.path.split(cqCodePane.get_path())[0].endswith('FreeCAD'):
            FreeCAD.Console.PrintError(
                "You cannot save over a blank file, example file or template file.\r\n"
            )

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module"
        ).GetBool("executeOnSave"):
            CadQueryExecuteScript().Activated()
    def Activated(self):
        # So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = Shared.getActiveCodePane()

        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        # Make sure the user didn't click cancel
        if filename[0]:
            # Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.get_path()))[0]
                FreeCAD.closeDocument(docname)
            except:
                # Assume that there was no 3D view to close
                pass

            # Change the name of our script window's tab
            Shared.setActiveWindowTitle(os.path.basename(filename[0]))

            # Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated()
    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()
    def Activated(self):
         #Getting the main window will allow us to find the children we need to work with
        mw = FreeCADGui.getMainWindow()

        #We need this so we can load the file into it
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

        reply = QtGui.QMessageBox.question(cqCodePane, "QMessageBox.question()", "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.file.path) == 0:
                filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), "/home/",
                                                             mw.tr("CadQuery Files (*.py)"))
            else:
                filename = cqCodePane.file.path

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

        #Clear our script and whatever was rendered by it out
        cqCodePane.file.close()
        clearAll()
Example #10
0
    def Activated(self):
        # Grab our code editor so we can interact with it
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

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

        # Check to see if we need to save the script
        if cqCodePane.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.file.path) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(
                        mw, mw.tr("Save CadQuery Script As"), "/home/", mw.tr("CadQuery Files (*.py)")
                    )
                else:
                    filename = cqCodePane.file.path

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

        # Close the matching 3D view if it's open
        if cqCodePane.file.path is not None:
            docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]

            try:
                FreeCAD.closeDocument(docname)
            except:
                # Assume that the document has already been closed
                pass

        # Clear our script and whatever was rendered by it out
        cqCodePane.file.close()
    def Activated(self):
        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:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        #Make sure the user didn't click cancel
        if filename[0]:
            #Save the file before the re-render
            ExportCQ.save(filename[0])
            execfile(filename[0])
Example #12
0
    def Activated(self):
        #Grab our code editor so we can interact with it
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

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

        #Check to see if we need to save the script
        if cqCodePane.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.file.path) == 0:
                    filename = QtGui.QFileDialog.getSaveFileName(
                        mw, mw.tr("Save CadQuery Script As"), "/home/",
                        mw.tr("CadQuery Files (*.py)"))
                else:
                    filename = cqCodePane.file.path

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

        #Close the matching 3D view if it's open
        if cqCodePane.file.path is not None:
            docname = os.path.splitext(os.path.basename(
                cqCodePane.file.path))[0]

            try:
                FreeCAD.closeDocument(docname)
            except:
                #Assume that the document has already been closed
                pass

        #Clear our script and whatever was rendered by it out
        cqCodePane.file.close()
    def Activated(self):
        #Grab our code editor so we can interact with it
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

        #If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py' \
                or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'):
            FreeCAD.Console.PrintError("You cannot save over a blank file, example file or template file.\r\n")

            CadQuerySaveAsScript().Activated()

            return

        #Rely on our export library to help us save the file
        ExportCQ.save()

        #Execute the script if the user has asked for it
        if Settings.execute_on_save:
            CadQueryExecuteScript().Activated()
Example #14
0
    def Activated(self):
        #Grab our code editor so we can interact with it
        mw = FreeCADGui.getMainWindow()
        cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")

        #If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py' \
                or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'):
            FreeCAD.Console.PrintError("You cannot save over a blank file, example file or template file.\r\n")

            CadQuerySaveAsScript().Activated()

            return

        #Rely on our export library to help us save the file
        ExportCQ.save()

        #Execute the script if the user has asked for it
        if Settings.execute_on_save:
            CadQueryExecuteScript().Activated()
    def Activated(self):
        # Grab our code editor so we can interact with it
        cqCodePane = Shared.getActiveCodePane()

        # If there are no windows open there is nothing to save
        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # If the code pane doesn't have a filename, we need to present the save as dialog
        if len(cqCodePane.get_path()) == 0 or os.path.basename(cqCodePane.get_path()) == 'script_template.py' \
                or os.path.split(cqCodePane.get_path())[0].endswith('FreeCAD'):
            FreeCAD.Console.PrintError("You cannot save over a blank file, example file or template file.\r\n")

            CadQuerySaveAsScript().Activated()

            return

        # Rely on our export library to help us save the file
        ExportCQ.save()

        # Execute the script if the user has asked for it
        if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetBool("executeOnSave"):
            CadQueryExecuteScript().Activated()
 def Activated(self):
     #Rely on our export library to help us save the file
     ExportCQ.save()