1 """Graphical APDU Tracer.
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
26 import wx
27
28 from smartcard.CardConnectionObserver import CardConnectionObserver
29 from smartcard.util import toHexString
30
31 [
32 wxID_APDUTEXTCTRL,
33 ] = [wx.NewId() for x in range(1)]
34
35
37
39 wx.Panel.__init__(self, parent, -1)
40
41 boxsizer = wx.BoxSizer(wx.HORIZONTAL)
42 self.apdutextctrl = wx.TextCtrl(
43 self, wxID_APDUTEXTCTRL,
44 "",
45 pos=wx.DefaultPosition,
46 style=wx.TE_MULTILINE | wx.TE_READONLY)
47 boxsizer.Add(self.apdutextctrl, 1, wx.EXPAND | wx.ALL, 5)
48 self.SetSizer(boxsizer)
49 self.SetAutoLayout(True)
50
51 self.Bind(wx.EVT_TEXT_MAXLEN, self.OnMaxLength, self.apdutextctrl)
52
54 '''Reset text buffer when max length is reached.'''
55 self.apdutextctrl.SetValue("")
56 evt.Skip()
57
58 - def update(self, cardconnection, ccevent):
59 '''CardConnectionObserver callback.'''
60
61 apduline = ""
62 if 'connect' == ccevent.type:
63 apduline += 'connecting to ' + cardconnection.getReader()
64
65 elif 'disconnect' == ccevent.type:
66 apduline += 'disconnecting from ' + cardconnection.getReader()
67
68 elif 'command' == ccevent.type:
69 apduline += '> ' + toHexString(ccevent.args[0])
70
71 elif 'response' == ccevent.type:
72 if [] == ccevent.args[0]:
73 apduline += "< %-2X %-2X" % tuple(ccevent.args[-2:])
74 else:
75 apduline += "< " + toHexString(ccevent.args[0]) + \
76 "%-2X %-2X" % tuple(ccevent.args[-2:])
77
78 self.apdutextctrl.AppendText(apduline + "\n")
79