Code cleanup and minor bug fixes.
This commit is contained in:
parent
765c9d168d
commit
544faacaf2
|
@ -26,7 +26,7 @@ class CadQueryClearOutput:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
#Grab our code editor so we can interact with it
|
# Grab our main window so we can interact with it
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
|
|
||||||
reportView = mw.findChild(QtGui.QDockWidget, "Report view")
|
reportView = mw.findChild(QtGui.QDockWidget, "Report view")
|
||||||
|
@ -44,15 +44,12 @@ class CadQueryCloseScript:
|
||||||
|
|
||||||
def IsActive(self):
|
def IsActive(self):
|
||||||
return True
|
return True
|
||||||
# if FreeCAD.ActiveDocument is None:
|
|
||||||
# return False
|
|
||||||
# else:
|
|
||||||
# return True
|
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
#Grab our code editor so we can interact with it
|
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")
|
|
||||||
|
# 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 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:
|
if cqCodePane is None or len(cqCodePane.file.path) == 0:
|
||||||
|
@ -116,16 +113,6 @@ class CadQueryExecuteExample:
|
||||||
# We've created a library that FreeCAD can use as well to open CQ files
|
# 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))
|
ImportCQ.open(os.path.join(exs_dir_path, self.exFile))
|
||||||
|
|
||||||
# docname = os.path.splitext(os.path.basename(self.exFile))[0]
|
|
||||||
# FreeCAD.newDocument(docname)
|
|
||||||
|
|
||||||
#Execute the script
|
|
||||||
#CadQueryExecuteScript().Activated()
|
|
||||||
|
|
||||||
#Get a nice view of our model
|
|
||||||
#FreeCADGui.activeDocument().activeView().viewAxometric()
|
|
||||||
#FreeCADGui.SendMsgToActiveView("ViewFit")
|
|
||||||
|
|
||||||
|
|
||||||
class CadQueryExecuteScript:
|
class CadQueryExecuteScript:
|
||||||
"""CadQuery's command to execute a script file"""
|
"""CadQuery's command to execute a script file"""
|
||||||
|
@ -151,8 +138,6 @@ class CadQueryExecuteScript:
|
||||||
tempFile.write(cqCodePane.toPlainText().encode('utf-8'))
|
tempFile.write(cqCodePane.toPlainText().encode('utf-8'))
|
||||||
tempFile.close()
|
tempFile.close()
|
||||||
|
|
||||||
#mdi = mw.findChild(QtGui.QMdiArea)
|
|
||||||
#docname = mdi.currentSubWindow().getWindowTitle()
|
|
||||||
docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
|
docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
|
||||||
|
|
||||||
# Make sure we replace any troublesome characters
|
# Make sure we replace any troublesome characters
|
||||||
|
@ -240,16 +225,6 @@ class CadQueryOpenScript:
|
||||||
# We've created a library that FreeCAD can use as well to open CQ files
|
# We've created a library that FreeCAD can use as well to open CQ files
|
||||||
ImportCQ.open(filename[0])
|
ImportCQ.open(filename[0])
|
||||||
|
|
||||||
# docname = os.path.splitext(os.path.basename(filename[0]))[0]
|
|
||||||
# FreeCAD.newDocument(docname)
|
|
||||||
|
|
||||||
#Execute the script
|
|
||||||
# CadQueryExecuteScript().Activated()
|
|
||||||
|
|
||||||
#Get a nice view of our model
|
|
||||||
# FreeCADGui.activeDocument().activeView().viewAxometric()
|
|
||||||
# FreeCADGui.SendMsgToActiveView("ViewFit")
|
|
||||||
|
|
||||||
|
|
||||||
class CadQuerySaveScript:
|
class CadQuerySaveScript:
|
||||||
"""CadQuery's command to save a script file"""
|
"""CadQuery's command to save a script file"""
|
||||||
|
@ -267,6 +242,11 @@ class CadQuerySaveScript:
|
||||||
# Grab our code editor so we can interact with it
|
# Grab our code editor so we can interact with it
|
||||||
cqCodePane = Shared.getActiveCodePane()
|
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 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' \
|
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'):
|
or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'):
|
||||||
|
@ -301,6 +281,10 @@ class CadQuerySaveAsScript:
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
cqCodePane = Shared.getActiveCodePane()
|
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
|
# Try to keep track of the previous path used to open as a convenience to the user
|
||||||
if self.previousPath is None:
|
if self.previousPath is None:
|
||||||
self.previousPath = "/home/"
|
self.previousPath = "/home/"
|
||||||
|
|
|
@ -45,7 +45,6 @@ def open(filename):
|
||||||
# Set up so that we can import from our embedded packages
|
# Set up so that we can import from our embedded packages
|
||||||
module_base_path = module_locator.module_path()
|
module_base_path = module_locator.module_path()
|
||||||
libs_dir_path = os.path.join(module_base_path, 'Libs')
|
libs_dir_path = os.path.join(module_base_path, 'Libs')
|
||||||
sys.path.insert(0, libs_dir_path)
|
|
||||||
|
|
||||||
from pyqode.core.modes import FileWatcherMode
|
from pyqode.core.modes import FileWatcherMode
|
||||||
from pyqode.core.modes import RightMarginMode
|
from pyqode.core.modes import RightMarginMode
|
||||||
|
@ -59,7 +58,6 @@ def open(filename):
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
|
|
||||||
# Grab just the file name from the path/file that's being executed
|
# Grab just the file name from the path/file that's being executed
|
||||||
# docname = os.path.splitext(os.path.basename(filename))[0]
|
|
||||||
docname = os.path.basename(filename)
|
docname = os.path.basename(filename)
|
||||||
|
|
||||||
# Set up the text area for our CQ code
|
# Set up the text area for our CQ code
|
||||||
|
|
|
@ -3,3 +3,31 @@
|
||||||
|
|
||||||
#TODO: The FreeCAD devs like to put as much init code as possible in here so that the module can be used without the
|
#TODO: The FreeCAD devs like to put as much init code as possible in here so that the module can be used without the
|
||||||
#TODO: GUI if desired
|
#TODO: GUI if desired
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import module_locator
|
||||||
|
|
||||||
|
# Set up so that we can import from our embedded packages
|
||||||
|
module_base_path = module_locator.module_path()
|
||||||
|
libs_dir_path = os.path.join(module_base_path, 'Libs')
|
||||||
|
sys.path.insert(0, libs_dir_path)
|
||||||
|
|
||||||
|
# Tack on our CadQuery library git subtree
|
||||||
|
cq_lib_path = os.path.join(libs_dir_path, 'cadquery-lib')
|
||||||
|
sys.path.insert(1, cq_lib_path)
|
||||||
|
|
||||||
|
# Make sure we get the right libs under the FreeCAD installation
|
||||||
|
fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
|
||||||
|
fc_lib_path = os.path.join(fc_base_path, 'lib')
|
||||||
|
fc_bin_path = os.path.join(fc_base_path, 'bin')
|
||||||
|
|
||||||
|
# Make sure that the directories exist before we add them to sys.path
|
||||||
|
# This could cause problems or solve them by overriding what CQ is setting for the paths
|
||||||
|
if os.path.exists(fc_lib_path):
|
||||||
|
sys.path.insert(1, fc_lib_path)
|
||||||
|
if os.path.exists(fc_bin_path):
|
||||||
|
sys.path.insert(1, fc_bin_path)
|
||||||
|
|
||||||
|
# Need to set this for PyQode
|
||||||
|
os.environ['QT_API'] = 'pyside'
|
|
@ -15,11 +15,6 @@ class CadQueryWorkbench (Workbench):
|
||||||
closedWidgets = []
|
closedWidgets = []
|
||||||
|
|
||||||
def Initialize(self):
|
def Initialize(self):
|
||||||
import os
|
|
||||||
|
|
||||||
#Need to set this for PyQode
|
|
||||||
os.environ['QT_API'] = 'pyside'
|
|
||||||
|
|
||||||
#Turn off logging for now
|
#Turn off logging for now
|
||||||
#import logging
|
#import logging
|
||||||
#logging.basicConfig(filename='C:\\Users\\Jeremy\\Documents\\', level=logging.DEBUG)
|
#logging.basicConfig(filename='C:\\Users\\Jeremy\\Documents\\', level=logging.DEBUG)
|
||||||
|
@ -39,31 +34,11 @@ class CadQueryWorkbench (Workbench):
|
||||||
self.appendMenu('CadQuery', ['Separator', 'CadQueryExecuteScript', 'CadQueryClearOutput'])
|
self.appendMenu('CadQuery', ['Separator', 'CadQueryExecuteScript', 'CadQueryClearOutput'])
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
import os, sys
|
import os
|
||||||
import module_locator
|
import module_locator
|
||||||
from Gui import Command, ImportCQ
|
from Gui import ImportCQ
|
||||||
import Settings
|
|
||||||
|
|
||||||
#Set up so that we can import from our embedded packages
|
|
||||||
module_base_path = module_locator.module_path()
|
module_base_path = module_locator.module_path()
|
||||||
libs_dir_path = os.path.join(module_base_path, 'Libs')
|
|
||||||
sys.path.insert(0, libs_dir_path)
|
|
||||||
|
|
||||||
# Tack on our CadQuery library git subtree
|
|
||||||
cq_lib_path = os.path.join(libs_dir_path, 'cadquery-lib')
|
|
||||||
sys.path.insert(1, cq_lib_path)
|
|
||||||
|
|
||||||
#Make sure we get the right libs under the FreeCAD installation
|
|
||||||
fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
|
|
||||||
fc_lib_path = os.path.join(fc_base_path, 'lib')
|
|
||||||
fc_bin_path = os.path.join(fc_base_path, 'bin')
|
|
||||||
|
|
||||||
#Make sure that the directories exist before we add them to sys.path
|
|
||||||
#This could cause problems or solve them by overriding what CQ is setting for the paths
|
|
||||||
if os.path.exists(fc_lib_path):
|
|
||||||
sys.path.insert(1, fc_lib_path)
|
|
||||||
if os.path.exists(fc_bin_path):
|
|
||||||
sys.path.insert(1, fc_bin_path)
|
|
||||||
|
|
||||||
import cadquery
|
import cadquery
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
|
@ -71,7 +46,7 @@ class CadQueryWorkbench (Workbench):
|
||||||
msg = QtGui.QApplication.translate(
|
msg = QtGui.QApplication.translate(
|
||||||
"cqCodeWidget",
|
"cqCodeWidget",
|
||||||
"CadQuery " + cadquery.__version__ + "\r\n"
|
"CadQuery " + cadquery.__version__ + "\r\n"
|
||||||
"CadQuery is a parametric scripting language "
|
"CadQuery is a parametric scripting API "
|
||||||
"for creating and traversing CAD models\r\n"
|
"for creating and traversing CAD models\r\n"
|
||||||
"Author: David Cowden\r\n"
|
"Author: David Cowden\r\n"
|
||||||
"License: Apache-2.0\r\n"
|
"License: Apache-2.0\r\n"
|
||||||
|
@ -104,30 +79,7 @@ class CadQueryWorkbench (Workbench):
|
||||||
Gui.Command.CadQueryExecuteScript().Activated()
|
Gui.Command.CadQueryExecuteScript().Activated()
|
||||||
|
|
||||||
def Deactivated(self):
|
def Deactivated(self):
|
||||||
import Gui.Command
|
pass
|
||||||
from PySide import QtGui
|
|
||||||
|
|
||||||
# msg = QtGui.QApplication.translate(
|
|
||||||
# "cqCodeWidget",
|
|
||||||
# "\r\nCadQuery Workbench Deactivated\r\n",
|
|
||||||
# None,
|
|
||||||
# QtGui.QApplication.UnicodeUTF8)
|
|
||||||
#
|
|
||||||
# #Put the UI back the way we found it
|
|
||||||
# FreeCAD.Console.PrintMessage(msg)
|
|
||||||
|
|
||||||
# # Getting the main window will allow us to start setting things up the way we want
|
|
||||||
# mw = FreeCADGui.getMainWindow()
|
|
||||||
#
|
|
||||||
# cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")
|
|
||||||
# cqCodePane.close()
|
|
||||||
# cqCodePane.setParent(None)
|
|
||||||
#
|
|
||||||
# dockWidgets = mw.findChildren(QtGui.QDockWidget)
|
|
||||||
#
|
|
||||||
# for widget in dockWidgets:
|
|
||||||
# if widget.objectName() == "cqCodeView":
|
|
||||||
# mw.removeDockWidget(widget)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ListExamples():
|
def ListExamples():
|
||||||
|
|
|
@ -25,14 +25,13 @@ def clearActiveDocument():
|
||||||
def getActiveCodePane():
|
def getActiveCodePane():
|
||||||
"""Gets the currently active code pane, even if its 3D view is selected."""
|
"""Gets the currently active code pane, even if its 3D view is selected."""
|
||||||
|
|
||||||
# TODO: Make sure that the code pane is selected, even if the associated 3D view currently has focus
|
|
||||||
|
|
||||||
# Grab our code editor so we can interact with it
|
# Grab our code editor so we can interact with it
|
||||||
mw = FreeCADGui.getMainWindow()
|
mw = FreeCADGui.getMainWindow()
|
||||||
mdi = mw.findChild(QtGui.QMdiArea)
|
mdi = mw.findChild(QtGui.QMdiArea)
|
||||||
|
|
||||||
# If our current subwindow doesn't contain a script, we need to find the one that does
|
# If our current subwindow doesn't contain a script, we need to find the one that does
|
||||||
mdiWin = mdi.currentSubWindow()
|
mdiWin = mdi.currentSubWindow()
|
||||||
|
if mdiWin == None: return None # We need to warn the caller that there is no code pane
|
||||||
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
|
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
|
||||||
subList = mdi.subWindowList()
|
subList = mdi.subWindowList()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user