Changed the text encoding menus of the old web browser to not show the alias names for the text codecs.

Sat, 27 May 2017 18:51:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 May 2017 18:51:22 +0200
changeset 5744
d53474dcb9e6
parent 5743
630a68372016
child 5745
4f4316e83318

Changed the text encoding menus of the old web browser to not show the alias names for the text codecs.

Helpviewer/HelpWindow.py file | annotate | diff | comparison | revisions
--- a/Helpviewer/HelpWindow.py	Sat May 27 18:17:03 2017 +0200
+++ b/Helpviewer/HelpWindow.py	Sat May 27 18:51:22 2017 +0200
@@ -3445,6 +3445,46 @@
         """
         return self.searchEdit.openSearchManager()
     
+    def __createTextEncodingAction(self, codec, defaultCodec, parentMenu):
+        """
+        Private method to create an action for the text encoding menu.
+        
+        @param codec name of the codec to create an action for
+        @type str
+        @param defaultCodec name of the default codec
+        @type str
+        @param parentMenu reference to the parent menu
+        @type QMenu
+        """
+        act = QAction(codec, parentMenu)
+        act.setData(codec)
+        act.setCheckable(True)
+        if defaultCodec == codec:
+            act.setChecked(True)
+        
+        parentMenu.addAction(act)
+    
+    def __createTextEncodingSubmenu(self, title, codecNames, parentMenu):
+        """
+        Private method to create a text encoding sub menu.
+        
+        @param title title of the menu
+        @type str
+        @param codecNames list of codec names for the menu
+        @type list of str
+        @param parentMenu reference to the parent menu
+        @type QMenu
+        """
+        if codecNames:
+            defaultCodec = \
+                QWebSettings.globalSettings().defaultTextEncoding().lower()
+            
+            menu = QMenu(title, parentMenu)
+            for codec in codecNames:
+                self.__createTextEncodingAction(codec, defaultCodec, menu)
+            
+            parentMenu.addMenu(menu)
+    
     def __aboutToShowTextEncodingMenu(self):
         """
         Private slot to populate the text encoding menu.
@@ -3452,8 +3492,11 @@
         self.__textEncodingMenu.clear()
         
         codecs = []
-        for codec in QTextCodec.availableCodecs():
-            codecs.append(str(codec, encoding="utf-8").lower())
+        for mib in QTextCodec.availableMibs():
+            codec = str(QTextCodec.codecForMib(mib).name(),
+                        encoding="utf-8").lower()
+            if codec not in codecs:
+                codecs.append(codec)
         codecs.sort()
         
         defaultTextEncoding = \
@@ -3461,47 +3504,44 @@
         if defaultTextEncoding in codecs:
             currentCodec = defaultTextEncoding
         else:
-            currentCodec = ""
-        
-        isDefaultEncodingUsed = True
-        isoMenu = QMenu(self.tr("ISO"), self.__textEncodingMenu)
-        winMenu = QMenu(self.tr("Windows"), self.__textEncodingMenu)
-        isciiMenu = QMenu(self.tr("ISCII"), self.__textEncodingMenu)
-        uniMenu = QMenu(self.tr("Unicode"), self.__textEncodingMenu)
-        otherMenu = QMenu(self.tr("Other"), self.__textEncodingMenu)
-        ibmMenu = QMenu(self.tr("IBM"), self.__textEncodingMenu)
+            currentCodec = "system"
+        
+        isoCodecs = []
+        winCodecs = []
+        isciiCodecs = []
+        uniCodecs = []
+        ibmCodecs = []
+        otherCodecs = []
         
         for codec in codecs:
-            if codec.startswith(("iso", "latin", "csisolatin")):
-                act = isoMenu.addAction(codec)
-            elif codec.startswith(("windows", "cp1")):
-                act = winMenu.addAction(codec)
+            if codec.startswith(("iso", "latin")):
+                isoCodecs.append(codec)
+            elif codec.startswith(("windows")):
+                winCodecs.append(codec)
             elif codec.startswith("iscii"):
-                act = isciiMenu.addAction(codec)
+                isciiCodecs.append(codec)
             elif codec.startswith("utf"):
-                act = uniMenu.addAction(codec)
-            elif codec.startswith(("ibm", "csibm", "cp")):
-                act = ibmMenu.addAction(codec)
+                uniCodecs.append(codec)
+            elif codec.startswith(("ibm")):
+                ibmCodecs.append(codec)
+            elif codec == "system":
+                self.__createTextEncodingAction(codec, currentCodec,
+                                                self.__textEncodingMenu)
             else:
-                act = otherMenu.addAction(codec)
-            
-            act.setData(codec)
-            act.setCheckable(True)
-            if currentCodec == codec:
-                act.setChecked(True)
-                isDefaultEncodingUsed = False
-        
-        act = self.__textEncodingMenu.addAction(
-            self.tr("Default Encoding"))
-        act.setData("")
-        act.setCheckable(True)
-        act.setChecked(isDefaultEncodingUsed)
-        self.__textEncodingMenu.addMenu(uniMenu)
-        self.__textEncodingMenu.addMenu(isoMenu)
-        self.__textEncodingMenu.addMenu(winMenu)
-        self.__textEncodingMenu.addMenu(ibmMenu)
-        self.__textEncodingMenu.addMenu(isciiMenu)
-        self.__textEncodingMenu.addMenu(otherMenu)
+                otherCodecs.append(codec)
+        
+        self.__createTextEncodingSubmenu(self.tr("ISO"), isoCodecs,
+                                         self.__textEncodingMenu)
+        self.__createTextEncodingSubmenu(self.tr("Unicode"), uniCodecs,
+                                         self.__textEncodingMenu)
+        self.__createTextEncodingSubmenu(self.tr("Windows"), winCodecs,
+                                         self.__textEncodingMenu)
+        self.__createTextEncodingSubmenu(self.tr("ISCII"), isciiCodecs,
+                                         self.__textEncodingMenu)
+        self.__createTextEncodingSubmenu(self.tr("IBM"), ibmCodecs,
+                                         self.__textEncodingMenu)
+        self.__createTextEncodingSubmenu(self.tr("Other"), otherCodecs,
+                                         self.__textEncodingMenu)
     
     def __setTextEncoding(self, act):
         """

eric ide

mercurial