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.

407 lines
18 KiB

10 years ago
10 years ago
11 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
7 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
10 years ago
10 years ago
9 years ago
  1. Gooey (Beta)
  2. =====
  3. Turn (almost) any Python Console Program into a GUI application with one line
  4. <p align="center">
  5. <img src="https://cloud.githubusercontent.com/assets/1408720/7904381/f54f97f6-07c5-11e5-9bcb-c3c102920769.png" />
  6. </p>
  7. Table of Contents
  8. -----------------
  9. - [Gooey](#gooey)
  10. - [Table of contents](#table-of-contents)
  11. - [Latest Update](#latest-update)
  12. - [Quick Start](#quick-start)
  13. - [Installation Instructions](#installation-instructions)
  14. - [Usage](#usage)
  15. - [Examples](#examples)
  16. - [What It Is](#what-is-it)
  17. - [Why Is It](#why)
  18. - [Who is this for](#who-is-this-for)
  19. - [How does it work](#how-does-it-work)
  20. - [Internationalization](#internationalization)
  21. - [Configuration](#configuration)
  22. - [Run Modes](#run-modes)
  23. - [Full/Advanced](#advanced)
  24. - [Basic](#basic)
  25. - [No Config](#no-config)
  26. - [Customizing Icons](#customizing-icons)
  27. - [Packaging](#packaging)
  28. - [Screenshots](#screenshots)
  29. - [Change Log](#change-log)
  30. - [TODO](#todo)
  31. - [Contributing](#wanna-help)
  32. - [Image Credits](#image-credits)
  33. ----------
  34. ### Artist Wanted!
  35. Want to contribute to Gooey? We need icons/logos!
  36. Drop me an <a href="mailto:audionautic@gmail.com">email</a> if you want to help out!
  37. ----------------
  38. ## Quick Start
  39. ### Installation instructions
  40. The easiest way to install Gooey is via `pip`
  41. pip install Gooey
  42. Alternatively, you can install Gooey by cloning the project to your local directory
  43. git clone https://github.com/chriskiehl/Gooey.git
  44. run `setup.py`
  45. python setup.py install
  46. After Gooey is installed, make sure [wxPython](http://www.wxpython.org/download.php) is installed on your machine as well. Unfortanately, this cannot be done from the CLI and should be manually downloaded from the [wxPython website](http://www.wxpython.org/download.php).
  47. ### Usage
  48. Gooey is attached to your code via a simple decorator on whichever method has your `argparse` declarations (usually `main`).
  49. from gooey import Gooey
  50. @Gooey <--- all it takes! :)
  51. def main():
  52. parser = ArgumentParser(...)
  53. # rest of code
  54. Different styling and functionality can be configured by passing arguments into the decorator.
  55. # options
  56. @Gooey(advanced=Boolean, # toggle whether to show advanced config or not
  57. language=language_string, # Translations configurable via json
  58. show_config=True, # skip config screens all together
  59. target=executable_cmd, # Explicitly set the subprocess executable arguments
  60. program_name='name', # Defaults to script name
  61. program_description, # Defaults to ArgParse Description
  62. default_size=(610, 530), # starting size of the GUI
  63. required_cols=1, # number of columns in the "Required" section
  64. optional_cols=2, # number of columbs in the "Optional" section
  65. dump_build_config=False, # Dump the JSON Gooey uses to configure itself
  66. load_build_config=None, # Loads a JSON Gooey-generated configuration
  67. monospace_display=False) # Uses a mono-spaced font in the output screen
  68. )
  69. def main():
  70. parser = ArgumentParser(...)
  71. # rest of code
  72. See: [How does it Work](#how-does-it-work) section for details on each option.
  73. Gooey will do its best to choose sensible widget defaults to display in the GUI. However, if more fine tuning is desired, you can use the drop-in replacement `GooeyParser` in place of `ArgumentParser`. This lets you control which widget displays in the GUI. See: [GooeyParser](#gooeyparser)
  74. from gooey import Gooey, GooeyParser
  75. @Gooey
  76. def main():
  77. parser = GooeyParser(description="My Cool GUI Program!")
  78. parser.add_argument('Filename', widget="FileChooser")
  79. parser.add_argument('Date', widget="DateChooser")
  80. ...
  81. ### Examples
  82. Gooey downloaded and installed? Great! Wanna see it in action? Head over the the [Examples Repository](https://github.com/chriskiehl/GooeyExamples) to download a few ready-to-go example scripts. They'll give you a quick tour of all Gooey's various layouts, widgets, and features.
  83. [Direct Download](https://github.com/chriskiehl/GooeyExamples/archive/master.zip)
  84. What is it?
  85. -----------
  86. Gooey converts your Console Applications into end-user-friendly GUI applications. It lets you focus on building robust, configurable programs in a familiar way, all without having to worry about how it will be presented to and interacted with by your average user.
  87. Why?
  88. ---
  89. Because as much as we love the command prompt, the rest of the world looks at it like an ugly relic from the early '80s. On top of that, more often than not programs need to do more than just one thing, and that means giving options, which previously meant either building a GUI, or trying to explain how to supply arguments to a Console Application. Gooey was made to (hopefully) solve those problems. It makes programs easy to use, and pretty to look at!
  90. Who is this for?
  91. ----------------
  92. If you're building utilities for yourself, other programmers, or something which produces a result that you want to capture and pipe over to another console application (e.g. *nix philosophy utils), Gooey probably isn't the tool for you. However, if you're building 'run and done,' around-the-office-style scripts, things that shovel bits from point A to point B, or simply something that's targeted at a non-programmer, Gooey is the perfect tool for the job. It lets you build as complex of an application as your heart desires all while getting the GUI side for free.
  93. How does it work?
  94. -----------------
  95. Gooey is attached to your code via a simple decorator on whichever method has your `argparse` declarations.
  96. @Gooey
  97. def my_run_func():
  98. parser = ArgumentParser(...)
  99. # rest of code
  100. At run-time, it parses your Python script for all references to `ArgumentParser`. (The older `optparse` is currently not supported.) These references are then extracted, assigned a `component type` based on the `'action'` they provide, and finally used to assemble the GUI.
  101. #### Mappings:
  102. Gooey does its best to choose sensible defaults based on the options it finds. Currently, `ArgumentParser._actions` are mapped to the following `WX` components.
  103. | Parser Action | Widget | Example |
  104. |:----------------------|-----------|------|
  105. | store | TextCtrl | <img src="https://cloud.githubusercontent.com/assets/1408720/7904380/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png"/>|
  106. | store_const | CheckBox | <img src="https://cloud.githubusercontent.com/assets/1408720/7904367/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/>|
  107. | store_true| CheckBox | <img src="https://cloud.githubusercontent.com/assets/1408720/7904367/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/>|
  108. | store_False | CheckBox| <img src="https://cloud.githubusercontent.com/assets/1408720/7904367/f538c850-07c5-11e5-8cbe-864badfa54a9.png"/> |
  109. | append | TextCtrl | <img src="https://cloud.githubusercontent.com/assets/1408720/7904380/f54e9f5e-07c5-11e5-86e5-82f011c538cf.png"/> |
  110. | count| DropDown &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <img src="https://cloud.githubusercontent.com/assets/1408720/7904371/f53ccbe4-07c5-11e5-80e5-510e2aa22922.png"/> |
  111. | Mutually Exclusive Group | RadioGroup | <img src="https://cloud.githubusercontent.com/assets/1408720/7904383/f553feb8-07c5-11e5-9d5b-eaa4772075a9.png"/>
  112. |choice &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| DropDown | <img src="https://cloud.githubusercontent.com/assets/1408720/7904379/f54e4da6-07c5-11e5-9e66-d8e6d7f18ac6.png"/> |
  113. ### GooeyParser
  114. If the above defaults aren't cutting it, you can control the exact widget type by using the drop-in `ArgumentParser` replacement `GooeyParser`. This gives you the additional keyword argument `widget`, to which you can supply the name of the component you want to display. Best part? You don't have to change any of your `argparse` code to use it. Drop it in, and you're good to go.
  115. **Example:**
  116. from argparse import ArgumentParser
  117. ....
  118. def main():
  119. parser = ArgumentParser(description="My Cool Gooey App!")
  120. parser.add_argument('filename', help="name of the file to process")
  121. Given then above, Gooey would select a normal `TextField` as the widget type like this:
  122. <p align="center">
  123. <img src="https://cloud.githubusercontent.com/assets/1408720/7904368/f5393e20-07c5-11e5-88e9-c153fc3ecfaa.PNG">
  124. </p>
  125. However, by dropping in `GooeyParser` and supplying a `widget` name, you can display a much more user friendly `FileChooser`
  126. from gooey import GooeyParser
  127. ....
  128. def main():
  129. parser = GooeyParser(description="My Cool Gooey App!")
  130. parser.add_argument('filename', help="name of the file to process", widget='FileChooser')
  131. <p align="center"><img src="https://cloud.githubusercontent.com/assets/1408720/7904370/f53ae23e-07c5-11e5-8757-c8aa6f3013b5.PNG"></p>
  132. **Custom Widgets:**
  133. | Widget | Example |
  134. |----------------|------------------------------|
  135. | DirChooser/FileChooser | <p align="center"><img src="https://cloud.githubusercontent.com/assets/1408720/7904377/f5483b28-07c5-11e5-9d01-1935635fc22d.gif" width="400"></p> |
  136. | DateChooser &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| <p align="center"><img src="https://cloud.githubusercontent.com/assets/1408720/7904376/f544756a-07c5-11e5-86d6-862ac146ad35.gif" width="400"></p> |
  137. | PasswordField | <p align="center"><img src="https://user-images.githubusercontent.com/1408720/28953722-eae72cca-788e-11e7-8fa1-9a1ef332a053.png" width="400"></p> |
  138. Internationalization
  139. --------------------
  140. <img src="https://cloud.githubusercontent.com/assets/1408720/7904365/f52e9f1a-07c5-11e5-8f31-36a8fc14ac02.jpg" align="right" />
  141. Gooey is international ready and easily ported to your host language. Languages are controlled via an argument to the `Gooey` decorator.
  142. @Gooey(language='russian')
  143. def main():
  144. ...
  145. All program text is stored externally in `json` files. So adding new langauge support is as easy as pasting a few key/value pairs in the `gooey/languages/` directory.
  146. Thanks to some awesome [contributers](https://github.com/chriskiehl/Gooey/graphs/contributors), Gooey currently comes pre-stocked with the following language sets:
  147. - English
  148. - Dutch
  149. - French
  150. - Portuguese
  151. Want to add another one? Submit a [pull request!](https://github.com/chriskiehl/Gooey/compare)
  152. -------------------------------------------
  153. Configuration
  154. -------------
  155. Just about everything in Gooey can be customized by passing arguments to the decorator.
  156. | Parameter | Summary |
  157. |-----------|---------|
  158. | advanced | Toggles whether to show the 'full' configuration screen, or a simplified version |
  159. | show_config | Skips the configuration all together and runs the program immediately |
  160. | language | Tells Gooey which language set to load from the `gooey/languages` directory.|
  161. | target | Tells Gooey how to re-invoke itself. By default Gooey will find python, but this allows you to specify the program (and arguments if supplied).|
  162. |program_name | The name displayed in the title bar of the GUI window. If not supplied, the title defaults to the script name pulled from `sys.argv[0]`. |
  163. | program_description | Sets the text displayed in the top panel of the `Settings` screen. Defaults to the description pulled from `ArgumentParser`. |
  164. | default_size | Initial size of the window |
  165. | required_cols | Controls how many columns are in the Required Arguments section |
  166. | optional_cols | Controls how many columns are in the Optional Arguments section |
  167. | dump_build_config | Saves a `json` copy of its build configuration on disk for reuse/editing |
  168. | load_build_config | Loads a `json` copy of its build configuration from disk |
  169. | monospace_display | Uses a mono-spaced font in the output screen |
  170. | image_dir | Path to the directory in which Gooey should look for custom images/icons |
  171. | language_dir | Path to the directory in which Gooey should look for custom languages files |
  172. Run Modes
  173. ---------
  174. Gooey has a handful of presentation modes so you can tailor its layout to your content type and user's level or experience.
  175. ### Advanced
  176. The default view is the "full" or "advanced" configuration screen. It has two different layouts depending on the type of command line interface it's wrapping. For most applications, the flat layout will be the one to go with, as its layout matches best to the familiar CLI schema of a primary command followed by many options (e.g. Curl, FFMPEG).
  177. On the other side is the Column Layout. This one is best suited for CLIs that have multiple paths or are made up of multiple little tools each with their own arguments and options (think: git). It displays the primary paths along the left column, and their corresponding arguments in the right. This is a great way to package a lot of varied functionality into a single app.
  178. <p align="center">
  179. <img src="https://cloud.githubusercontent.com/assets/1408720/7927433/f06a36cc-08ad-11e5-843e-9322df96d4d6.png">
  180. </p>
  181. Both views present each action in the `Argument Parser` as a unique GUI component. It makes it ideal for presenting the program to users which are unfamiliar with command line options and/or Console Programs in general. Help messages are displayed along side each component to make it as clear as possible which each widget does.
  182. **Setting the layout style:**
  183. Currently, the layouts can't be explicitely specified via a parameter (on the TODO!). The layouts are built depending on whether or not there are `subparsers` used in your code base. So, if you want to trigger the `Column Layout`, you'll need to add a `subparser` to your `argparse` code.
  184. It can be toggled via the `advanced` parameter in the `Gooey` decorator.
  185. @gooey(advanced=True)
  186. def main():
  187. # rest of code
  188. --------------------------------------------
  189. ### Basic
  190. The basic view is best for times when the user is familiar with Console Applications, but you still want to present something a little more polished than a simple terminal. The basic display is accessed by setting the `advanced` parameter in the `gooey` decorator to `False`.
  191. @gooey(advanced=False)
  192. def main():
  193. # rest of code
  194. <p align="center">
  195. <img src="https://cloud.githubusercontent.com/assets/1408720/7904369/f53a4306-07c5-11e5-8e63-b510d6db9953.png">
  196. </p>
  197. ----------------------------------------------
  198. ### No Config
  199. No Config pretty much does what you'd expect: it doesn't show a configuration screen. It hops right to the `display` section and begins execution of the host program. This is the one for improving the appearance of little one-off scripts.
  200. <p align="center">
  201. <img src="https://cloud.githubusercontent.com/assets/1408720/7904382/f54fe6f2-07c5-11e5-92e4-f72a2ae12862.png">
  202. </p>
  203. ---------------------------------------
  204. ## Customizing Icons
  205. Gooey comes with a set of six default icons. These can be overridden with your own custom images/icons by telling Gooey to search additional directories when initializing. This is done via the `image_dir` argument to the `Goeey` decorator.
  206. @Gooey(program_name='Custom icon demo', image_dir='/path/to/my/image/directory')
  207. def main():
  208. # rest of program
  209. Images are discovered by Gooey based on their _filenames_. So, for example, in order to supply a custom configuration icon, simply place an image with the filename `config_icon.png` in your images directory. These are the filenames which can be overridden:
  210. * program_icon.ico
  211. * success_icon.png
  212. * running_icon.png
  213. * loading_icon.gif
  214. * config_icon.png
  215. * error_icon.png
  216. ## Packaging
  217. Thanks to some [awesome contributers](https://github.com/chriskiehl/Gooey/issues/58), packaging Gooey as an executable is super easy.
  218. The tl;dr [pyinstaller](https://github.com/pyinstaller/pyinstaller) version is to drop this [build.spec](https://github.com/chriskiehl/Gooey/files/29568/build.spec.txt) into the root directory of your application. Edit its contents so that the `application` and `name` are relevant to your project, then execute `pyinstaller build.spec` to bundle your app into a ready-to-go executable.
  219. Detailed step by step instructions can be found [here](http://chriskiehl.com/article/packaging-gooey-with-pyinstaller/).
  220. Screenshots
  221. ------------
  222. | Flat Layout | Column Layout |Success Screen | Error Screen | Warning Dialog |
  223. |-------------|---------------|---------------|--------------|----------------|
  224. | <img src="https://cloud.githubusercontent.com/assets/1408720/7950190/4414e54e-0965-11e5-964b-f717a7adaac6.jpg"> | <img src="https://cloud.githubusercontent.com/assets/1408720/7950189/4411b824-0965-11e5-905a-3a2b5df0efb3.jpg"> | <img src="https://cloud.githubusercontent.com/assets/1408720/7950192/44165442-0965-11e5-8edf-b8305353285f.jpg"> | <img src="https://cloud.githubusercontent.com/assets/1408720/7950188/4410dcce-0965-11e5-8243-c1d832c05887.jpg"> | <img src="https://cloud.githubusercontent.com/assets/1408720/7950191/4415432c-0965-11e5-9190-17f55460faf3.jpg"> |
  225. ----------------------------------------------
  226. ### Change Log
  227. ----------
  228. - Subparser Support!
  229. - Moved all internal messaging to pubsub
  230. - expanded i18n converage
  231. - allowed returning to the main configuration screen
  232. - Fixed success checkmark showing on failure
  233. - Refactoring to beauty
  234. - Removed parsing code, replaced it with @SylvainDe patch
  235. - Fixed issue #87
  236. - Fixed issue #85
  237. - Argparse no longer required to be in `main` (issue 84)
  238. - Drag and Drop support (`Issue #28`)
  239. - Added drag and drop support
  240. - Added new widget packs: DateChooser, FileChooser, DirChooser
  241. - fixed several parsing related issues.
  242. - Gooey now has a sane setup.py (thanks to hero user LudoVio)
  243. - Gooey now builds from json for easy configurability
  244. - Side Note: This was done with big strides towards making Gooey language agnostic. Coming Soon!
  245. - Fixed GUI layout so that resizing works better
  246. Wanna help?
  247. -----------
  248. Code, translation, graphics? Pull requests are welcome.
  249. [1]: http://i.imgur.com/7fKUvw9.png