Undertaking the task of converting a Visual Basic application to Python/C/C++.
I have undertaken the task of dusting off a VB application I delivered to a client about 2 years ago and converting it to Python and C/C++. You might rightfully conclude from my previous blog entries that I am leaning toward Python/C and C++/LAMP as my development platform of choice. I do have a more favorable view of Python than Java or .NET, and I am just driven by curiosity about Python and C/C++ and what I am missing from my education about programming and systems design by having been stuck on VB 6 for the past 3 1/2 years.
So, yesterday, I started authoring a document about the application I am porting to Python/C/C++/MySQL. The application currently has 29 different GUI modules (I will avoid the use of the word "form", *ahem*), which might be reduced to about 26 or fewer GUI classes through code reuse. According to my document, the design and creation of the database in MySQL will come first, then the design of prototype GUIs. Then, the creation of the database services in C or C++ will be next, followed by the finalization of the GUI modules in the language we decide will be best for production(Python, C/C++, or Tcl).
Last night, I reviewed the table schemas in the database and am close to finishing a script for MySQL that will create the tables. The hard part of migrating the data might be in importing it into MySQL (the actual production DB is a SQL Server DB). Later, I started working with Tkinter in Python to learn how to create a GUI module and how to work with widgets. I couldn't resist the excuse to work with Python, I guess. I read a tutorial on Tkinter produced by John Shipman of New Mexico Tech, which I believe I found via Google, as well as chapters from Mark Lutz's book, Programming Python. I created my first form, with text and button widgets, and created event handlers to clear the text widgets when the Clear button is pressed, and to close the application when the Exit button is pressed. So far, so good.
It is indeed a different experience designing a GUI module with Python/Tkinter than it is with VB. No IDE to speak of, no property pages to access, no IntelliSense dropdown, no form designer. Everything is done in code. It might be a little hard to get used to at first, but the rewarding part about this approach to developing applications might well be the control that one has over the look and feel of the application. What I have discovered with Tkinter is that you really do have a lot of control over the appearance of your GUI app through setting attributes of widgets and the use of geometry managers. Tkinter has three geometry managers available, and the best practice appears to be to choose one of them and stick to it for each GUI class. Shipman urges the reader to choose the grid geometry manager, and all of his code samples use calls to grid to place widgets in the GUI modules. For me, grid is easy to use because it draws upon the concept of a table and table cells to create rows and columns and set the width and height of each cell. Widgets are placed within the cells of the grid and aligned or "stickied" within the cells according to the attributes specified.
When I look at the documentation for Tkinter, one thought crosses my mind: there certainly aren't very many widgets in the the Tkinter toolset. Maybe this is a misreading of the situation, but the doc from Lutz, Shipman, and Frederik Lundh (who also wrote a guide on Tkinter) seem to indicate that Tkinter only has 15 base widgets that are supported. If this is the case, we may want to look into using wxPython, wxWindows or Win32 when it comes to building the production app. However, Lutz also has some more sophisticated examples of GUIs written in Tkinter in his book, which I plan to examine to see what can be done with Tkinter. It seems to me, though, that wxWindows does have a more extensive library of widgets. The project I am working on porting to Python makes use of a few different ActiveX controls in VB, and wxPython and wxWindows might have something that is closer to this functionality than what Tkinter can deliver. One other possibility is whether Tk via Tcl might support more widgets.
Comments