Skip to content

Commit

Permalink
Start: Allow to display more than one custom folder on the start page
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Oct 20, 2020
1 parent b5dc388 commit eee68a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Start/Gui/DlgStartPreferences.ui
Expand Up @@ -107,7 +107,7 @@
<item row="2" column="1">
<widget class="Gui::PrefFileChooser" name="fileChooser_3">
<property name="toolTip">
<string>An optional custom folder to be displayed at the bottom of the first page</string>
<string>An optional custom folder to be displayed at the bottom of the first page. By using ";;" to separate paths, you can add several folders here</string>
</property>
<property name="mode">
<enum>Gui::FileChooser::Directory</enum>
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Start/StartPage/LoadCustom.py
Expand Up @@ -26,8 +26,11 @@
else:
from urllib.parse import unquote
# filename will be given before this script is run
cfolder = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
if cfolder:
cfolders = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
if cfolders:
dirnumber = int(filename[0])
filename = filename[2:]
cfolder = cfolders.split(";;")[dirnumber]
if not os.path.isdir(cfolder):
cfolder = os.path.dirname(cfolder)
f = unquote(filename).replace("+"," ")
Expand Down
27 changes: 15 additions & 12 deletions src/Mod/Start/StartPage/StartPage.py
Expand Up @@ -402,18 +402,21 @@ def handle():
# build SECTION_CUSTOM

SECTION_CUSTOM = encode("")
cfolder = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
if cfolder:
if not os.path.isdir(cfolder):
cfolder = os.path.dirname(cfolder)
SECTION_CUSTOM = encode("<h2>"+os.path.basename(os.path.normpath(cfolder))+"</h2>")
SECTION_CUSTOM += "<ul>"
for basename in os.listdir(cfolder):
filename = os.path.join(cfolder,basename)
SECTION_CUSTOM += encode(buildCard(filename,method="LoadCustom.py?filename="))
SECTION_CUSTOM += "</ul>"
# hide the custom section tooltip if custom section is set (users know about it if they enabled it)
HTML = HTML.replace("id=\"customtip\"","id=\"customtip\" style=\"display:none;\"")
cfolders = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","")
if cfolders:
dn = 0
for cfolder in cfolders.split(";;"): # allow several paths separated by ;;
if not os.path.isdir(cfolder):
cfolder = os.path.dirname(cfolder)
SECTION_CUSTOM += encode("<h2>"+os.path.basename(os.path.normpath(cfolder))+"</h2>")
SECTION_CUSTOM += "<ul>"
for basename in os.listdir(cfolder):
filename = os.path.join(cfolder,basename)
SECTION_CUSTOM += encode(buildCard(filename,method="LoadCustom.py?filename="+str(dn)+"_"))
SECTION_CUSTOM += "</ul>"
# hide the custom section tooltip if custom section is set (users know about it if they enabled it)
HTML = HTML.replace("id=\"customtip\"","id=\"customtip\" style=\"display:none;\"")
dn += 1
HTML = HTML.replace("SECTION_CUSTOM",SECTION_CUSTOM)

# build IMAGE_SRC paths
Expand Down

0 comments on commit eee68a3

Please sign in to comment.