{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2102e30e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sys import executable, argv\n",
    "from subprocess import check_output\n",
    "from PyQt5.QtWidgets import QFileDialog, QApplication\n",
    "\n",
    "def gui_fname(directory='./'):\n",
    "    \"\"\"Open a file dialog, starting in the given directory, and return\n",
    "    the chosen filename\"\"\"\n",
    "    # run this exact file in a separate process, and grab the result\n",
    "    file = check_output([executable, __file__, directory])\n",
    "    return file.strip()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    directory = argv[1]\n",
    "    app = QApplication([directory])\n",
    "    fname = QFileDialog.getOpenFileName(None, \"Select a file...\", \n",
    "            directory, filter=\"All files (*)\")\n",
    "    print(fname[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
