Hello World¶
Creating a GUI application in Camelot is really easy. The resulting application will offer some compelling features, such as high quality widgets, responsiveness (no screen freezes) and automatic data binding between the model and the UI. What’s more, writing unit tests for a Camelot application is easy as well.
This tutorial will demonstrate how write a simple Hello World application and unit test it.
Get started¶
If you you’re not sure you have installed Camelot properly on your system, please have a look at the installation part of the documentation.
Using your favourite text editor or IDE, create a file called main.py, and add these import statements :
from camelot.admin.action import Action
from camelot.view import action_steps
from camelot.view.main import main_action
Make sure you are able to execute this file, either through the IDE or from the command line
python main.py
As this means the imports succeed, and Camelot is installed properly.
The Camelot library consists of a couple of modules, in this example, two of them are needed :
- camelot.admin : high level definition of the user interaction, such as how forms and tables should look like, and the general flow of the application.
- camelot.view : the reusable parts out of which the user interaction is build. This includes editors and dialogs.
Define the application¶
One of the basic concepts of Camelot are actions. Each Action class defines part of the flow of the application. So each Camelot application should be a subclass of the camelot.admin.action.base.Action class :
class HelloWorld(Action):
def model_run(self, model_context):
yield action_steps.MessageBox(u'Hello World')
A subclass of the camelot.admin.action.base.Action class, should overwrite the model_run generator. A generator is like a normal method, but it has no return statement, instead it has one or more yield statements.
The model_run generator has a yield statement whenever it wants to interact with the user, that is, ask the user a question, pop up a window or update the interface. Each yield statement within the model_run method should yield a camelot.admin.action.base.ActionStep object.
An ActionStep class is a reusable part of the user interaction, there are steps to ask questions, display messages, show print previews, etc. In this example, the camelot.view.action_steps.gui.MessageBox step is used to show a message box to the user.
Run the application¶
The last part needed is the construction of the action object, named hello_world and to add some magic to get it running when main.py is executed:
if __name__=='__main__':
hello_world = HelloWorld()
main_action(hello_world)
The complete application looks like this :
# begin camelot imports
from camelot.admin.action import Action
from camelot.view import action_steps
from camelot.view.main import main_action
# end camelot imports
# begin application definition
class HelloWorld(Action):
def model_run(self, model_context):
yield action_steps.MessageBox(u'Hello World')
# end application definition
# begin application start magic
if __name__=='__main__':
hello_world = HelloWorld()
main_action(hello_world)
# end application start magic
It can be run from the command line, or from the IDE
python main.py
In the case everything goes well, a Hello World dialog box should pop up.

Writing unittests¶
While everybody will agree that automated testing of an application is important to maintain quality over time, it remains very difficult to perform automated unit testing of the user interaction.
Camelot was designed with test driven development in mind. This means you can create your unittests before even starting to develop the application itself.
The complete application can be tested using nothing more than the unittest module from the standard library. As an example, create a file test.py with this code, in the same directory as main.py.
import unittest
class HelloWorldCase(unittest.TestCase):
def test_hello_world(self):
from .main import HelloWorld
hello_world = HelloWorld()
for step in hello_world.model_run(None):
self.assertTrue(step)
if __name__=='__main__':
unittest.main()
Before we can run the test, a empty file called __init__.py should be created in the same directory as main.py and test.py, this is to make sure the . import works.
Then, the tests can be started from the command line, or from the IDE
python test.py
Since the model_run method is a generator, all the unit test has to do is to loop over the steps generated by the method. This simulates running the application, and each interaction with the user can be modelled.
Where to go from here¶
Where to go from here depends on the kind of application you want to build. Here are some pointers :
Have a look at the various action steps that can be used inside the model run method. Such as :
- camelot.view.action_steps.print_preview.PrintPreview to allow the user to preview and print a document
- camelot.view.action_steps.select_file.SelectFile to ask the user to select a file that the application will process
When building a real application, don’t just subclass Action, but subclass camelot.admin.action.application.Application which will take care of the splash screen, set the application name for the OS and others.
If you want to build SQLAlchemy based database applications, follow this tutorial.
Whatever the application you want to build, make sure you understand the actions.
Get community support on the mailing list.
Get commercial support from Conceptive Engineering.