tuikit/common.py
changeset 16 8791a7da6835
parent 5 ae128c885d0f
child 23 4e72fd2a0e14
equal deleted inserted replaced
15:c55b4749e562 16:8791a7da6835
     4 class Coords:
     4 class Coords:
     5     def __init__(self, x=0, y=0):
     5     def __init__(self, x=0, y=0):
     6         self.x = x
     6         self.x = x
     7         self.y = y
     7         self.y = y
     8 
     8 
       
     9     def __getitem__(self, key):
       
    10         try:
       
    11             tupl = (self.x, self.y)
       
    12             return tupl[key]
       
    13         except TypeError:
       
    14             pass
       
    15         return self.__dict__[key]
       
    16     
       
    17     def __setitem__(self, key, value):
       
    18         if key == 0:
       
    19             self.x = value
       
    20         if key == 1:
       
    21             self.y = value
     9 
    22 
    10     def __repr__(self):
    23     def __repr__(self):
    11         return 'Coords(%(x)s,%(y)s)' % self.__dict__
    24         return 'Coords(x={0.x},y={0.y})'.format(self)
       
    25 
       
    26 
       
    27 class Size:
       
    28     def __init__(self, w=None, h=None):
       
    29         self.w = w
       
    30         self.h = h
       
    31     
       
    32     def __getitem__(self, key):
       
    33         try:
       
    34             tupl = (self.w, self.h)
       
    35             return tupl[key]
       
    36         except TypeError:
       
    37             pass
       
    38         return self.__dict__[key]
       
    39 
       
    40     def __setitem__(self, key, value):
       
    41         if key == 0:
       
    42             self.w = value
       
    43         if key == 1:
       
    44             self.h = value
       
    45     
       
    46     def __repr__(self):
       
    47         return 'Size(w={0.w},h={0.h})'.format(self)
    12 
    48 
    13 
    49 
    14 class Rect:
    50 class Rect:
    15     def __init__(self, x=0, y=0, w=0, h=0):
    51     def __init__(self, x=0, y=0, w=0, h=0):
    16         self.x = x
    52         self.x = x
    17         self.y = y
    53         self.y = y
    18         self.w = w
    54         self.w = w
    19         self.h = h
    55         self.h = h
    20 
    56 
       
    57     def __repr__(self):
       
    58         return 'Rect(x={0.x},y={0.y},w={0.w},h={0.h})'.format(self)
    21 
    59 
       
    60 
       
    61 class Borders:
       
    62     def __init__(self, l=0, t=0, r=0, b=0):
       
    63         self.l = l # left
       
    64         self.t = t # top
       
    65         self.r = r # right
       
    66         self.b = b # bottom
       
    67 
       
    68     def __getitem__(self, key):
       
    69         try:
       
    70             tupl = (self.l, self.t, self.r, self.b)
       
    71             return tupl[key]
       
    72         except TypeError:
       
    73             pass
       
    74         return self.__dict__[key]
       
    75     
    22     def __repr__(self):
    76     def __repr__(self):
    23         return 'Rect(%(x)s,%(y)s,%(w)s,%(h)s)' % self.__dict__
    77         return 'Borders(l={0.l},t={0.t},r={0.r},b={0.b})'.format(self)
    24 
    78