Lesson 9: Collecting Parameters
| filename: | lesson09-collect_parameters.py |
| getName() | Lesson 09 - Collecting Parameters |
| getDescription() | Lesson 09 - Collects some parameters, and passes them through to the execute() function. |
Last lesson we saw how to show a dialog to the user. You can use dialogs to ask questions, show results, or generally interract
with the user. Because on a desktop computer, the interface is called the Graphical User Interface (or GUI), writing code to interract with the user is called GUI Programming. Last lesson, you learnt how to show a very simple dialog to the user. Now, we'll learn how to show more complex dialogs.
GUI Programming - Background Information
Note Studio is built using wxPython. What is wxPython? Well, it's a combination of two things:
- wxWidgets: a library which allows you to program dialogs, windows, etc on various platforms
- wxPython: a module which lets you call wxWidgets routines from Python. It allows you to write a GUI application using Python.
Learning wxPython programming is easier than most other GUI programming libraries. But it's still no small undertaking. The
best way to learn is probably:
- learn by example, and
- learn on a need-to-know basis.
So in this lesson, we will build a dialog which uses a number of different methods to collect input from the user. We'll use:
- a file chooser
- an edit box
- a combo box
- radio buttons
- a checkbox, and
- a list box
This is nowhere near a full list of GUI components, but it is a few of the common ones. When you go to build your own GUI,
you can borrow code from this lesson to get you started.
For more information, you can refer to the wxPython documentation.
Also, if you download wxPython, it contains a most excellent demo which shows you (with code) how to use most wxPython objects.
The easiest way to start with any wxPython component you're not familiar with, is to go and steal the demo code, and start
modifying it for your purposes.
Example
Blah
Technical Information on wxPython
Like any software library, wxPython is constantly being upgraded. Note Studio 3.0 was built on wxPython 2.4. Your plugins
will also have to work with wxPython 2.4. So when you refer to wxPython documentation, you should make sure it is the 2.4
version, otherwise it will not be 100% correct.
In future versions, it is likely that Note Studio will be built on later versions of wxPython.
General Comments on GUI Programming
This has been quite a long lesson. We accelerated from the previous lesson (which will now seem quite simple), and covered
a lot of ground. If you've got this far - well done!
You've probably seen that GUI programming can be quite a lot of effort. So, is it necessary? Well, it depends on who is going
to use the plugin.
When Not To Bother
There are different reasons for writing a plugin. Sometimes, a plugin will perform a task that you want to repeat often. Sometimes,
it will perform a one-off task.
At Dogmelon, we regularly develop plugins for our own personal use, when we want to get certain information out of Note Studio.
But we rarely write a GUI for it. Because the plugin is for our own use, and we are extremely comfortable with Python and
plugin programming, whenever we want it to run differently we would just go in and edit the code. For example, rather than
code up a dialog allowing us to choose a directory, we would just hard-code a directory. If we want to change to a different
directory, we'd just edit the code to change it.
We would rarely need to code a GUI for our own use.
When To Bother With A GUI
If you are writing a plugin which will be used by other people, then it's probably time to add the polish of an easy-to-use
GUI. It's better than telling users: 'Go in and change line 57 from X to Y'. Give them a GUI to let them decide how your plugin
will run.
It's time to write a GUI when you care about how easy it is for other people to use your Plugin.