You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
11 KiB

2 years ago
2 years ago
  1. from gooey.gui.components.filtering.prefix_filter import PrefixTokenizers
  2. def _include_layout_docs(f):
  3. """
  4. Combines the layout_options docsstring with the
  5. wrapped function's doc string.
  6. """
  7. f.__doc__ = (f.__doc__ or '') + (LayoutOptions.__doc__ or '')
  8. return f
  9. def _include_global_option_docs(f):
  10. """
  11. Combines docstrings for options available to
  12. all widget types.
  13. """
  14. _doc = """:param initial_value: Sets the initial value in the UI.
  15. """
  16. f.__doc__ = (f.__doc__ or '') + _doc
  17. return f
  18. def _include_chooser_msg_wildcard_docs(f):
  19. """
  20. Combines the basic Chooser options (wildard, message) docsstring
  21. with the wrapped function's doc string.
  22. """
  23. _doc = """:param wildcard: Sets the wildcard, which can contain multiple file types, for
  24. example: "BMP files (.bmp)|.bmp|GIF files (.gif)|.gif"
  25. :param message: Sets the message that will be displayed on the dialog.
  26. """
  27. f.__doc__ = (f.__doc__ or '') + _doc
  28. return f
  29. def _include_choose_dir_file_docs(f):
  30. """
  31. Combines the basic Chooser options (wildard, message) docsstring
  32. with the wrapped function's doc string.
  33. """
  34. _doc = """:param default_dir: The default directory selected when the dialog spawns
  35. :param default_file: The default filename used in the dialog
  36. """
  37. f.__doc__ = (f.__doc__ or '') + _doc
  38. return f
  39. def LayoutOptions(label_color=None,
  40. label_bg_color=None,
  41. help_color=None,
  42. help_bg_color=None,
  43. error_color=None,
  44. error_bg_color=None,
  45. show_label=True,
  46. show_help=True,
  47. visible=True,
  48. full_width=False):
  49. """
  50. Layout Options:
  51. ---------------
  52. Color options can be passed either as a hex string ('#ff0000') or as
  53. a collection of RGB values (e.g. `[255, 0, 0]` or `(255, 0, 0)`)
  54. :param label_color: The foreground color of the label text
  55. :param label_bg_color: The background color of the label text.
  56. :param help_color: The foreground color of the help text.
  57. :param help_bg_color: The background color of the help text.
  58. :param error_color: The foreground color of the error text (when visible).
  59. :param error_bg_color: The background color of the error text (when visible).
  60. :param show_label: Toggles whether or not to display the label text
  61. :param show_help: Toggles whether or not to display the help text
  62. :param visible: Hides the entire widget when False. Note: the widget
  63. is still present in the UI and will still send along any
  64. default values that have been provided in code. This option
  65. is here for when you want to hide certain advanced / dangerous
  66. inputs from your GUI users.
  67. :param full_width: This is a layout hint for this widget. When True the widget
  68. will fill the entire available space within a given row.
  69. Otherwise, it will be sized based on the column rules
  70. provided elsewhere.
  71. """
  72. return _clean(locals())
  73. @_include_layout_docs
  74. @_include_global_option_docs
  75. def TextField(initial_value=None, validator=None, **layout_options):
  76. return _clean(locals())
  77. @_include_layout_docs
  78. @_include_global_option_docs
  79. def PasswordField(initial_value=None, validator=None, **layout_options):
  80. return _clean(locals())
  81. @_include_layout_docs
  82. @_include_global_option_docs
  83. def IntegerField(initial_value=None, validator=None, min=0, max=100, increment=1, **layout_options):
  84. """
  85. :param min: The minimum value allowed
  86. :param max: The maximum value allowed
  87. :param increment: The step size of the spinner
  88. """
  89. return _clean(locals())
  90. @_include_layout_docs
  91. @_include_global_option_docs
  92. def Slider(initial_value=None, validator=None, min=0, max=100, increment=1, **layout_options):
  93. """
  94. :param min: The minimum value allowed
  95. :param max: The maximum value allowed
  96. :param increment: The step size of the slider
  97. """
  98. return _clean(locals())
  99. @_include_layout_docs
  100. @_include_global_option_docs
  101. def DecimalField(validator=None,
  102. initial_value=None,
  103. min=0.0,
  104. max=1.0,
  105. increment=0.01,
  106. precision=2,
  107. **layout_options):
  108. """
  109. :param min: The minimum value allowed
  110. :param max: The maximum value allowed
  111. :param increment: The step size of the spinner
  112. :param precision: The precision of the decimal (0-20)
  113. """
  114. return _clean(locals())
  115. @_include_layout_docs
  116. @_include_global_option_docs
  117. def TextArea(initial_value=None, height=None, readonly=False, validator=None, **layout_options):
  118. """
  119. :param height: The height of the TextArea.
  120. :param readonly: Controls whether or not user's may modify the contents
  121. """
  122. return _clean(locals())
  123. @_include_layout_docs
  124. @_include_global_option_docs
  125. def RichTextConsole(**layout_options):
  126. return _clean(locals())
  127. @_include_layout_docs
  128. @_include_global_option_docs
  129. def ListBox(initial_value=None, height=None, **layout_options):
  130. """
  131. :param height: The height of the Listbox
  132. """
  133. return _clean(locals())
  134. # TODO: what are this guy's layout options..?
  135. def MutexGroup(initial_selection=None, title=None, **layout_options):
  136. """
  137. :param initial_selection: The index of the option which should be initially selected.
  138. :param title: Adds the supplied title above the RadioGroup options (when present)
  139. """
  140. return _clean(locals())
  141. @_include_layout_docs
  142. @_include_global_option_docs
  143. def Dropdown(initial_value=None, **layout_options):
  144. return _clean(locals())
  145. @_include_layout_docs
  146. @_include_global_option_docs
  147. def Counter(initial_value=None, **layout_options):
  148. return _clean(locals())
  149. @_include_layout_docs
  150. @_include_global_option_docs
  151. def CheckBox(initial_value=None, **layout_options):
  152. return _clean(locals())
  153. @_include_layout_docs
  154. @_include_global_option_docs
  155. def BlockCheckBox(initial_value=None, checkbox_label=None, **layout_options):
  156. return _clean(locals())
  157. @_include_layout_docs
  158. @_include_global_option_docs
  159. def FilterableDropdown(placeholder=None,
  160. empty_message=None,
  161. max_size=80,
  162. search_strategy=None,
  163. initial_value=None,
  164. **layout_options):
  165. """
  166. :param placeholder: Text to display when the user has provided no input
  167. :param empty_message: Text to display if the user's query doesn't match anything
  168. :param max_size: maximum height of the dropdown
  169. :param search_strategy: see: PrefixSearchStrategy
  170. """
  171. return _clean(locals())
  172. def PrefixSearchStrategy(
  173. choice_tokenizer=PrefixTokenizers.WORDS,
  174. input_tokenizer=PrefixTokenizers.REGEX('\s'),
  175. ignore_case=True,
  176. operator='AND',
  177. index_suffix=False):
  178. """
  179. :param choice_tokenizer: See: PrefixTokenizers - sets the tokenization strategy
  180. for the `choices`
  181. :param input_tokenizer: See: PrefixTokenizers sets how the users's `input` get tokenized.
  182. :param ignore_case: Controls whether or not to honor case while searching
  183. :param operator: see: `OperatorType` - controls whether or not individual
  184. search tokens
  185. get `AND`ed or `OR`d together when evaluating a match.
  186. :param index_suffix: When enabled, generates a suffix-tree to enable efficient
  187. partial-matching against any of the tokens.
  188. """
  189. return {**_clean(locals()), 'type': 'PrefixFilter'}
  190. @_include_layout_docs
  191. @_include_global_option_docs
  192. @_include_choose_dir_file_docs
  193. @_include_chooser_msg_wildcard_docs
  194. def FileChooser(wildcard=None,
  195. default_dir=None,
  196. default_file=None,
  197. message=None,
  198. initial_value=None,
  199. **layout_options):
  200. return _clean(locals())
  201. @_include_layout_docs
  202. @_include_global_option_docs
  203. @_include_chooser_msg_wildcard_docs
  204. def DirectoryChooser(wildcard=None,
  205. default_path=None,
  206. message=None,
  207. initial_value=None,
  208. **layout_options):
  209. """
  210. :param default_path: The default path selected when the dialog spawns
  211. """
  212. return _clean(locals())
  213. @_include_layout_docs
  214. @_include_global_option_docs
  215. @_include_choose_dir_file_docs
  216. @_include_chooser_msg_wildcard_docs
  217. def FileSaver(wildcard=None,
  218. default_dir=None,
  219. default_file=None,
  220. message=None,
  221. initial_value=None,
  222. **layout_options):
  223. return _clean(locals())
  224. @_include_layout_docs
  225. @_include_global_option_docs
  226. @_include_choose_dir_file_docs
  227. @_include_chooser_msg_wildcard_docs
  228. def MultiFileSaver(wildcard=None,
  229. default_dir=None,
  230. default_file=None,
  231. message=None,
  232. initial_value=None,
  233. **layout_options):
  234. return _clean(locals())
  235. def ExpressionValidator(test=None, message=None):
  236. """
  237. Creates the data for a basic expression validator.
  238. Your test function can be made up of any valid Python expression.
  239. It receives the variable user_input as an argument against which to
  240. perform its validation. Note that all values coming from Gooey
  241. are in the form of a string, so you'll have to cast as needed
  242. in order to perform your validation.
  243. """
  244. return {**_clean(locals()), 'type': 'ExpressionValidator'}
  245. def RegexValidator(test=None, message=None):
  246. """
  247. Creates the data for a basic RegexValidator.
  248. :param test: the regex expression. This should be the expression
  249. directly (i.e. `test='\d+'`). Gooey will test
  250. that the user's input satisfies this expression.
  251. :param message: The message to display if the input doesn't match
  252. the regex
  253. """
  254. return {**_clean(locals()), 'type': 'RegexValidator'}
  255. def ArgumentGroup(show_border=False,
  256. show_underline=True,
  257. label_color=None,
  258. columns=None,
  259. margin_top=None):
  260. """
  261. :param show_border: When True a labeled border will surround all widgets added to this group.
  262. :param show_underline: Controls whether or not to display the underline when using the default border style
  263. :param label_color: The foreground color for the group name
  264. :param columns: Controls the number of widgets on each row
  265. :param margin_top: specifies the top margin in pixels for this group
  266. """
  267. return _clean(locals())
  268. def _clean(options):
  269. cleaned = {k: v for k, v in options.items()
  270. if v is not None and k != "layout_options"}
  271. return {**options.get('layout_options', {}), **cleaned}