Pytonic is an open source full integrated IDE that makes easy to build business applications with IronPython.
Creating a first simple application
Posted by: Pytonic on 17 Sep 2011
1/ Launching the Pytonic application
Go into PyTonic folder and double click on "PyTonic.exe" file.
2/ Create a new project
Click on "Create a new project" (you can also use the "Project" menu, then select "New project").
Make sure that ".NET IronPython Project" is selected, then enter "SimpleTutorial" as project name and choose the location of the project on your hard drive.
If the folder doesn't exists yet, it will be created if the option "Create directory for project" is checked.
You should have something similar to the following screenshot.
The default project template has been loaded.
3/ Database configuration
A database must be configured to be able to use PyTonic. Currently Microsoft SQL Server, MySQL and SQLite database engine are supported.
First create the database on your SQL Server.
Then, double click on "config/database.xml" file to edit it.
Enter the correct parameters to connect to the database you just created.
"DatabaseEngine" can be "mssql" or "mysql" or "sqlite".
Save the file.
Note :
When using "sqlite", "DatabaseServer" can be left empty or filled with an absolute path. If you left it empty, the database will be stored in the project folder, using the name defined in "DatabaseName".
4/ Defining the database model
Before starting to develop, we need to define a first table in our database.
Rename the file "database/tables/table_company.xml" to "table_people.xml", then open it.
Change the table name from "company" to "people" and remove every lines starting with "<addfield".
Now we will add some fields to the "people table".
A quick way to add a new field is to use the code snippets :
Hit "CTRL-B" then select the "addField_varchar" snippet.
Add 5 fields, like on the next screenshot :
Save the "table_people.xml" file.
5/ Generating the database model
Each time you make changes to your database, you need to regenerate the database model.
Click on the refresh button.
You may get the following error when clicking on the refresh button.
If it happens, first check if your database parameters are correct, then close and restart PyTonic and click again on the "refresh" button.
Once the model has been generated, you will see 2 new files in the "database" folder :
- "model.cs" which contains the C# code that will create the database objects
- "model.dll" a compiled version of the "model.cs" file, for faster loading
6/ Creating a new module "people"
We will create a new module to manage the "people" table.
Right click on "module" folder and select the option "add -> new folder".
Set the new folder name to "people".
By convention the module should have the same than the main table that will be used in that module.
When using the templates to create the forms and the Python code, this folder name will be used to define what table to use.
7/ Creating files to manage the list of "peoples"
First we will use a template to create a Python file to manage the list of records in the "people" table.
Right click on the "people" folder and select "Add -> DevExpress -> New Python-List..."
Set the name to "list_people.py".
By convention, the name is set to "list_" + table name + ".py".
Now we will use another template for the form that will display the table grid for the table "people".
Right click on the "people" folder and select "Add -> DevExpress -> New Form-List..."
Set the name to "list_people.xml".
Like for the Python file, by convention, the name is set to "list_" + table name + ".xml".
8/ Modifying the design of the "people list" form
We need to modify the default form provided in the template to use the correct table fields.
Right click on the "list_people.xml" file and select "Design form".
The form designer is opened, showing the default design provided by the template we used.
Click on "Run designer" button to define the columns we want to display in the data grid.
Click on "Columns" button in the left panel.
Remove the columns "column_code" and "column_name" by selecting them in the list and clicking on "Remove" button.
Add a new column by clicking on "Add" button.
Give the name "column_firstName" to the column.
Set the Caption property to "people.firstName" and the FieldName property to "people_firstName".
By convention the caption will be "module name.field name".
Now create another column to display the "last name".
Change the caption of the form by modifying the "Text" property (be sure that the form is selection).
Be careful, don't use the "delete" key. In the current version, "delete" key is *always* removing the selected component. Use the "backspace" key instead when you want to delete some text in a field.
Set the value to "people.list" (the convention is "module_name.identifier", this will be used in the localization module and explained in next tutorials).
Save the modified design (CTRL-S) and close the designer.
Now, let's run this form.
Open the "list_people.py" file in the IDE (double click on it) and launch it by pressing the "F5" key.
You will receive this error message (the default template tries to use a table field that doesn't exists) :
Once you click on "OK", the form will still be displayed :
9/ Modifying the Python code
We need to modify the Python code, first close the displayed form (shortcut : CTRL-W).
Locate the "load_records" function (this function is in charge of loading data from the database to display them in the grid) and change "people_name" to "people_lastName, people_firstName".
Save the file (CTRL-S) and relaunch it (F5 key).
Now the form is displayed again without error, but we still have no data, we need to allow data entry.
10/ Managing data entry
Right click on "people" folder and select "Add -> DevExpress -> New Form-add...".
Set the name of the new file to "add_people.xml".
Right click on this newly created "add_people.xml" file and select "Design form" option.
The designer is opened and the default template for the data entry form is displayed.
Change the labels to match with the fields that are in our "people" table.
Delete the two "TextBox" controls (select them and press the delete key).
Your form will look like that :
Now add a new TextBox component on the form (using drag and drop) and name it "people_firstName" (by convention with name it like the database field).
Add another TextBox named "people_lastName", your form should look like that :
Save the file and close the designer.
We now need to add the Python code to manage the data entry, right click on "people" folder and select "Add -> DevExpress -> New Python-Add...".
The new Python file should be named "add_people.py".
Open the "add_people.py" file and locate the "loadRecord" function.
Some code needs to be modified to use the fields of our table :
Change "_code" to "_firstName" and "_name" to "_lastName" :
Location the "addRecord" function :
Change "_code" to "_firstName" and "_name" to "_lastName" :
Save the file.
11/ Testing the application
Select / open the file "list_people.py" in the editor.
Launch it by pressing the F5 key.
You should now be able to add / edit / delete the records.