home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / pref / pg_general_profile.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  10.3 KB  |  248 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. from common import profile
  6. from config import platformName
  7. from gui.uberwidgets.formattedinput2.formatprefsmixin import PrefInput
  8. import wx
  9. import os
  10. import sys
  11. import stdpaths
  12. from gui.pref.prefcontrols import *
  13. import platform
  14. if platformName == 'mac' and int(platform.mac_ver()[0][3]) >= 5:
  15.     from gui.native.mac.maciconeditor import IconEditor
  16. else:
  17.     from gui.pref.iconeditor import IconEditor
  18. from gui.pref.prefstrings import general_profile as _
  19.  
  20. def save_profile(new_profile):
  21.     profile.set_profile_blob(new_profile)
  22.  
  23.  
  24. def get_promote():
  25.     return profile.prefs['profile.promote']
  26.  
  27.  
  28. def get_shortcut(pth):
  29.     import comtypes.client as client
  30.     shell = client.CreateObject('WScript.Shell')
  31.     scut = client.dynamic.Dispatch(shell.CreateShortcut(pth))
  32.     return scut
  33.  
  34.  
  35. def on_startup_change(new):
  36.     if platformName == 'mac':
  37.         import loginitems
  38.         appdir = os.path.abspath(os.path.join(sys.argv[0], '..', '..', '..'))
  39.         if new and not loginitems.hasitem(appdir):
  40.             loginitems.additem(appdir)
  41.         elif not new and loginitems.hasitem(appdir):
  42.             loginitems.removeitem('Digsby')
  43.         
  44.         return None
  45.     path = path
  46.     import path
  47.     shortcuts = startup_shortcuts()
  48.     if new and not shortcuts:
  49.         import sys
  50.         import locale
  51.         exe = sys.executable.decode('locale')
  52.         pth = stdpaths.userstartup / 'digsby.lnk'
  53.         scut = get_shortcut(pth)
  54.         scut.TargetPath = exe.encode('filesys')
  55.         scut.WorkingDirectory = unicode(path(exe).parent).encode('filesys')
  56.         scut.Save()
  57.     elif shortcuts and not new:
  58.         for scut in shortcuts:
  59.             
  60.             try:
  61.                 scut.remove()
  62.             continue
  63.             except Exception:
  64.                 e = None
  65.                 log.info('Error removing shortcut %r: %r', scut, e)
  66.                 continue
  67.                 continue
  68.             
  69.  
  70.         
  71.     
  72.  
  73.  
  74. def startup_shortcuts():
  75.     if 'wxMSW' in wx.PlatformInfo:
  76.         shortcuts = digsby_shortcuts(stdpaths.userstartup)
  77.         shortcuts.extend(digsby_shortcuts(stdpaths.startup))
  78.         return shortcuts
  79.     return False
  80.  
  81.  
  82. def digsby_shortcuts(dir):
  83.     path = path
  84.     import path
  85.     import sys
  86.     import locale
  87.     res = []
  88.     if 'wxMSW' not in wx.PlatformInfo:
  89.         return res
  90.     dir = path(dir)
  91.     exe = path(sys.executable.decode('locale')).basename().encode('filesys')
  92.     if not dir.isdir():
  93.         print 'warning, no startup dir', dir
  94.         return []
  95.     for lnk in dir.walk('*.lnk'):
  96.         scut = get_shortcut(lnk)
  97.         if exe == path(scut.TargetPath).basename():
  98.             res.append(lnk)
  99.             continue
  100.         dir.isdir()
  101.     
  102.     return res
  103.  
  104. from gui.uberwidgets.PrefPanel import PrefPanel, PrefCollection
  105.  
  106. def panel(panel, sizer, addgroup, exithooks):
  107.     startup = wx.CheckBox(panel, label = _('&Launch Digsby when this computer starts'))
  108.     
  109.     try:
  110.         startupval = bool(startup_shortcuts())
  111.     except Exception:
  112.         startupval = False
  113.         startup.Disable()
  114.  
  115.     startup.Value = startupval
  116.     startup.Bind((wx.EVT_CHECKBOX,), (lambda e: on_startup_change(startup.Value)))
  117.     grp1 = PrefPanel(panel, PrefCollection(startup, Check('digsby.updater.auto_download', _('&Automatically download software updates')), Check('login.reconnect.attempt', _('&If connection to IM service is lost, automatically attempt to reconnect')), Check('social.feed_ads', _('Show trending news articles in social network feeds (powered by OneRiot)')), layout = VSizer(), itemoptions = (0, wx.BOTTOM | wx.TOP, 3)), _('General Options'))
  118.     (p, input, chk) = build_profile_panel(panel)
  119.     
  120.     panel.get_profile = lambda : input.GetFormattedValue()
  121.     
  122.     panel.get_promote = lambda : chk.Value
  123.     (exithooks,) += (lambda : save_profile(panel.get_profile()))
  124.     profile_grp = PrefPanel(panel, p, _('Profile (AIM Only)'))
  125.     ico = build_buddy_icon_panel(panel, 'bicon')
  126.     buddy_icon_grp = PrefPanel(panel, ico, _('Buddy Icon'))
  127.     innersz = wx.BoxSizer(wx.HORIZONTAL)
  128.     innersz.Add(profile_grp, 1, wx.EXPAND)
  129.     innersz.Add(buddy_icon_grp, 0, wx.LEFT, 6)
  130.     lang_choices = [
  131.         ('en', 'English')]
  132.     langchoice = Choice('locale', lang_choices)(panel)
  133.     lang_grp = PrefPanel(panel, langchoice, _('Language'))
  134.     sizer.AddMany([
  135.         (grp1, 0, wx.EXPAND | wx.ALL, 3),
  136.         (innersz, 0, wx.EXPAND | wx.ALL, 3),
  137.         (lang_grp, 0, wx.EXPAND | wx.ALL, 3)])
  138.     sizer.AddStretchSpacer()
  139.     wx.CallAfter(input.SetFormattedValue, profile.profile)
  140.     panel.Layout()
  141.     return panel
  142.  
  143.  
  144. class BitmapPanel(wx.Panel):
  145.     
  146.     def __init__(self, *a, **k):
  147.         wx.Panel.__init__(self, *a, **k)
  148.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  149.         self._icon = None
  150.  
  151.     icon = property((lambda self: self._icon), (lambda self, i: (setattr(self, '_icon', i), self.Refresh())))
  152.     
  153.     def OnPaint(self, e):
  154.         e.Skip()
  155.         icon = self.icon
  156.         dc = wx.PaintDC(self)
  157.         if icon is not None:
  158.             (w, h) = self.Size
  159.             icopos = (w / 2 - icon.Width / 2, h / 2 - icon.Height / 2)
  160.             dc.DrawBitmap(icon, *icopos)
  161.             dc.Brush = wx.TRANSPARENT_BRUSH
  162.             dc.Pen = wx.Pen(wx.Color(213, 213, 213))
  163.             dc.DrawRectangleRect(wx.RectPS(icopos, (icon.Width, icon.Height)))
  164.         
  165.  
  166.  
  167.  
  168. def build_buddy_icon_panel(parent, prefix):
  169.     p = wx.Panel(parent)
  170.     icon_panel = BitmapPanel(p, size = (128, 128))
  171.     picon = profile.get_icon_bitmap()
  172.     if picon is not None:
  173.         icon_panel.icon = picon.ResizedSmaller(128)
  174.     else:
  175.         icon_panel.icon = None
  176.     button = wx.Button(p, -1, _('Change'))
  177.     if platformName == 'mac':
  178.         button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
  179.         icon_button_flags = (0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.BOTTOM, 4)
  180.     else:
  181.         icon_button_flags = (0, wx.EXPAND | wx.TOP, 5)
  182.     
  183.     def changeicon(e):
  184.         if IconEditor.RaiseExisting():
  185.             return None
  186.         if not profile.get_icon_bytes():
  187.             pass
  188.         ie = IconEditor(p, '')
  189.         
  190.         def onOK():
  191.             if ie.ImageChanged:
  192.                 log.info('iconeditor.ImageChanged = True')
  193.                 import hub
  194.                 h = hub.get_instance()
  195.                 bytes = ie.Bytes
  196.                 h.set_buddy_icon_file(bytes)
  197.                 icon_panel.icon = profile.get_icon_bitmap()
  198.             
  199.  
  200.         ie.Prompt(onOK)
  201.  
  202.     button.Bind(wx.EVT_BUTTON, changeicon)
  203.     sz.Add(icon_panel)
  204.     sz.Add(button, *icon_button_flags)
  205.     return p
  206.  
  207.  
  208. def build_profile_panel(parent):
  209.     p = wx.Panel(parent)
  210.     input = PrefInput(p, autosize = False, multiFormat = True, showFormattingBar = platformName != 'mac', skin = 'AppDefaults.FormattingBar', formatpref = 'profile.formatting')
  211.     chk = Check('profile.promote', _('&Promote Digsby in my AIM profile'))(p)
  212.     chk.Value = get_promote()
  213.     if platformName == 'mac':
  214.         checkbox = chk
  215.         chk = wx.BoxSizer(wx.HORIZONTAL)
  216.         chk.Add(checkbox)
  217.         chk.AddStretchSpacer(1)
  218.         chk.Add(input.CreateFontButton(p))
  219.         chk.AddSpacer(4)
  220.         chk_sizer_flags = (0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)
  221.     else:
  222.         chk_sizer_flags = (0, wx.TOP, 3)
  223.     s = p.Sizer = VSizer()
  224.     s.Add(input, 1, wx.EXPAND | wx.ALL, 1)
  225.     s.Add(chk, *chk_sizer_flags)
  226.     
  227.     def OnPaintWithOutline(event):
  228.         dc = wx.AutoBufferedPaintDC(p)
  229.         rect = wx.RectS(p.Size)
  230.         irect = wx.Rect(input.Rect)
  231.         irect.Inflate(1, 1)
  232.         dc.Brush = wx.WHITE_BRUSH
  233.         dc.Pen = wx.TRANSPARENT_PEN
  234.         dc.DrawRectangleRect(rect)
  235.         dc.Pen = wx.Pen(wx.Color(213, 213, 213))
  236.         dc.DrawRectangleRect(irect)
  237.  
  238.     p.Bind(wx.EVT_PAINT, OnPaintWithOutline)
  239.     return (p, input, chk)
  240.  
  241.  
  242. def build_name_panel(parent):
  243.     s = wx.BoxSizer(wx.VERTICAL)
  244.     txt = Text(parent, 'profile.name')
  245.     s.Add(txt)
  246.     return s
  247.  
  248.