Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The most straightforward approach for utility type program would be something like the following pseudocode-ish Python with hints of PyGTK. Imagine a utility that manipulates files in a certain fashion.</p> <pre><code>class File(object): """This class handles various filesystem-related tasks.""" def __init__(self, path): pass def open(self): pass def rename(self, new_name): pass def move(self, to): pass class Window(gtk.Window): """This class is the actual GUI window with widgets.""" def __init__(self): self.entry_rename = gtk.Entry() self.entry_move = gtk.Entry() self.btn_quit = gtk.Button('Quit') class App(object): """This is your main app that displays the GUI and responds to signals.""" def __init__(self): self.window = Window() # signal handlers self.window.connect('destroy', self.on_quit) self.window.entry_rename.connect('changed', self.on_rename_changed) self.window.entry_move.connect('changed', self.on_move_changed) self.window.btn_quit.connect('clicked', self.on_quit) # and so on... def on_quit(self): """Quit the app.""" pass def on_rename_changed(self): """User typed something into an entry box, do something with text.""" f = File('somefile.txt') f.rename(self.entry_rename.get_text()) def on_move_changed(self): """User typed something into another entry box, do something with text.""" f = File('somefile.txt') f.move(self.entry_move.get_text()) </code></pre> <p>You can think of this as an informal MVC: <code>File</code> is you model, <code>Window</code> is the view and <code>App</code> is the controller.</p> <p>Of course, there are other, more formal approaches. Wikis of most Python GUI toolkits have articles about possible arhitectures. See, for example, the wxPython <a href="http://wiki.wxpython.org/ModelViewController" rel="nofollow">wiki article on MVC</a>. There is also an MVC framework for PyGTK, called <a href="http://sourceforge.net/apps/trac/pygtkmvc/wiki" rel="nofollow">pygtkmvc</a>. </p> <p><em>I have an opinion that unless you are absolutely sure that you need such a formal approach, you're better off using something like the code above</em>. Web frameworks benefit from a more formal approach because there are many more pieces to connect: HTTP requests, HTML, JavaScript, SQL, business logic, presentation logic, routing and so on even for the simplest apps. With your typical Python GUI app, you just have to handle the business logic and event handling, all in Python.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload