Attachment 'views.py'

Download

   1 #----------------------------------------------------------------------------
   2 # Name:         views.py
   3 # Purpose:      Hold the application visual representation
   4 #
   5 # Author:       Peter Damoc (peter at sigmacore.net)
   6 #               adapted from Martin Fowler's MVP example
   7 # Created:      January 2006
   8 # Version:      0.2 
   9 # Licence:      wxWindows license
  10 
  11 import wx
  12 
  13 class AlbumWindow(wx.Frame):
  14     '''
  15     This class holds the visual representation of your application
  16     '''
  17     def __init__(self):
  18         '''
  19         Here first we create the wx.App then we put together all the widgets
  20         '''
  21         self.app = wx.App(0)
  22         wx.Frame.__init__(self, None)
  23         self.SetBackgroundColour("lightgray")
  24         
  25         self.albums = wx.ListBox(self, size=(160, 240))
  26         self.artist = wx.TextCtrl(self, size=(160, -1))
  27         self.title = wx.TextCtrl(self)
  28         self.classical = wx.CheckBox(self, label="classical")
  29         self.composer = wx.TextCtrl(self)
  30         
  31         self.apply = wx.Button(self, label="Apply")
  32         self.cancel = wx.Button(self, label="Cancel")
  33         self.add = wx.Button(self, label="New Album")
  34         self.order = wx.Button(self, label="A->Z")
  35 
  36         leftSizer = wx.GridBagSizer(5,5)
  37         leftSizer.Add(self.albums, (0,0), (1,2),flag=wx.EXPAND)
  38         leftSizer.Add(self.add, (1,0), (1,1),flag=wx.EXPAND)
  39         leftSizer.Add(self.order, (1,1), (1,1),flag=wx.EXPAND)
  40         
  41         applyCancelSizer = wx.BoxSizer(wx.HORIZONTAL)
  42         applyCancelSizer.Add(self.apply, 0, wx.ALIGN_RIGHT)
  43         applyCancelSizer.Add(self.cancel, 0, wx.ALIGN_LEFT)
  44         
  45         albumSizer = wx.GridBagSizer(5,5)
  46         albumSizer.Add(wx.StaticText(self, label="Artist: "), (0,0), flag=wx.ALIGN_RIGHT)
  47         albumSizer.Add(self.artist, (0,1),flag=wx.EXPAND)
  48         albumSizer.Add(wx.StaticText(self, label="Album: "), (1,0), flag=wx.ALIGN_RIGHT)
  49         albumSizer.Add(self.title, (1,1), flag=wx.EXPAND)
  50         albumSizer.Add(self.classical, (2,0), (1,2), flag=wx.ALIGN_CENTER)        
  51         albumSizer.Add(wx.StaticText(self, label="Composer: "), (3,0), flag=wx.ALIGN_RIGHT)
  52         albumSizer.Add(self.composer, (3,1), flag=wx.EXPAND)
  53         albumSizer.Add(applyCancelSizer, (5,0), (1,2), flag=wx.ALIGN_CENTER)        
  54         
  55         
  56         mainSizer = wx.BoxSizer(wx.HORIZONTAL)
  57         mainSizer.Add(leftSizer, 0, wx.EXPAND|wx.ALL, 5)
  58         mainSizer.Add(albumSizer, 0, wx.EXPAND|wx.ALL, 5)
  59         
  60         self.SetSizerAndFit(mainSizer)
  61         
  62     def setTitle(self, title):
  63         self.title.SetValue(title)
  64         
  65     def setArtist(self, artist):
  66         self.artist.SetValue(artist)
  67         
  68     def setClassical(self, isClassical):
  69         self.classical.SetValue(isClassical)
  70         
  71     def setComposer(self, composer):
  72         self.composer.SetValue(composer)
  73         
  74     def setComposerEnabled(self, enabled):
  75         self.composer.Enable(enabled)
  76         
  77     def setApplyEnabled(self, enabled):
  78         self.apply.Enable(enabled)
  79         
  80     def setCancelEnabled(self, enabled):
  81         self.cancel.Enable(enabled)
  82         
  83     def setWindowTitle(self, title):
  84         self.SetTitle(title)
  85         
  86     def setAlbums(self, albums):
  87         '''
  88         This method contains a small optimisation to take care of the flicker that appears during 
  89         the updates. Exercise: comment out the Freeze and Thaw lines and see what happens
  90         '''
  91         self.Freeze()
  92         self.albums.Set([album.title for album in albums])
  93         self.Thaw()
  94         
  95     def setSelectedAlbum(self, albumIndex):
  96         self.albums.SetSelection(albumIndex)
  97         
  98     def setOrderLabel(self, label):
  99         self.order.SetLabel(label)
 100     
 101     def getOrderLabel(self):
 102         return self.order.GetLabel()
 103         
 104     def getTitle(self):
 105         return self.title.GetValue()
 106     
 107     def getArtist(self):
 108         return self.artist.GetValue()
 109         
 110     def getComposer(self):
 111         return self.composer.GetValue()
 112 
 113     def getSelectedAlbum(self):
 114         return self.albums.GetSelection()
 115 
 116     def isClassical(self):
 117         return self.classical.GetValue()
 118 
 119     def start(self):
 120         '''
 121         Upon start we just show the frame and enter the MainLoop
 122         '''
 123         self.CenterOnScreen()
 124         self.Show()
 125         self.app.MainLoop()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-10-04 09:16:02, 0.7 KB) [[attachment:albums.pyw]]
  • [get | view] (2009-10-04 09:16:02, 1.5 KB) [[attachment:interactors.py]]
  • [get | view] (2009-10-04 09:16:02, 2.3 KB) [[attachment:mock_objects.py]]
  • [get | view] (2009-10-04 09:16:02, 1.1 KB) [[attachment:models.py]]
  • [get | view] (2009-10-04 09:16:02, 12.4 KB) [[attachment:mvp.png]]
  • [get | view] (2009-10-04 09:16:02, 5.5 KB) [[attachment:mvp.zip]]
  • [get | view] (2009-10-04 09:16:02, 12.9 KB) [[attachment:mvp2.png]]
  • [get | view] (2009-10-04 09:16:02, 5.9 KB) [[attachment:mvp2.zip]]
  • [get | view] (2009-10-04 09:16:02, 3.8 KB) [[attachment:package.zip]]
  • [get | view] (2009-10-04 09:16:02, 4.4 KB) [[attachment:presenters.py]]
  • [get | view] (2009-10-04 09:16:02, 2.2 KB) [[attachment:test_presenters.py]]
  • [get | view] (2009-10-04 09:16:02, 4.3 KB) [[attachment:views.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.