gooey.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """DataLad GUI"""
  2. __docformat__ = 'restructuredtext'
  3. from datalad.interface.base import Interface
  4. from datalad.interface.base import build_doc
  5. from datalad.support.param import Parameter
  6. from datalad.distribution.dataset import datasetmethod
  7. from datalad.interface.utils import eval_results
  8. from datalad.interface.results import get_status_dict
  9. from .postinstall import perform_post_install_tasks
  10. import logging
  11. lgr = logging.getLogger('datalad.ext.gooey.gooey')
  12. import sys
  13. # decoration auto-generates standard help
  14. @build_doc
  15. # all commands must be derived from Interface
  16. class Gooey(Interface):
  17. # first docstring line is used a short description in the cmdline help
  18. # the rest is put in the verbose help and manpage
  19. """DataLad GUI
  20. Long description of arbitrary volume.
  21. """
  22. # usage examples
  23. _examples_ = [
  24. dict(
  25. text=(
  26. "Launch the DataLad Graphical User Interface (GUI, a.k.a Gooey) "
  27. "at the specified location."
  28. ),
  29. code_py="gooey(path='path/to/root/explorer/directory')",
  30. code_cmd="datalad gooey --path 'path/to/root/explorer/directory'",
  31. ),
  32. ]
  33. # parameters of the command, must be exhaustive
  34. _params_ = dict(
  35. # name of the parameter, must match argument name
  36. path=Parameter(
  37. # cmdline argument definitions, incl aliases
  38. args=("-p", "--path"),
  39. # documentation
  40. doc="""The root location from which the Gooey file explorer will be
  41. launched (default is current working directory)""",
  42. ),
  43. postinstall=Parameter(
  44. args=("--postinstall",),
  45. doc="Perform post-installation tasks",
  46. action="store_true",
  47. # default=False,
  48. ),
  49. )
  50. @staticmethod
  51. # decorator binds the command to the Dataset class as a method
  52. @datasetmethod(name='gooey')
  53. # generic handling of command results (logging, rendering, filtering, ...)
  54. @eval_results
  55. # signature must match parameter list above
  56. # additional generic arguments are added by decorators
  57. def __call__(path: str = None, postinstall: bool = False):
  58. # local import to keep entrypoint import independent of PySide
  59. # availability
  60. from .app import GooeyApp, QApplication
  61. # if requested, perform post-install tasks and exit
  62. if postinstall:
  63. perform_post_install_tasks()
  64. return
  65. qtapp = QApplication(sys.argv)
  66. gooey = GooeyApp(path)
  67. gooey.main_window.show()
  68. # capture Qt's own exit code for error reporting
  69. qt_exitcode = qtapp.exec()
  70. # tell the app to undo its modifications (UI redirection etc.)
  71. gooey.deinit()
  72. yield get_status_dict(
  73. action='gooey',
  74. path=str(gooey.rootpath),
  75. status='ok' if not qt_exitcode else 'error',
  76. # no message when everything was OK
  77. message='Qt UI errored ' if qt_exitcode else None)