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
32
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
41
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
58
59
60
104