home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / controls.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  5.2 KB  |  135 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5.  
  6. def Button(parent, text, callback, **kwargs):
  7.     button = wx.Button(parent, -1, _(text), **kwargs)
  8.     button.Bind((wx.EVT_BUTTON,), (lambda : callback()))
  9.     return button
  10.  
  11.  
  12. def Text(parent, text, *args, **kwargs):
  13.     return wx.StaticText(parent, -1, text, *args, **kwargs)
  14.  
  15.  
  16. def CheckBox(parent, text, value = sentinel, **kwargs):
  17.     checkbox = wx.CheckBox(parent, -1, _(text), **kwargs)
  18.     if value is not sentinel:
  19.         checkbox.Value = value
  20.     
  21.     return checkbox
  22.  
  23.  
  24. def TextInput(parent, value = sentinel, *args, **kwargs):
  25.     textctrl = wx.TextCtrl(parent, -1, *args, **kwargs)
  26.     if value is not sentinel:
  27.         textctrl.Value = value
  28.     
  29.     return textctrl
  30.  
  31.  
  32. def BoxSizer(type, *elems, **opts):
  33.     s = wx.BoxSizer({
  34.         'H': wx.HORIZONTAL,
  35.         'V': wx.VERTICAL }[type])
  36.     border = opts.get('border', 6)
  37.     return add_all(elems, s, border)
  38.  
  39.  
  40. def add_all(elems, s, border):
  41.     for elem in elems:
  42.         if elem == 'stretch':
  43.             s.AddStretchSpacer()
  44.             continue
  45.         s.Add(elem, 0, wx.ALL | wx.EXPAND, border)
  46.     
  47.     return s
  48.  
  49.  
  50. def HSizer(*elems, **opts):
  51.     return BoxSizer('H', *elems, **opts)
  52.  
  53.  
  54. def VSizer(*elems, **opts):
  55.     return BoxSizer('V', *elems, **opts)
  56.  
  57.  
  58. def FGridSizer(rows, cols, *elems, **opts):
  59.     s = wx.FlexGridSizer(rows, cols, vgap = opts.get('vgap', 0), hgap = opts.get('hgap', 0))
  60.     border = opts.get('border', 6)
  61.     add_all(elems, s, border)
  62.     return s
  63.  
  64.  
  65. class CustomControls(object):
  66.     
  67.     def __init__(self, parent):
  68.         self.parent = parent
  69.  
  70.     
  71.     class _TextInput(wx.TextCtrl):
  72.         
  73.         def __init__(self, controls, parent, value = sentinel, get_ = None, set_ = None, *args, **kwargs):
  74.             self.controls = controls
  75.             self.get_ = get_
  76.             self.set_ = set_
  77.             wx.TextCtrl.__init__(self, parent, -1, *args, **kwargs)
  78.  
  79.         
  80.         def GetValue(self):
  81.             if self.get_ is not None:
  82.                 return self.get_(wx.TextCtrl.GetValue(self))
  83.             return wx.TextCtrl.GetValue(self)
  84.  
  85.         
  86.         def SetValue(self, x):
  87.             if self.set_ is not None:
  88.                 return wx.TextCtrl.SetValue(self, self.set_(x))
  89.             return wx.TextCtrl.SetValue(self, x)
  90.  
  91.         Value = property(GetValue, SetValue)
  92.  
  93.     
  94.     def TextInput(self, *a, **k):
  95.         return self._TextInput(self, parent = self.parent, *a, **k)
  96.  
  97.     
  98.     def LabeledTextInput(self, label, *a, **k):
  99.         label_ = Text(self.parent, label)
  100.         text = self.TextInput(*a, **k)
  101.         return (label_, text)
  102.  
  103.     
  104.     def intBox(self, *a, **k):
  105.         return self.TextInput(get_ = int, set_ = str)
  106.  
  107.  
  108.  
  109. class RadioPanel(wx.BoxSizer):
  110.     
  111.     def __init__(self, parent, choices, clique = None):
  112.         wx.BoxSizer.__init__(self, wx.VERTICAL)
  113.         self.Buttons = []
  114.         for i, choice in enumerate(choices):
  115.             b = wx.RadioButton(parent, -1, choice)
  116.             b.Bind(wx.EVT_RADIOBUTTON, (lambda e, i = (i,): setattr(self, 'Value', i)))
  117.             self.Buttons.append(b)
  118.             if clique is not None:
  119.                 clique.add(b)
  120.             
  121.             self.Add(b, 0, wx.ALL, b.GetDefaultBorder())
  122.         
  123.  
  124.     
  125.     def GetValue(self):
  126.         return self.Value
  127.  
  128.     
  129.     def SetValue(self, val):
  130.         val = None if val != '' else 0
  131.         self.Buttons[val].SetValue(True)
  132.         self.Value = val
  133.  
  134.  
  135.