Project scheduling software (scriptable, cross-platform, and open source)
GanttPV Home
Why GanttPV? Help Scripts Server Developer Object Role Modeling
Forum

How to create GanttPV scripts

The easiest way to learn GanttPV scripting is to modify and experiment with existing scripts. You will need to learn something about the Python scripting language, and, depending on your goals, you might need to know about the wxPython widgets library.

Python is a delightful scripting language. The best introduction to the language is the Python Tutorial (tut.pdf) that comes with Python. It can be downloaded from the Python web site. Python documentation is surprisingly good and beautifully formatted. The Python Library Reference (lib.pdf) is also useful. But the best book to keep in hand is the Python Pocket Reference by Mark Lutz from O'Reilly. (If only their other pocket books were as good.)

If you want your script to interact with the users, you will need to learn something about wxPython, the Python interface to the wxWidgets GUI development library. The library itself is near wonderful (if rough around the edges), but the documentation is poor. wxPython is only usable because of an excellent set of demo programs (full of working examples of key features) and an active developers mailing list. If possible try to cut and paste something from another script that is close to what you need.

You will also need to learn how data is organized and updated in GanttPV. The following information is provided to help you to understand what scripts are doing.

Visit the "Creating Scripts for GanttPV" forum

The scripts forum is the place to:

  • Ask questions about any of the current scripts.
  • Make suggestions for new scripts.
  • Get ideas on how to write your own scripts.

You may wish to register in the forum. Registration will reserve the name you chose and allow you to edit your posts.

If you decide not to register, you may still make posts in your name. When you have the post ready to add, just enter your name and leave the password field blank.

Think tables

GanttPV data is defined as tables ("Project", "Task", "Holiday") and columns ("Name", "StartDate"). See Data. Each project, task, or holiday is a row in one of these table. Every row is identified by a unique "ID" number.

To access data you specify: the table, the id, and the column name. For example, to print the name of project number one, you would type:

    print Data.Database["Project"][1]["Name"]

For "Project" and some other tables a short cut is provided, so you may also see the shorter form:

    print Data.Project[1]["Name"]

Use Update and SetUndo for all changes to the database

Treat GanttPV data tables as "READ ONLY". Don't change them directly. All updates should be made through the routines "Update" and "SetUndo".

There are several reasons for this: (1) it makes the effects of your script undo-able, (2) it refreshes all reports that may be affected by the change, (3) it will make planned future upgrades much easier (for example, keeping project data in a relational database).

Here is an example of how you would change the name of project #1 to "New Name".

    change = { 'Table': 'Project', 'ID': 1, 'Name': 'New Name' }
    Data.Update(change)
    Data.SetUndo('Change Project Name')

Routines that can be used in your scripts

RoutineDescriptionAvailable
Data.SetUndo(string) The string will be displayed in the Undo menu item. All Updates since the last SetUndo are treated as a group and will all be undone together. v0.1
Data.Update(dict) Pass Update a dictionary. Entries "Table" and "ID" identify the table and row to be updated. If "ID" is not provided, a new row will be created. The new ID can be retrieved from the dictionary that is returned. All other key values should be column names. The function returns an dictionary of old values for columns that were changed. v0.1
Data.DateConv[date] * Convert text date ("YYYY-MM-DD") to internal date index (integer). v0.1
Data.DateIndex[index] * Convert internal date index (integer) to text date ("YYYY-MM-DD"). v0.1
Data.DateInfo[index] * Returns three values: (1) number of work hours during day, (2) the cumulative work hours since an internal reference date, (3) a number representing the day of the week (0 = Monday). v0.1
Data.GetToday() * Returns the current date in "YYYY-MM-DD" format, like "2004-01-09". v0.1
Data.GetColumnList(reportid) Returns an array of column ids for the specified report. v0.1
Data.GetRowList(reportid) Returns an array of row ids for the specified report. Be careful, this list will include hidden or deleted rows. v0.1

* Names marked by an asterisk are tentative and may be changed based on later reflection and feedback. We look forward to you comments and suggestions on names in the GanttPV Forum.