Add new file section and file templates to StartPage

This commit is contained in:
qewer33
2023-08-11 19:50:26 +03:00
parent e2597aa77b
commit 0e606ec1d1
12 changed files with 380 additions and 201 deletions

View File

@@ -26,6 +26,12 @@ SET(StartPage_ImageResources
images/installed.png
images/new_file_thumbnail.svg
images/settings.png
images/new_empty_file.png
images/new_import_file.png
images/new_parametric_part.png
images/new_csg_part.png
images/new_2d_draft.png
images/new_architecture.png
)
SET(StartPage_Resources

View File

@@ -21,8 +21,37 @@
import FreeCAD
import FreeCADGui
FreeCADGui.runCommand('Std_New')
from StartPage import StartPage
StartPage.postStart()
# template will be given before this script is run
template_name = str(template)
match template_name:
case "empty_file":
FreeCADGui.runCommand('Std_New')
StartPage.postStart()
case "import_file":
FreeCADGui.runCommand('Std_New')
StartPage.postStart()
FreeCADGui.runCommand("Std_Import")
case "parametric_part":
FreeCADGui.runCommand('Std_New')
FreeCADGui.activateWorkbench("PartDesignWorkbench")
FreeCADGui.runCommand("PartDesign_Body")
FreeCADGui.Selection.addSelection('Unnamed','Body')
FreeCADGui.runCommand('PartDesign_NewSketch',0)
FreeCADGui.Selection.clearSelection()
StartPage.postStart(False)
case "csg_part":
FreeCADGui.runCommand('Std_New')
FreeCADGui.activateWorkbench("PartWorkbench")
StartPage.postStart(False)
case "2d_draft":
FreeCADGui.runCommand('Std_New')
FreeCADGui.activateWorkbench("DraftWorkbench")
FreeCADGui.runCommand("Std_ViewTop")
StartPage.postStart(False)
case "architecture":
FreeCADGui.runCommand('Std_New')
FreeCADGui.activateWorkbench("ArchWorkbench")
StartPage.postStart(False)

View File

@@ -1,4 +1,4 @@
html{
html {
height: 100%;
display: flex;
flex-direction: column;
@@ -11,49 +11,63 @@ body {
font-size: FONTSIZE;
height: 100%;
}
OVERFLOW
a, a:link, a:visited {
OVERFLOW
a,
a:link,
a:visited {
text-decoration: none;
color: LINKCOLOR;
font-weight: bold;
}
h1 {
width: 100%;
text-align: center;
}
h2 {
text-align: center;
clear: both;
padding-top: 15px;
}
hr {
height: 20px;
border: none;
}
.hidden {
display: none;
}
.version {
font-size: 0.8em;
float: right;
padding-right: 10px;
}
.settingsicon {
width: 16px;
height: 16px;
margin-left: 20px;
vertical-align:middle;
vertical-align: middle;
}
.container {
margin: 2%;
height: 95%;
}
ul.tabs {
margin: 9px 0;
}
ul.tabs li {
list-style: none;
display: inline;
}
ul.tabs li a {
color: TEXTCOLOR;
background-color: BOXCOLOR;
@@ -62,22 +76,26 @@ ul.tabs li a {
font-size: 1em;
font-weight: bold;
text-transform: uppercase;
border:1px solid BOXCOLOR;
border: 1px solid BOXCOLOR;
border-radius: 3px 3px 0px 0px;
box-shadow: #445 0 -5px 5px;
outline: 0;
}
ul.tabs li a:hover {
background-color: TEXTCOLOR;
color: BASECOLOR;
border-color: TEXTCOLOR;
}
ul.tabs li a.active, ul.tabs li a.active:hover {
ul.tabs li a.active,
ul.tabs li a.active:hover {
color: TEXTCOLOR;
background-color: BASECOLOR;
border-bottom: 1px solid BASECOLOR;
border-color: BASECOLOR;
}
.panel {
background: BASECOLOR;
color: TEXTCOLOR;
@@ -88,9 +106,11 @@ ul.tabs li a.active, ul.tabs li a.active:hover {
overflow: auto;
box-shadow: SHADOW 0 2px 5px;
}
ul.icons {
clear: both;
}
.icon {
list-style: none;
display: inline;
@@ -104,32 +124,76 @@ ul.icons {
box-shadow: SHADOW 0 0px 6px;
word-wrap: break-word;
}
.icon h4 {
margin: 3px 0;
max-width: 90%;
}
.icon img {
width: 128px;
height: 128px;
}
.icon p {
margin: 0;
}
.caption {
clear: both;
}
a .caption, a .caption:link, a .caption:visited {
color: TEXTCOLOR;
text-decoration-color: TEXTCOLOR;
}
.caption p {
font-weight: normal;
}
a .caption,
a .caption:link,
a .caption:visited {
color: TEXTCOLOR;
text-decoration-color: TEXTCOLOR;
}
.icon-new-template {
list-style: none;
display: flex;
align-items: center;
float: left;
padding: 5px 10px;
width: 235px;
height: 70px;
background: BOXCOLOR;
border-radius: 3px;
margin: 10px;
box-shadow: SHADOW 0 0px 6px;
word-wrap: break-word;
}
.icon-new-template a {
display: flex;
}
.icon-new-template h3 {
margin: 3px 0;
max-width: 90%;
text-align: left;
margin-bottom: 5px;
}
.icon-new-template img {
width: 64px;
height: 64px;
margin-right: 10px;
}
.icon-new-template p {
margin: 0;
}
.docbox a:hover {
text-decoration: underline;
}
.docbox {
float: left;
padding: 10px;
@@ -139,63 +203,88 @@ a .caption, a .caption:link, a .caption:visited {
margin: 10px;
box-shadow: SHADOW 0 0px 6px;
}
.docbox h2 {
text-align: center;
}
.docbox img {
max-width: 24px;
max-height: 24px;
}
.forum img {
max-width: 100% !important;
max-height: 100% !important;
}
.allwidth {
max-width: 98%;
}
h3 a {
height: 32px;
vertical-align: middle;
padding-bottom: 18px;
padding-left: 5px;
}
#commits ul {
margin: 30px 0;
}
#commits ul li, .forum ul li {
#commits ul li,
.forum ul li {
margin-bottom: 10px;
}
.footnote {
text-align: center;
display: block; /* footnote tips display */
display: block;
/* footnote tips display */
clear: both;
padding-top: 10px;
}
ul.workbenches, ul.addonslist {
ul.workbenches,
ul.addonslist {
overflow: hidden;
padding: 10px;
}
ul.workbenches li, ul.addonslist li {
ul.workbenches li,
ul.addonslist li {
list-style: none;
float: left;
display: inline;
width: 50%;
}
.forum {
display: none; /* forum display */ /* don't change this line */
display: none;
/* forum display */
/* don't change this line */
}
.forum pre {
white-space: pre-wrap;
}
.thumbnails {
float: left;
width: 100%; /* thumbs display */ /* don't change this line */
width: 100%;
/* thumbs display */
/* don't change this line */
}
.notes {
display: none; /* notes display */ /* don't change this line */
display: none;
/* notes display */
/* don't change this line */
float: right;
width: 30%;
}
#notepad {
width: 95%;
height: 100%;
@@ -209,13 +298,13 @@ ul.workbenches li, ul.addonslist li {
.iframe {
display:block;
display: block;
margin: auto;
text-align: center;
width:50%;
height:100%;
width: 50%;
height: 100%;
}
.iframecontainer {
height:90%;
height: 90%;
}

View File

@@ -1,163 +1,170 @@
<!DOCTYPE html>
<html lang="BCP47_LANGUAGE">
<head>
<title>T_TITLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script>JS</script>
<style>CSS</style>
<!--QSS-->
</head>
<body onload="load()">
<div class="container">
<div class="title">
<div class="version">
VERSIONSTRING
<a title="T_VTOOLTIP" href="OpenSettings.py">
<img class="settingsicon" src="IMAGE_SRC_SETTINGS" alt="T_VTOOLTIP">
</a>
</div>
</div>
<ul id="tabs" class="tabs">
<li><a id="htab1" class="active" onClick="toggle('tab1')" href="#">T_DOCUMENTS</a></li>
<li><a id="htab2" onClick="toggle('tab2')" href="#">T_HELP</a></li>
<li><a id="htab3" onClick="toggle('tab3')" href="#">T_ACTIVITY</a></li>
<li><a href="https://blog.freecad.org/" title="Link to the
FreeCAD blog">BLOG</a></li>
</ul>
<div id="tab1" class="panel">
<div class="thumbnails">
SECTION_RECENTFILES
<div class="footnote">
<b>T_TIP</b>: T_ADJUSTRECENT<br/>
</div>
SECTION_EXAMPLES
SECTION_CUSTOM
<div id="customtip" class="footnote">
T_CUSTOM
</div>
</div>
<div class="notes">
<h2>T_NOTES</h2>
<textarea id="notepad"></textarea>
</div>
</div>
<div id="tab2" class="panel hidden">
<div class="docbox">
<h2>T_GENERALDOCUMENTATION</h2>
<h3>
<img src="IMAGE_SRC_USERHUB" alt="T_USERHUB"/>
<a href="https://www.freecad.org/wiki/User_hub">T_USERHUB</a>
</h3>
<p>T_DESCR_USERHUB</p>
<h3>
<img src="IMAGE_SRC_POWERHUB" alt="T_POWERHUB"/>
<a href="https://www.freecad.org/wiki/Power_users_hub">T_POWERHUB</a>
</h3>
<p>T_DESCR_POWERHUB</p>
<h3>
<img src="IMAGE_SRC_DEVHUB" alt="T_DEVHUB"/>
<a href="https://www.freecad.org/wiki/Developer_hub">T_DEVHUB</a>
</h3>
<p>T_DESCR_DEVHUB</p>
<h3>
<img src="IMAGE_SRC_MANUAL" alt="T_MANUAL"/>
<a href="https://www.freecad.org/wiki/Manual:Introduction">T_MANUAL</a>
</h3>
<p>T_DESCR_MANUAL</p>
</div>
<div class="docbox">
<h2>T_WBHELP</h2>
<p>T_DESCR_WBHELP</p>
UL_WORKBENCHES
</div>
<div class="docbox">
<h2>T_COMMUNITYHELP</h2>
<p>T_DESCR_COMMUNITYHELP1</p>
<p>T_DESCR_COMMUNITYHELP2</p>
<p>T_DESCR_COMMUNITYHELP3</p>
</div>
<div class="docbox">
<h2>T_ADDONS</h2>
<p>T_DESCR_ADDONS</p>
<div id="addons">T_OFFLINEPLACEHOLDER</div>
</div>
<div class="footnote">
<b>T_TIP</b>: T_OFFLINEHELP
</div>
<div class="footnote">
<b>T_TIP</b>: T_EXTERNALLINKS
</div>
</div>
<div id="tab3" class="panel tab3 hidden">
<h2>T_RECENTCOMMITS</h2>
<div class="docbox allwidth">
<div class="footnote">T_DESCR_RECENTCOMMITS</div>
<div id="commits">T_OFFLINEPLACEHOLDER</div>
<div class="footnote">
<a href="http://github.com/FreeCAD/FreeCAD/commits/master">T_SEEONGITHUB</a>
</div>
</div>
<h2 class="forum">T_FORUM</h2>
<div class="docbox allwidth forum">
<div class="footnote">T_DESCR_FORUM</div>
<div id="forum">T_OFFLINEPLACEHOLDER</div>
</div>
<div class="footnote">
<b>T_TIP</b>: T_EXTERNALLINKS
</div>
<head>
<title>T_TITLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>JS</script>
<style>
CSS
</style>
<!--QSS-->
</head>
<body onload="load()">
<div class="container">
<div class="title">
<div class="version">
VERSIONSTRING
<a title="T_VTOOLTIP" href="OpenSettings.py">
<img class="settingsicon" src="IMAGE_SRC_SETTINGS" alt="T_VTOOLTIP">
</a>
</div>
</div>
</body>
</html>
<ul id="tabs" class="tabs">
<li><a id="htab1" class="active" onClick="toggle('tab1')" href="#">T_DOCUMENTS</a></li>
<li><a id="htab2" onClick="toggle('tab2')" href="#">T_HELP</a></li>
<li><a id="htab3" onClick="toggle('tab3')" href="#">T_ACTIVITY</a></li>
<li><a href="https://blog.freecad.org/" title="Link to the
FreeCAD blog">BLOG</a></li>
</ul>
<div id="tab1" class="panel">
<div class="thumbnails">
SECTION_NEW_FILE
SECTION_RECENTFILES
<div class="footnote">
<b>T_TIP</b>: T_ADJUSTRECENT
</div>
SECTION_EXAMPLES
SECTION_CUSTOM
<div id="customtip" class="footnote">
T_CUSTOM
</div>
</div>
<div class="notes">
<h2>T_NOTES</h2>
<textarea id="notepad"></textarea>
</div>
</div>
<div id="tab2" class="panel hidden">
<div class="docbox">
<h2>T_GENERALDOCUMENTATION</h2>
<h3>
<img src="IMAGE_SRC_USERHUB" alt="T_USERHUB" />
<a href="https://www.freecad.org/wiki/User_hub">T_USERHUB</a>
</h3>
<p>T_DESCR_USERHUB</p>
<h3>
<img src="IMAGE_SRC_POWERHUB" alt="T_POWERHUB" />
<a href="https://www.freecad.org/wiki/Power_users_hub">T_POWERHUB</a>
</h3>
<p>T_DESCR_POWERHUB</p>
<h3>
<img src="IMAGE_SRC_DEVHUB" alt="T_DEVHUB" />
<a href="https://www.freecad.org/wiki/Developer_hub">T_DEVHUB</a>
</h3>
<p>T_DESCR_DEVHUB</p>
<h3>
<img src="IMAGE_SRC_MANUAL" alt="T_MANUAL" />
<a href="https://www.freecad.org/wiki/Manual:Introduction">T_MANUAL</a>
</h3>
<p>T_DESCR_MANUAL</p>
</div>
<div class="docbox">
<h2>T_WBHELP</h2>
<p>T_DESCR_WBHELP</p>
UL_WORKBENCHES
</div>
<div class="docbox">
<h2>T_COMMUNITYHELP</h2>
<p>T_DESCR_COMMUNITYHELP1</p>
<p>T_DESCR_COMMUNITYHELP2</p>
<p>T_DESCR_COMMUNITYHELP3</p>
</div>
<div class="docbox">
<h2>T_ADDONS</h2>
<p>T_DESCR_ADDONS</p>
<div id="addons">T_OFFLINEPLACEHOLDER</div>
</div>
<div class="footnote">
<b>T_TIP</b>: T_OFFLINEHELP
</div>
<div class="footnote">
<b>T_TIP</b>: T_EXTERNALLINKS
</div>
</div>
<div id="tab3" class="panel tab3 hidden">
<h2>T_RECENTCOMMITS</h2>
<div class="docbox allwidth">
<div class="footnote">T_DESCR_RECENTCOMMITS</div>
<div id="commits">T_OFFLINEPLACEHOLDER</div>
<div class="footnote">
<a href="http://github.com/FreeCAD/FreeCAD/commits/master">T_SEEONGITHUB</a>
</div>
</div>
<h2 class="forum">T_FORUM</h2>
<div class="docbox allwidth forum">
<div class="footnote">T_DESCR_FORUM</div>
<div id="forum">T_OFFLINEPLACEHOLDER</div>
</div>
<div class="footnote">
<b>T_TIP</b>: T_EXTERNALLINKS
</div>
</div>
</div>
</body>
</html>

View File

@@ -251,6 +251,38 @@ def getDefaultIcon():
def build_new_file_card(template):
"builds an html <li> element respresenting a new file template"
templates = {
"empty_file": [TranslationTexts.T_TEMPLATE_EMPTYFILE_NAME, TranslationTexts.T_TEMPLATE_EMPTYFILE_DESC],
"import_file": [TranslationTexts.T_TEMPLATE_IMPORTFILE_NAME, TranslationTexts.T_TEMPLATE_IMPORTFILE_DESC],
"parametric_part": [TranslationTexts.T_TEMPLATE_PARAMETRICPART_NAME, TranslationTexts.T_TEMPLATE_PARAMETRICPART_DESC],
"csg_part": [TranslationTexts.T_TEMPLATE_CSGPART_NAME, TranslationTexts.T_TEMPLATE_CSGPART_DESC],
"2d_draft": [TranslationTexts.T_TEMPLATE_2DDRAFT_NAME, TranslationTexts.T_TEMPLATE_2DDRAFT_DESC],
"architecture": [TranslationTexts.T_TEMPLATE_ARCHITECTURE_NAME, TranslationTexts.T_TEMPLATE_ARCHITECTURE_DESC]
}
if template not in templates:
return
image = 'file:///'+os.path.join(os.path.join(FreeCAD.getResourceDir(), "Mod", "Start", "StartPage"), 'images/new_'+template+".png").replace('\\','/')
result = ""
result += '<li class="icon-new-template">'
result += '<a href="LoadNew.py?template='+urllib.parse.quote(template)+'">'
result += '<img src="'+image+'" alt="'+template+'">'
result += '<div class="caption">'
result += '<h3>'+templates[template][0]+'</h3>'
result += '<p>'+templates[template][1]+'</p>'
result += '</div>'
result += '</a>'
result += '</li>'
return result
def buildCard(filename,method,arg=None):
"""builds an html <li> element representing a file.
@@ -391,23 +423,25 @@ def handle():
i.save(createimg)
iconbank["createimg"] = createimg
# build SECTION_NEW_FILE
SECTION_NEW_FILE = "<h2>"+TranslationTexts.T_NEWFILE+"</h2>"
SECTION_NEW_FILE += "<ul>"
SECTION_NEW_FILE += build_new_file_card("empty_file")
SECTION_NEW_FILE += build_new_file_card("import_file")
SECTION_NEW_FILE += build_new_file_card("parametric_part")
SECTION_NEW_FILE += build_new_file_card("csg_part")
SECTION_NEW_FILE += build_new_file_card("2d_draft")
SECTION_NEW_FILE += build_new_file_card("architecture")
SECTION_NEW_FILE += '</ul>'
HTML = HTML.replace("SECTION_NEW_FILE",SECTION_NEW_FILE)
# build SECTION_RECENTFILES
rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
rfcount = rf.GetInt("RecentFiles",0)
SECTION_RECENTFILES = "<h2>"+TranslationTexts.T_RECENTFILES+"</h2>"
SECTION_RECENTFILES += "<ul>"
SECTION_RECENTFILES += '<li class="icon">'
SECTION_RECENTFILES += '<a href="LoadNew.py" title="'+TranslationTexts.T_CREATENEW+'">'
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("NewFileGradient",False):
SECTION_RECENTFILES += '<img src="file:///'+iconbank["createimg"].replace('\\','/')+'" alt="'+TranslationTexts.T_CREATENEW+'">'
else:
SECTION_RECENTFILES += '<img src="file:///'+os.path.join(resources_dir, "images/new_file_thumbnail.svg").replace('\\','/')+'" alt="'+TranslationTexts.T_CREATENEW+'">'
SECTION_RECENTFILES += '<div class="caption">'
SECTION_RECENTFILES += '<h4>'+TranslationTexts.T_CREATENEW+'</h4>'
SECTION_RECENTFILES += '</div>'
SECTION_RECENTFILES += '</a>'
SECTION_RECENTFILES += '</li>'
for i in range(rfcount):
filename = rf.GetString("MRU%d" % (i))
SECTION_RECENTFILES += buildCard(filename,method="LoadMRU.py?MRU=",arg=str(i))
@@ -618,20 +652,21 @@ def exportTestFile():
def postStart():
def postStart(switch_wb = True):
"executes needed operations after loading a file"
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
# switch workbench
wb = param.GetString("AutoloadModule","")
if "$LastModule" == wb:
wb = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetString("LastModule","")
if wb:
# don't switch workbenches if we are not in Start anymore
if FreeCADGui.activeWorkbench() and (FreeCADGui.activeWorkbench().name() == "StartWorkbench"):
FreeCADGui.activateWorkbench(wb)
if switch_wb:
wb = param.GetString("AutoloadModule","")
if "$LastModule" == wb:
wb = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetString("LastModule","")
if wb:
# don't switch workbenches if we are not in Start anymore
if FreeCADGui.activeWorkbench() and (FreeCADGui.activeWorkbench().name() == "StartWorkbench"):
FreeCADGui.activateWorkbench(wb)
# close start tab
cl = param.GetBool("closeStart",False)

View File

@@ -38,6 +38,19 @@ T_TITLE = translate("StartPage", "Start")
T_DOCUMENTS = translate("StartPage", "Documents")
T_HELP = translate("StartPage", "Help")
T_ACTIVITY = translate("StartPage", "Activity")
T_NEWFILE = translate("StartPage", "New file")
T_TEMPLATE_EMPTYFILE_NAME = translate("StartPage", "Empty File")
T_TEMPLATE_EMPTYFILE_DESC = translate("StartPage", "Create an empty FreeCAD file")
T_TEMPLATE_IMPORTFILE_NAME = translate("StartPage", "Import File")
T_TEMPLATE_IMPORTFILE_DESC = translate("StartPage", "Work on an existing CAD or 3D model file")
T_TEMPLATE_PARAMETRICPART_NAME = translate("StartPage", "Parametric Part")
T_TEMPLATE_PARAMETRICPART_DESC = translate("StartPage", "Template for a part with the Part Design workbench")
T_TEMPLATE_CSGPART_NAME = translate("StartPage", "CSG Part")
T_TEMPLATE_CSGPART_DESC = translate("StartPage", "Template for a part with the Part workbench")
T_TEMPLATE_2DDRAFT_NAME = translate("StartPage", "2D Draft")
T_TEMPLATE_2DDRAFT_DESC = translate("StartPage", "Template for a 2D draft with the Draft workbench")
T_TEMPLATE_ARCHITECTURE_NAME = translate("StartPage", "Architecture")
T_TEMPLATE_ARCHITECTURE_DESC = translate("StartPage", "Template for a an architecture project")
T_RECENTFILES = translate("StartPage", "Recent files")
T_TIP = translate("StartPage", "Tip")
T_ADJUSTRECENT = translate("StartPage", "Adjust the number of recent files to be shown here in menu Edit -> Preferences -> General -> Size of recent file list")

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB