Python - Separate program logic and GUI code?
What would be the best way of separating program logic to the GUI code?
I wanted different GUI (GTK, KDE, CLI) code using the same program logic.
I was thinking of using different python module (winecellar-common, winecellar-gtk, winecellar开发者_Python百科-cli) not sure how I would do this and if its the best way.
*EDITED*
Just to add to my question what would be the best way to organize the projects file structure and build platform with different modules. Keep in mind its mainly being used on Ubuntu.
Define functions or classes for your business logic in one module, and define your presentation in another, using those functions to get your presentation. You should almost entirely be using functions and classes from the main module in the GUI module. You should do the same thing for your CLI. That way, you can have different distributions with different interfaces, and not have to create a different "logic" file for each one.
Basically, you have the right idea. Just keep them as separate as possibility so that a.) you can support multiple interfaces easily and b.) you can easily make changes to the interfaces.
Maybe "Model-View-Controller" pattern will be useful for you. There is a nice tutorial with wxPython on implementing this architecture: http://wiki.wxpython.org/ModelViewController
精彩评论