eric6/Preferences/__init__.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8265
0090cfa83159
child 8400
b3eefd7e58d1
--- a/eric6/Preferences/__init__.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/Preferences/__init__.py	Sat May 01 14:27:20 2021 +0200
@@ -22,6 +22,7 @@
 import shutil
 import json
 import sys
+import contextlib
 
 from PyQt5.QtCore import (
     QDir, QPoint, QLocale, QSettings, QFileInfo, QCoreApplication, QByteArray,
@@ -50,7 +51,7 @@
 from QScintilla.Shell import ShellHistoryStyle
 
 
-class Prefs(object):
+class Prefs:
     """
     A class to hold all configuration items for the application.
     """
@@ -1148,15 +1149,13 @@
                 webEngineSettings.testAttribute(
                     QWebEngineSettings.WebAttribute.DnsPrefetchEnabled),
         })
-        try:
+        with contextlib.suppress(AttributeError):
             # Qt 5.13
             cls.webBrowserDefaults.update({
                 "PdfViewerEnabled":
                     webEngineSettings.testAttribute(
                         QWebEngineSettings.WebAttribute.PdfViewerEnabled),
             })
-        except AttributeError:
-            pass
         
         cls.webEngineSettingsIntitialized = True
     
@@ -1175,7 +1174,7 @@
         "CallTipsEnabled": True,
         "WrapEnabled": True,
         "MaxHistoryEntries": 100,
-        "HistoryStyle": ShellHistoryStyle.LinuxStyle,
+        "HistoryStyle": ShellHistoryStyle.LINUXSTYLE,
         "HistoryWrap": False,
         "HistoryNavigateByCursor": False,
         "SyntaxHighlightingEnabled": True,
@@ -1574,14 +1573,12 @@
     
     # second step, write the tool group entries
     prefClass.settings.setValue("Toolgroups/Groups", len(toolGroups))
-    groupIndex = 0
-    for group in toolGroups:
+    for groupIndex, group in enumerate(toolGroups):
         prefClass.settings.setValue(
             "Toolgroups/{0:02d}/Name".format(groupIndex), group[0])
         prefClass.settings.setValue(
             "Toolgroups/{0:02d}/Items".format(groupIndex), len(group[1]))
-        ind = 0
-        for tool in group[1]:
+        for ind, tool in enumerate(group[1]):
             prefClass.settings.setValue(
                 "Toolgroups/{0:02d}/{1:02d}/Menutext".format(groupIndex, ind),
                 tool['menutext'])
@@ -1598,8 +1595,6 @@
             prefClass.settings.setValue(
                 "Toolgroups/{0:02d}/{1:02d}/Redirect".format(groupIndex, ind),
                 tool['redirect'])
-            ind += 1
-        groupIndex += 1
     prefClass.settings.setValue("Toolgroups/Current Group", currentGroup)
     
 
@@ -1618,11 +1613,9 @@
         dn.mkdir(".eric6")
     QCoreApplication.setOrganizationName(Globals.settingsNameOrganization)
     QCoreApplication.setApplicationName(Globals.settingsNameGlobal)
-    try:
+    with contextlib.suppress(AttributeError):
         Prefs.settings.setAtomicSyncRequired(False)
-    except AttributeError:
-        # backward compatibility fot Qt < 5.10
-        pass
+        # backward compatibility for Qt < 5.10
     
     Prefs.settings.value("UI/SingleApplicationMode")
     
@@ -1789,10 +1782,7 @@
             return "standard"
         else:
             return debugClientType
-    elif key == "PythonExtensions":
-        # we don't support Python2 anymore
-        return ""
-    elif key == "Python2VirtualEnv":
+    elif key in ("PythonExtensions", "Python2VirtualEnv"):
         # we don't support Python2 anymore
         return ""
     else:
@@ -1877,7 +1867,7 @@
     """
     lang = prefClass.settings.value("UI/Language",
                                     prefClass.uiDefaults["Language"])
-    if lang == "None" or lang == "" or lang is None:
+    if lang in ("None", "", None):
         return None
     else:
         return lang
@@ -2204,10 +2194,8 @@
     @param value the colour to be set
     @param prefClass preferences class used as the storage area
     """
-    if value.alpha() < 255:
-        val = "#{0:8x}".format(value.rgba())
-    else:
-        val = value.name()
+    val = ("#{0:8x}".format(value.rgba()) if value.alpha() < 255
+           else value.name())
     prefClass.settings.setValue("Editor/Colour/" + key, val)
     
 
@@ -2250,10 +2238,7 @@
     @return requested list of API files
     @rtype list of str
     """
-    if projectType:
-        key = "{0}_{1}".format(language, projectType)
-    else:
-        key = language
+    key = "{0}_{1}".format(language, projectType) if projectType else language
     apis = prefClass.settings.value("Editor/APIs/" + key)
     if apis is not None:
         if len(apis) and apis[0] == "":
@@ -2281,10 +2266,7 @@
     @param prefClass preferences class used as the storage area
     @type Prefs
     """
-    if projectType:
-        key = "{0}_{1}".format(language, projectType)
-    else:
-        key = language
+    key = "{0}_{1}".format(language, projectType) if projectType else language
     prefClass.settings.setValue("Editor/APIs/" + key, apilist)
     
 
@@ -2336,10 +2318,7 @@
             editorLexerAssoc[key] = editorLexerAssocDefaults[key]
     else:
         for key in keyList:
-            if key in editorLexerAssocDefaults:
-                defaultValue = editorLexerAssocDefaults[key]
-            else:
-                defaultValue = ""
+            defaultValue = editorLexerAssocDefaults.get(key, "")
             editorLexerAssoc[key] = prefClass.settings.value(
                 "Editor/LexerAssociations/" + key, defaultValue)
         
@@ -2891,20 +2870,17 @@
         # value is list of tuples of (keyword, engine name)
         prefClass.settings.remove("WebBrowser/" + key)
         prefClass.settings.beginWriteArray("WebBrowser/" + key, len(value))
-        index = 0
-        for v in value:
+        for index, v in enumerate(value):
             prefClass.settings.setArrayIndex(index)
             prefClass.settings.setValue("Keyword", v[0])
             prefClass.settings.setValue("Engine", v[1])
-            index += 1
         prefClass.settings.endArray()
     elif key == "DownloadManagerDownloads":
         # value is list of dicts containing the URL, save location, done flag,
         # page URL, date/time downloaded
         prefClass.settings.remove("Help/" + key)
         prefClass.settings.beginWriteArray("WebBrowser/" + key, len(value))
-        index = 0
-        for v in value:
+        for index, v in enumerate(value):
             prefClass.settings.setArrayIndex(index)
             prefClass.settings.setValue("URL", v["URL"])
             prefClass.settings.setValue("Location", v["Location"])
@@ -2912,19 +2888,16 @@
             prefClass.settings.setValue("PageURL", v["PageURL"])
             prefClass.settings.setValue(
                 "Downloaded", v["Downloaded"].toString("yyyy-MM-dd hh:mm:ss"))
-            index += 1
         prefClass.settings.endArray()
     elif key == "RssFeeds":
         # value is list of tuples of (URL, title, icon)
         prefClass.settings.remove("WebBrowser/" + key)
         prefClass.settings.beginWriteArray("WebBrowser/" + key, len(value))
-        index = 0
-        for v in value:
+        for index, v in enumerate(value):
             prefClass.settings.setArrayIndex(index)
             prefClass.settings.setValue("URL", v[0])
             prefClass.settings.setValue("Title", v[1])
             prefClass.settings.setValue("Icon", v[2])
-            index += 1
         prefClass.settings.endArray()
     elif key in ["SyncFtpPassword", "SyncEncryptionKey"]:
         from Utilities.crypto import pwConvert
@@ -3486,10 +3459,8 @@
     @param value the colour to be set
     @param prefClass preferences class used as the storage area
     """
-    if value.alpha() < 255:
-        val = "#{0:8x}".format(value.rgba())
-    else:
-        val = value.name()
+    val = ("#{0:8x}".format(value.rgba())
+           if value.alpha() < 255 else value.name())
     prefClass.settings.setValue("Diff/" + key, val)
 
 

eric ide

mercurial