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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from util.primitives import Storage
  5. from util.primitives.funcs import do
  6. import gettext
  7. gettext.install('digsby')
  8. from gui.controls import *
  9. import jabber
  10. import wx
  11.  
  12. class Holder(object):
  13.     pass
  14.  
  15.  
  16. class vcardcontrols(CustomControls):
  17.     
  18.     class _VCardOrg(Holder):
  19.         
  20.         def __init__(self, controls, parent):
  21.             self.parent = parent
  22.             self.controls = controls
  23.             (self.namelabel, self.nametext) = self.controls.LabeledTextInput(_('Name'))
  24.             (self.unitlabel, self.unittext) = self.controls.LabeledTextInput(_('Unit'))
  25.             self.elems = [
  26.                 self.namelabel,
  27.                 self.nametext,
  28.                 self.unitlabel,
  29.                 self.unittext]
  30.  
  31.         
  32.         def GetValue(self):
  33.             if (any,)((lambda .0: for attr in .0:
  34. getattr(self, attr + 'text').Value)([
  35.                 'name',
  36.                 'unit'])):
  37.                 org = jabber.vcard.VCardOrg('ORG', '')
  38.                 for attr in [
  39.                     'name',
  40.                     'unit']:
  41.                     val = getattr(self, attr + 'text').Value
  42.                     if val:
  43.                         setattr(org, attr, val)
  44.                         continue
  45.                 
  46.                 return org
  47.             return None
  48.  
  49.         
  50.         def SetValue(self, org):
  51.             for attr in [
  52.                 'name',
  53.                 'unit']:
  54.                 if not getattr(org, attr):
  55.                     pass
  56.                 getattr(self, attr + 'text').Value = ''
  57.             
  58.  
  59.         
  60.         def clear(self):
  61.             for attr in [
  62.                 'name',
  63.                 'unit']:
  64.                 getattr(self, attr + 'text').Value = ''
  65.             
  66.  
  67.         Value = property(GetValue, SetValue)
  68.  
  69.     
  70.     def VCardOrg(self):
  71.         return self._VCardOrg(self, self.parent)
  72.  
  73.     
  74.     class _VCardName(Holder):
  75.         
  76.         def __init__(self, controls, parent):
  77.             self.parent = parent
  78.             self.controls = controls
  79.             l = self.controls.LabeledTextInput
  80.             d = dict(family = (_('Last Name'),), given = (_('First Name'),), middle = (_('Middle Name'),), prefix = (_('Prefix'),), suffix = (_('Suffix'),))
  81.             self.elems = []
  82.             for i in d.iteritems():
  83.                 (one, two) = l(*i[1])
  84.                 self.elems.append(one)
  85.                 self.elems.append(two)
  86.                 setattr(self, i[0] + 'label', one)
  87.                 setattr(self, i[0] + 'text', two)
  88.             
  89.  
  90.         
  91.         def GetValue(self):
  92.             name = jabber.vcard.VCardName('N', '')
  93.             for attr in [
  94.                 'family',
  95.                 'given',
  96.                 'middle',
  97.                 'prefix',
  98.                 'suffix']:
  99.                 setattr(name, attr, getattr(self, attr + 'text').Value)
  100.             
  101.             return name
  102.  
  103.         
  104.         def SetValue(self, name):
  105.             for attr in [
  106.                 'family',
  107.                 'given',
  108.                 'middle',
  109.                 'prefix',
  110.                 'suffix']:
  111.                 getattr(self, attr + 'text').Value = getattr(name, attr)
  112.             
  113.  
  114.         Value = property(GetValue, SetValue)
  115.  
  116.     
  117.     def VCardName(self):
  118.         return self._VCardName(self, self.parent)
  119.  
  120.     
  121.     class _VCardString(object):
  122.         _class = jabber.vcard.VCardString
  123.         
  124.         def __init__(self, controls, parent, type_, label):
  125.             self.parent = parent
  126.             self.controls = controls
  127.             self.type_ = type_
  128.             if label is not None:
  129.                 l = self.controls.LabeledTextInput
  130.                 (self.stringlabel, self.stringtext) = l(label)
  131.                 self.elems = [
  132.                     self.stringlabel,
  133.                     self.stringtext]
  134.             else:
  135.                 self.stringtext = self.controls.TextInput()
  136.                 self.elems = [
  137.                     self.stringtext]
  138.  
  139.         
  140.         def GetValue(self):
  141.             
  142.             try:
  143.                 strng = self._class(self.type_, self.stringtext.Value)
  144.                 return strng
  145.             except:
  146.                 return None
  147.  
  148.  
  149.         
  150.         def SetValue(self, strng):
  151.             self.stringtext.Value = strng.value
  152.  
  153.         
  154.         def clear(self):
  155.             self.stringtext.Value = ''
  156.  
  157.         Value = property(GetValue, SetValue)
  158.  
  159.     
  160.     class _VCardXString(_VCardString):
  161.         _class = jabber.vcard.VCardXString
  162.  
  163.     
  164.     def VCardString(self, type_, label):
  165.         return self._VCardString(self, self.parent, type_, label)
  166.  
  167.     
  168.     def VCardXString(self, type_, label):
  169.         return self._VCardXString(self, self.parent, type_, label)
  170.  
  171.     
  172.     class _VCardTel(Holder):
  173.         
  174.         def __init__(self, controls, parent):
  175.             self.parent = parent
  176.             self.controls = controls
  177.             (self.numberlabel, self.numbertext) = self.controls.LabeledTextInput(_('Number'))
  178.             self.type = Storage()
  179.             self.type.Value = []
  180.             self.elems = [
  181.                 self.numberlabel,
  182.                 self.numbertext]
  183.  
  184.         
  185.         def GetValue(self):
  186.             if getattr(self, 'numbertext').Value:
  187.                 tel = jabber.vcard.VCardTel('TEL', '')
  188.                 val = getattr(self, 'numbertext').Value
  189.                 tel.number = val
  190.                 if self.type.Value:
  191.                     tel.type = self.type.Value[:]
  192.                 
  193.                 return tel
  194.             return None
  195.  
  196.         
  197.         def SetValue(self, tel):
  198.             self.type.Value = tel.type[:]
  199.             self.numbertext.Value = tel.number
  200.  
  201.         
  202.         def clear(self):
  203.             self.type.Value = []
  204.             self.numbertext.Value = ''
  205.  
  206.         Value = property(GetValue, SetValue)
  207.  
  208.     
  209.     def VCardTel(self):
  210.         return self._VCardTel(self, self.parent)
  211.  
  212.     
  213.     class _VCardEmail(Holder):
  214.         
  215.         def __init__(self, controls, parent):
  216.             self.parent = parent
  217.             self.controls = controls
  218.             (self.addresslabel, self.addresstext) = self.controls.LabeledTextInput(_('Email'))
  219.             self.type = Storage()
  220.             self.type.Value = []
  221.             self.elems = [
  222.                 self.addresslabel,
  223.                 self.addresstext]
  224.  
  225.         
  226.         def GetValue(self):
  227.             if getattr(self, 'addresstext').Value:
  228.                 email = jabber.vcard.VCardEmail('EMAIL', '')
  229.                 val = getattr(self, 'addresstext').Value
  230.                 email.address = val
  231.                 if self.type.Value:
  232.                     email.type = self.type.Value[:]
  233.                 
  234.                 return email
  235.             return None
  236.  
  237.         
  238.         def SetValue(self, email):
  239.             self.type.Value = email.type[:]
  240.             self.addresstext.Value = email.address
  241.  
  242.         
  243.         def clear(self):
  244.             self.type.Value = []
  245.             self.addresstext.Value = ''
  246.  
  247.         Value = property(GetValue, SetValue)
  248.  
  249.     
  250.     def VCardEmail(self):
  251.         return self._VCardEmail(self, self.parent)
  252.  
  253.     
  254.     class _VCardAdr(Holder):
  255.         
  256.         def __init__(self, controls, parent):
  257.             self.parent = parent
  258.             self.controls = controls
  259.             l = self.controls.LabeledTextInput
  260.             self.poboxtext = Storage()
  261.             self.poboxtext.Value = ''
  262.             common_ = ('H',)
  263.             d = [
  264.                 ('street', _('Street')),
  265.                 ('extadr', ''),
  266.                 ('locality', _('City')),
  267.                 ('region', _('State')),
  268.                 ('pcode', _('Postal Code')),
  269.                 ('ctry', _('Country'))]
  270.             self.elems = []
  271.             for i in d:
  272.                 (one, two) = l(i[1])
  273.                 self.elems.append(one)
  274.                 self.elems.append(two)
  275.                 setattr(self, i[0] + 'label', one)
  276.                 setattr(self, i[0] + 'text', two)
  277.             
  278.  
  279.         
  280.         def GetValue(self):
  281.             if (any,)((lambda .0: for attr in .0:
  282. getattr(self, attr + 'text').Value)([
  283.                 'street',
  284.                 'extadr',
  285.                 'pobox',
  286.                 'locality',
  287.                 'region',
  288.                 'pcode',
  289.                 'ctry'])):
  290.                 adr = jabber.vcard.VCardAdr('ADR', '')
  291.                 for attr in [
  292.                     'street',
  293.                     'extadr',
  294.                     'pobox',
  295.                     'locality',
  296.                     'region',
  297.                     'pcode',
  298.                     'ctry']:
  299.                     val = getattr(self, attr + 'text').Value
  300.                     if val:
  301.                         setattr(adr, attr, val)
  302.                         continue
  303.                 
  304.                 return adr
  305.             return None
  306.  
  307.         
  308.         def SetValue(self, adr):
  309.             for attr in [
  310.                 'street',
  311.                 'extadr',
  312.                 'pobox',
  313.                 'locality',
  314.                 'region',
  315.                 'pcode',
  316.                 'ctry']:
  317.                 if not getattr(adr, attr):
  318.                     pass
  319.                 getattr(self, attr + 'text').Value = ''
  320.             
  321.  
  322.         
  323.         def clear(self):
  324.             for attr in [
  325.                 'street',
  326.                 'extadr',
  327.                 'pobox',
  328.                 'locality',
  329.                 'region',
  330.                 'pcode',
  331.                 'ctry']:
  332.                 getattr(self, attr + 'text').Value = ''
  333.             
  334.  
  335.         Value = property(GetValue, SetValue)
  336.  
  337.     
  338.     def VCardAdr(self):
  339.         return self._VCardAdr(self, self.parent)
  340.  
  341.  
  342.  
  343. class VCardGUI(dict):
  344.     components = {
  345.         'FN': 'VCardString',
  346.         'N': 'store',
  347.         'NICKNAME': 'VCardString',
  348.         'PHOTO': 'store',
  349.         'BDAY': 'VCardString',
  350.         'ADR': 'VCardAdr',
  351.         'LABEL': 'store',
  352.         'TEL': 'VCardTel',
  353.         'EMAIL': 'VCardEmail',
  354.         'JABBERID': 'store',
  355.         'MAILER': 'store',
  356.         'TZ': 'store',
  357.         'GEO': 'store',
  358.         'TITLE': 'VCardString',
  359.         'ROLE': 'VCardString',
  360.         'LOGO': 'store',
  361.         'ORG': 'VCardOrg',
  362.         'CATEGORIES': 'store',
  363.         'NOTE': 'store',
  364.         'PRODID': 'store',
  365.         'REV': 'store',
  366.         'SORT-STRING': 'store',
  367.         'SOUND': 'store',
  368.         'UID': 'store',
  369.         'URL': 'VCardString',
  370.         'CLASS': 'store',
  371.         'KEY': 'store',
  372.         'DESC': 'VCardXString' }
  373.     
  374.     def __init__(self, protocol = None, vcard = None):
  375.         dict.__init__(self)
  376.         self.protocol = protocol
  377.         vc = None if vcard is not None else self.protocol.vcard
  378.         self.init_gui()
  379.         self.page1()
  380.         self.page2()
  381.         self.page3()
  382.         self.page4()
  383.         self.assign_vc(vc)
  384.         f = self.frame
  385.         f.Fit()
  386.         f.MinSize = wx.Size(f.Size.x * 1.5, f.Size.y)
  387.         f.Fit()
  388.         skin = skin
  389.         import gui
  390.         if protocol is None:
  391.             f.SetFrameIcon(skin.get('AppDefaults.TaskbarIcon'))
  392.         else:
  393.             f.SetFrameIcon(protocol.serviceicon)
  394.         wx.CallAfter(f.Show)
  395.  
  396.     
  397.     def init_gui(self):
  398.         name = None if self.protocol is not None else 'vCard Viewer'
  399.         title = None if self.protocol is not None else _('vCard Viewer')
  400.         self.frame = f = wx.Frame(None, -1, title = title, name = name)
  401.         self.notebook = wx.Notebook(f, -1)
  402.         if self.protocol is not None:
  403.             f.Sizer = s = wx.BoxSizer(wx.VERTICAL)
  404.             s.Add(self.notebook, 1, wx.EXPAND)
  405.             p = wx.Panel(f)
  406.             save = wx.Button(p, wx.ID_SAVE, 'Save')
  407.             retrieve = Button(p, _('Retreive'), self.on_retrieve)
  408.             cancel = wx.Button(p, wx.ID_CANCEL, 'Cancel')
  409.             save.Bind((wx.EVT_BUTTON,), (lambda e: self.on_save()))
  410.             p.Sizer = h = wx.BoxSizer(wx.HORIZONTAL)
  411.             h.AddStretchSpacer(1)
  412.             (do,)((lambda .0: for b in .0:
  413. h.Add(b, 0, wx.EXPAND | wx.ALL, 3))([
  414.                 save,
  415.                 retrieve,
  416.                 cancel]))
  417.             s.Add(p, 0, wx.EXPAND)
  418.         
  419.  
  420.     
  421.     def on_save(self):
  422.         print 'onsave'
  423.         self.protocol.save_vcard(self.retrieve_vcard())
  424.  
  425.     
  426.     def on_retrieve(self):
  427.         self.protocol.request_vcard('', success = self.handle_vc_stanza)
  428.  
  429.     
  430.     def handle_vc_stanza(self, stanza):
  431.         q = stanza.get_query()
  432.         if not q:
  433.             return None
  434.         self.assign_vc(jabber.VCard(q))
  435.  
  436.     
  437.     def assign_vc(self, vc):
  438.         for k, v in self.components.items():
  439.             if v == 'store':
  440.                 self[k] = vc[k]
  441.                 continue
  442.         
  443.         self.assign_page1(vc)
  444.         self.assign_page2(vc)
  445.         self.assign_page3(vc)
  446.         self.assign_page4(vc)
  447.  
  448.     
  449.     def assign_lists(self, names, vc):
  450.         for name in names:
  451.             self['_' + name] = vc[name][1:]
  452.             if vc[name]:
  453.                 self[name].Value = vc[name][0]
  454.                 continue
  455.             self[name].clear()
  456.         
  457.  
  458.     
  459.     def retrieve_lists(self, names, vc):
  460.         for name in names:
  461.             if self[name].Value:
  462.                 vc.content[name] = [
  463.                     self[name].Value]
  464.             
  465.             vc.content[name][1:] = self['_' + name]
  466.         
  467.  
  468.     
  469.     def assign_page1(self, vc):
  470.         if vc['FN'] is not None:
  471.             self['FN'].Value = vc['FN']
  472.         else:
  473.             self['FN'].clear()
  474.         self.assign_lists(('NICKNAME', 'BDAY', 'TEL', 'URL', 'EMAIL'), vc)
  475.  
  476.     
  477.     def page1(self):
  478.         p = wx.Panel(self.notebook)
  479.         self.notebook.AddPage(p, _('General'))
  480.         c = vcardcontrols(p)
  481.         vcs = c.VCardString
  482.         self['FN'] = vcs('FN', _('Full Name'))
  483.         self['NICKNAME'] = vcs('NICKNAME', _('Nickname'))
  484.         self['BDAY'] = vcs('BDAY', _('Birthday'))
  485.         self['TEL'] = c.VCardTel()
  486.         self['URL'] = vcs('URL', _('Homepage'))
  487.         self['EMAIL'] = c.VCardEmail()
  488.         s = FGridSizer(0, 2, *sum([
  489.             self['FN'].elems,
  490.             self['NICKNAME'].elems,
  491.             self['BDAY'].elems,
  492.             self['TEL'].elems,
  493.             self['URL'].elems,
  494.             self['EMAIL'].elems], []))
  495.         s.AddGrowableCol(1)
  496.         p.Sizer = s
  497.  
  498.     
  499.     def assign_page2(self, vc):
  500.         self.assign_lists(('ORG', 'TITLE', 'ROLE'), vc)
  501.  
  502.     
  503.     def page2(self):
  504.         p = wx.Panel(self.notebook)
  505.         self.notebook.AddPage(p, _('Work'))
  506.         c = vcardcontrols(p)
  507.         vcs = c.VCardString
  508.         self['ORG'] = c.VCardOrg()
  509.         self['TITLE'] = vcs('TITLE', _('Position'))
  510.         self['ROLE'] = vcs('ROLE', _('Role'))
  511.         s = FGridSizer(0, 2, *sum([
  512.             self['ORG'].elems,
  513.             self['TITLE'].elems,
  514.             self['ROLE'].elems], []))
  515.         s.AddGrowableCol(1)
  516.         p.Sizer = s
  517.  
  518.     
  519.     def assign_page3(self, vc):
  520.         self.assign_lists(('ADR',), vc)
  521.  
  522.     
  523.     def page3(self):
  524.         p = wx.Panel(self.notebook)
  525.         self.notebook.AddPage(p, _('Location'))
  526.         c = vcardcontrols(p)
  527.         self['ADR'] = c.VCardAdr()
  528.         s = FGridSizer(0, 2, *self['ADR'].elems)
  529.         s.AddGrowableCol(1)
  530.         p.Sizer = s
  531.  
  532.     
  533.     def assign_page4(self, vc):
  534.         self.assign_lists(('DESC',), vc)
  535.  
  536.     
  537.     def page4(self):
  538.         p = wx.Panel(self.notebook)
  539.         self.notebook.AddPage(p, _('About'))
  540.         c = vcardcontrols(p)
  541.         self['DESC'] = c.VCardXString('DESC', None)
  542.         s = FGridSizer(0, 1, self['DESC'].stringtext)
  543.         s.AddGrowableCol(0)
  544.         s.AddGrowableRow(0)
  545.         p.Sizer = s
  546.  
  547.     
  548.     def retrieve_vcard(self):
  549.         vc = jabber.vcard.VCard('')
  550.         for k, v in self.components.items():
  551.             if v == 'store':
  552.                 vc.content[k] = self[k]
  553.                 continue
  554.         
  555.         vc.content['FN'] = self['FN'].Value
  556.         self.retrieve_lists(('NICKNAME', 'BDAY', 'TEL', 'URL', 'EMAIL', 'ORG', 'TITLE', 'ROLE', 'ADR', 'DESC'), vc)
  557.         return vc
  558.  
  559.     
  560.     def Prompt(self, callback):
  561.         return True
  562.  
  563.  
  564.