From dd19005c95078149097134086c12806e88fe4202 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 23 Aug 2018 16:00:18 -0300 Subject: [PATCH] Start: misc improvements - Hide recent files section if recent files prefs is set to 0 - Better filetype management - Better tooltip on file thumbnails - Added notes section (enable in preferences) --- src/Mod/Start/Gui/DlgStartPreferences.ui | 296 +++++++++++-------- src/Mod/Start/Gui/DlgStartPreferencesImp.cpp | 2 + src/Mod/Start/StartPage/StartPage.css | 34 ++- src/Mod/Start/StartPage/StartPage.html | 34 ++- src/Mod/Start/StartPage/StartPage.js | 6 + src/Mod/Start/StartPage/StartPage.py | 187 ++++++------ src/Mod/Start/StartPage/TranslationTexts.py | 3 + src/Mod/Web/Gui/BrowserView.cpp | 5 + 8 files changed, 326 insertions(+), 241 deletions(-) diff --git a/src/Mod/Start/Gui/DlgStartPreferences.ui b/src/Mod/Start/Gui/DlgStartPreferences.ui index 88ac6d4d3b..d5a8167474 100644 --- a/src/Mod/Start/Gui/DlgStartPreferences.ui +++ b/src/Mod/Start/Gui/DlgStartPreferences.ui @@ -7,7 +7,7 @@ 0 0 476 - 645 + 743 @@ -37,12 +37,74 @@ - + - Start page options + Contents - - + + + + + Show forum + + + + + + + Show examples folder contents + + + + + + + Show additional folder + + + + + + + if you want the examples to show on the first page + + + Qt::RightToLeft + + + + + + true + + + ShowExamples + + + Mod/Start + + + + + + + If this is checked, the latest posts from the FreeCAD forum will be displayed on the Activity tab + + + Qt::RightToLeft + + + + + + ShowForum + + + Mod/Start + + + + an optional custom folder to be displayed at the bottom of the first page @@ -55,13 +117,41 @@ - - + + - Show additional folder + Show notepad + + + + Shows a notepad next to the file thumbnails, where you can keep notes across FreeCAD sessions + + + Qt::RightToLeft + + + + + + ShowNotes + + + Mod/Start + + + + + + + + + + Fonts and colors + + @@ -88,13 +178,6 @@ - - - - Show examples folder contents - - - @@ -110,7 +193,7 @@ false - in same page + in FreeCAD true @@ -197,13 +280,6 @@ - - - - Switch workbench after loafing - - - @@ -270,9 +346,6 @@ - - - @@ -397,35 +470,6 @@ - - - - Close start page after loading - - - - - - - if you want the examples to show on the first page - - - Qt::RightToLeft - - - - - - true - - - ShowExamples - - - Mod/Start - - - @@ -433,77 +477,6 @@ - - - - Should the start page be closed after loading? - - - Qt::RightToLeft - - - - - - closeStart - - - Mod/Start - - - - - - - Close & switch on file open - - - - - - - If FreeCAD is started by opening a file, apply the two settings above - - - Qt::RightToLeft - - - - - - DoNotShowOnOpen - - - Mod/Start - - - - - - - Show forum - - - - - - - If this is checked, the latest posts from the FreeCAD forum will be displayed on the Activity tab - - - Qt::RightToLeft - - - - - - ShowForum - - - Mod/Start - - - @@ -563,6 +536,77 @@ + + + + Options + + + + + + + + + Should the start page be closed after loading? + + + Qt::RightToLeft + + + + + + closeStart + + + Mod/Start + + + + + + + Switch workbench after loafing + + + + + + + Close start page after loading + + + + + + + Close & switch on file open + + + + + + + If FreeCAD is started by opening a file, apply the two settings above + + + Qt::RightToLeft + + + + + + DoNotShowOnOpen + + + Mod/Start + + + + + + diff --git a/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp b/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp index 48025b1263..b4a8eca936 100644 --- a/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp +++ b/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp @@ -91,6 +91,7 @@ void DlgStartPreferencesImp::saveSettings() fileChooser_3->onSave(); radioButton_1->onSave(); radioButton_2->onSave(); + checkBox->onSave(); checkBox_1->onSave(); checkBox_2->onSave(); checkBox_3->onSave(); @@ -119,6 +120,7 @@ void DlgStartPreferencesImp::loadSettings() fileChooser_3->onRestore(); radioButton_1->onRestore(); radioButton_2->onRestore(); + checkBox->onRestore(); checkBox_1->onRestore(); checkBox_2->onRestore(); checkBox_3->onRestore(); diff --git a/src/Mod/Start/StartPage/StartPage.css b/src/Mod/Start/StartPage/StartPage.css index f15541f949..d3cebf027b 100644 --- a/src/Mod/Start/StartPage/StartPage.css +++ b/src/Mod/Start/StartPage/StartPage.css @@ -9,9 +9,6 @@ a, a:link, a:visited { color: LINKCOLOR; font-weight: bold; } -a:hover { - text-decoration: underline; -} h1 { width: 100%; text-align: center; @@ -50,7 +47,7 @@ ul.tabs li a { font-size: 1em; font-weight: bold; text-transform: uppercase; - border:1px solid SHADOW; + border:1px solid BOXCOLOR; border-radius: 1px; box-shadow: #445 0 -5px 5px; outline: 0; @@ -101,6 +98,16 @@ ul.icons { .icon p { margin: 0; } +.caption { + clear: both; +} +a .caption, a .caption:link, a .caption:visited { + color: TEXTCOLOR; + text-decoration-color: TEXTCOLOR; +} +.docbox a:hover { + text-decoration: underline; +} .docbox { float: left; padding: 10px; @@ -153,8 +160,25 @@ ul.workbenches li, ul.addonslist li { width: 50%; } .forum { - display: none; /* forum display */ + 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 */ +} +.notes { + display: none; /* notes display */ /* don't change this line */ + float: right; + width: 30%; +} +#notepad { + width: 100%; + height: 100%; + color: TEXTCOLOR; + background: BOXCOLOR; + border: none; + padding: 5px; +} diff --git a/src/Mod/Start/StartPage/StartPage.html b/src/Mod/Start/StartPage/StartPage.html index 0168dc4ce9..37b84dc4a0 100644 --- a/src/Mod/Start/StartPage/StartPage.html +++ b/src/Mod/Start/StartPage/StartPage.html @@ -17,21 +17,31 @@
  • T_ACTIVITY
  • + +
    -

    T_RECENTFILES

    - - UL_RECENTFILES - -
    - T_TIP: T_ADJUSTRECENT
    + SECTION_RECENTFILES + +
    + T_TIP: T_ADJUSTRECENT
    +
    + + SECTION_EXAMPLES + + SECTION_CUSTOM + +
    + T_CUSTOM +
    +
    - SECTION_EXAMPLES - - SECTION_CUSTOM - -
    - T_CUSTOM +
    + +

    T_NOTES

    + + +
    diff --git a/src/Mod/Start/StartPage/StartPage.js b/src/Mod/Start/StartPage/StartPage.js index 578d78b436..1742a5253c 100644 --- a/src/Mod/Start/StartPage/StartPage.js +++ b/src/Mod/Start/StartPage/StartPage.js @@ -46,6 +46,12 @@ function load() { tobj.addScriptTag(); // Execute (add) the script tag ddiv.innerHTML = "Downloading addons list..."; } + if (localStorage["notepad"]) { + document.getElementById("notepad").value = localStorage["notepad"]; // Load notepad from local storage + } + document.getElementById("notepad").addEventListener( "input", function () { + localStorage.setItem("notepad", document.getElementById("notepad").value); // Save notepad on type + }, false); } } diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 5d18e661a6..05789ea963 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -47,23 +47,20 @@ def gethexcolor(color): -def isplainfile(filename): +def isOpenableByFreeCAD(filename): - "check if this is any type we don't want to show" + "check if FreeCAD can handle this file type" if os.path.isdir(filename): return False - basename = os.path.basename(filename) - if basename.startswith("."): - return False - if basename[-1].isdigit(): - if basename[-7:-1].lower() == "fcstd": # freecad backup file - return False - if basename.endswith("~"): - return False - if basename.lower().endswith(".bak"): - return False - return True + extensions = [key.lower() for key in FreeCAD.getImportType().keys()] + ext = os.path.splitext(filename)[1].lower() + if ext: + if ext[0] == ".": + ext = ext[1:] + if ext in extensions: + return True + return False @@ -72,10 +69,12 @@ def getInfo(filename): "returns available file information" global iconbank,tempfolder + + tformat = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("TimeFormat","%m/%d/%Y %H:%M:%S") def getLocalTime(timestamp): "returns a local time from a timestamp" - return time.strftime("%m/%d/%Y %H:%M:%S",time.localtime(timestamp)) + return time.strftime(tformat,time.localtime(timestamp)) def getSize(size): "returns a human-readable size" @@ -90,17 +89,18 @@ def getInfo(filename): if os.path.exists(filename): if os.path.isdir(filename): - return None,None,None + return None # get normal file info s = os.stat(filename) size = getSize(s.st_size) - #ctime = getLocalTime(s.st_ctime) - #mtime = getLocalTime(s.st_mtime) - author = TranslationTexts.T_UNKNOWN - #company = TranslationTexts.T_UNKNOWN - #lic = TranslationTexts.T_UNKNOWN + ctime = getLocalTime(s.st_ctime) + mtime = getLocalTime(s.st_mtime) + author = "" + company = TranslationTexts.T_UNKNOWN + lic = TranslationTexts.T_UNKNOWN image = None + descr = "" # get additional info from fcstd files if filename.lower().endswith(".fcstd"): @@ -113,12 +113,15 @@ def getInfo(filename): r = re.findall("Property name=\"CreatedBy.*?String value=\"(.*?)\"\/>",doc) if r: author = r[0] - #r = re.findall("Property name=\"Company.*?String value=\"(.*?)\"\/>",doc) - #if r: - # company = r - #r = re.findall("Property name=\"License.*?String value=\"(.*?)\"\/>",doc) - #if r: - # lic =r + r = re.findall("Property name=\"Company.*?String value=\"(.*?)\"\/>",doc) + if r: + company = r[0] + r = re.findall("Property name=\"License.*?String value=\"(.*?)\"\/>",doc) + if r: + lic = r[0] + r = re.findall("Property name=\"Comment.*?String value=\"(.*?)\"\/>",doc) + if r: + descr = r[0] if "thumbnails/Thumbnail.png" in files: if filename in iconbank: image = iconbank[filename] @@ -144,9 +147,42 @@ def getInfo(filename): px.save(image) iconbank[t] = image - return image,size,author + return [image,size,author,ctime,mtime,descr,company,lic] - return None,None,None + return None + + + +def buildCard(filename,method,arg=None): + + "builds a html
  • element representing a file. method is a script + a keyword, for ex. url.py?key=" + + result = "" + if os.path.exists(filename) and isOpenableByFreeCAD(filename): + basename = os.path.basename(filename) + if not arg: + arg = basename + finfo = getInfo(filename) + if finfo: + image = finfo[0] + size = finfo[1] + author = finfo[2] + infostring = TranslationTexts.T_CREATIONDATE+": "+finfo[3]+"\n" + infostring += TranslationTexts.T_LASTMODIFIED+": "+finfo[4] + if finfo[5]: + infostring += "\n\n" + finfo[5] + if size: + result += '
  • ' + result += '' + result += '' + result += '
    ' + result += '

    '+basename+'

    ' + result += '

    '+size+'

    ' + result += '

    '+author+'

    ' + result += '
    ' + result += '
    ' + result += '
  • ' + return result @@ -156,7 +192,6 @@ def handle(): global iconbank,tempfolder - # reuse stuff from previous runs to reduce temp dir clutter import Start @@ -167,7 +202,6 @@ def handle(): else: tempfolder = tempfile.mkdtemp(prefix="FreeCADStartThumbnails") - # build the html page skeleton resources_dir = os.path.join(FreeCAD.getResourceDir(), "Mod", "Start", "StartPage") @@ -188,7 +222,6 @@ def handle(): HTML = HTML.replace("JS",JS) HTML = HTML.replace("CSS",CSS) - # get the stylesheet if we are using one if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("UseStyleSheet",False): @@ -198,21 +231,18 @@ def handle(): ALTCSS = f.read().decode("utf8") HTML = HTML.replace("","") - # get FreeCAD version v = FreeCAD.Version() VERSIONSTRING = TranslationTexts.T_VERSION + " " + v[0] + "." + v[1] + " " + TranslationTexts.T_BUILD + " " + v[2] HTML = HTML.replace("VERSIONSTRING",VERSIONSTRING) - # translate texts HTML = HTML.replace("T_TITLE",TranslationTexts.T_TITLE) HTML = HTML.replace("T_DOCUMENTS",TranslationTexts.T_DOCUMENTS) HTML = HTML.replace("T_HELP",TranslationTexts.T_HELP) HTML = HTML.replace("T_ACTIVITY",TranslationTexts.T_ACTIVITY) - HTML = HTML.replace("T_RECENTFILES",TranslationTexts.T_RECENTFILES) HTML = HTML.replace("T_TIP",TranslationTexts.T_TIP) HTML = HTML.replace("T_ADJUSTRECENT",TranslationTexts.T_ADJUSTRECENT) HTML = HTML.replace("T_GENERALDOCUMENTATION",TranslationTexts.T_GENERALDOCUMENTATION) @@ -241,7 +271,7 @@ def handle(): HTML = HTML.replace("T_FORUM",TranslationTexts.T_FORUM) HTML = HTML.replace("T_DESCR_FORUM",TranslationTexts.T_DESCR_FORUM) HTML = HTML.replace("T_EXTERNALLINKS",TranslationTexts.T_EXTERNALLINKS) - + HTML = HTML.replace("T_NOTES",TranslationTexts.T_NOTES) # build a "create new" icon with the FreeCAD background color gradient @@ -260,44 +290,29 @@ def handle(): i.save(createimg) iconbank["createimg"] = createimg + # build SECTION_RECENTFILES - # build UL_RECENTFILES - + SECTION_RECENTFILES = "" rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles") rfcount = rf.GetInt("RecentFiles",0) if rfcount: - UL_RECENTFILES = "' if sys.version_info.major < 3: - UL_RECENTFILES = UL_RECENTFILES.decode("utf8") - HTML = HTML.replace("UL_RECENTFILES",UL_RECENTFILES) - + SECTION_RECENTFILES = SECTION_RECENTFILES.decode("utf8") + HTML = HTML.replace("SECTION_RECENTFILES",SECTION_RECENTFILES) # build SECTION_EXAMPLES @@ -307,25 +322,12 @@ def handle(): SECTION_EXAMPLES += "
      " for basename in os.listdir(FreeCAD.getResourceDir()+"examples"): filename = FreeCAD.getResourceDir()+"examples"+os.sep+basename - if filename.endswith(".FCStd") or filename.endswith(".fcstd") or filename.endswith(".stp"): - image,size,author = getInfo(filename) - if size: - SECTION_EXAMPLES += '
    • ' - SECTION_EXAMPLES += '' - SECTION_EXAMPLES += '' - SECTION_EXAMPLES += '' - SECTION_EXAMPLES += '
      ' - SECTION_EXAMPLES += '

      '+basename+'

      ' - SECTION_EXAMPLES += '

      '+size+'

      ' - SECTION_EXAMPLES += '

      '+author+'

      ' - SECTION_EXAMPLES += '
      ' - SECTION_EXAMPLES += '
    • ' + SECTION_EXAMPLES += buildCard(filename,method="LoadExample.py?filename=") SECTION_EXAMPLES += "
    " if sys.version_info.major < 3: SECTION_EXAMPLES = SECTION_EXAMPLES.decode("utf8") HTML = HTML.replace("SECTION_EXAMPLES",SECTION_EXAMPLES) - # build SECTION_CUSTOM SECTION_CUSTOM = "" @@ -337,25 +339,12 @@ def handle(): SECTION_CUSTOM += "
      " for basename in os.listdir(cfolder): filename = os.path.join(cfolder,basename) - if isplainfile(filename): - image,size,author = getInfo(filename) - if size: - SECTION_CUSTOM += '
    • ' - SECTION_CUSTOM += '' - SECTION_CUSTOM += '' - SECTION_CUSTOM += '' - SECTION_CUSTOM += '
      ' - SECTION_CUSTOM += '

      '+basename+'

      ' - SECTION_CUSTOM += '

      '+size+'

      ' - SECTION_CUSTOM += '

      '+author+'

      ' - SECTION_CUSTOM += '
      ' - SECTION_CUSTOM += '
    • ' + SECTION_CUSTOM += buildCard(filename,method="LoadCustom.py?filename=") SECTION_CUSTOM += "
    " if sys.version_info.major < 3: SECTION_CUSTOM = SECTION_CUSTOM.decode("utf8") HTML = HTML.replace("SECTION_CUSTOM",SECTION_CUSTOM) - # build UL_WORKBENCHES wblist = [] @@ -401,6 +390,7 @@ def handle(): HTML = HTML.replace("UL_WORKBENCHES",UL_WORKBENCHES) # Detect additional addons that are not a workbench + try: import dxfLibrary except: @@ -421,7 +411,6 @@ def handle(): wblist.append("cadexchanger") HTML = HTML.replace("var wblist = [];","var wblist = " + str(wblist) + ";") - # set and replace colors and font settings p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start") @@ -451,26 +440,28 @@ def handle(): HTML = HTML.replace("FONTFAMILY",FONTFAMILY) HTML = HTML.replace("FONTSIZE",str(FONTSIZE)+"px") - # enable web access if permitted if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("AllowDownload",False): HTML = HTML.replace("var allowDownloads = 0;","var allowDownloads = 1;") - # enable or disable forum if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("ShowForum",False): HTML = HTML.replace("var showForum = 0;","var showForum = 1;") HTML = HTML.replace("display: none; /* forum display */","display: block; /* forum display */") + # enable or disable notepad + + if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("ShowNotes",False): + HTML = HTML.replace("display: none; /* notes display */","display: block; /* notes display */") + HTML = HTML.replace("width: 100%; /* thumbs display */","width: 70%; /* thumbs display */") # store variables for further use Start.iconbank = iconbank Start.tempfolder = tempfolder - # encode if necessary if sys.version_info.major < 3: diff --git a/src/Mod/Start/StartPage/TranslationTexts.py b/src/Mod/Start/StartPage/TranslationTexts.py index f1c9d274b7..d22cd151e0 100644 --- a/src/Mod/Start/StartPage/TranslationTexts.py +++ b/src/Mod/Start/StartPage/TranslationTexts.py @@ -77,3 +77,6 @@ T_UNKNOWN = translate("StartPage", "Unknown") T_FORUM = translate("StartPage", "Forum") T_DESCR_FORUM = translate("StartPage", "The latest posts on the FreeCAD forum:") T_EXTERNALLINKS = translate("StartPage", "To open any of the links above in your desktop browser, Right-click -> Open in external browser") +T_CREATIONDATE = translate("StartPage", "Creation date") +T_LASTMODIFIED = translate("StartPage", "Last modification") +T_NOTES = translate("StartPage", "Notes") diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index c2e735de68..262670141c 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -232,6 +232,11 @@ BrowserView::BrowserView(QWidget* parent) // set our custom cookie manager FcCookieJar* cookiejar = new FcCookieJar(this); view->page()->networkAccessManager()->setCookieJar(cookiejar); + + // enable local storage so we can store stuff across sessions (startpage) + QWebSettings* settings = view->settings(); + settings->setAttribute(QWebSettings::LocalStorageEnabled, true); + settings->setLocalStoragePath(QString::fromUtf8((App::Application::getUserAppDataDir()+"webdata").c_str())); // setting background to white QPalette palette = view->palette();