home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / pref / pg_general_profile.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  9.4 KB  |  239 lines

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