src/eric7/Project/Project.py

branch
eric7-maintenance
changeset 10272
7ae72d1df070
parent 10174
6aac1022f330
parent 10263
f4bb67586615
child 10349
df7edc29cbfb
equal deleted inserted replaced
10226:3a99ac054b39 10272:7ae72d1df070
710 @return list of known file categories 710 @return list of known file categories
711 @rtype list of str 711 @rtype list of str
712 """ 712 """
713 return list(self.__fileCategoriesRepository.keys()) 713 return list(self.__fileCategoriesRepository.keys())
714 714
715 def getFileCategoryFilters(
716 self, categories=None, withOthers=False, withAll=True
717 ):
718 """
719 Public method to get a list of file selection filters for the given categories.
720
721 @param categories list of file type categories (defaults to None).
722 A value of None means all categories except 'OTHERS'.
723 @type list of str (optional)
724 @param withOthers flag indicating to include the 'OTHERS' category
725 (defaults to False)
726 @type bool (optional)
727 @param withAll flag indicating to include a filter for 'All Files'
728 (defaults to True)
729 @type bool (optional)
730 @return list of file selection filter strings
731 @rtype list of str
732 """
733 if categories is None:
734 categories = [c for c in self.__fileCategoriesRepository if c != "OTHERS"]
735 if withOthers:
736 categories.append("OTHERS")
737
738 patterns = collections.defaultdict(list)
739 for pattern, filetype in self.__pdata["FILETYPES"].items():
740 if filetype in categories and filetype in self.__fileCategoriesRepository:
741 patterns[filetype].append(pattern)
742
743 filters = []
744 for filetype in patterns:
745 filters.append(
746 self.__fileCategoriesRepository[
747 filetype.upper()
748 ].fileCategoryFilterTemplate.format(
749 " ".join(sorted(patterns[filetype]))
750 )
751 )
752 filters = sorted(filters)
753 if withAll:
754 filters.append(self.tr("All Files (*)"))
755
756 return filters
757
715 def getFileCategoryFilterString( 758 def getFileCategoryFilterString(
716 self, categories=None, withOthers=False, withAll=True 759 self, categories=None, withOthers=False, withAll=True
717 ): 760 ):
718 """ 761 """
719 Public method to get a file selection string for the given categories. 762 Public method to get a file selection string for the given categories.
728 (defaults to True) 771 (defaults to True)
729 @type bool (optional) 772 @type bool (optional)
730 @return file selection filter string 773 @return file selection filter string
731 @rtype str 774 @rtype str
732 """ 775 """
733 if categories is None: 776 return ";;".join(
734 categories = [c for c in self.__fileCategoriesRepository if c != "OTHERS"] 777 self.getFileCategoryFilters(
735 if withOthers: 778 categ=categories, withOthers=withOthers, withAll=withAll
736 categories.append("OTHERS") 779 )
737 780 )
738 patterns = collections.defaultdict(list)
739 for pattern, filetype in self.__pdata["FILETYPES"].items():
740 if filetype in categories and filetype in self.__fileCategoriesRepository:
741 patterns[filetype].append(pattern)
742
743 filters = []
744 for filetype in patterns:
745 filters.append(
746 self.__fileCategoriesRepository[
747 filetype.upper()
748 ].fileCategoryFilterTemplate.format(
749 " ".join(sorted(patterns[filetype]))
750 )
751 )
752 filterString = ";;".join(sorted(filters))
753 if withAll:
754 filterString += ";;" + self.tr("All Files (*)")
755
756 return filterString
757 781
758 def getFileCategoryString(self, category): 782 def getFileCategoryString(self, category):
759 """ 783 """
760 Public method to get a user string for the given category. 784 Public method to get a user string for the given category.
761 785
1754 1778
1755 @param langFile the translation file to be removed (string) 1779 @param langFile the translation file to be removed (string)
1756 """ 1780 """
1757 langFile = self.getRelativePath(langFile) 1781 langFile = self.getRelativePath(langFile)
1758 qmFile = self.__binaryTranslationFile(langFile) 1782 qmFile = self.__binaryTranslationFile(langFile)
1759 self.__pdata["TRANSLATIONS"].remove(langFile) 1783 with contextlib.suppress(ValueError):
1760 self.__model.removeItem(langFile) 1784 self.__model.removeItem(langFile)
1785 self.__pdata["TRANSLATIONS"].remove(langFile)
1761 if qmFile: 1786 if qmFile:
1762 with contextlib.suppress(ValueError): 1787 with contextlib.suppress(ValueError):
1763 if self.__pdata["TRANSLATIONSBINPATH"]: 1788 if self.__pdata["TRANSLATIONSBINPATH"]:
1764 qmFile = self.getRelativePath( 1789 qmFile = self.getRelativePath(
1765 os.path.join( 1790 os.path.join(
1766 self.__pdata["TRANSLATIONSBINPATH"], 1791 self.__pdata["TRANSLATIONSBINPATH"],
1767 os.path.basename(qmFile), 1792 os.path.basename(qmFile),
1768 ) 1793 )
1769 ) 1794 )
1795 self.__model.removeItem(qmFile)
1770 self.__pdata["TRANSLATIONS"].remove(qmFile) 1796 self.__pdata["TRANSLATIONS"].remove(qmFile)
1771 self.__model.removeItem(qmFile)
1772 self.setDirty(True) 1797 self.setDirty(True)
1773 1798
1774 def deleteLanguageFile(self, langFile): 1799 def deleteLanguageFile(self, langFile):
1775 """ 1800 """
1776 Public slot to delete a translation from the project directory. 1801 Public slot to delete a translation from the project directory.
1899 @param startdir start directory for the selection dialog 1924 @param startdir start directory for the selection dialog
1900 @type str 1925 @type str
1901 """ 1926 """
1902 from .AddFileDialog import AddFileDialog 1927 from .AddFileDialog import AddFileDialog
1903 1928
1904 if startdir is None: 1929 if not startdir:
1905 startdir = self.ppath 1930 startdir = self.ppath
1906 1931
1907 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir) 1932 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir)
1908 if dlg.exec() == QDialog.DialogCode.Accepted: 1933 if dlg.exec() == QDialog.DialogCode.Accepted:
1909 fnames, target, isSource = dlg.getData() 1934 fnames, target, isSource = dlg.getData()
2077 @param startdir start directory for the selection dialog 2102 @param startdir start directory for the selection dialog
2078 @type str 2103 @type str
2079 """ 2104 """
2080 from .AddDirectoryDialog import AddDirectoryDialog 2105 from .AddDirectoryDialog import AddDirectoryDialog
2081 2106
2082 if startdir is None: 2107 if not startdir:
2083 startdir = self.ppath 2108 startdir = self.ppath
2084 2109
2085 dlg = AddDirectoryDialog(self, fileTypeFilter, self.parent(), startdir=startdir) 2110 dlg = AddDirectoryDialog(self, fileTypeFilter, self.parent(), startdir=startdir)
2086 if dlg.exec() == QDialog.DialogCode.Accepted: 2111 if dlg.exec() == QDialog.DialogCode.Accepted:
2087 filetype, source, target, recursive = dlg.getData() 2112 filetype, source, target, recursive = dlg.getData()

eric ide

mercurial