views:

122

answers:

2

I'm planning to do an Desktop application using Python, to learn some Desktop concepts. I'm going to use GTK or Qt, I still haven't decided which one.

Fact is: I would like to create an application with the possibility to be called from command line, AND using a GUI. So it would be useful for cmd fans, and GUI users as well.

It would be interesting to create a web interface too in the future, so it could be run in a server somewhere using an html interface created with a template language.

I'm thinking about two approaches: - Creating a "model" (core module, where all the functionality resides) with a simple interface which is called from a desktop/web implementation; - Creating a "model" with an html interface, and embeb a browser component so I could reuse all the code in both desktop/web scenarios.

My question is: which exactly concepts are involved in this project? What advantages/disadvantages each approach has? Are they possible?

By naming "interface", I'm planning to just do some interfaces.py files with def calls. Is this a bad approach?

I would like to know some book recommendations, or resources to both options - or source code from projects which share the same GUI/cmd/web goals I'm after.

Thanks in advance!

+1  A: 

Decoupling the presentation layer from application logic makes it possible!.

You can divide your application into layers, a layer is a reusable portion of code that performs a specific function.

For example, you can divide the application into two or more layers, one layer with the presentation of the application and the other with the model. This allows reuse of the entire model of the application with different implementations of the presentation layer.

The presentation layer contains the components that implement and display the user interface and manage user interaction. This layer includes controls for user input and display, in addition to components that organize user interaction. Can have multiple implementations of the presentation layer technologies such as PyQt4, PyGtk, Html, console, etc.

Why Separating Model Is Useful?

You may wonder why it is important to move as much logic outside the presentation layer and into the model layer. The biggest reason is reuse: logic placed in a model increases the reusability of an application. As applications grow, applications often grow into other realms. Applications may start out as a web application, but some of the functionality may later be moved to a smart client application. Portions of an application may be split between a web site and a web or windows service that runs on a server. In addition, keeping logic helps aid in developing a good design (sometimes code can get sloppier in the UI).

However, there are some caveats to this: it takes a little longer to develop applications when most of the logic resides in the business layer. The reason is this often involves creating several sets of objects (data layer and access code, plus business objects) rather than embedding it in the application. The extra time that it takes to do this can be a turnoff for some managers and project leads, especially because it often requires you to be knowledgeable about object-oriented programming, more than most people are comfortable with.

You can search about N-Layered architectural style on the Internet.

This is a sample application that implements several types of user interfaces, but based on. NET framework, for python is similar.

http://microsoftnlayerapp.codeplex.com/

I am working on a big project based on PyQt4 presentation framework. one of the styles of architecture applied is N-Layers. If you want a simple example based on PyQt4, send me a email.

jordenysp
+1  A: 

What about a link to the source?

Having a CLI command and a GUI front-end is really common on unix platforms... The TransmissionBT bit torrent client is a good example of what you plan to do.

giassai
Good resource, thanks!
Somebody still uses you MS-DOS