how to make a Command Line Interface from a given data model used for GUI
HI, guys. I am developing a GUI to configure and call several external programs with Python and I use wxPython for the GUI toolkits. Basically, instead of typing commands and parameters in each shell for each application (one application via one shell), the GUI is visualizing these parameters and call them as subprocesses. I have built the data model and the relevant view/gui controls (mainly by using the observer pattern or try to separate model with the gui widgets), and it is OK.
Now there is a request from my colleagues and many other people (even including myself), is it possible to have a command line interface for the subprocesses, or even for the whole configuration GUI, based on the data model I already have? This is due to the fact that many people prefer CLI, CLI is better in reliability, and also needs of programmer debugging and interfacing.
As I am rather new to developing a CLI, I really need some help from you. I appreciate any advice and information from you.
to be more specific,
If I completely forget about the data model built for GUI, start from scratch. Is there some good materials or samples to have a reference?
If I still want to utilize the data model built for GUI, is it possible? If possible, what shall I do and any s开发者_开发百科amples to follow? Do I need to refactor the data model?
Is it possible to have the CLI and GUI at the same time? I mean, can I take the CLI as another view of the data model? Or there is other right approach?
Thank you very much for your help!!
Is it possible to have the CLI and GUI at the same time? I mean, can I take the CLI as another view of the data model? Or there is other right approach?
That's correct, a CLI is just another frontend to access the data model. You said your model is clean of GUI code? (it should, even if you only had one frontend) in this case adding CLI capabilities should be trivial; a sane command-line design (options, subcommands) and optparse is all you need.
If you can call your data model's methods from your GUI and they don't depend on anything in the GUI, then yes, you should be able to call those same methods from another GUI, be it CLI, pyGTK or whatever.
精彩评论