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