class DESFireDialogBase_FileOperation ( wx.Dialog ):
    
    def __init__( self, parent ):
        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"DESFire File Operation", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        
        bSizer193 = wx.BoxSizer( wx.VERTICAL )
        
        bSizer194 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._statictextFileNo = wx.StaticText( self, wx.ID_ANY, u"File No", wx.DefaultPosition, wx.Size( 45,-1 ), wx.ALIGN_CENTRE )
        self._statictextFileNo.Wrap( -1 )
        self._statictextFileNo.SetMinSize( wx.Size( 45,-1 ) )
        self._statictextFileNo.SetMaxSize( wx.Size( 45,-1 ) )
        
        bSizer194.Add( self._statictextFileNo, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self._textctrlFileNo = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        self._textctrlFileNo.SetMaxLength( 2 ) 
        self._textctrlFileNo.Enable( False )
        
        bSizer194.Add( self._textctrlFileNo, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer193.Add( bSizer194, 1, wx.EXPAND, 5 )
        
        bSizer195 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._statictextOffset = wx.StaticText( self, wx.ID_ANY, u"Offset", wx.DefaultPosition, wx.Size( 45,-1 ), wx.ALIGN_CENTRE )
        self._statictextOffset.Wrap( -1 )
        self._statictextOffset.SetMinSize( wx.Size( 45,-1 ) )
        self._statictextOffset.SetMaxSize( wx.Size( 45,-1 ) )
        
        bSizer195.Add( self._statictextOffset, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self._textctrlOffset = wx.TextCtrl( self, wx.ID_ANY, u"000000", wx.DefaultPosition, wx.DefaultSize, 0 )
        self._textctrlOffset.SetMaxLength( 6 ) 
        bSizer195.Add( self._textctrlOffset, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer193.Add( bSizer195, 1, wx.EXPAND, 5 )
        
        bSizer196 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._statictextLength = wx.StaticText( self, wx.ID_ANY, u"Length", wx.DefaultPosition, wx.Size( 45,-1 ), wx.ALIGN_CENTRE )
        self._statictextLength.Wrap( -1 )
        self._statictextLength.SetMinSize( wx.Size( 45,-1 ) )
        self._statictextLength.SetMaxSize( wx.Size( 45,-1 ) )
        
        bSizer196.Add( self._statictextLength, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self._textctrlLength = wx.TextCtrl( self, wx.ID_ANY, u"000000", wx.DefaultPosition, wx.DefaultSize, 0 )
        self._textctrlLength.SetMaxLength( 6 ) 
        bSizer196.Add( self._textctrlLength, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer193.Add( bSizer196, 1, wx.EXPAND, 5 )
        
        bSizer197 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._statictextData = wx.StaticText( self, wx.ID_ANY, u"DATA", wx.DefaultPosition, wx.Size( 45,-1 ), wx.ALIGN_CENTRE )
        self._statictextData.Wrap( -1 )
        self._statictextData.SetMinSize( wx.Size( 45,-1 ) )
        self._statictextData.SetMaxSize( wx.Size( 45,-1 ) )
        
        bSizer197.Add( self._statictextData, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self._textctrlData = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        self._textctrlData.SetMaxLength( 222 ) 
        bSizer197.Add( self._textctrlData, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer193.Add( bSizer197, 1, wx.EXPAND, 5 )
        
        bSizer199 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._statictextValue = wx.StaticText( self, wx.ID_ANY, u"Value", wx.DefaultPosition, wx.Size( 45,-1 ), wx.ALIGN_CENTRE )
        self._statictextValue.Wrap( -1 )
        self._statictextValue.SetMinSize( wx.Size( 45,-1 ) )
        self._statictextValue.SetMaxSize( wx.Size( 45,-1 ) )
        
        bSizer199.Add( self._statictextValue, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self._textctrlValue = wx.TextCtrl( self, wx.ID_ANY, u"00000000", wx.DefaultPosition, wx.DefaultSize, 0 )
        self._textctrlValue.SetMaxLength( 8 ) 
        bSizer199.Add( self._textctrlValue, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer193.Add( bSizer199, 1, wx.EXPAND, 5 )
        
        bSizer198 = wx.BoxSizer( wx.HORIZONTAL )
        
        self._buttonOK = wx.Button( self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer198.Add( self._buttonOK, 0, wx.ALL, 5 )
        
        self._buttonCancel = wx.Button( self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer198.Add( self._buttonCancel, 0, wx.ALL, 5 )
        
        
        bSizer193.Add( bSizer198, 1, wx.EXPAND, 5 )
        
        
        self.SetSizer( bSizer193 )
        self.Layout()
        bSizer193.Fit( self )
        
        self.Centre( wx.BOTH )
        
        # Connect Events
        self._buttonOK.Bind( wx.EVT_BUTTON, self._buttonOKOnButtonClick )
        self._buttonCancel.Bind( wx.EVT_BUTTON, self._buttonCancelOnButtonClick )
    
    def __del__( self ):
        pass
    
    
    # Virtual event handlers, overide them in your derived class
    def _buttonOKOnButtonClick( self, event ):
        event.Skip()
    
    def _buttonCancelOnButtonClick( self, event ):
        event.Skip() IDOK = 1 IDCANCEL = 2 class Util(object):
    '''
    Util functions;
    '''
    
    HEXCHARS = '0123456789ABCDEFabcdef'
    
    @staticmethod
    def removespace(s):
        s = s.replace(' ', '')
        s = s.replace('\t', '')
        s = s.replace('\r', '')
        s = s.replace('\n', '')
        return s
    
    @staticmethod
    def c2v(c):
        """Get value of one char; Argument c is the input char;"""
        cv = ord(c)
        if ((cv >= ord('0')) and (cv <= ord('9'))):
            return cv - ord('0')
        elif ((cv >= ord('A')) and (cv <= ord('F'))):
            return cv - ord('A') + 10
        elif ((cv >= ord('a')) and (cv <= ord('f'))):
            return cv - ord('a') + 10
        else:
            raise ValueError
    
    @staticmethod
    def s2vl(s):
        """Convert string to value list; Argument s is the input string; ("00A4040000" => {0x00, 0xA4, 0x04, 0x00, 0x00})"""
        s = Util.removespace(s)
        if (len(s) & 1) != 0:
            raise ValueError()
        for c in s:
            if c not in Util.HEXCHARS:
                raise ValueError()
        vl = []
        for i in xrange(0, len(s) / 2):
            vl.append(Util.c2v(s[i * 2]) << 4 | Util.c2v(s[i * 2 + 1]))
        return vl

    @staticmethod
    def s2vs(s):
        s = Util.removespace(s)
        if (len(s) & 1) != 0:
            raise ValueError()
        for c in s:
            if c not in Util.HEXCHARS:
                raise ValueError()
        vs = ''
        for i in xrange(0, len(s) / 2):
            vs += chr(Util.c2v(s[i * 2]) << 4 | Util.c2v(s[i * 2 + 1]))
        return vs
    
    @staticmethod
    def vl2s(vl, pad=''):
        """Convert value list to string; ({0x00, 0xA4, 0x04, 0x00, 0x00} => "00A4040000")"""
        return pad.join("%02X" %(v) for v in vl)

    @staticmethod
    def vs2s(vs, pad=''):
        """Convert value list to string; ('\x00\xA4\x04\x00\x00' => "00A4040000")"""
        return pad.join("%02X" %(ord(v)) for v in vs)

    @staticmethod
    def getTimeStr(tv):
        """Get time string to display; tv is the time value;"""
        if tv < 0:
            timeStr = '< 0'
        elif tv < 0.000001:
            timeStr = '%3.3fns' %(tv * (10 ** 9))
        elif tv < 0.001:
            timeStr = '%3.3fus' %(tv * (10 ** 6))
        elif tv < 1.0:
            timeStr = '%3.3fms' %(tv * (10 ** 3))
        else:
            timeStr = '%3.3fs' %(tv * (10 ** 0))
        return timeStr

    @staticmethod
    def isprint_keycode(kc): return kc >= 32 and kc <= 126

    @staticmethod
    def isprint_char(c): return ord(c) >= 32 and ord(c) <= 126

    @staticmethod
    def ishexchar_kc(kc):
        isHexChar = False
        if Util.isprint_keycode(kc):
            if kc >= ord('0') and kc <= ord('9'):
                isHexChar = True
            elif kc >= ord('a') and kc <= ord('f'):
                isHexChar = True
            elif kc >= ord('A') and kc <= ord('F'):
                isHexChar = True
        else:
            isHexChar = True
        return isHexChar

    @staticmethod
    def ishexchar_c(c):
        isHexChar = False
        if Util.isprint_char(c):
            if c >= '0' and c <= '9':
                isHexChar = True
            elif c >= 'a' and c <= 'f':
                isHexChar = True
            elif c >= 'A' and c <= 'F':
                isHexChar = True
        return isHexChar

    @staticmethod
    def isnumchar_kc(kc):
        isNumChar = False
        if Util.isprint_keycode(kc):
            if kc >= ord('0') and kc <= ord('9'):
                isNumChar = True
        else:
            isNumChar = True
        return isNumChar

    @staticmethod
    def isnumchar_c(c):
        isNumChar = False
        if Util.isprint_char(c):
            if c >= '0' and c <= '9':
                isNumChar = True
        else:
            isNumChar = True
        return isNumChar
    
    @staticmethod
    def ishexstr(s):
        s = Util.removespace(s)
        ishexstr = True
        for c in s:
            if not Util.ishexchar_c(c):
                ishexstr = False
                break
        return ishexstr
    
    @staticmethod
    def bytes3_to_byte_array(value):
        return [(value & 0xff), (value >> 8) & 0xff, (value >> 16) & 0xff ]

    @staticmethod
    def byte_array3_to_dword(byte_array):
        return byte_array[0] | (byte_array[1] << 8) | (byte_array[2] << 16)

    @staticmethod
    def byte_array4_to_dword(byte_array):
        return byte_array[0] | (byte_array[1] << 8) | (byte_array[2] << 16) | (byte_array[3] << 24)

    @staticmethod
    def calculate_crc(data, size, reg):
        for octet in data[:size]:
            for pos in range(8):
                bit = (reg ^ ((octet >> pos) & 1)) & 1
                reg = reg >> 1
                if bit:
                    reg = reg ^ 0x8408
        return reg READ_DATA                   = 0x8D WRITE_DATA                  = 0x3D CREDIT                      = 0x0C DEBIT                       = 0xDC LIMITED_CREDIT              = 0x1C WRITE_RECORD                = 0x3B READ_RECORDS                = 0xBB
from pyResMan.BaseDialogs.pyResManDESFireDialogBase_FileOperation import DESFireDialogBase_FileOperation
from pyResMan.Util import IDOK, IDCANCEL, Util
from pyResMan.DESFireEx import READ_DATA, WRITE_DATA, CREDIT, DEBIT,\
    LIMITED_CREDIT, WRITE_RECORD, READ_RECORDS
'''
Created on 2017/04/19

@author: zhenkui
'''

class DESFireDialog_FileOperation(DESFireDialogBase_FileOperation):
    '''
    '''


    def __init__(self, parent, command_type, file_id):
        '''
        Constructor
        '''

        DESFireDialogBase_FileOperation.__init__(self, parent)