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-2012 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 get 41 # notified of added/removed readers 42 self.readermonitor = ReaderMonitor() 43 self.readermonitor.addObserver(self)
44
45 - def update(self, observable, handlers):
46 """Toolbar ReaderObserver callback that is notified when 47 readers are added or removed.""" 48 addedreaders, removedreaders = handlers 49 for reader in addedreaders: 50 item = self.Append(str(reader)) 51 self.SetClientData(item, reader) 52 for reader in removedreaders: 53 item = self.FindString(str(reader)) 54 if wx.NOT_FOUND != item: 55 self.Delete(item) 56 selection = self.GetSelection()
57 #if wx.NOT_FOUND == selection: 58 # self.SetSelection(0) 59 60
61 -class ReaderToolbar(wx.ToolBar):
62 """ReaderToolbar. Contains controls to select a reader from a listbox 63 and connect to the cards.""" 64
65 - def __init__(self, parent):
66 """Constructor, creating the reader toolbar.""" 67 wx.ToolBar.__init__( 68 self, 69 parent, 70 pos=wx.DefaultPosition, 71 size=wx.DefaultSize, 72 style=wx.SIMPLE_BORDER | wx.TB_HORIZONTAL | wx.TB_FLAT | wx.TB_TEXT, 73 name='Reader Toolbar') 74 75 # create bitmaps for toolbar 76 tsize = (16, 16) 77 if None != ICO_READER: 78 bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) 79 else: 80 bmpReader = wx.ArtProvider_GetBitmap( 81 wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) 82 if None != ICO_SMARTCARD: 83 bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) 84 else: 85 bmpCard = wx.ArtProvider_GetBitmap( 86 wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) 87 self.readercombobox = ReaderComboBox(self) 88 89 # create and add controls 90 self.AddSimpleTool( 91 10, 92 bmpReader, 93 "Select smart card reader", 94 "Select smart card reader") 95 self.AddControl(self.readercombobox) 96 self.AddSeparator() 97 self.AddSimpleTool( 98 20, 99 bmpCard, "Connect to smartcard", 100 "Connect to smart card") 101 self.AddSeparator() 102 103 self.Realize()
104