def setSourceToSearch(self, _isReload=True, _isLoadFromCache=False): try: if self.sourceToSearch is None or _isReload: sourceToSearch = "" self.isMultipleSource = False pathToSearchs = str(self.lePathToSeach.text()) if fu.isExist(pathToSearchs) is False and pathToSearchs.find(";") != -1: self.isMultipleSource = True for pathToSearch in uni.getListFromListString(pathToSearchs, ";"): if pathToSearch in self.sourceToSearchCache and _isLoadFromCache: sourceToSearch += self.sourceToSearchCache[pathToSearch] else: pathToSearch = fu.checkSource(pathToSearch) if pathToSearch is not None: if fu.isReadableFileOrDir(pathToSearch): if fu.isFile(pathToSearch) and fu.isBinary(pathToSearch) is False: sts = fu.readFromFile(pathToSearch) + "\n" sourceToSearch += sts self.sourceToSearchCache[pathToSearch] = sts elif fu.isDir(pathToSearch): sts = fu.getFileTree(pathToSearch, -1, "return", "plainText", "fileList") + "\n" sourceToSearch += sts self.sourceToSearchCache[pathToSearch] = sts self.sourceToSearch = sourceToSearch if sourceToSearch != "": return True return False else: return True except: ReportBug.ReportBug()
def build(self): try: uni.isCanBeShowOnMainWindow = False outputTarget = "file" outputType = "html" contentType = "fileTree" if self.cbOutputTarget.currentIndex() == 1: outputTarget = "dialog" elif self.cbOutputTarget.currentIndex() == 2: outputTarget = "clipboard" if self.cbOutputType.currentIndex() == 1: outputType = "plainText" if self.cbContentType.currentIndex() == 1: contentType = "fileList" fu.getFileTree(str(self.lePath.text()), self.cbSubDirectoryDeep.currentText(), outputTarget, outputType, contentType, "title") if self.cbOutputTarget.currentIndex() == 2: Dialogs.show(translate("FileTreeBuilder", "Builded File Tree"), translate("FileTreeBuilder", "File tree copied to clipboard.")) uni.isCanBeShowOnMainWindow = True except: ReportBug.ReportBug()
def setSourceToSearch(self, _isReload=True, _isLoadFromCache=False): try: if self.sourceToSearch is None or _isReload: sourceToSearch = "" self.isMultipleSource = False pathToSearchs = str(self.lePathToSeach.text()) if fu.isExist(pathToSearchs) is False and pathToSearchs.find( ";") != -1: self.isMultipleSource = True for pathToSearch in uni.getListFromListString( pathToSearchs, ";"): if pathToSearch in self.sourceToSearchCache and _isLoadFromCache: sourceToSearch += self.sourceToSearchCache[ pathToSearch] else: pathToSearch = fu.checkSource(pathToSearch) if pathToSearch is not None: if fu.isReadableFileOrDir(pathToSearch): if fu.isFile(pathToSearch) and fu.isBinary( pathToSearch) is False: sts = fu.readFromFile(pathToSearch) + "\n" sourceToSearch += sts self.sourceToSearchCache[ pathToSearch] = sts elif fu.isDir(pathToSearch): sts = fu.getFileTree( pathToSearch, -1, "return", "plainText", "fileList") + "\n" sourceToSearch += sts self.sourceToSearchCache[ pathToSearch] = sts self.sourceToSearch = sourceToSearch if sourceToSearch != "": return True return False else: return True except: ReportBug.ReportBug()
def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName(translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName(translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show(translate("MenuBar", "Current State Saved"), translate("MenuBar", "Current state saved with preferences.<br>You can continue where you left off.")) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread(["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show(translate("ToolsBar", "Directory Icon Checked"), translate("ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed.")) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask(translate("ToolsBar", "Empty Directories Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow().FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show(translate("ToolsBar", "Directory Cleaned"), translate("ToolsBar", "The current directory is cleaned based on the criteria you set.")) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher([getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask(translate("ToolsBar", "All Files Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles(getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show(translate("ToolsBar", "Removed Only All Files"), str(translate("ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile(fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()
def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName( translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName( translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show( translate("MenuBar", "Current State Saved"), translate( "MenuBar", "Current state saved with preferences.<br>You can continue where you left off." )) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread( ["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show( translate("ToolsBar", "Directory Icon Checked"), translate( "ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed." )) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask( translate("ToolsBar", "Empty Directories Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?" )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow( ).FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show( translate("ToolsBar", "Directory Cleaned"), translate( "ToolsBar", "The current directory is cleaned based on the criteria you set." )) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher( [getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask( translate("ToolsBar", "All Files Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles( getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show( translate("ToolsBar", "Removed Only All Files"), str( translate( "ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile( fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()