Skip to content

Commit

Permalink
Merge pull request #136 from jmwright/kill-pyqode
Browse files Browse the repository at this point in the history
Kill pyqode
  • Loading branch information
jmwright committed Dec 29, 2018
2 parents 4dc437e + a140199 commit 59bbbc3
Show file tree
Hide file tree
Showing 523 changed files with 6,301 additions and 135,309 deletions.
50 changes: 35 additions & 15 deletions CQGui/Command.py
Expand Up @@ -13,10 +13,10 @@
except:
from . import ImportCQ
import module_locator
import Settings
import Shared
from random import random
from contextlib import contextmanager
from SettingsDialog import SettingsDialog
from cadquery import cqgi
from Helpers import show

Expand Down Expand Up @@ -85,11 +85,11 @@ def Activated(self):
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:
if cqCodePane is None or len(cqCodePane.get_path()) == 0:
return

# Check to see if we need to save the script
if cqCodePane.dirty:
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)

Expand All @@ -98,11 +98,11 @@ def Activated(self):

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:
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.file.path
filename = cqCodePane.get_path()

# Make sure we got a valid file name
if filename is not None:
Expand Down Expand Up @@ -142,7 +142,7 @@ class CadQueryExecuteScript:

def GetResources(self):
return {"MenuText": "Execute Script",
"Accel": Settings.execute_keybinding,
"Accel": FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetString("executeKeybinding"),
"ToolTip": "Executes the CadQuery script",
"Pixmap": ":/icons/media-playback-start.svg"}

Expand Down Expand Up @@ -193,8 +193,8 @@ def Activated(self):

build_result = cqModel.build(build_parameters=build_parameters)

if Settings.report_execute_time:
FreeCAD.Console.PrintMessage("Script executed in " + str(build_result.buildTime) + " seconds\r\n")
# if Settings.report_execute_time:
# FreeCAD.Console.PrintMessage("Script executed in " + str(build_result.buildTime) + " seconds\r\n")

# Make sure that the build was successful
if build_result.success:
Expand Down Expand Up @@ -224,8 +224,8 @@ def Activated(self):
tempFile.close()

# Set some environment variables that may help the user
os.environ["MYSCRIPT_FULL_PATH"] = cqCodePane.file.path
os.environ["MYSCRIPT_DIR"] = os.path.dirname(os.path.abspath(cqCodePane.file.path))
os.environ["MYSCRIPT_FULL_PATH"] = cqCodePane.get_path()
os.environ["MYSCRIPT_DIR"] = os.path.dirname(os.path.abspath(cqCodePane.get_path()))

# We import this way because using execfile() causes non-standard script execution in some situations
with revert_sys_modules():
Expand All @@ -235,7 +235,7 @@ def Activated(self):
"cqCodeWidget",
"Executed ",
None)
FreeCAD.Console.PrintMessage(msg + cqCodePane.file.path + "\r\n")
FreeCAD.Console.PrintMessage(msg + cqCodePane.get_path() + "\r\n")


class CadQueryNewScript:
Expand Down Expand Up @@ -320,8 +320,8 @@ def Activated(self):
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)[0].endswith('FreeCAD'):
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()
Expand All @@ -332,7 +332,7 @@ def Activated(self):
ExportCQ.save()

# Execute the script if the user has asked for it
if Settings.execute_on_save:
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetBool("executeOnSave"):
CadQueryExecuteScript().Activated()

class CadQuerySaveAsScript:
Expand Down Expand Up @@ -370,7 +370,7 @@ def Activated(self):
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]
docname = os.path.splitext(os.path.basename(cqCodePane.get_path()))[0]
FreeCAD.closeDocument(docname)
except:
# Assume that there was no 3D view to close
Expand Down Expand Up @@ -461,3 +461,23 @@ def Activated(self):
parameters = cqModel.metadata.parameters

Shared.populateParameterEditor(parameters)

class CadQuerySettings:
"""Opens a settings dialog, allowing the user to change the settings for this workbench"""

def GetResources(self):
return {"MenuText": "Settings",
"Accel": "",
"ToolTip": "Opens the settings dialog",
"Pixmap": ":/icons/preferences-general.svg"}

def IsActive(self):
return True

def Activated(self):
win = SettingsDialog()

win.exec_()

# if win.exec_() == QtGui.QDialog.Accepted:
# print("Settings finished")
8 changes: 2 additions & 6 deletions CQGui/ExportCQ.py
Expand Up @@ -17,14 +17,10 @@ def save(filename=None):
#Grab our code editor so we can interact with it
cqCodePane = Shared.getActiveCodePane()

#If we weren't provided a file name, we need to find it from the text field
if filename is None:
cqCodePane.file.save()
else:
cqCodePane.file.save(filename)
cqCodePane.save(filename)

msg = QtGui.QApplication.translate(
"cqCodeWidget",
"Saved ",
None)
FreeCAD.Console.PrintMessage(msg + cqCodePane.file.path + "\r\n")
FreeCAD.Console.PrintMessage(msg + cqCodePane.get_path() + "\r\n")
47 changes: 9 additions & 38 deletions CQGui/ImportCQ.py
Expand Up @@ -4,8 +4,9 @@
import sys
import FreeCAD, FreeCADGui
from PySide import QtGui
from PySide import QtCore
import module_locator
import Settings
from CodeEditor import CodeEditor

#Distinguish python built-in open function from the one declared here
if open.__module__ == '__builtin__':
Expand All @@ -31,15 +32,6 @@ def open(filename):
ver = hex(sys.hexversion)
interpreter = "python%s.%s" % (ver[2], ver[4]) # => 'python2.7'

# CadQuery now supports Python 3
# If the user doesn't have Python 2.7, warn them
# if interpreter != 'python2.7':
# msg = QtGui.QApplication.translate(
# "cqCodeWidget",
# "Please install Python 2.7",
# None)
# FreeCAD.Console.PrintError(msg + "\r\n")

# The extra version numbers won't work on Windows
if sys.platform.startswith('win'):
interpreter = 'python'
Expand All @@ -48,10 +40,6 @@ def open(filename):
module_base_path = module_locator.module_path()
libs_dir_path = os.path.join(module_base_path, 'Libs')

from pyqode.core.modes import FileWatcherMode
from pyqode.core.modes import RightMarginMode
from pyqode.python.widgets import PyCodeEdit

# 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')
Expand All @@ -62,41 +50,24 @@ def open(filename):
# Grab just the file name from the path/file that's being executed
docname = os.path.basename(filename)

# Set up the text area for our CQ code
server_path = os.path.join(module_base_path, 'cq_server.py')

# Windows needs some extra help with paths
if sys.platform.startswith('win'):
codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
, args=['-s', fc_lib_path, libs_dir_path])
else:
codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
, args=['-s', libs_dir_path])

# Allow easy use of an external editor
if Settings.use_external_editor:
codePane.modes.append(FileWatcherMode())
codePane.modes.get(FileWatcherMode).file_reloaded.connect(AutoExecute)
codePane.modes.get(FileWatcherMode).auto_reload = True

# Set the margin to be at 119 characters instead of 79
codePane.modes.get(RightMarginMode).position = Settings.max_line_length

# Set the font size of the Python editor
codePane.font_size = Settings.font_size
# Pull the font size from the FreeCAD-stored settings
fontSize = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetInt("fontSize")

# Set up the code editor
codePane = CodeEditor()
codePane.setFont(QtGui.QFont('SansSerif', fontSize))
codePane.setObjectName("cqCodePane_" + os.path.splitext(os.path.basename(filename))[0])

mdi = mw.findChild(QtGui.QMdiArea)
# add a widget to the mdi area
# add a code editor widget to the mdi area
sub = mdi.addSubWindow(codePane)
sub.setWindowTitle(docname)
sub.setWindowIcon(QtGui.QIcon(':/icons/applications-python.svg'))
sub.show()
mw.update()

#Pull the text of the CQ script file into our code pane
codePane.file.open(filename)
codePane.open(filename)

msg = QtGui.QApplication.translate(
"cqCodeWidget",
Expand Down

0 comments on commit 59bbbc3

Please sign in to comment.