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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from copy import deepcopy
  6. from wx import StaticText, EXPAND, TOP, ALIGN_CENTER, VERTICAL, HORIZONTAL, Color, ALIGN_CENTER_VERTICAL, CheckBox, Choice
  7. UPDATE_DESC_TEXT = _('Twitter allows for 150 requests per hour. Make sure to\nleave room for manual updates and other actions.')
  8. UPDATE_TYPES = [
  9.     ('friends_timeline', _('Friends:')),
  10.     ('replies', _('Mentions:')),
  11.     ('direct_messages', _('Directs:')),
  12.     ('search_updatefreq', _('Searches:'))]
  13.  
  14. def adds_to_total(updatetype):
  15.     return updatetype != 'search_updatefreq'
  16.  
  17. UPDATE_CHOICES = [
  18.     ('1', 1),
  19.     ('2', 2),
  20.     ('3', 3),
  21.     ('4', 4),
  22.     ('5', 5),
  23.     ('10', 10),
  24.     ('15', 15),
  25.     ('20', 20),
  26.     ('30', 30)]
  27. UPDATE_CHOICES = [ (s + _(' minutes'), n) for s, n in UPDATE_CHOICES ]
  28. UPDATE_CHOICES.append((_('Never'), 0))
  29. UPDATE_GUI_STRINGS = [ s for s, n in UPDATE_CHOICES ]
  30. UPDATE_VALUES = dict((lambda .0: for s, n in .0:
  31. (n, i))(enumerate(UPDATE_CHOICES)))
  32.  
  33. def color_for_total(total):
  34.     if total > 150:
  35.         return Color(255, 0, 0)
  36.     if total > 125:
  37.         return Color(255, 165, 0)
  38.     return Color(0, 0, 0)
  39.  
  40.  
  41. def protocolinfo():
  42.     protocols = protocols
  43.     import common.protocolmeta
  44.     return protocols['twitter']
  45.  
  46.  
  47. class TwitterAccountPanel(wx.Panel):
  48.     
  49.     def __init__(self, parent, account):
  50.         wx.Panel.__init__(self, parent)
  51.         self.construct()
  52.         self.layout()
  53.         self.Bind(wx.EVT_CHOICE, self.SelectionChanged)
  54.         self.set_values(account)
  55.         self.SelectionChanged()
  56.  
  57.     
  58.     def set_values(self, account):
  59.         defaults = deepcopy(protocolinfo().defaults)
  60.         defaults.update(getattr(account, 'update_frequencies', { }))
  61.         self.auto_throttle.Value = getattr(account, 'auto_throttle', defaults.get('auto_throttle'))
  62.         for name, _ in UPDATE_TYPES:
  63.             self.choices[name].Selection = UPDATE_VALUES.get(defaults.get(name), 4)
  64.         
  65.  
  66.     
  67.     def construct(self):
  68.         self.header = StaticText(self, -1, _('Update Frequency:'))
  69.         self.header.SetBold()
  70.         self.desc = StaticText(self, -1, UPDATE_DESC_TEXT)
  71.         self.update_texts = { }
  72.         self.choices = { }
  73.         for name, guistring in enumerate(UPDATE_TYPES):
  74.             self.update_texts[name] = StaticText(self, -1, guistring)
  75.             self.choices[name] = Choice(self, choices = UPDATE_GUI_STRINGS)
  76.         
  77.         self.total = StaticText(self, style = ALIGN_CENTER)
  78.         self.total.SetBold()
  79.         self.auto_throttle = CheckBox(self, label = _('Auto-throttle when Twitter lowers the rate limit.'), name = 'auto_throttle')
  80.  
  81.     
  82.     def info(self):
  83.         d = (dict,)((lambda .0: for name, _gui in .0:
  84. (name, UPDATE_CHOICES[self.choices[name].Selection][1]))(UPDATE_TYPES))
  85.         d['auto_throttle'] = self.auto_throttle.Value
  86.         return d
  87.  
  88.     
  89.     def layout(self):
  90.         gb = wx.GridBagSizer(hgap = 3, vgap = 3)
  91.         for name, guistring in enumerate(UPDATE_TYPES):
  92.             gb.Add(self.update_texts[name], (i, 0), flag = ALIGN_CENTER_VERTICAL)
  93.             gb.Add(self.choices[name], (i, 1))
  94.         
  95.         gb_h = wx.BoxSizer(HORIZONTAL)
  96.         gb_h.Add(gb, 0, EXPAND)
  97.         t_v = wx.BoxSizer(VERTICAL)
  98.         t_v.AddStretchSpacer(1)
  99.         t_v.Add(self.total, 0, EXPAND | ALIGN_CENTER)
  100.         t_v.AddStretchSpacer(1)
  101.         gb_h.Add(t_v, 1, EXPAND | ALIGN_CENTER)
  102.         inner_sz = wx.BoxSizer(VERTICAL)
  103.         inner_sz.AddMany([
  104.             (self.header, 0, EXPAND),
  105.             (self.desc, 0, EXPAND | TOP, 5),
  106.             (gb_h, 0, EXPAND | TOP, 7),
  107.             (self.auto_throttle, 0, EXPAND | TOP, 7)])
  108.         sz = self.Sizer = wx.BoxSizer(HORIZONTAL)
  109.         sz.Add(inner_sz, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 7)
  110.  
  111.     
  112.     def SelectionChanged(self, e = None):
  113.         mins = _[1]
  114.         total_updates = sum((lambda .0: for min in .0:
  115. None if min else 0)(mins))
  116.         total_txt = self.total
  117.         total_txt.SetLabel('%d / %s' % (total_updates, _('hour')))
  118.         total_txt.ForegroundColour = color_for_total(total_updates)
  119.         self.Layout()
  120.  
  121.  
  122.