With version 4.2, I turned my attention to facilitating rework in PAGE. That is, how do you use PAGE to tweak the GUI without loosing the supporting code that you have written? At the same time I want to allow one to view the changes with the run command button in the Python console.
Here is the situation. You design a GUI and generate the Python code using PAGE, which creates skeleton functions. You then fleshed out the skeleton functions to support the GUI and then decided to modify the GUI. If then you again generate the Python code for the GUI, you do not want to loose the application code which you have written to realize the application. This is the rework problem: How to keep your hard fought code when reworking the GUI?
Starting with version 4.2, I have tried to separate as completely as possible the automatically generated GUI code from the added support code. My approach is to create the generated GUI code in one Python module and the supporting code including skeleton functions and Tk variables in a separate Python module to be imported by the GUI module. That is, now PAGE generates two Python modules, one for the GUI and one for the supporting code complete with the necessary linkage.
PAGE implements this schema as follows. PAGE now works with three files:
It is expected that the user will generate a new version of the GUI module whenever he modifies the GUI but will need to modify the support module only when new Tk variables or callback functions are defined. The first will be much more frequent than the latter. Further, version 4.3 provides a mechanism for updating the support module by adding the new Tk variables and callback functions skeletons to an existing support module.
In the above, “<name>” is the application name (it was called the project name in the original Visual Tcl program) selected by the user when the system saves the ”.tcl” or extracted from the file name which may be supplied as a parameter when invoking PAGE.
Generation of either Python module will attempt to save the tcl file and in so doing may ask if you really want to save it. If you do not answer “yes” the root file name may not be known and bad code could be generated.
Let me repeat: You should only generate the support module once for an application; otherwise any code which you manually added will be lost. Well, just in case you do that inadvertently, PAGE will save some previous versions as backups. If you add new or change widgets in the GUI or modify callback functions or Tk variables changes will have to be made to the support module.
When saving the support module PAGE will test to see if a support module with the same name exists and if it does, it will question the user as to whether he wishes to continue.
For an example of the separation of the GUI module from the support module, see the WCPE directory in the examples directory. This is a program that displays the program of WCPE which is one of my favorite classical music stations. In this example all of the functional code is located in WCPE_support.py and the GUI design is recorded in WCPE.py which is the main module. I found it very tricky to deal with time zones and did not want to loose any of that code and have to redo it or to deal with diff’s ; at the same time, I was constantly tweaking the GUI. I generated the import module once and proceeded fill out the “init” function and the callback functions in WCPE_support.py while tweaking the GUI, i.e., changing its location, color, the size of the display fields, etc..
Also, in the examples directory, you can compare the progress_bar and the rework_progress_bar. The directory rework_progress_bar contains the changes that I made to the files in progress_bar to conform to the new rework scheme. It may be instructive in that it exemplifies an application comprised of two top level windows where one of the windows accesses Tkinter variables in the second window.
With chagrin, I apologize to the PAGE users for not having thought of this solution to rework long ago. Even though I have tested the idea with several examples, some of which are included in the section on examples, I worry that I have overlooked something big. So if you find any problems or oversights, please let me know.
The is the new feature of PAGE introduced with version 4.3. The basic idea is that reworking the GUI design may introduce new callback functions or Tk variables which need to incorporated into the support module. PAGE can now add those entities to the support module. That is, new skeletal functions are added and new entries are added to the set_Tk_var function, if necessary a set_Tk_var is added.
If Control-I was selected, then the user will be given the options of:
To rephrase the above, when the user selects Gen_Python->Generate Support Module from the main menu or selects Control-I, PAGE will analyze an existing support module and compare the callback functions and Tk variables in it with those utilized in the reworked design. If new entities are required the user will be given the option of automatically adding them. Existing code is not removed or modified. It is up to the user to remove or otherwise deal with code no longer needed.
One possibly confusing aspect of PAGE is the saving of the three files associated with a PAGE GUI:
PAGE implements several mechanisms for saving these files as discussed below.
As stated elsewhere the root name is derived from the name of the tcl file. The Python GUI design file root name is the same as that of the tcl file and the Python support module is that root name concatenated with “_support”.
When either the Python GUI module or the support module are saved, existing modules are retained as backups. Up to five backup modules are retained to help avoid inadvertent lose of application code.
Code from the Python Console source window is not automatically saved, the user must select either the Save or Run button of the Python Console.
When PAGE is closed by either Quit, Control-Q, or Control-C, the save action is the same as for the File->Save. Again, the GUI module and the support module are not affected.