Package smartcard :: Package wx :: Module ReaderToolbar
[hide private]
[frames] | no frames]

Source Code for Module smartcard.wx.ReaderToolbar

 1  """wxPython toolbar with reader icons implementing ReaderObserver. 
 2   
 3  __author__ = "gemalto http://www.gemalto.com" 
 4   
 5  Copyright 2001-2011 gemalto 
 6  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
 7   
 8  This file is part of pyscard. 
 9   
10  pyscard is free software; you can redistribute it and/or modify 
11  it under the terms of the GNU Lesser General Public License as published by 
12  the Free Software Foundation; either version 2.1 of the License, or 
13  (at your option) any later version. 
14   
15  pyscard is distributed in the hope that it will be useful, 
16  but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18  GNU Lesser General Public License for more details. 
19   
20  You should have received a copy of the GNU Lesser General Public License 
21  along with pyscard; if not, write to the Free Software 
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
23  """ 
24   
25  import  wx 
26   
27  from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver 
28  from smartcard.wx import ICO_SMARTCARD, ICO_READER 
29   
30   
31 -class ReaderComboBox(wx.ComboBox, ReaderObserver):
32
33 - def __init__(self, parent):
34 """Constructor. Registers as ReaderObserver to get 35 notifications of reader insertion/removal.""" 36 wx.ComboBox.__init__(self, parent, wx.NewId(), 37 size=(170, -1), style=wx.CB_DROPDOWN | wx.CB_SORT, 38 choices=[]) 39 40 # register as a ReaderObserver; we will ge notified of added/removed readers 41 self.readermonitor = ReaderMonitor() 42 self.readermonitor.addObserver(self)
43
44 - def update(self, observable, (addedreaders, removedreaders)):
45 """Toolbar ReaderObserver callback that is notified when 46 readers are added or removed.""" 47 for reader in addedreaders: 48 item = self.Append(str(reader)) 49 self.SetClientData(item, reader) 50 for reader in removedreaders: 51 item = self.FindString(str(reader)) 52 if wx.NOT_FOUND != item: 53 self.Delete(item) 54 selection = self.GetSelection()
55 #if wx.NOT_FOUND == selection: 56 # self.SetSelection(0) 57 58
59 -class ReaderToolbar(wx.ToolBar):
60 """ReaderToolbar. Contains controls to select a reader from a listbox 61 and connect to the cards.""" 62
63 - def __init__(self, parent):
64 """Constructor, creating the reader toolbar.""" 65 wx.ToolBar.__init__(self, 66 parent, 67 pos=wx.DefaultPosition, 68 size=wx.DefaultSize, 69 style=wx.SIMPLE_BORDER | wx.TB_HORIZONTAL | wx.TB_FLAT | wx.TB_TEXT, 70 name='Reader Toolbar') 71 72 # create bitmaps for toolbar 73 tsize = (16, 16) 74 if None != ICO_READER: 75 bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) 76 else: 77 bmpReader = wx.ArtProvider_GetBitmap(wx.ART_HELP_BOOK, wx.ART_OTHER, isz) 78 if None != ICO_SMARTCARD: 79 bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) 80 else: 81 bmpCard = wx.ArtProvider_GetBitmap(wx.ART_HELP_BOOK, wx.ART_OTHER, isz) 82 self.readercombobox = ReaderComboBox(self) 83 84 # create and add controls 85 self.AddSimpleTool(10, bmpReader, "Select smart card reader", "Select smart card reader") 86 self.AddControl(self.readercombobox) 87 self.AddSeparator() 88 self.AddSimpleTool(20, bmpCard, "Connect to smartcard", "Connect to smart card") 89 self.AddSeparator() 90 91 self.Realize()
92