From eef27b845f5409dafbe3434ef16cd0fd3c06b311 Mon Sep 17 00:00:00 2001 From: luz paz Date: Sat, 8 Jan 2022 11:29:27 -0500 Subject: [PATCH] Start: header uniformity + whitespace management + misc. pep8 fixes --- src/Mod/Start/StartPage/EnableDownload.py | 5 ++-- src/Mod/Start/StartPage/LoadCustom.py | 16 ++++++++----- src/Mod/Start/StartPage/LoadExample.py | 8 ++++--- src/Mod/Start/StartPage/LoadMRU.py | 1 - src/Mod/Start/StartPage/LoadNew.py | 3 +-- src/Mod/Start/StartPage/OpenSettings.py | 1 - src/Mod/Start/StartPage/StartPage.py | 26 ++++++++++++++------- src/Mod/Start/StartPage/TranslationTexts.py | 2 +- src/Mod/Start/TestStart/TestStartPage.py | 8 +++---- 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/Mod/Start/StartPage/EnableDownload.py b/src/Mod/Start/StartPage/EnableDownload.py index f7f117969e..1e85c0b9f6 100644 --- a/src/Mod/Start/StartPage/EnableDownload.py +++ b/src/Mod/Start/StartPage/EnableDownload.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2012 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * @@ -21,5 +20,5 @@ #*************************************************************************** import FreeCAD -rf=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start") -rf.SetBool("AllowDownload",True) +rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start") +rf.SetBool("AllowDownload", True) diff --git a/src/Mod/Start/StartPage/LoadCustom.py b/src/Mod/Start/StartPage/LoadCustom.py index 21efebc213..2cdaa1e0e6 100644 --- a/src/Mod/Start/StartPage/LoadCustom.py +++ b/src/Mod/Start/StartPage/LoadCustom.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2018 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * @@ -20,11 +19,17 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,os,sys +import os +import sys +import FreeCAD +import FreeCADGui + if sys.version_info.major < 3: from urllib import unquote else: from urllib.parse import unquote + + # filename will be given before this script is run cfolders = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetString("ShowCustomFolder","") if cfolders: @@ -33,13 +38,12 @@ if cfolders: cfolder = cfolders.split(";;")[dirnumber] if not os.path.isdir(cfolder): cfolder = os.path.dirname(cfolder) - f = unquote(filename).replace("+"," ") + f = unquote(filename).replace("+", " ") if f.lower().endswith(".fcstd"): - FreeCAD.open(os.path.join(cfolder,f)) + FreeCAD.open(os.path.join(cfolder, f)) else: - FreeCAD.loadFile(os.path.join(cfolder,f)) + FreeCAD.loadFile(os.path.join(cfolder, f)) FreeCADGui.activeDocument().sendMsgToViews("ViewFit") from StartPage import StartPage StartPage.postStart() - diff --git a/src/Mod/Start/StartPage/LoadExample.py b/src/Mod/Start/StartPage/LoadExample.py index 3031b177cc..1b689fb3f5 100644 --- a/src/Mod/Start/StartPage/LoadExample.py +++ b/src/Mod/Start/StartPage/LoadExample.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2016 Bernd Hahnebach * #* * #* This program is free software; you can redistribute it and/or modify * @@ -20,9 +19,12 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,os +import os +import FreeCAD +import FreeCADGui + # filename will be given before this script is run -FreeCAD.loadFile(os.path.join(FreeCAD.getResourceDir()+"examples",filename)) +FreeCAD.loadFile(os.path.join(FreeCAD.getResourceDir() + "examples", filename)) FreeCADGui.activeDocument().sendMsgToViews("ViewFit") from StartPage import StartPage diff --git a/src/Mod/Start/StartPage/LoadMRU.py b/src/Mod/Start/StartPage/LoadMRU.py index 7b7e14c7d6..61fa84f934 100644 --- a/src/Mod/Start/StartPage/LoadMRU.py +++ b/src/Mod/Start/StartPage/LoadMRU.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2018 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * diff --git a/src/Mod/Start/StartPage/LoadNew.py b/src/Mod/Start/StartPage/LoadNew.py index bf0040ceba..db75b4f8ee 100644 --- a/src/Mod/Start/StartPage/LoadNew.py +++ b/src/Mod/Start/StartPage/LoadNew.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2018 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * @@ -27,4 +26,4 @@ FreeCAD.newDocument() FreeCADGui.activeDocument().activeView().viewDefaultOrientation() from StartPage import StartPage -StartPage.postStart() \ No newline at end of file +StartPage.postStart() diff --git a/src/Mod/Start/StartPage/OpenSettings.py b/src/Mod/Start/StartPage/OpenSettings.py index 65fe7993ce..fe92339ebb 100644 --- a/src/Mod/Start/StartPage/OpenSettings.py +++ b/src/Mod/Start/StartPage/OpenSettings.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2020 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 88556f1fb4..74466276ce 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2018 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * @@ -21,22 +20,30 @@ #*************************************************************************** -# This is the start page template. It builds a HTML global variable that contains -# the html code of the start page. It is built only once per FreeCAD session for now... +# This is the start page template. It builds an HTML global variable that +# contains the html code of the start page. +# Note: It is built only once per FreeCAD session for now... import six -import sys,os,FreeCAD,FreeCADGui,tempfile,time,zipfile,re +import sys +import os +import tempfile +import time +import zipfile +import re +import FreeCAD +import FreeCADGui import urllib.parse from . import TranslationTexts -from PySide import QtCore,QtGui +from PySide import QtCore, QtGui FreeCADGui.addLanguagePath(":/translations") FreeCADGui.updateLocale() iconprovider = QtGui.QFileIconProvider() -iconbank = {} # to store already created icons so we don't overpollute the temp dir -tempfolder = None # store icons inside a subfolder in temp dir -defaulticon = None # store a default icon for problematic file types +iconbank = {} # store pre-existing icons so we don't overpollute temp dir +tempfolder = None # store icons inside a subfolder in temp dir +defaulticon = None # store a default icon for problematic file types def encode(text): @@ -235,7 +242,8 @@ def getDefaultIcon(): def buildCard(filename,method,arg=None): - "builds a html
  • element representing a file. method is a script + a keyword, for ex. url.py?key=" + """builds an html
  • element representing a file. + method is a script + a keyword, for ex. url.py?key=""" result = encode("") if os.path.exists(filename) and isOpenableByFreeCAD(filename): diff --git a/src/Mod/Start/StartPage/TranslationTexts.py b/src/Mod/Start/StartPage/TranslationTexts.py index dbe76a34d5..edb0d98f13 100644 --- a/src/Mod/Start/StartPage/TranslationTexts.py +++ b/src/Mod/Start/StartPage/TranslationTexts.py @@ -1,5 +1,4 @@ #*************************************************************************** -#* * #* Copyright (c) 2012 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * @@ -23,6 +22,7 @@ import sys from PySide import QtGui + def translate(context,text): "convenience function for the Qt translator" diff --git a/src/Mod/Start/TestStart/TestStartPage.py b/src/Mod/Start/TestStart/TestStartPage.py index 7cc1da5761..01d4b9e6ab 100644 --- a/src/Mod/Start/TestStart/TestStartPage.py +++ b/src/Mod/Start/TestStart/TestStartPage.py @@ -40,7 +40,7 @@ class TestStartPage(unittest.TestCase): """Check to see if all of the CSS placeholders have been replaced.""" placeholders = ["BACKGROUND","BGTCOLOR","FONTFAMILY","FONTSIZE","LINKCOLOR", "TEXTCOLOR","BOXCOLOR","BASECOLOR","SHADOW"] - + page = StartPage.handle() for placeholder in placeholders: self.assertNotIn (placeholder, page, "{} was not removed from the CSS".format(placeholder)) @@ -87,7 +87,7 @@ class TestStartPage(unittest.TestCase): if len(badFilenames) > 0: self.fail("The following filenames contain backslashes, which is prohibited in HTML: {}".format(badFilenames)) - + def test_html_validates(self): # Send the generated html to the W3C validator for analysis (removing potentially-sensitive data first) @@ -139,7 +139,7 @@ class TestStartPage(unittest.TestCase): except urllib.error.URLError: FreeCAD.Console.PrintWarning("Could not communicate with W3C validator") - + if errorCount > 0 or warningCount > 0: StartPage.exportTestFile() FreeCAD.Console.PrintWarning("HTML validation failed: Start page source written to your home directory for analysis.") @@ -156,7 +156,7 @@ class TestStartPage(unittest.TestCase): # Anonymize titles, which are used for mouseover text and might contain document information titleRE = re.compile(r'title="[\s\S]*?"') # Some titles have newlines in them html = titleRE.sub(repl=r'title="Y"', string=html) - + # Anonymize the document names, which we display in

    tags h4RE = re.compile(r'

    .*?

    ') html = h4RE.sub(repl=r'

    Z

    ', string=html)