Start: Misc fixes to start page

- Use smaller icons in file thumbs if desired size is not available
- Fixed loading of stp examples
- Cleaned wrong files appearing in examples
- Added preference setting to configure font and font size
This commit is contained in:
Yorik van Havre
2018-08-22 11:45:11 -03:00
parent 964a9422ff
commit 88b9d158cf
5 changed files with 121 additions and 49 deletions

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>476</width>
<height>585</height>
<height>645</height>
</rect>
</property>
<property name="windowTitle">
@@ -42,7 +42,7 @@
<string>Start page options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="12" column="1">
<item row="13" 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>
@@ -55,7 +55,7 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="13" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Show additional folder</string>
@@ -88,7 +88,7 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Show examples folder contents</string>
@@ -102,7 +102,7 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Gui::PrefRadioButton" name="radioButton_2">
@@ -197,13 +197,32 @@
</property>
</widget>
</item>
<item row="14" column="0">
<item row="15" column="0">
<widget class="QLabel" name="autoModuleLabel">
<property name="text">
<string>Switch workbench after loafing</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_5">
<property name="toolTip">
<string>If this is checked, if a style sheet is specified in General preferences, it will be used and override the colors below</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string/>
</property>
<property name="prefEntry" stdset="0">
<cstring>UseStyleSheet</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Start</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@@ -251,7 +270,7 @@
</property>
</widget>
</item>
<item row="14" column="1">
<item row="15" column="1">
<widget class="QComboBox" name="AutoloadModuleCombo"/>
</item>
<item row="9" column="1" alignment="Qt::AlignRight">
@@ -368,7 +387,7 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="11" column="0">
<widget class="QLabel" name="label_7">
<property name="enabled">
<bool>false</bool>
@@ -378,14 +397,14 @@
</property>
</widget>
</item>
<item row="15" column="0">
<item row="16" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Close start page after loading</string>
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_1">
<property name="toolTip">
<string>if you want the examples to show on the first page</string>
@@ -414,7 +433,7 @@
</property>
</widget>
</item>
<item row="15" column="1">
<item row="16" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_2">
<property name="toolTip">
<string>Should the start page be closed after loading?</string>
@@ -433,14 +452,14 @@
</property>
</widget>
</item>
<item row="16" column="0">
<item row="17" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Close &amp; switch on file open</string>
</property>
</widget>
</item>
<item row="16" column="1">
<item row="17" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_3">
<property name="toolTip">
<string>If FreeCAD is started by opening a file, apply the two settings above</string>
@@ -459,14 +478,14 @@
</property>
</widget>
</item>
<item row="13" column="0">
<item row="14" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Show forum</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_4">
<property name="toolTip">
<string>If this is checked, the latest posts from the FreeCAD forum will be displayed on the Activity tab</string>
@@ -492,25 +511,55 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefCheckBox" name="checkBox_5">
<property name="toolTip">
<string>If this is checked, if a style sheet is specified in General preferences, it will be used and override the colors below</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<item row="10" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string/>
</property>
<property name="prefEntry" stdset="0">
<cstring>UseStyleSheet</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Start</cstring>
<string>Font family</string>
</property>
</widget>
</item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="Gui::PrefLineEdit" name="lineEdit">
<property name="toolTip">
<string>The font family to use on the start page. Can be a font name or a comma-separated series of fallback fonts</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Arial,Helvetica,sans</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>FontFamily</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Start</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="spinBox">
<property name="toolTip">
<string>The base font size to use for all texts of the Start page</string>
</property>
<property name="suffix">
<string>px</string>
</property>
<property name="value">
<number>13</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>FontSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Start</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -545,6 +594,11 @@
<extends>Gui::FileChooser</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefColorButton</class>
<extends>Gui::ColorButton</extends>
@@ -560,6 +614,11 @@
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefLineEdit</class>
<extends>QLineEdit</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -96,6 +96,8 @@ void DlgStartPreferencesImp::saveSettings()
checkBox_3->onSave();
checkBox_4->onSave();
checkBox_5->onSave();
lineEdit->onSave();
spinBox->onSave();
}
void DlgStartPreferencesImp::loadSettings()
@@ -122,6 +124,8 @@ void DlgStartPreferencesImp::loadSettings()
checkBox_3->onRestore();
checkBox_4->onRestore();
checkBox_5->onRestore();
lineEdit->onRestore();
spinBox->onRestore();
}
/**

View File

@@ -23,7 +23,7 @@
import FreeCAD,FreeCADGui,os
# filename will be given before this script is run
FreeCAD.open(os.path.join(FreeCAD.getResourceDir()+"examples",filename))
FreeCAD.loadFile(os.path.join(FreeCAD.getResourceDir()+"examples",filename))
FreeCADGui.activeDocument().sendMsgToViews("ViewFit")
from StartPage import StartPage

View File

@@ -1,8 +1,8 @@
body {
background: BACKGROUND;
color: BGTCOLOR;
font-family: Arial, Helvetica, Sans;
font-size: 13px;
font-family: FONTFAMILY;
font-size: FONTSIZE;
}
a, a:link, a:visited {
text-decoration: none;

View File

@@ -88,6 +88,9 @@ def getInfo(filename):
return hsize
if os.path.exists(filename):
if os.path.isdir(filename):
return None,None,None
# get normal file info
s = os.stat(filename)
@@ -135,7 +138,8 @@ def getInfo(filename):
image = iconbank[t]
else:
icon = iconprovider.icon(i)
px = icon.pixmap(128,128)
preferred = icon.actualSize(QtCore.QSize(128,128))
px = icon.pixmap(preferred)
image = tempfile.mkstemp(dir=tempfolder,suffix='.png')[1]
px.save(image)
iconbank[t] = image
@@ -303,18 +307,19 @@ def handle():
SECTION_EXAMPLES += "<ul>"
for basename in os.listdir(FreeCAD.getResourceDir()+"examples"):
filename = FreeCAD.getResourceDir()+"examples"+os.sep+basename
image,size,author = getInfo(filename)
if size:
SECTION_EXAMPLES += '<li class="icon">'
SECTION_EXAMPLES += '<a href="LoadExample.py?filename='+basename+'" title="'+basename+'">'
SECTION_EXAMPLES += '<img src="'+image+'">'
SECTION_EXAMPLES += '</a>'
SECTION_EXAMPLES += '<div class="caption">'
SECTION_EXAMPLES += '<h4>'+basename+'</h4>'
SECTION_EXAMPLES += '<p>'+size+'</p>'
SECTION_EXAMPLES += '<p>'+author+'</p>'
SECTION_EXAMPLES += '</div>'
SECTION_EXAMPLES += '</li>'
if filename.endswith(".FCStd") or filename.endswith(".fcstd") or filename.endswith(".stp"):
image,size,author = getInfo(filename)
if size:
SECTION_EXAMPLES += '<li class="icon">'
SECTION_EXAMPLES += '<a href="LoadExample.py?filename='+basename+'" title="'+basename+'">'
SECTION_EXAMPLES += '<img src="'+image+'">'
SECTION_EXAMPLES += '</a>'
SECTION_EXAMPLES += '<div class="caption">'
SECTION_EXAMPLES += '<h4>'+basename+'</h4>'
SECTION_EXAMPLES += '<p>'+size+'</p>'
SECTION_EXAMPLES += '<p>'+author+'</p>'
SECTION_EXAMPLES += '</div>'
SECTION_EXAMPLES += '</li>'
SECTION_EXAMPLES += "</ul>"
if sys.version_info.major < 3:
SECTION_EXAMPLES = SECTION_EXAMPLES.decode("utf8")
@@ -417,7 +422,7 @@ def handle():
HTML = HTML.replace("var wblist = [];","var wblist = " + str(wblist) + ";")
# set and replace colors
# set and replace colors and font settings
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
if p.GetString("BackgroundImage",""):
@@ -433,14 +438,18 @@ def handle():
SHADOW = "#888888"
if QtGui.QColor(BASECOLOR).valueF() < 0.5: # dark page - we need to make darker shadows
SHADOW = "#000000"
FONTFAMILY = p.GetString("FontFamily","Arial,Helvetica,sans")
if not FONTFAMILY:
FONTFAMILY = "Arial,Helvetica,sans"
FONTSIZE = p.GetInt("FontSize",13)
HTML = HTML.replace("BASECOLOR",BASECOLOR)
HTML = HTML.replace("BOXCOLOR",BOXCOLOR)
HTML = HTML.replace("LINKCOLOR",LINKCOLOR)
HTML = HTML.replace("TEXTCOLOR",TEXTCOLOR)
HTML = HTML.replace("BGTCOLOR",BGTCOLOR)
HTML = HTML.replace("BACKGROUND",BACKGROUND)
HTML = HTML.replace("SHADOW",SHADOW)
HTML = HTML.replace("FONTFAMILY",FONTFAMILY)
HTML = HTML.replace("FONTSIZE",str(FONTSIZE)+"px")
# enable web access if permitted