eric6/Project/Project.py

changeset 8240
93b8a353c4bf
parent 8237
acc1490f822e
child 8243
cc717c2ae956
equal deleted inserted replaced
8239:59a9a658618c 8240:93b8a353c4bf
12 import shutil 12 import shutil
13 import glob 13 import glob
14 import fnmatch 14 import fnmatch
15 import copy 15 import copy
16 import zipfile 16 import zipfile
17 import contextlib
17 18
18 from PyQt5.QtCore import ( 19 from PyQt5.QtCore import (
19 pyqtSlot, QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, 20 pyqtSlot, QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice,
20 QByteArray, QObject, QProcess 21 QByteArray, QObject, QProcess
21 ) 22 )
642 "PySide6", "PySide6C"]: 643 "PySide6", "PySide6C"]:
643 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" 644 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS"
644 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" 645 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS"
645 646
646 # Project type specific ones 647 # Project type specific ones
647 try: 648 with contextlib.suppress(KeyError):
648 if self.__fileTypeCallbacks[ 649 if self.__fileTypeCallbacks[
649 self.pdata["PROJECTTYPE"]] is not None: 650 self.pdata["PROJECTTYPE"]] is not None:
650 ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() 651 ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]()
651 self.pdata["FILETYPES"].update(ftypes) 652 self.pdata["FILETYPES"].update(ftypes)
652 except KeyError:
653 pass
654 653
655 self.setDirty(True) 654 self.setDirty(True)
656 655
657 def updateFileTypes(self): 656 def updateFileTypes(self):
658 """ 657 """
666 "PySide6", "PySide6C"]: 665 "PySide6", "PySide6C"]:
667 if "*.ts" not in self.pdata["FILETYPES"]: 666 if "*.ts" not in self.pdata["FILETYPES"]:
668 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" 667 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS"
669 if "*.qm" not in self.pdata["FILETYPES"]: 668 if "*.qm" not in self.pdata["FILETYPES"]:
670 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" 669 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS"
671 try: 670 with contextlib.suppress(KeyError):
672 if self.__fileTypeCallbacks[ 671 if self.__fileTypeCallbacks[
673 self.pdata["PROJECTTYPE"]] is not None: 672 self.pdata["PROJECTTYPE"]] is not None:
674 ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() 673 ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]()
675 for pattern, ftype in list(ftypes.items()): 674 for pattern, ftype in list(ftypes.items()):
676 if pattern not in self.pdata["FILETYPES"]: 675 if pattern not in self.pdata["FILETYPES"]:
677 self.pdata["FILETYPES"][pattern] = ftype 676 self.pdata["FILETYPES"][pattern] = ftype
678 self.setDirty(True) 677 self.setDirty(True)
679 except KeyError:
680 pass
681 678
682 def __loadRecent(self): 679 def __loadRecent(self):
683 """ 680 """
684 Private method to load the recently opened project filenames. 681 Private method to load the recently opened project filenames.
685 """ 682 """
2918 if fnmatch.fnmatch(filename, pattern): 2915 if fnmatch.fnmatch(filename, pattern):
2919 return language 2916 return language
2920 2917
2921 # try project type specific defaults next 2918 # try project type specific defaults next
2922 projectType = self.pdata["PROJECTTYPE"] 2919 projectType = self.pdata["PROJECTTYPE"]
2923 try: 2920 with contextlib.suppress(KeyError):
2924 if self.__lexerAssociationCallbacks[projectType] is not None: 2921 if self.__lexerAssociationCallbacks[projectType] is not None:
2925 return self.__lexerAssociationCallbacks[projectType](filename) 2922 return self.__lexerAssociationCallbacks[projectType](filename)
2926 except KeyError:
2927 pass
2928 2923
2929 # return empty string to signal to use the global setting 2924 # return empty string to signal to use the global setting
2930 return "" 2925 return ""
2931 2926
2932 @pyqtSlot() 2927 @pyqtSlot()
4780 Public method to remove actions from the list of actions. 4775 Public method to remove actions from the list of actions.
4781 4776
4782 @param actions list of actions (list of E5Action) 4777 @param actions list of actions (list of E5Action)
4783 """ 4778 """
4784 for act in actions: 4779 for act in actions:
4785 try: 4780 with contextlib.suppress(ValueError):
4786 self.actions.remove(act) 4781 self.actions.remove(act)
4787 except ValueError:
4788 pass
4789 4782
4790 def getMenu(self, menuName): 4783 def getMenu(self, menuName):
4791 """ 4784 """
4792 Public method to get a reference to the main menu or a submenu. 4785 Public method to get a reference to the main menu or a submenu.
4793 4786

eric ide

mercurial