home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / twitter / twitter_account_gui.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  6.5 KB  |  149 lines

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