document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #
  2. #
  3. #               Python Assistant Window
  4. #               v 0.1 initial release
  5. #
  6. #
  7. #***********************************************************************************
  8. #
  9. # provide a text editing window with functions to aid in coding Python within FreeCAD
  10. #
  11. ############ To Do ############
  12. # - contextual window doesn\'t fire if cursor is on last position in file
  13. # - executing "from PySide import QtGui, QtCore" on console seems to close window
  14. # - is it possible to copy code to console and then select and execute it?
  15. ##############################
  16. #***********************************************************************************
  17. # The next three variables define the width and height and vertical positioning
  18. # of the Python Assistant Window
  19. # \'pawWidthPercent\' specifies the percentage of the screen width to be assigned to the Python Assistant Window
  20. # \'pawHeightPercent\' specifies the percentage of the screen height to be assigned to the Python Assistant Window
  21. # \'pawAtBottomFlag\' specifies if the Python Assistant Window is at the top or the bottom
  22. # The Python Assistant Window is automatically placed at the left,
  23. # so pawWidthPercent = 26, pawHeightPercent = 41, pawAtBottomFlag = False will cause the
  24. # following:
  25. # 1) the main FreeCAD window will be placed in the upper left corner of the screen,
  26. #    it\'s height will be 100% of the screen height,
  27. #    it\'s width will be 74% (=100%-26%) of the screen
  28. # 2) the Python Assistant Window will be placed in the left side of the screen,
  29. #    it\'s height will be 41% of the screen height,
  30. #    it\'s width will be 26% of the screen
  31. #    it will be at the top (leaving empty space below it)
  32. # The empty space (either above or below the Python Assistant Window),
  33. # is left for the text editor (for editing the Macros) to be placed in.
  34. #
  35. pawWidthPercentInitial      = 37.5 # percent of the screen width
  36. pawHeightPercentInitial     = 32.0 # percent of the screen height
  37. pawAtBottomFlagInitial      = True
  38. #***********************************************************************************
  39. # import statements
  40. import sys, operator, os
  41. from os.path import expanduser
  42. from PySide import QtGui, QtCore
  43.  
  44. # UI Class definitions
  45.  
  46. class PythonAssistantWindow(QtGui.QMainWindow):
  47.     """"""
  48.     def __init__(self, pythonTextToEdit):
  49.         self.textIn = pythonTextToEdit
  50.         super(PythonAssistantWindow, self).__init__()
  51.         self.initUI(pythonTextToEdit)
  52.     def initUI(self, pythonTextToEdit):
  53.         """Constructor"""
  54.         # set default return value and pointer to subsequent child window
  55.         self.result         = userCancelled
  56.         self.childWindow    = None
  57.         self.alertWindow    = None
  58.         # set window dimensions for Python Advisor Window from the constants at the top of Macro file
  59.         self.pawWinWidth    = pawWidthPercentInitial/100.0 * availableWidth
  60.         self.pawWinHeight   = pawHeightPercentInitial/100.0 * availableHeight
  61.         self.left           = screenWidth - self.pawWinWidth
  62.         if pawAtBottomFlagInitial:
  63.             self.top        = screenHeight - self.pawWinHeight
  64.         else:
  65.             self.top        = 0    
  66.         self.editorHeight   = self.pawWinHeight
  67.         # set dimensions for main FreeCAD window
  68.         self.mainWinWidth   = availableWidth - (self.pawWinWidth+interWindowGap)
  69.         self.mainWinHeight  = availableHeight
  70.         # define main window
  71.         FreeCADGui.getMainWindow().setGeometry(0, 0, self.mainWinWidth, self.mainWinHeight)
  72.         # now set up this window
  73.         self.setGeometry(self.left, self.top, self.pawWinWidth, self.pawWinHeight)
  74.         self.setWindowTitle("Python Assistant Window")
  75.         #
  76.         centralWidget       =  QtGui.QWidget(self)
  77.         layout              =  QtGui.QGridLayout()
  78.         centralWidget.setLayout(layout)
  79.         # set up text editing widget
  80.         self.text_editor = QtGui.QPlainTextEdit(self)
  81.         self.text_editor.move(0,0)
  82.         self.text_editor.resize(self.pawWinWidth,self.editorHeight)
  83.         self.text_editor.appendPlainText(self.textIn)
  84.         self.text_editor.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
  85.         self.text_editor.textChanged.connect(self.onTextChanged)
  86.         # set up a monospace font for the text editor to match the Python console
  87.         font = QtGui.QFont()
  88.         font.setFamily("Courier")
  89.         font.setStyleHint(QtGui.QFont.Monospace)
  90.         font.setFixedPitch(True)
  91.         font.setPointSize(12)
  92.         self.text_editor.setFont(font)
  93.         #self.text_editor.cursorPositionChanged.connect(self.onCursorPosition)
  94.         self.cursor = self.text_editor.textCursor()
  95.         # populate layout
  96.         layout.addWidget(self.text_editor,0,0)
  97.         self.setCentralWidget(centralWidget)
  98.         # set contextual menu options for text editing widget
  99.         # menu dividers
  100.         mnuDivider1 = QtGui.QAction(self)
  101.         mnuDivider1.setText(menuDividerText)
  102.         mnuDivider1.triggered.connect(self.onMenuDivider)
  103.         mnuDivider2 = QtGui.QAction(self)
  104.         mnuDivider2.setText(menuDividerText)
  105.         mnuDivider2.triggered.connect(self.onMenuDivider)
  106.         mnuDivider3 = QtGui.QAction(self)
  107.         mnuDivider3.setText(menuDividerText)
  108.         mnuDivider3.triggered.connect(self.onMenuDivider)
  109.         mnuDivider4 = QtGui.QAction(self)
  110.         mnuDivider4.setText(menuDividerText)
  111.         mnuDivider4.triggered.connect(self.onMenuDivider)
  112.         # clear text
  113.         mnuClear = QtGui.QAction(self)
  114.         mnuClear.setText("Clear")
  115.         mnuClear.triggered.connect(self.onClear)
  116.         # paste copy/paste buffer
  117.         mnuPaste = QtGui.QAction(self)
  118.         mnuPaste.setText("Paste")
  119.         mnuPaste.triggered.connect(self.onPaste)
  120.         # paste contents of console
  121.         mnuAppendFromConsole = QtGui.QAction(self)
  122.         mnuAppendFromConsole.setText("Append contents of console")
  123.         mnuAppendFromConsole.triggered.connect(self.onAppendFromConsole)
  124.         # select between markers
  125.         mnuSelectMarkers = QtGui.QAction(self)
  126.         mnuSelectMarkers.setText("Select between markers")
  127.         mnuSelectMarkers.triggered.connect(self.onSelectMarkers)
  128.         # select all
  129.         mnuSelectAll = QtGui.QAction(self)
  130.         mnuSelectAll.setText("Select all")
  131.         mnuSelectAll.triggered.connect(self.onSelectAll)
  132.         # insert marker
  133.         mnuInsertMarker = QtGui.QAction(self)
  134.         mnuInsertMarker.setText("Insert marker")
  135.         mnuInsertMarker.triggered.connect(self.onInsertMarker)
  136.         # remove console generated ">>> " character strings
  137.         mnuStripPrefix = QtGui.QAction(self)
  138.         mnuStripPrefix.setText("Remove \'>>> \'")
  139.         mnuStripPrefix.triggered.connect(self.onStripPrefix)
  140.         # remove blank lines
  141.         mnuReduceBlankLines = QtGui.QAction(self)
  142.         mnuReduceBlankLines.setText("Delete multiple blank lines")
  143.         mnuReduceBlankLines.triggered.connect(self.onReduceBlankLines)
  144.         # copy selection
  145.         mnuCopy = QtGui.QAction(self)
  146.         mnuCopy.setText("Copy")
  147.         mnuCopy.triggered.connect(self.onCopy)
  148.         # copy selection to console
  149.         mnuCopySelectionToConsole = QtGui.QAction(self)
  150.         mnuCopySelectionToConsole.setText("Copy selection to console")
  151.         mnuCopySelectionToConsole.triggered.connect(self.onCopySelectionToConsole)
  152.         # copy to console
  153.         mnuCopyToConsole = QtGui.QAction(self)
  154.         mnuCopyToConsole.setText("Copy contents to console")
  155.         mnuCopyToConsole.triggered.connect(self.onCopyToConsole)
  156.         # save as file
  157.         mnuSaveAsFile = QtGui.QAction(self)
  158.         mnuSaveAsFile.setText("Save contents to file")
  159.         mnuSaveAsFile.triggered.connect(self.onSaveAsFile)
  160.         # close window
  161.         mnuCloseWindow = QtGui.QAction(self)
  162.         mnuCloseWindow.setText("Close window")
  163.         mnuCloseWindow.triggered.connect(self.onCloseWindow)
  164.         # alter GUI settings
  165.         mnuSettings = QtGui.QAction(self)
  166.         mnuSettings.setText("=Alter GUI settings=")
  167.         mnuSettings.triggered.connect(self.onSettings)
  168.         # define menu and add options
  169.         self.text_editor.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
  170.         self.text_editor.addAction(mnuCopy)
  171.         self.text_editor.addAction(mnuCopySelectionToConsole)
  172.         self.text_editor.addAction(mnuCopyToConsole)
  173.         self.text_editor.addAction(mnuDivider1)
  174.         self.text_editor.addAction(mnuPaste)
  175.         self.text_editor.addAction(mnuAppendFromConsole)
  176.         self.text_editor.addAction(mnuSelectMarkers)
  177.         self.text_editor.addAction(mnuSelectAll)
  178.         self.text_editor.addAction(mnuClear)
  179.         self.text_editor.addAction(mnuDivider2)
  180.         self.text_editor.addAction(mnuInsertMarker)
  181.         self.text_editor.addAction(mnuStripPrefix)
  182.         self.text_editor.addAction(mnuReduceBlankLines)
  183.         self.text_editor.addAction(mnuDivider3)
  184.         self.text_editor.addAction(mnuSaveAsFile)
  185.         self.text_editor.addAction(mnuSettings)
  186.         self.text_editor.addAction(mnuCloseWindow)
  187.         #
  188.         self.show()
  189.     #----------------------------------------------------------------------
  190.     def onMenuDivider(self):
  191.         # just a divider in the menu so we don\'t do anything
  192.         pass
  193.     def onClear(self):
  194.         # clear editing field
  195.         self.text_editor.clear()
  196.     def onPaste(self):
  197.         # paste contents of system copy/paste buffer into QPlainTextEdit field
  198.         self.text_editor.paste()
  199.     def onAppendFromConsole(self):
  200.         # copy text from "Python console"
  201.         mainWindow  = FreeCADGui.getMainWindow()
  202.         pcDW        = mainWindow.findChild(QtGui.QDockWidget, "Python console")
  203.         pcPTE       = pcDW.findChild(QtGui.QPlainTextEdit, "Python console")
  204.         consoleStr  = pcPTE.document().toPlainText()
  205.         self.text_editor.appendPlainText(copyFromConsoleText)
  206.         self.text_editor.appendPlainText("")
  207.         self.text_editor.appendPlainText(consoleStr)
  208.     def onCopy(self):
  209.         # copy selected text to system copy/paste buffer
  210.         self.text_editor.copy()
  211.     def onCopySelectionToConsole(self):
  212.         # copy selected text to "Python console"
  213.         mainWindow  = FreeCADGui.getMainWindow()
  214.         pcDW        = mainWindow.findChild(QtGui.QDockWidget, "Python console")
  215.         pcPTE       = pcDW.findChild(QtGui.QPlainTextEdit, "Python console")
  216.         #
  217.         cursor      = self.text_editor.textCursor()
  218.         cursorText  = self.text_editor.toPlainText()
  219.         textToCopy = cursorText[cursor.selectionStart():cursor.selectionEnd()]
  220.         if len(textToCopy)>0:
  221.             pcPTE.appendPlainText(textToCopy)
  222.     def onCopyToConsole(self):
  223.         # copy text to "Python console"
  224.         mainWindow  = FreeCADGui.getMainWindow()
  225.         pcDW        = mainWindow.findChild(QtGui.QDockWidget, "Python console")
  226.         pcPTE       = pcDW.findChild(QtGui.QPlainTextEdit, "Python console")
  227.         pcPTE.appendPlainText(copyToConsoleText)
  228.         pcPTE.appendPlainText()
  229.     def onInsertMarker(self):
  230.         # insert marker
  231.         self.text_editor.insertPlainText(markerText)
  232.     def onStripPrefix(self):
  233.         # strip out ">>> " from text edit window
  234.         self.text_editor.selectAll()
  235.         if len(self.text_editor.toPlainText())>0:
  236.             self.text_editor.selectAll()
  237.             tmp = self.text_editor.toPlainText()
  238.             self.text_editor.clear()
  239.             self.text_editor.appendPlainText(tmp.replace(">>> ",""))
  240.     def onReduceBlankLines(self):
  241.         # reduce multiple blank lines to single blank lines
  242.         contents = self.text_editor.toPlainText()
  243.         self.text_editor.clear()
  244.         self.text_editor.appendPlainText(os.linesep.join([s for s in contents.splitlines() if s]))
  245.     def onSelectMarkers(self):
  246.         cursor      = self.text_editor.textCursor()
  247.         cursorText  = self.text_editor.toPlainText()
  248.         bNum = cursor.blockNumber(); cNum = cursor.columnNumber()
  249.         pos = cursor.position(); cursorTextLength = len(cursorText)
  250.         occurrences = [i for i in range(len(cursorText)) if cursorText.startswith(markerText, i)]
  251.         if len(occurrences)==0:
  252.             self.alertWindow = QtGui.QMessageBox()
  253.             self.alertWindow.setText("There are no markers...")
  254.             self.alertWindow.show()
  255.         elif len(occurrences)==1:
  256.             hdrStart = occurrences[0]
  257.             hdrEnd = hdrStart + markerTextLength
  258.             if pos<hdrStart:
  259.                 selectStart = 0; selectEnd = hdrStart
  260.                 self.cursor.setPosition(selectStart)
  261.                 self.cursor.setPosition(selectEnd, QtGui.QTextCursor.KeepAnchor)
  262.                 self.text_editor.setTextCursor(self.cursor)
  263.             if pos>hdrEnd:
  264.                 selectStart = hdrEnd; selectEnd = cursorTextLength
  265.                 self.cursor.setPosition(selectStart)
  266.                 self.cursor.setPosition(selectEnd, QtGui.QTextCursor.KeepAnchor)
  267.                 self.text_editor.setTextCursor(self.cursor)
  268.         else:
  269.             startOccurrences = list(); endOccurrences = list(occurrences)
  270.             for i in range(len(occurrences)):
  271.                 startOccurrences.append(occurrences[i] + markerTextLength + 1)
  272.             startOccurrences.insert( 0, 0)
  273.             endOccurrences.insert( len(occurrences), cursorTextLength)
  274.             for i in range(len(occurrences)+1):
  275.                 if startOccurrences[i]<pos<endOccurrences[i]:
  276.                     if i==0:
  277.                         selectStart = startOccurrences[i]
  278.                     else:
  279.                         selectStart = startOccurrences[i]-1
  280.                     selectEnd = endOccurrences[i]
  281.                     self.cursor.setPosition(selectStart)
  282.                     self.cursor.setPosition(selectEnd, QtGui.QTextCursor.KeepAnchor)
  283.                     self.text_editor.setTextCursor(self.cursor)
  284.                     break
  285.     def onSelectAll(self):
  286.         self.text_editor.selectAll()
  287.     def onCloseWindow(self):
  288.         self.close()
  289.     def onSettings(self):
  290.         # get new width (as %), height (as %), vertical flag
  291.         self.childWindow = GetGuiConfigParams(self)
  292.         pass
  293.     def onTextChanged(self):
  294.         FreeCAD.PythonAssistantWindowStatus[1] = True
  295.     def onCursorPosition(self):
  296.         #print ("Line: {} | Column: {}".format(
  297.         #   self.text_editor.textCursor().blockNumber(),
  298.         #   self.text_editor.textCursor().columnNumber()))
  299.         #print self.text_editor.textCursor().position()+self.text_editor.textCursor().columnNumber()
  300.         pass
  301.     def onSaveAsFile(self):
  302.         filePath = QtGui.QFileDialog.getSaveFileName(parent=None,caption="Save contents as",dir=expanduser("~"),filter="*.txt")
  303.         file = open(filePath[0],"w")
  304.         file.write(self.text_editor.toPlainText())
  305.         file.close()
  306.     def closeEvent(self,event):
  307.         # write out contents for next session
  308.         file = open(persistenceFile,"w")
  309.         file.write(self.text_editor.toPlainText())
  310.         file.close()
  311.         # clear global flag
  312.         del FreeCAD.PythonAssistantWindowStatus
  313.         self.close()
  314.  
  315. class GetGuiConfigParams(QtGui.QMainWindow):
  316.     """"""
  317.     def __init__(self, parentWindow):
  318.         self.parentWindow = parentWindow
  319.         super(GetGuiConfigParams, self).__init__()
  320.         self.initUI(parentWindow)
  321.     def initUI(self, parentWindow):
  322.         """Constructor"""
  323.         self.result                         = userCancelled
  324.         # grab geometry from our parent so we can tell if user has changed values
  325.         self.initialParentWindowX           = self.parentWindow.geometry().x()
  326.         self.initialParentWindowY           = self.parentWindow.geometry().y()
  327.         self.initialParentWindowH           = self.parentWindow.geometry().height()
  328.         self.initialParentWindowW           = self.parentWindow.geometry().width()
  329.         self.initialHeightSliderSetting     = self.initialParentWindowH/float(availableHeight)*100
  330.         self.initialWidthSliderSetting      = self.initialParentWindowW/float(availableWidth-interWindowGap)*100
  331.         # set some fixed GUI attributes
  332.         width                               = 450
  333.         height                              = 40
  334.         buttonWidth                         = 80
  335.         sliderWidth                         = 100
  336.         self.setWindowTitle("GUI Configuration")
  337.         self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
  338.         self.resize(width, height)
  339.         self.widthSlider                    = self.initialWidthSliderSetting
  340.         self.heightSlider                   = self.initialHeightSliderSetting
  341.         #
  342.         centralWidget                       =  QtGui.QWidget(self)
  343.         layout                              =  QtGui.QGridLayout()
  344.         centralWidget.setLayout(layout)
  345.         verticalLine                        =  QtGui.QFrame()
  346.         # sliders
  347.         widthSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
  348.         widthSlider.setFocusPolicy(QtCore.Qt.NoFocus)
  349.         widthSlider.valueChanged[int].connect(self.widthSliderChangeValue)
  350.         widthSlider.setFixedWidth(sliderWidth)
  351.         widthSlider.setValue(self.initialWidthSliderSetting)
  352.         heightSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
  353.         heightSlider.setFocusPolicy(QtCore.Qt.NoFocus)
  354.         heightSlider.valueChanged[int].connect(self.heightSliderChangeValue)
  355.         heightSlider.setFixedWidth(sliderWidth)
  356.         heightSlider.setValue(self.initialHeightSliderSetting)
  357.         # labels
  358.         pawWidthLbl     = QtGui.QLabel("Python Assistant Window width", self)
  359.         pawHeightLbl    = QtGui.QLabel("Python Assistant Window height", self)
  360.         # radio buttons - window top or bottom
  361.         self.rb1 = QtGui.QRadioButton("Window at Top",self)
  362.         self.rb1.clicked.connect(self.onRb1)
  363.         self.rb2 = QtGui.QRadioButton("Window at Bottom",self)
  364.         self.rb2.toggle() # set default value
  365.         self.rb2.clicked.connect(self.onRb2)
  366.         if self.parentWindow.geometry().y()==0:
  367.             self.rb1.toggle()
  368.         # cancel button
  369.         cancelButton = QtGui.QPushButton(\'Cancel\', self)
  370.         cancelButton.clicked.connect(self.onCancel)
  371.         cancelButton.setFixedWidth(buttonWidth)
  372.         # OK button
  373.         okButton = QtGui.QPushButton(\'OK\', self)
  374.         okButton.clicked.connect(self.onOk)
  375.         okButton.setFixedWidth(buttonWidth)
  376.         #
  377.         verticalLine.setFrameStyle(QtGui.QFrame.VLine)
  378.         verticalLine.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
  379.         #
  380.         pawWidthLbl.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
  381.         pawHeightLbl.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
  382.         self.rb1.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
  383.         self.rb2.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
  384.         # populate layout
  385.         layout.addWidget(widthSlider,0,0)
  386.         layout.addWidget(pawWidthLbl,0,1)
  387.         layout.addWidget(heightSlider,2,0)
  388.         layout.addWidget(pawHeightLbl,2,1)
  389.         layout.addWidget(verticalLine,0,2,3,1)
  390.         layout.addWidget(self.rb1,0,3)
  391.         layout.addWidget(self.rb2,2,3)
  392.         layout.addWidget(cancelButton,3,1,QtCore.Qt.AlignRight)
  393.         layout.addWidget(okButton,3,3)
  394.         #
  395.         self.setCentralWidget(centralWidget)
  396.         #
  397.         self.show()
  398.     def widthSliderChangeValue(self, value):
  399.         self.widthSliderValue = value
  400.     def heightSliderChangeValue(self, value):
  401.         self.heightSliderValue = value
  402.     def onRb1(self):
  403.         pass
  404.     def onRb2(self):
  405.         pass
  406.     def onCancel(self):
  407.         self.result = userCancelled
  408.         self.close()
  409.     def onOk(self):
  410.         self.result = "OK"
  411.         # the two slider values are the width and height of the Python Assistant Window
  412.         # resize main FreeCAD window
  413.         freeCadMainWidth    = ((1-(self.widthSliderValue/100.0)) * availableWidth)-(3*interWindowGap)
  414.         FreeCADGui.getMainWindow().setGeometry(0, 0, freeCadMainWidth, availableHeight)
  415.         # resize the PAW window
  416.         newPawWidth         = availableWidth-freeCadMainWidth
  417.         newPawHeight        = (self.heightSliderValue/100.0) * availableHeight
  418.         if self.rb1.isChecked():
  419.             newPawTop       = 0
  420.         else:
  421.             newPawTop       = availableHeight - newPawHeight
  422.         self.parentWindow.setGeometry(freeCadMainWidth+interWindowGap, newPawTop, newPawWidth-interWindowGap, newPawHeight)
  423.         self.close()
  424.  
  425. #----------------------------------------------------------------------
  426.  
  427. # Class definitions
  428.        
  429. # Function definitions
  430.  
  431. def onFreeCADShutdown():
  432.     # this will be invoked when FreeCAD is told to shut down
  433.     #QtGui.QMessageBox.information(None,"","FreeCAD shutting down")
  434.     if FreeCAD.PythonAssistantWindowStatus[1]:
  435.         reply = QtGui.QMessageBox.question(None, "",
  436.             "The Python Assistant Window has changes, do you want to save them?",
  437.             QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
  438.         if reply == QtGui.QMessageBox.Yes:
  439.             # write out contents for next session
  440.             file = open(persistenceFile,"w")
  441.             file.write(FreeCAD.PythonAssistantWindowStatus[0].text_editor.toPlainText())
  442.             file.close()
  443.     del FreeCAD.PythonAssistantWindowStatus
  444.  
  445. # Constant definitions
  446.  
  447. userCancelled       = "Cancelled"
  448. markerText          = "#=========== marker ===========\\n"
  449. markerTextLength    = len(markerText)
  450. copyFromConsoleText = "#=========== copy from console ==========="
  451. copyToConsoleText   = "#============ copy to console ============"
  452. menuDividerText     = "--------"
  453. interWindowGap      = 3 # space between 2 windows for appearance sake
  454. persistenceFile     = App.ConfigGet("UserAppData")+"PythonAssistantWindow.txt"
  455. # code ***********************************************************************************
  456. # put down user data saving routine for when FreeCAD exits
  457. mw=Gui.getMainWindow()
  458. mw.mainWindowClosed.connect(onFreeCADShutdown)
  459. # get screen dimensions
  460. screenWidth         = QtGui.QDesktopWidget().screenGeometry().width()
  461. screenHeight        = QtGui.QDesktopWidget().screenGeometry().height()
  462. # get dimensions for available space on screen
  463. availableWidth      = QtGui.QDesktopWidget().availableGeometry().width()
  464. availableHeight     = QtGui.QDesktopWidget().availableGeometry().height()
  465.  
  466. if not hasattr(FreeCAD,"PythonAssistantWindowStatus"):
  467.     previousContents = ""
  468.     if os.path.isfile(persistenceFile):
  469.         # read contents of last session
  470.         file = open(persistenceFile,"r")
  471.         previousContents = file.read()
  472.         file.close()
  473.     # open window with contents from last session
  474.     form = PythonAssistantWindow(previousContents)
  475.     # save pointer to window so it can be located again and Raised when it becomes obscured
  476.     FreeCAD.PythonAssistantWindowStatus = [None, False]
  477.     FreeCAD.PythonAssistantWindowStatus[0] = form
  478. else:
  479.     # window is open so Raise it so it is visible
  480.     FreeCAD.PythonAssistantWindowStatus[0].raise_()
  481.     pass
  482. #
  483. #OS: Mac OS X
  484. #Word size: 64-bit
  485. #Version: 0.14.3703 (Git)
  486. #Branch: releases/FreeCAD-0-14
  487. #Hash: c6edd47334a3e6f209e493773093db2b9b4f0e40
  488. #Python version: 2.7.5
  489. #Qt version: 4.8.6
  490. #Coin version: 3.1.3
  491. #SoQt version: 1.5.0
  492. #OCC version: 6.7.0
  493. #
  494. #thus ends the macro...
');