home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import wx
- import sys
- from copy import deepcopy
- from wx import StaticText, EXPAND, TOP, ALIGN_CENTER, VERTICAL, HORIZONTAL, Color, ALIGN_CENTER_VERTICAL, CheckBox, Choice
- UPDATE_DESC_TEXT = _('Twitter allows for 150 requests per hour. Make sure to\nleave room for manual updates and other actions.')
- UPDATE_TYPES = [
- ('friends_timeline', _('Friends:')),
- ('replies', _('Mentions:')),
- ('direct_messages', _('Directs:')),
- ('search_updatefreq', _('Searches:'))]
-
- def adds_to_total(updatetype):
- return updatetype != 'search_updatefreq'
-
- UPDATE_CHOICES = [
- ('1', 1),
- ('2', 2),
- ('3', 3),
- ('4', 4),
- ('5', 5),
- ('10', 10),
- ('15', 15),
- ('20', 20),
- ('30', 30)]
- UPDATE_CHOICES = [ (s + _(' minutes'), n) for s, n in UPDATE_CHOICES ]
- UPDATE_CHOICES.append((_('Never'), 0))
- UPDATE_GUI_STRINGS = [ s for s, n in UPDATE_CHOICES ]
- UPDATE_VALUES = dict((lambda .0: for s, n in .0:
- (n, i))(enumerate(UPDATE_CHOICES)))
-
- def color_for_total(total):
- if total > 150:
- return Color(255, 0, 0)
- if total > 125:
- return Color(255, 165, 0)
- return Color(0, 0, 0)
-
-
- def protocolinfo():
- protocols = protocols
- import common.protocolmeta
- return protocols['twitter']
-
-
- class TwitterAccountPanel(wx.Panel):
-
- def __init__(self, parent, account):
- wx.Panel.__init__(self, parent)
- self.construct()
- self.layout()
- self.Bind(wx.EVT_CHOICE, self.SelectionChanged)
- self.set_values(account)
- self.SelectionChanged()
-
-
- def show_server_options(self):
- return getattr(sys, 'DEV', False)
-
- show_server_options = property(show_server_options)
-
- def set_values(self, account):
- defaults = deepcopy(protocolinfo().defaults)
- defaults.update(getattr(account, 'update_frequencies', { }))
- self.auto_throttle.Value = getattr(account, 'auto_throttle', defaults.get('auto_throttle'))
- for name, _ in UPDATE_TYPES:
- self.choices[name].Selection = UPDATE_VALUES.get(defaults.get(name), 4)
-
- if self.show_server_options:
- api_server = getattr(account, 'api_server', None)
- if api_server is not None:
- self.server.Value = api_server
-
-
-
-
- def construct(self):
- self.header = StaticText(self, -1, _('Update Frequency:'))
- self.header.SetBold()
- self.desc = StaticText(self, -1, UPDATE_DESC_TEXT)
- self.update_texts = { }
- self.choices = { }
- for name, guistring in enumerate(UPDATE_TYPES):
- self.update_texts[name] = StaticText(self, -1, guistring)
- self.choices[name] = Choice(self, choices = UPDATE_GUI_STRINGS)
-
- self.total = StaticText(self, style = ALIGN_CENTER)
- self.total.SetBold()
- self.auto_throttle = CheckBox(self, label = _('Auto-throttle when Twitter lowers the rate limit.'), name = 'auto_throttle')
- if self.show_server_options:
- self.server_text = StaticText(self, -1, _('Server'))
- self.server = wx.TextCtrl(self, -1)
-
-
-
- def info(self):
- d = (dict,)((lambda .0: for name, _gui in .0:
- (name, UPDATE_CHOICES[self.choices[name].Selection][1]))(UPDATE_TYPES))
- d['auto_throttle'] = self.auto_throttle.Value
- if self.show_server_options:
- if not self.server.Value.strip():
- pass
- d['api_server'] = None
-
- return d
-
-
- def layout(self):
- gb = wx.GridBagSizer(hgap = 3, vgap = 3)
- for name, guistring in enumerate(UPDATE_TYPES):
- gb.Add(self.update_texts[name], (i, 0), flag = ALIGN_CENTER_VERTICAL)
- gb.Add(self.choices[name], (i, 1))
-
- gb_h = wx.BoxSizer(HORIZONTAL)
- gb_h.Add(gb, 0, EXPAND)
- t_v = wx.BoxSizer(VERTICAL)
- t_v.AddStretchSpacer(1)
- t_v.Add(self.total, 0, EXPAND | ALIGN_CENTER)
- t_v.AddStretchSpacer(1)
- gb_h.Add(t_v, 1, EXPAND | ALIGN_CENTER)
- inner_sz = wx.BoxSizer(VERTICAL)
- if self.show_server_options:
- hsz = wx.BoxSizer(HORIZONTAL)
- hsz.Add(self.server_text, 0, EXPAND | wx.RIGHT, 7)
- hsz.Add(self.server, 1, EXPAND | wx.BOTTOM, 7)
- inner_sz.Add(hsz, 0, EXPAND)
-
- inner_sz.AddMany([
- (self.header, 0, EXPAND),
- (self.desc, 0, EXPAND | TOP, 5),
- (gb_h, 0, EXPAND | TOP, 7),
- (self.auto_throttle, 0, EXPAND | TOP, 7)])
- sz = self.Sizer = wx.BoxSizer(HORIZONTAL)
- sz.Add(inner_sz, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 7)
-
-
- def SelectionChanged(self, e = None):
- mins = _[1]
- total_updates = sum((lambda .0: for min in .0:
- None if min else 0)(mins))
- total_txt = self.total
- total_txt.SetLabel('%d / %s' % (total_updates, _('hour')))
- total_txt.ForegroundColour = color_for_total(total_updates)
- self.Layout()
-
-
-