def fileDialog(parent, title, initPath, filters, save=True): '''Create a file dialog Args: parent (QWidget): Parent Widget title (str): Dialog title initPath (str): Initial Path filters (list of str): List of valid extension ie:["ma", "mb"] save (bool): Open dialog in save mode Returns: str ''' filters = ";;".join(["%s (*.%s)" % (filter, filter) for filter in filters] + ["All files (*.*)"]) fileDialog = QFileDialog(parent, title, initPath, filters) if save: fileDialog.setAcceptMode(QFileDialog.AcceptSave) else: fileDialog.setAcceptMode(QFileDialog.AcceptOpen) fileDialog.exec_() if not fileDialog.result(): return path = str(fileDialog.selectedFiles()[0]) if not save and not os.path.exists(path): return return path
def _on_show_browse_image_dialog(self): """ Internal callback function that shows a file dialog for choosing an image from disk """ file_dialog = QFileDialog(self, caption='Open Image', filter='Image Files (*.png *.jpg)') file_dialog.fileSelected.connect(self.set_thumbnail_path) file_dialog.exec_()
def openFile(self): if self.hasLogin: dialog = QFileDialog() # dayu_theme.apply(dialog) dialog.setStyleSheet(Data.getQSS()) #根据当前所在文件目录,设置默认打开文件格式 dialog.setNameFilter(u"资源文件(*.png);;图片文件(*.jpg *.png *.jpeg);;") #加载对应的文件 dialog.setFileMode(QFileDialog.ExistingFiles) dialog.setViewMode(QFileDialog.Detail) self.paths = None if dialog.exec_(): self.paths = dialog.selectedFiles() if self.paths == None: return # 创建标签选择窗口 self.tagWidget = Tag.TagWidget(self.paths, self.userName) self.tagWidget.show() Data.setWindowCenter(self.tagWidget) self.tagWidget.send_tag_signal.connect( self.cenWinAddTags) # 链接添加标签的信号到中心窗口添加标签方法 self.tagWidget.load_file_signal.connect(self.slot_show_loading) else: self.slot_show_message(MMessage.info, (u'请先登录账号!'))
def setHeadPorfie(self): dialog = QFileDialog() dialog.setStyleSheet(Data.getQSS()) #根据当前所在文件目录,设置默认打开文件格式 dialog.setNameFilter(u"图片文件(*.jpg *.png *.jpeg);;") #加载对应的文件 dialog.setFileMode(QFileDialog.ExistingFiles) dialog.setViewMode(QFileDialog.Detail) if dialog.exec_(): imgPaths = dialog.selectedFiles() self.imgPath = imgPaths[0] img = cv2.imread(self.imgPath) flag = min(img.shape[0], img.shape[1]) newimg = img[((img.shape[0] - flag) // 2):((img.shape[0] + flag) // 2), ((img.shape[1] - flag) // 2):((img.shape[1] + flag) // 2)] newimg = cv2.resize(newimg, (150, 150), interpolation=cv2.INTER_AREA) cv2.imwrite(hpPath + "\\" + "buffer.jpg", newimg) #将图片作为缓存存入指定文件内 # pixmap = QtGui.QPixmap(hpPath + "\\" + "buffer.jpg") # self.lab_headProfile.setPixmap(pixmap) # 打开头像编辑器 self.hpw = headProfieWindow(self.imgPath) self.hpw.show()
def editHeadProfile(self): dialog = QFileDialog() dialog.setStyleSheet(Data.getQSS()) #根据当前所在文件目录,设置默认打开文件格式 dialog.setNameFilter(u"图片文件(*.jpg *.png *.jpeg);;") #加载对应的文件 dialog.setFileMode(QFileDialog.ExistingFiles) dialog.setViewMode(QFileDialog.Detail) if dialog.exec_(): imgPaths = dialog.selectedFiles() imgPath = imgPaths[0] self.editHeadProfileWin = headProfieWindow(imgPath) self.editHeadProfileWin.show() self.editHeadProfileWin.hPOK_signal.connect( lambda: self.setPicture()) #选中图片,更新头像 self.editHeadProfileWin.hPOK_signal.connect(lambda: self.setWCHP())