fix #1991 : display message for dxf library missing
at the import of importDXF and open, insert and export functions. Also the message allow user to enabled FreeCAD to download the library.
This commit is contained in:
parent
0063b80937
commit
10aa881f72
|
@ -55,23 +55,7 @@ if gui:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# check dxfLibrary version
|
def errorDXFLib(gui):
|
||||||
try:
|
|
||||||
if FreeCAD.ConfigGet("UserAppData") not in sys.path:
|
|
||||||
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
|
|
||||||
import dxfLibrary
|
|
||||||
import dxfColorMap
|
|
||||||
import dxfReader
|
|
||||||
except ImportError:
|
|
||||||
libsok = False
|
|
||||||
FreeCAD.Console.PrintWarning("DXF libraries not found. Downloading...\n")
|
|
||||||
else:
|
|
||||||
if "v"+str(CURRENTDXFLIB) in dxfLibrary.__version__:
|
|
||||||
libsok = True
|
|
||||||
else:
|
|
||||||
FreeCAD.Console.PrintWarning("DXF libraries need to be updated. Downloading...\n")
|
|
||||||
libsok = False
|
|
||||||
if not libsok:
|
|
||||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||||
dxfAllowDownload = p.GetBool("dxfAllowDownload",False)
|
dxfAllowDownload = p.GetBool("dxfAllowDownload",False)
|
||||||
if dxfAllowDownload:
|
if dxfAllowDownload:
|
||||||
|
@ -99,32 +83,54 @@ and place them in your macros folder.""")
|
||||||
FreeCAD.Console.PrintWarning("Please check https://github.com/yorikvanhavre/Draft-dxf-importer\n")
|
FreeCAD.Console.PrintWarning("Please check https://github.com/yorikvanhavre/Draft-dxf-importer\n")
|
||||||
break
|
break
|
||||||
progressbar.stop()
|
progressbar.stop()
|
||||||
|
|
||||||
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
|
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
|
||||||
try:
|
|
||||||
import dxfColorMap, dxfLibrary, dxfReader
|
|
||||||
except ImportError:
|
|
||||||
dxfReader = None
|
|
||||||
dxfLibrary = None
|
|
||||||
else:
|
else:
|
||||||
if gui:
|
if gui:
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
from DraftTools import translate
|
from DraftTools import translate
|
||||||
message = translate('draft',"""The DXF import/export libraries needed by FreeCAD to handle
|
message = translate('draft',"""The DXF import/export libraries needed by FreeCAD to handle
|
||||||
the DXF format were not found on this system.
|
the DXF format were not found on this system.
|
||||||
Please either enable FreeCAD to download these libraries:
|
Please either enable FreeCAD to download these libraries:
|
||||||
1 - Load Draft workbench
|
1 - Load Draft workbench
|
||||||
2 - Menu Edit > Preferences > Import-Export > DXF > Enable downloads
|
2 - Menu Edit > Preferences > Import-Export > DXF > Enable downloads
|
||||||
Or download these libraries manually, as explained on
|
Or download these libraries manually, as explained on
|
||||||
https://github.com/yorikvanhavre/Draft-dxf-importer""")
|
https://github.com/yorikvanhavre/Draft-dxf-importer
|
||||||
QtGui.QMessageBox.information(None,"",message)
|
To enabled FreeCAD to download these libraries, answer Yes.""")
|
||||||
|
reply = QtGui.QMessageBox.question(None,"",message,
|
||||||
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
|
||||||
|
if reply == QtGui.QMessageBox.Yes:
|
||||||
|
p.SetBool("dxfAllowDownload",True)
|
||||||
|
errorDXFLib(gui)
|
||||||
|
if reply == QtGui.QMessageBox.No:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
FreeCAD.Console.PrintWarning("The DXF import/export libraries needed by FreeCAD to handle the DXF format are not installed.\n")
|
FreeCAD.Console.PrintWarning("The DXF import/export libraries needed by FreeCAD to handle the DXF format are not installed.\n")
|
||||||
FreeCAD.Console.PrintWarning("Please check https://github.com/yorikvanhavre/Draft-dxf-importer\n")
|
FreeCAD.Console.PrintWarning("Please check https://github.com/yorikvanhavre/Draft-dxf-importer\n")
|
||||||
|
|
||||||
|
# check dxfLibrary version
|
||||||
|
try:
|
||||||
|
if FreeCAD.ConfigGet("UserAppData") not in sys.path:
|
||||||
|
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
|
||||||
|
import dxfLibrary
|
||||||
|
import dxfColorMap
|
||||||
|
import dxfReader
|
||||||
|
except ImportError:
|
||||||
|
libsok = False
|
||||||
|
FreeCAD.Console.PrintWarning("DXF libraries not found. Trying to download...\n")
|
||||||
|
else:
|
||||||
|
if "v"+str(CURRENTDXFLIB) in dxfLibrary.__version__:
|
||||||
|
libsok = True
|
||||||
|
else:
|
||||||
|
FreeCAD.Console.PrintWarning("DXF libraries need to be updated. Trying to download...\n")
|
||||||
|
libsok = False
|
||||||
|
if not libsok:
|
||||||
|
errorDXFLib(gui)
|
||||||
|
try:
|
||||||
|
import dxfColorMap, dxfLibrary, dxfReader
|
||||||
|
except ImportError:
|
||||||
dxfReader = None
|
dxfReader = None
|
||||||
dxfLibrary = None
|
dxfLibrary = None
|
||||||
|
|
||||||
|
|
||||||
if open.__module__ == '__builtin__':
|
if open.__module__ == '__builtin__':
|
||||||
pythonopen = open # to distinguish python built-in open function from the one declared here
|
pythonopen = open # to distinguish python built-in open function from the one declared here
|
||||||
|
|
||||||
|
@ -1464,6 +1470,8 @@ def open(filename):
|
||||||
doc.Label = decodeName(docname)
|
doc.Label = decodeName(docname)
|
||||||
processdxf(doc,filename)
|
processdxf(doc,filename)
|
||||||
return doc
|
return doc
|
||||||
|
else:
|
||||||
|
errorDXFLib(gui)
|
||||||
|
|
||||||
def insert(filename,docname):
|
def insert(filename,docname):
|
||||||
"called when freecad imports a file"
|
"called when freecad imports a file"
|
||||||
|
@ -1480,6 +1488,8 @@ def insert(filename,docname):
|
||||||
processdxf(doc,filename)
|
processdxf(doc,filename)
|
||||||
for l in layers:
|
for l in layers:
|
||||||
importgroup.addObject(l)
|
importgroup.addObject(l)
|
||||||
|
else:
|
||||||
|
errorDXFLib(gui)
|
||||||
|
|
||||||
def getShapes(filename):
|
def getShapes(filename):
|
||||||
"reads a dxf file and returns a list of shapes from its contents"
|
"reads a dxf file and returns a list of shapes from its contents"
|
||||||
|
@ -1808,7 +1818,8 @@ def export(objectslist,filename,nospline=False,lwPoly=False):
|
||||||
|
|
||||||
dxf.saveas(filename)
|
dxf.saveas(filename)
|
||||||
FreeCAD.Console.PrintMessage("successfully exported "+filename+"\r\n")
|
FreeCAD.Console.PrintMessage("successfully exported "+filename+"\r\n")
|
||||||
|
else:
|
||||||
|
errorDXFLib(gui)
|
||||||
|
|
||||||
def exportPage(page,filename):
|
def exportPage(page,filename):
|
||||||
"special export for pages"
|
"special export for pages"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user