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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import wx
  6. from wx import VERTICAL, HORIZONTAL, ALIGN_CENTER_HORIZONTAL, EXPAND, ALL, LEFT, RIGHT, TOP, BOTTOM, ALIGN_CENTER_VERTICAL, ALIGN_LEFT
  7. TOPLESS = ALL & ~TOP
  8. from gui.visuallisteditor import VisualListEditorList
  9. from gui.toolbox import build_button_sizer, wx_prop
  10. from gui.textutil import CopyFont
  11. from gui.validators import LengthLimit
  12. from util import Storage as S
  13. from logging import getLogger
  14. log = getLogger('contactdialogs')
  15. info = log.info
  16. from common import profile
  17. REQUIRE_ALIAS = True
  18.  
  19. def get_profile():
  20.     profile = profile
  21.     import common
  22.     return profile
  23.  
  24.  
  25. def contact_string(c):
  26.     return '%s (%s)' % (c.name, c.protocol.name)
  27.  
  28.  
  29. def account_string(a):
  30.     return '%s (%s)' % (a.name, a.protocol)
  31.  
  32.  
  33. def send_files(parent, buddy, files):
  34.     if len(files) == 1:
  35.         msg = _('Would you like to send "%s" to %s?') % (files[0], buddy.name)
  36.     else:
  37.         msg = _('Would you like to send %d files to %s?') % (len(files), buddy.name)
  38.     if wx.YES == wx.MessageBox(msg, _('Send Files'), style = wx.YES_NO, parent = parent):
  39.         for filename in files:
  40.             buddy.send_file(filename)
  41.         
  42.     
  43.  
  44.  
  45. class ContactPanel(wx.Panel):
  46.     
  47.     def __init__(self, parent, to_group = None):
  48.         wx.Panel.__init__(self, parent)
  49.         self.construct()
  50.         self.layout()
  51.         profile = profile
  52.         import common
  53.         profile.account_manager.connected_accounts.add_observer(self.on_conns_changed)
  54.         self.on_conns_changed(profile.account_manager.connected_accounts, to_group)
  55.  
  56.     
  57.     def on_close(self):
  58.         profile.account_manager.connected_accounts.remove_observer(self.on_conns_changed)
  59.  
  60.     
  61.     def on_conns_changed(self, connected_accounts, *a):
  62.         choice = self.acct_choice
  63.         sel = choice.GetStringSelection()
  64.         choice.Frozen().__enter__()
  65.         
  66.         try:
  67.             choice.Clear()
  68.             for acct in connected_accounts:
  69.                 proto_str = account_string(acct)
  70.                 choice.Append(proto_str)
  71.         finally:
  72.             pass
  73.  
  74.         choice.Frozen().__exit__ if sel else choice.SetSelection(0)
  75.  
  76.     
  77.     def construct(self):
  78.         self.name_st = wx.StaticText(self, -1, _('Contact &Name:'))
  79.         self.name_txt = wx.TextCtrl(self, -1, validator = LengthLimit(255))
  80.         self.acct_st = wx.StaticText(self, -1, _('Accoun&t:'))
  81.         self.acct_choice = wx.Choice(self, -1)
  82.         
  83.         self.get_acct = lambda : get_profile().account_manager.connected_accounts[self.acct_choice.Selection]
  84.         self.save = wx.Button(self, wx.ID_SAVE, _('&Add'))
  85.         self.save.SetDefault()
  86.         self.save.Bind(wx.EVT_BUTTON, self.Parent.on_save)
  87.         self.cancel = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
  88.  
  89.     name = wx_prop('name_txt')
  90.     
  91.     def get_info(self):
  92.         return S(name = self.name, account = self.get_acct())
  93.  
  94.     
  95.     def layout(self):
  96.         self.Sizer = sz = wx.BoxSizer(wx.VERTICAL)
  97.         sz.Add(self.name_st, 0, wx.EXPAND | wx.ALL, 5)
  98.         sz.Add(self.name_txt, 0, wx.EXPAND | wx.ALL, 5)
  99.         sz.Add((0, 5))
  100.         sz.Add(self.acct_st, 0, wx.EXPAND | wx.ALL, 5)
  101.         sz.Add(self.acct_choice, 0, wx.EXPAND | wx.ALL, 5)
  102.         sz.Add(build_button_sizer(save = self.save, cancel = self.cancel), 0, wx.EXPAND | wx.SOUTH | wx.EAST | wx.WEST, 4)
  103.  
  104.  
  105.  
  106. class MetaListEditor(VisualListEditorList):
  107.     
  108.     def __init__(self, parent, list2sort, listcallback = None):
  109.         VisualListEditorList.__init__(self, parent, list2sort, listcallback = listcallback)
  110.  
  111.     
  112.     def OnDrawItem(self, dc, rect, n):
  113.         dc.Font = self.Font
  114.         buddy = self.thelist[n]
  115.         icon = buddy.buddy_icon.Resized(16)
  116.         serv = buddy.serviceicon.Resized(16)
  117.         x = rect.x + 3
  118.         y = rect.y + 3
  119.         textrect = wx.Rect(x + 16 + 3, rect.y, rect.Width - x - 38, rect.Height)
  120.         dc.DrawLabel(buddy.name, textrect, ALIGN_CENTER_VERTICAL | ALIGN_LEFT)
  121.         dc.DrawBitmap(icon, x, y, True)
  122.         dc.DrawBitmap(serv, rect.x + rect.Width - 16 - 3, y, True)
  123.  
  124.  
  125.  
  126. class MetaContactPanel(wx.Panel):
  127.     
  128.     def __init__(self, parent, contacts = [], metacontact = None, order = None):
  129.         wx.Panel.__init__(self, parent)
  130.         self.contacts = contacts
  131.         self.metacontact = metacontact
  132.         self.order = order
  133.         self.construct()
  134.         self.layout()
  135.  
  136.     
  137.     def construct(self):
  138.         
  139.         Text = lambda s: wx.StaticText(self, -1, _(s))
  140.         self.line1 = Text(_('Would you like to merge these contacts?'))
  141.         self.line1.Font = CopyFont(self.line1.Font, weight = wx.BOLD)
  142.         self.line2 = Text(_('They will appear as one item on your buddy list.'))
  143.         self.sep = wx.StaticLine(self, -1)
  144.         self.alias_label = wx.StaticText(self, -1, _('Alias:'))
  145.         self.alias_label.Font = CopyFont(self.alias_label.Font, weight = wx.BOLD)
  146.         alias = self.find_alias_suggestion()
  147.         self.alias_text = (None,)(wx.TextCtrl, self, -1 if alias else '', validator = LengthLimit(255))
  148.         s = self.save = wx.Button(self, wx.ID_SAVE, _('&Save'))
  149.         s.SetDefault()
  150.         s.Bind(wx.EVT_BUTTON, self.Parent.on_save)
  151.         if REQUIRE_ALIAS:
  152.             self.alias_text.Bind((wx.EVT_TEXT,), (lambda e: self.save.Enable(self.alias_text.Value != '')))
  153.             self.save.Enable(self.alias_text.Value != '')
  154.         
  155.         self.cancel = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
  156.         self.line4 = Text(_('Drag and drop to rearrange:'))
  157.         self.line4.Font = CopyFont(self.line4.Font, weight = wx.BOLD)
  158.         self.contacts_list = MetaListEditor(self, self.contacts, self.update_contacts_list)
  159.  
  160.     
  161.     def find_alias_suggestion(self):
  162.         if self.metacontact:
  163.             return self.metacontact.alias
  164.         for contact in self.contacts:
  165.             a = profile.get_contact_info(contact, 'alias')
  166.             if a:
  167.                 return a
  168.         
  169.         return ''
  170.  
  171.     
  172.     def update_contacts_list(self, contacts):
  173.         self.contacts = contacts
  174.  
  175.     
  176.     def layout(self):
  177.         self.Sizer = sz = wx.BoxSizer(VERTICAL)
  178.         h1 = wx.BoxSizer(VERTICAL)
  179.         h1.Add(self.line1, 0, ALIGN_CENTER_HORIZONTAL)
  180.         h1.Add(self.line2, 0, ALIGN_CENTER_HORIZONTAL | TOP, 3)
  181.         h1.Add(self.sep, 0, EXPAND | TOP, 6)
  182.         h1.Add(self.alias_label, 0, TOP, 6)
  183.         h1.Add(self.alias_text, 0, EXPAND | TOP, 3)
  184.         h1.Add(self.line4, 0, TOP, 6)
  185.         h1.Add(self.contacts_list, 1, EXPAND | TOP, 3)
  186.         sz.Add(h1, 1, EXPAND | ALL, 6)
  187.         sz.Add(build_button_sizer(save = self.save, cancel = self.cancel), 0, EXPAND | TOPLESS, 4)
  188.  
  189.     
  190.     def commit(self):
  191.         blist = get_profile().blist
  192.         mcs = blist.metacontacts
  193.         if self.metacontact:
  194.             self.metacontact.rename(self.alias)
  195.             mcs.edit(self.metacontact, self.contacts, grouppath = self.metacontact.mcinfo.groups)
  196.             return self.metacontact
  197.         meta = mcs.create(self.alias, self.contacts, update = False)
  198.         meta = mcs.metacontact_objs[meta]
  199.         return meta
  200.  
  201.     alias = wx_prop('alias_text')
  202.  
  203.  
  204. class ContactDialog(wx.Dialog):
  205.     
  206.     def __init__(self, parent, to_group = None):
  207.         wx.Dialog.__init__(self, parent, title = _('Add Contact'))
  208.         self.contact_panel = ContactPanel(self, to_group)
  209.         self.Sizer = s = wx.BoxSizer(wx.VERTICAL)
  210.         s.Add(self.contact_panel, 1, wx.EXPAND)
  211.         self.Fit()
  212.         self.contact_panel.name_txt.SetFocus()
  213.         self.Centre()
  214.  
  215.     
  216.     def Prompt(self, callback):
  217.         
  218.         try:
  219.             if wx.ID_SAVE == self.ShowModal():
  220.                 callback(**self.contact_panel.get_info())
  221.         finally:
  222.             self.contact_panel.on_close()
  223.             self.Destroy()
  224.  
  225.  
  226.     
  227.     def on_save(self, e):
  228.         self.SetReturnCode(wx.ID_SAVE)
  229.         if self.IsModal():
  230.             self.EndModal(wx.ID_SAVE)
  231.         
  232.  
  233.  
  234.  
  235. class MetaContactDialog(wx.Dialog):
  236.     minsize = (290, 290)
  237.     
  238.     def __init__(self, parent, contacts, metacontact = None, title = None, order = None):
  239.         if not title:
  240.             pass
  241.         wx.Dialog.__init__(self, parent, title = _('Merge Contacts'), pos = (400, 200), style = wx.DEFAULT_DIALOG_STYLE)
  242.         self.Sizer = s = wx.BoxSizer(wx.VERTICAL)
  243.         self.mc_panel = panel = MetaContactPanel(self, contacts, metacontact, order = order)
  244.         s.Add(panel, 1, wx.EXPAND)
  245.         self.Fit()
  246.  
  247.     
  248.     def add_contact(cls, parent, metacontact, contact, position = -1):
  249.         MetaContact = MetaContact
  250.         import contacts.metacontacts
  251.         if not isinstance(metacontact, MetaContact):
  252.             raise TypeError('parent (wxWindow), metacontact (MetaContact), contact (Contact), [position (-1 < p < len(metacontact))')
  253.         isinstance(metacontact, MetaContact)
  254.         contacts = list(metacontact)
  255.         if position < 0:
  256.             contacts.append(contact)
  257.         else:
  258.             contacts.insert(position, contact)
  259.         info('contact order for dialog: %r', contacts)
  260.         title = _('Merge Contacts')
  261.         return cls(parent, contacts, metacontact, title = title)
  262.  
  263.     add_contact = classmethod(add_contact)
  264.     
  265.     def on_save(self, e):
  266.         self.SetReturnCode(wx.ID_SAVE)
  267.         if self.IsModal():
  268.             self.EndModal(wx.ID_SAVE)
  269.         
  270.  
  271.     
  272.     def get_info(self):
  273.         return self.mc_panel.get_info()
  274.  
  275.     
  276.     def Prompt(self, ondone = None):
  277.         if wx.ID_SAVE == self.ShowModal():
  278.             result = self.mc_panel.commit()
  279.             if ondone:
  280.                 ondone(result)
  281.             
  282.         
  283.  
  284.  
  285.