Skip to content

Commit

Permalink
Draft: Disabled automatic DXF library download - fixes #1785
Browse files Browse the repository at this point in the history
Note for existing users: Can be reenabled in menu Edit > Preferences >
Import-Export > DXF > Automatic update
  • Loading branch information
yorikvanhavre committed Oct 18, 2014
1 parent dd392ef commit bd1bbff
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/Mod/Draft/Draft_rc.py

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions src/Mod/Draft/Resources/ui/userprefs-import1.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>521</width>
<height>528</height>
<width>505</width>
<height>543</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,6 +20,35 @@
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Automatic update</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_3">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;By checking this, you will allow FreeCAD to download and update the&lt;/p&gt;&lt;p&gt;components needed for DXF import and export. You can also do that&lt;/p&gt;&lt;p&gt;manually, by visiting https://github.com/yorikvanhavre/Draft-dxf-importer&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Allow FreeCAD to automatically download and update the DXF libraries</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>dxfAllowDownload</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupBox12">
<property name="title">
Expand Down
50 changes: 31 additions & 19 deletions src/Mod/Draft/importDXF.py
Expand Up @@ -69,27 +69,39 @@
FreeCAD.Console.PrintWarning("DXF libraries need to be updated. Downloading...\n")
libsok = False
if not libsok:
files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py']
baseurl = 'https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/'+str(CURRENTDXFLIB)+"/"
import ArchCommands
from FreeCAD import Base
progressbar = Base.ProgressIndicator()
progressbar.start("Downloading files...",4)
for f in files:
progressbar.next()
p = None
p = ArchCommands.download(baseurl+f,force=True)
if not p:
FreeCAD.Console.PrintWarning("Download of dxf libraries failed. Please download them manually from\nhttps://github.com/yorikvanhavre/Draft-dxf-importer\nand place them in your macros folder\n")
break
progressbar.stop()

sys.path.append(FreeCAD.ConfigGet("UserAppData"))
try:
import dxfColorMap, dxfLibrary, dxfReader
except ImportError:
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
dxfAllowDownload = p.GetBool("dxfAllowDownload",False)
if dxfAllowDownload:
files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py']
baseurl = 'https://raw.githubusercontent.com/yorikvanhavre/Draft-dxf-importer/'+str(CURRENTDXFLIB)+"/"
import ArchCommands
from FreeCAD import Base
progressbar = Base.ProgressIndicator()
progressbar.start("Downloading files...",4)
for f in files:
progressbar.next()
p = None
p = ArchCommands.download(baseurl+f,force=True)
if not p:
FreeCAD.Console.PrintWarning("Download of dxf libraries failed. Please download them manually from\nhttps://github.com/yorikvanhavre/Draft-dxf-importer\nand place them in your macros folder\n")
break
progressbar.stop()

sys.path.append(FreeCAD.ConfigGet("UserAppData"))
try:
import dxfColorMap, dxfLibrary, dxfReader
except ImportError:
dxfReader = None
dxfLibrary = None
else:
FreeCAD.Console.PrintWarning("The DXF import/export libraries needed by FreeCAD to handle the DXF format\n")
FreeCAD.Console.PrintWarning("were not found on this system. Please either enable FreeCAD to download these\n")
FreeCAD.Console.PrintWarning("libraries (menu Edit > Preferences > Import-Export > DXF > Enable downloads) or download\n")
FreeCAD.Console.PrintWarning("these libraries manually, as explained on\n")
FreeCAD.Console.PrintWarning("https://github.com/yorikvanhavre/Draft-dxf-importer\n")
dxfReader = None
dxfLibrary = None


if open.__module__ == '__builtin__':
pythonopen = open # to distinguish python built-in open function from the one declared here
Expand Down

0 comments on commit bd1bbff

Please sign in to comment.