QFileDialog for selecting Photos library

Environment

MacOS
Python 3.6
PyQt5

Code for the UI

Following code prepares UI components:

  1. a button to open a system dialog for selecting a file
  2. a label to display the absolute path of the file
def setupUi(self, MainWindow):
        ......
        self.lblPath = QtWidgets.QLabel(self.centralwidget)
        self.lblPath.setGeometry(QtCore.QRect(350, 280, 200, 16))
        self.lblPath.setObjectName("lblPath")

        self.btnSelectLibrary = QtWidgets.QPushButton(self.centralwidget)
        self.btnSelectLibrary.setGeometry(QtCore.QRect(320, 320, 131, 32))
        self.btnSelectLibrary.setObjectName("btnSelectLibrary")
        ......
Code for the button event
def retranslateUi(self, MainWindow):
        ......
        self.btnSelectLibrary.clicked.connect(self.selectLibraryPath)
        ......
Code for the dialog
    def selectLibraryPath(self):
        print("yes")
        dir, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Select the library", "/Users/", "*.photoslibrary")
        print(dir)
        if dir:
            self.lblPath.setText(dir)

Method getOpenFilename returns an array as following

(path, filter)

e.g,

('/Volumes/Mac Photos/MacPhotos.libraries/Photos.photoslibrary', '*.photoslibrary')

The first item of the array is what we expected.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,647评论 2 45
  • 文/等等 有时候,我们或许会一个人在孤独这条路上走很久走很久。久到天上的星星都藏起来了,马路上落满了行人匆匆的脚步...
    等等z阅读 1,133评论 13 9
  • 咒语: 阿目佉。摩诃目佉。痤隶。摩诃痤隶。柁翅。摩诃柁翅。常求利。 摩訶常求利。乌摩致。摩诃乌摩致。挓翅挓翅。摩訶...
    醉清风_01阅读 33,553评论 0 2
  • 文/西秦木子 1 从黑暗中涌出,柔软的轻纱 于天地间扩展 掩埋昨天的残骸,打开梦扉 新戏在晨曦中徐徐上演 2 渐行...
    西秦木子阅读 208评论 0 6
  • 今天去一个拉丁舞学校。舞蹈室里只有四位学生。有一个读高三学舞蹈的萝莉,萝莉18岁,瘦瘦高高,蓝色宽敞的毛衣难掩身段...
    嘉浠阅读 204评论 0 0