home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / capabilitiesbar.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  13.2 KB  |  347 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 logging import getLogger
  7. log = getLogger('capsbar')
  8. from common import caps, pref, setpref, profile
  9. from config import nativeIMWindow
  10. from util.primitives.funcs import Delegate
  11. from gui import skin
  12. from gui.textutil import default_font
  13. from gui.filetransfer import FileTransferDialog
  14. from gui.uberwidgets.UberBar import UberBar
  15. from gui.uberwidgets.simplemenu import SimpleMenu, SimpleMenuItem
  16. from gui.uberwidgets.UberButton import UberButton
  17. from gui.uberwidgets.umenu import UMenu
  18. from gui.uberwidgets.UberCombo import UberCombo
  19. from gui.uberwidgets.cleartext import ClearText
  20. from cgui import SimplePanel
  21. action_icons_key = 'conversation_window.actions_bar_icons'
  22. buttons = [
  23.     ('info', _('Info'), _('View buddy information')),
  24.     ('im', _('IM'), _('Instant message this buddy')),
  25.     ('video', _('Video'), _('Start an audio/video chat')),
  26.     ('files', _('Files'), _('Send files to this buddy')),
  27.     ('email', _('Email'), _('Send email')),
  28.     ('sms', _('SMS'), _('Send SMS messages'))]
  29.  
  30. class CapabilitiesBar(SimplePanel):
  31.     
  32.     def __init__(self, parent, buddy_callback, showCapabilities = True, infoboxmode = False):
  33.         SimplePanel.__init__(self, parent)
  34.         self.buddy_callback = buddy_callback
  35.         self.Bind((wx.EVT_PAINT,), (lambda e: wx.PaintDC(self)))
  36.         self.infoboxmode = infoboxmode
  37.         self._lastcaps = None
  38.         self.UpdateSkin()
  39.         self.Sizer = wx.BoxSizer(wx.VERTICAL)
  40.         for action in ('OnSendFiles', 'OnSendFolder', 'OnViewPastChats', 'OnAlert', 'OnBlock', 'OnAddContact'):
  41.             setattr(self, action, Delegate())
  42.         
  43.         self.cbar = bar = UberBar(self, skinkey = self.capabilitiesskin, overflowmode = True)
  44.         if not showCapabilities or nativeIMWindow:
  45.             self.cbar.Hide()
  46.         
  47.         if not infoboxmode:
  48.             self.cbar.Bind((wx.EVT_CONTEXT_MENU,), (lambda e: self.ActionsBarMenu.PopupMenu(event = e)))
  49.         
  50.         iconsize = skin.get('ActionsBar.IconSize')
  51.         icons = skin.get('ActionsBar.Icons')
  52.         for attr, title, tooltip in buttons:
  53.             icon = getattr(icons, attr).Resized(iconsize)
  54.             if attr == 'files':
  55.                 button = UberButton(bar, -1, title, icon = icon, type = 'menu', menu = self.FileMenu)
  56.                 button.overflow_label = _('Send File')
  57.                 button.overflow_callback = self.OnSendFiles
  58.             elif attr == 'video' and infoboxmode:
  59.                 continue
  60.             
  61.             button = UberButton(bar, -1, title, icon = icon)
  62.             button.overflow_label = title
  63.             button.SetToolTipString(tooltip)
  64.             setattr(self, 'b' + attr, button)
  65.             bar.Add(button, calcSize = False)
  66.         
  67.         bar.OnUBSize()
  68.         if pref('messaging.groupchat.enabled', False) and not (self.infoboxmode):
  69.             self.bmultichat = UberButton(bar, -1, icon = skin.get('actionsbar.icons.roomlist').Resized(16), type = 'toggle')
  70.             self.bmultichat.SetToolTipString(_('Group Chat'))
  71.             bar.AddStatic(self.bmultichat)
  72.         
  73.         self.ihistory = SimpleMenuItem(_('View Past Chats'), method = self.OnViewPastChats)
  74.         
  75.         def show_prefs_notifications(a):
  76.             import gui.pref.prefsdialog as prefsdialog
  77.             prefsdialog.show('notifications')
  78.  
  79.         self.ialert = SimpleMenuItem(_('Alert Me When...'), method = show_prefs_notifications)
  80.         self.iblock = SimpleMenuItem(_('Block'), method = self.OnBlock)
  81.         if not self.infoboxmode:
  82.             self.iadd = SimpleMenuItem(_('Add Contact'), method = self.OnAddContact)
  83.             bar.AddMenuItem(self.iadd)
  84.         
  85.         bar.AddMenuItem(self.ihistory)
  86.         bar.AddMenuItem(self.ialert)
  87.         if not self.infoboxmode:
  88.             bar.AddMenuItem(SimpleMenuItem(id = -1))
  89.             bar.AddMenuItem(self.iblock)
  90.         
  91.         self.Sizer.Add(bar, 0, wx.EXPAND)
  92.         self.tfbar = tfbar = UberBar(self, skinkey = self.tofromskin)
  93.         self.tfbar.Hide()
  94.         tofrom_font = skin.get('tofrombar.font', default_font)
  95.         tofrom_color = skin.get('tofrombar.fontcolor', wx.BLACK)
  96.         talign = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT
  97.         self.to_label = ClearText(tfbar, _('To:'), alignment = talign)
  98.         self.to_label.Font = tofrom_font
  99.         self.to_label.FontColor = tofrom_color
  100.         self.from_label = ClearText(tfbar, _('From:'), alignment = talign)
  101.         self.from_label.Font = tofrom_font
  102.         self.from_label.FontColor = tofrom_color
  103.         self.cto = UberCombo(tfbar, skinkey = self.tofromcomboskin, typeable = False, size = (100, 20), minmenuwidth = 200)
  104.         self.cfrom = UberCombo(tfbar, skinkey = self.tofromcomboskin, typeable = False, size = (100, 20), minmenuwidth = 200)
  105.         tfbar.Add(self.to_label, calcSize = False)
  106.         tfbar.Add(self.cto, True, calcSize = False)
  107.         tfbar.Add(self.from_label, calcSize = False)
  108.         tfbar.Add(self.cfrom, True)
  109.         self.Sizer.Add(tfbar, 0, wx.EXPAND)
  110.         profile.prefs.link(action_icons_key, self.UpdateIcons)
  111.         self.cbar.overflowmenu.BeforeDisplay += self.ApplyCaps
  112.  
  113.     ToCombo = property((lambda self: self.cto))
  114.     FromCombo = property((lambda self: self.cfrom))
  115.     
  116.     def UpdateSkin(self):
  117.         sget = skin.get
  118.         self.capabilitiesskin = sget('actionsbar.toolbarskin', None)
  119.         self.tofromskin = sget('tofrombar.toolbarskin', None)
  120.         self.menuskin = sget('%s.menuskin' % self.capabilitiesskin, None)
  121.         self.tofromcomboskin = sget('tofrombar.comboboxskin', None)
  122.         self.iconsize = sget('ActionsBar.IconSize')
  123.         self.icons = sget('ActionsBar.Icons')
  124.         if hasattr(self, 'to_label'):
  125.             tofrom_font = sget('tofrombar.font', (lambda : default_font()))
  126.             tofrom_color = sget('tofrombar.fontcolor', (lambda : wx.BLACK))
  127.             self.to_label.Font = self.from_label.Font = tofrom_font
  128.             self.to_label.FontColor = self.from_label.FontColor = tofrom_color
  129.         
  130.         if hasattr(self, 'cbar'):
  131.             self.cbar.SetSkinKey(self.capabilitiesskin)
  132.         
  133.         if hasattr(self, 'tfbar'):
  134.             self.tfbar.SetSkinKey(self.tofromskin)
  135.         
  136.         if hasattr(self, 'cto'):
  137.             self.cto.SetSkinKey(self.tofromcomboskin)
  138.         
  139.         if hasattr(self, 'cfrom'):
  140.             self.cfrom.SetSkinKey(self.tofromcomboskin)
  141.         
  142.         self.UpdateIcons()
  143.  
  144.     
  145.     def UpdateIcons(self, *a):
  146.         icons_pref = pref(action_icons_key)
  147.         textonly = icons_pref == 'text'
  148.         icons = self.icons
  149.         size = self.iconsize
  150.         self.Frozen().__enter__()
  151.         
  152.         try:
  153.             for attr, title, tooltip in buttons:
  154.                 icon = self.Frozen().__exit__ if textonly else getattr(icons, attr).Resized(size)
  155.                 button = getattr(self, 'b' + attr, None)
  156.                 if button is not None:
  157.                     button.SetIcon(icon)
  158.                     self.Frozen()(button.SetAlignment if icons_pref == 'above' else wx.HORIZONTAL)
  159.                     None(button.SetLabel if icons_pref == 'icons' else title)
  160.                     continue
  161.         finally:
  162.             pass
  163.  
  164.         self.Parent.Layout()
  165.         self.Refresh()
  166.  
  167.     
  168.     def ShowToFrom(self, show = True):
  169.         return self.tfbar.Show(show)
  170.  
  171.     
  172.     def RoomListButtonShown(self):
  173.         bmultichat = getattr(self, 'bmultichat', None)
  174.         if bmultichat is not None:
  175.             pass
  176.         return bmultichat.IsShown()
  177.  
  178.     RoomListButtonShown = property(RoomListButtonShown)
  179.     
  180.     def ToFromShown(self):
  181.         return self.tfbar.IsShown()
  182.  
  183.     ToFromShown = property(ToFromShown)
  184.     
  185.     def ShowCapabilities(self, show = True):
  186.         return self.cbar.Show(show)
  187.  
  188.     
  189.     def CapabilitiesIsShown(self):
  190.         return self.cbar.IsShown()
  191.  
  192.     
  193.     def GetButton(self, button):
  194.         return getattr(self, 'b' + button, None)
  195.  
  196.     
  197.     def ApplyCaps(self, contact = None, convo = None):
  198.         if contact is None and convo is None:
  199.             convo = self.buddy_callback()
  200.             Conversation = Conversation
  201.             import common.Conversation
  202.             if not isinstance(convo, Conversation):
  203.                 contact = convo
  204.                 convo = None
  205.             
  206.         
  207.         c = None
  208.         if convo is not None:
  209.             if convo.ischat:
  210.                 c = set([
  211.                     caps.IM])
  212.             elif contact is None:
  213.                 contact = convo.buddy
  214.             
  215.         
  216.         if c is None:
  217.             c = set(contact.caps)
  218.         
  219.         if contact is not None:
  220.             c.add(('blocked', contact.blocked))
  221.         
  222.         if c == self._lastcaps:
  223.             return None
  224.         if contact is not None:
  225.             if contact.sms:
  226.                 pass
  227.         buttons_caps = [
  228.             ('binfo', not any((contact.mobile, self.infoboxmode))),
  229.             ('bim', caps.IM in c),
  230.             ('bfiles', caps.FILES in c),
  231.             ('bemail', caps.EMAIL in c),
  232.             ('bsms', caps.SMS in c),
  233.             ('bvideo', caps.VIDEO in c)]
  234.         for name, val in buttons_caps:
  235.             ctrl = getattr(self, name, None)
  236.             if ctrl is not None:
  237.                 ctrl.Show(ctrl, val, False)
  238.                 continue
  239.             c == self._lastcaps
  240.         
  241.         cbar = self.cbar
  242.         menu = cbar.overflowmenu
  243.         count = menu.spine.items.count
  244.         iblock = self.iblock
  245.         if caps.BLOCKABLE in c and not count(iblock):
  246.             cbar.AddMenuItem(SimpleMenuItem(id = -1))
  247.             cbar.AddMenuItem(iblock)
  248.         elif caps.BLOCKABLE not in c and count(iblock):
  249.             cbar.overflowmenu.RemoveItem(iblock)
  250.         
  251.         if contact is not None:
  252.             if contact.blocked:
  253.                 content = _('Unblock %s')
  254.             else:
  255.                 content = _('Block %s')
  256.             iblock.content = [
  257.                 content % contact.name]
  258.             contact.protocol
  259.         
  260.         self.set_groupchat_visibility(contact, convo)
  261.         i = len(menu.spine.items) - 1
  262.         if menu.GetItem(i).id == -1:
  263.             menu.RemoveItem(i)
  264.         
  265.         self.cbar.overflowbutton.Show(not getattr(contact, 'iswidget', False))
  266.         self._lastcaps = c
  267.         cbar.GenWidthRestriction(True)
  268.         self.update_add_contact_shown(convo)
  269.         self.Parent.Layout()
  270.  
  271.     
  272.     def update_add_contact_shown(self, convo):
  273.         if not hasattr(self, 'iadd'):
  274.             return None
  275.         if convo is not None:
  276.             pass
  277.         ischat = convo.ischat
  278.         overflow = self.cbar.overflowmenu
  279.         if ischat:
  280.             if overflow.GetIndex(self.iadd) != -1:
  281.                 overflow.RemoveItem(self.iadd)
  282.             
  283.         elif overflow.GetIndex(self.iadd) == -1:
  284.             overflow.InsertItem(overflow.GetIndex(self.ihistory), self.iadd)
  285.         
  286.  
  287.     
  288.     def set_groupchat_visibility(self, contact, convo):
  289.         if not hasattr(self, 'bmultichat'):
  290.             return None
  291.         proto = getattr(contact, 'protocol', getattr(convo, 'protocol', None))
  292.         groupchat = False
  293.  
  294.     
  295.     def FileMenu(self):
  296.         self._filemenu = SimpleMenu(self, self.menuskin)
  297.         self.send_file_item = SimpleMenuItem((_('Send File'),), (lambda : self.OnSendFiles()))
  298.         self._filemenu.AppendItem(self.send_file_item)
  299.         self._filemenu.AppendItem(SimpleMenuItem(_('Transfer History'), (lambda : FileTransferDialog.Display())))
  300.         return self._filemenu
  301.  
  302.     FileMenu = property(FileMenu)
  303.     
  304.     def ActionsBarMenu(self):
  305.         
  306.         try:
  307.             return self._actionsbarmenu
  308.         except AttributeError:
  309.             self._actionsbarmenu = self.build_actionsbar_menu()
  310.             return self._actionsbarmenu
  311.  
  312.  
  313.     ActionsBarMenu = property(ActionsBarMenu)
  314.     
  315.     def build_actionsbar_menu(self):
  316.         m = UMenu(self, onshow = self.update_actionsbar_menu)
  317.         c = self._actionsbar_checks = { }
  318.         for name, label in [
  319.             ('icons', _('Icons Only')),
  320.             ('text', _('Text Only')),
  321.             ('next', _('Icons Next to Text')),
  322.             ('above', _('Icons Above Text'))]:
  323.             
  324.             def cb(name = (name,)):
  325.                 self.Frozen().__enter__()
  326.                 
  327.                 try:
  328.                     setpref(action_icons_key, name)
  329.                 finally:
  330.                     pass
  331.  
  332.  
  333.             c[name] = m.AddCheckItem(label, callback = cb)
  334.         
  335.         m.AddSep()
  336.         m.AddItem(_('Hide Actions Bar'), callback = (lambda : setpref('messaging.show_actions_bar', False)))
  337.         return m
  338.  
  339.     
  340.     def update_actionsbar_menu(self, menu):
  341.         p = pref(action_icons_key)
  342.         for name, item in self._actionsbar_checks.iteritems():
  343.             item.Check(p == name)
  344.         
  345.  
  346.  
  347.