简体   繁体   中英

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,

  1. 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?

  2. If I still want to utilize the data model built for GUI, is it possible? If possible, what shall I do and any samples to follow? Do I need to refactor the data model?

  3. 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!!

如果可以从GUI调用数据模型的方法,并且它们不依赖于GUI中的任何内容,那么可以,您应该能够从另一个GUI调用相同的方法,无论是CLI,pyGTK还是其他方法。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM