file_not_found_dialog.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:cozy 作者: geigi 项目源码 文件源码
def locate(self, button):
        """
        Locate the file and update the database if the user selected one.
        """
        directory, filename = os.path.split(self.missing_file)
        dialog = Gtk.FileChooserDialog("Please locate the file " + filename, self.parent.window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        filter = Gtk.FileFilter()
        filter.add_pattern(filename)
        filter.set_name(filename)
        dialog.add_filter(filter)
        path, file_extension = os.path.splitext(self.missing_file)
        filter = Gtk.FileFilter()
        filter.add_pattern("*" + file_extension)
        filter.set_name(file_extension + " files")
        dialog.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.add_pattern("*")
        filter.set_name(_("All files"))
        dialog.add_filter(filter)
        dialog.set_local_only(False)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            new_location = dialog.get_filename()
            Track.update(file=new_location).where(
                Track.file == self.missing_file).execute()

            directory, filename = os.path.split(new_location)
            importer.import_file(filename, directory, new_location, update=True)
            self.parent.refresh_content()
            self.dialog.destroy()
            self.parent.dialog_open = False
            load_file(Track.select().where(Track.file == new_location).get())
            play_pause(None, True)

        dialog.destroy()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号