def loadNotesMetadata(self): localDir = QDir(self.localStoragePath) noteFileInfos = localDir.entryInfoList([MARKDOWN_PATTERN], QDir.Files | QDir.NoDotAndDotDot) for noteFileInfo in noteFileInfos: absPath = noteFileInfo.absoluteFilePath() name = noteFileInfo.baseName() contents = readMarkdownFile(absPath) self.allNotes.append(Note(name, absPath, contents)) print("Loaded note {} from {}".format(name, absPath))
def LoadScripts(self): Result = QFileDialog.getExistingDirectory(self) DirScript = QDir(Result) if DirScript.cd("Script"): if not self.ui.PathData.text().strip() != "": ####UnloadScripts ListScript = DirScript.entryInfoList(["*.py"]) for mod in ListScript: # removes module from the system mod_name = mod.baseName() if mod_name in sys.modules: #ListFunction = dir(mod_name) del sys.modules[mod_name] Helper.DeviceHelper.FunctionCallDict = {} self.ui.PathScript.setText(Result) #self.ui.LogTerminal.setText(DirScript.absolutePath()) sys.path.append(DirScript.absolutePath()) DirScript.entryInfoList(["*.py"]) for Script in ListScript: __import__(Script.baseName()) ListFunction = Helper.DeviceHelper.FunctionCallDict.values() for item in ListFunction: self.ui.ListScript.addItem(item) #for function in ListFunction: # Helper.DeviceHelper.function = types.MethodType(function,Helper.DeviceHelper) #setattr(Helper.DeviceHelper, ScriptModule.__dict__[function], function) #Helper.DeviceHelper.__dict__[function] = function ListVar = [] f = open(QDir(Result).absoluteFilePath("Var.txt"), 'r') for ligne in f.readlines(): ListVar.append(ligne) f.close() Helper.add_variable_Masterisation(ListVar) self.Manager.ReloadTerminaux() else: #Error print("Error")
def update_directory_info(): global dict_photos # Get list of all entries in directory and count files with supported file name extension dir = QDir(window.edit_src_dir.text()) list_files = dir.entryInfoList() # Clear data from previous runs dict_photos = dict() window.list_files.clear() QApplication.processEvents() QApplication.setOverrideCursor(Qt.WaitCursor) # Actual scanning of selected directory start = time.time() for entry in list_files: # lbl_current_file.setText("Current file: {0}".format(entry.absoluteFilePath())) if entry.isFile(): # Processing and capture time extraction print("Processing: {0}".format(entry.absoluteFilePath())) md = pyexiv2.ImageMetadata(entry.absoluteFilePath()) try: md.read() capture_time = md['Exif.Photo.DateTimeOriginal'].value print("Photo taken: {0}".format(capture_time)) dict_photos[entry.absoluteFilePath()] = capture_time except: print("Skipping file") QApplication.setOverrideCursor(Qt.ArrowCursor) print("\n\n") end = time.time() duration = end - start print("Processing took {:2.4f}s".format(duration)) window.lbl_dir_info.setText("Directory contains {0} images".format( len(dict_photos))) print("Valid image files: {0}/{1}".format(len(dict_photos), len(list_files))) if len(dict_photos) > 0: update_file_list()
def findFile(self, _filePath): # 通过递归的方式,遍历所有动画文件 animationFilePath = QDir(_filePath) animationFilePath.setFilter(QDir.Dirs | QDir.Files | QDir.NoDotAndDotDot) animationFilePath.setSorting(QDir.DirsFirst) list = animationFilePath.entryInfoList() if (len(list) < 1): return i = 0 # 采用递归算法 while (i < len(list)): fileInfo = list[i] bisDir = fileInfo.isDir() if (bisDir): self.findFile(fileInfo.filePath()) else: self.AnimationFileList.append(fileInfo.filePath()) i += 1