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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. from wx import PyDeadObjectError
  6.  
  7. try:
  8.     _
  9. except:
  10.     import gettext
  11.     gettext.install('Digsby')
  12.  
  13. import wx
  14. from gui.uberwidgets.uberbook.tabmanager import TabWindowManager
  15. from gui.uberwidgets.uberbook.UberBook import NoteBook
  16. from common import setpref, pref, profile, bind, prefprop
  17. from util import oset, traceguard
  18. from gui.uberwidgets.UberEvents import EVT_TAB_NOTIFIED
  19. from gui.toolbox import saveWindowPos, preLoadWindowPos, snap_pref
  20. from gui.native import memory_event
  21. IMFRAME_MINSIZE = (320, 220)
  22. CLOSETABS_TITLE = _('Close IM Window')
  23. CHECKBOX_TEXT = _('Warn me when I attempt to close multiple conversations')
  24. CLOSETABS_MSG = _('You are about to close %d conversations.  Are you sure you want to continue?')
  25. CLOSE_BUTTON_TEXT = _('Close &tabs')
  26. WARN_PREF = 'messaging.tabs.warn_on_close'
  27.  
  28. class CloseTabsDialog(wx.Dialog):
  29.     
  30.     def WarnMe(self):
  31.         return self.panel.warn_cb.Value
  32.  
  33.     WarnMe = property(WarnMe)
  34.     
  35.     def __init__(self, parent, num_tabs, warn_value = True):
  36.         wx.Dialog.__init__(self, parent, title = CLOSETABS_TITLE)
  37.         self.panel = CloseTabsPanel(self, num_tabs, warn_value)
  38.         self.Sizer = wx.BoxSizer(wx.VERTICAL)
  39.         self.Sizer.Add(self.panel, 1, wx.EXPAND)
  40.         self.Fit()
  41.  
  42.  
  43.  
  44. class CloseTabsPanel(wx.Panel):
  45.     
  46.     def __init__(self, parent, num_tabs, warnme_value = True):
  47.         wx.Panel.__init__(self, parent)
  48.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  49.         self.warn_cb = warn_cb = wx.CheckBox(self, -1, CHECKBOX_TEXT)
  50.         warn_cb.SetValue(warnme_value)
  51.         msgsizer = wx.BoxSizer(wx.VERTICAL)
  52.         self.close_msg = wx.StaticText(self, -1, CLOSETABS_MSG % num_tabs)
  53.         msgsizer.Add(self.close_msg, 0, wx.EXPAND | wx.SOUTH, 8)
  54.         msgsizer.Add(warn_cb, 0, wx.EXPAND)
  55.         h = wx.BoxSizer(wx.HORIZONTAL)
  56.         self.bitmap = wx.ArtProvider.GetBitmap(wx.ART_QUESTION)
  57.         self.bitmap.SetMaskColour(wx.BLACK)
  58.         h.Add((self.bitmap.Width, self.bitmap.Height), 0, wx.EXPAND | wx.ALL, 9)
  59.         h.Add(msgsizer, 0, wx.EXPAND | wx.ALL, 12)
  60.         close_button = wx.Button(self, wx.ID_OK, CLOSE_BUTTON_TEXT)
  61.         close_button.SetDefault()
  62.         close_button.SetFocus()
  63.         cancel_button = wx.Button(self, wx.ID_CANCEL, _('&Cancel'))
  64.         buttonsizer = wx.BoxSizer(wx.HORIZONTAL)
  65.         buttonsizer.AddStretchSpacer(1)
  66.         buttonsizer.Add(close_button, 0, wx.RIGHT, 6)
  67.         buttonsizer.Add(cancel_button)
  68.         buttonsizer.AddStretchSpacer(1)
  69.         s = self.Sizer = wx.BoxSizer(wx.VERTICAL)
  70.         s.Add(h, 0, wx.EXPAND | wx.ALL)
  71.         s.Add(buttonsizer, 0, wx.EXPAND | wx.BOTTOM, 12)
  72.  
  73.     
  74.     def OnPaint(self, e):
  75.         dc = wx.PaintDC(self)
  76.         pos = self.close_msg.Position
  77.         dc.DrawBitmap(self.bitmap, pos.x - self.bitmap.Width - 10, pos.y, True)
  78.  
  79.  
  80. from gui.native.toplevel import FlashOnce, Flash
  81.  
  82. class TitleBarTimer(wx.Timer):
  83.     shouldFlash = prefprop('conversation_window.notify_flash')
  84.     
  85.     def __init__(self, win, tabs):
  86.         wx.Timer.__init__(self)
  87.         self.win = win
  88.         self.tabs = tabs
  89.         self.index = 0
  90.  
  91.     
  92.     def Start(self):
  93.         self.title = self.win.Title
  94.         wx.Timer.Start(self, 2000)
  95.  
  96.     
  97.     def Notify(self):
  98.         win = self.win
  99.         tabs = self.tabs
  100.         if wx.IsDestroyed(win):
  101.             self.Stop()
  102.             return None
  103.         
  104.         if not win.IsActive() and len(tabs):
  105.             tabNum = len(tabs)
  106.             if self.index >= tabNum:
  107.                 None(win.SetTitle if tabNum > 1 else _('(New IM)'))
  108.                 self.index = 0
  109.             else:
  110.                 tab = tabs[self.index]
  111.                 if not wx.IsDestroyed(tab):
  112.                     win.SetTitle(tab.label1)
  113.                     self.index += 1
  114.                 else:
  115.                     tabs.remove(tab)
  116.             if self.shouldFlash:
  117.                 FlashOnce(win)
  118.             
  119.         else:
  120.             self.Stop()
  121.  
  122.     
  123.     def Stop(self):
  124.         wx.Timer.Stop(self)
  125.         self.win.SetTitle(self.title)
  126.         self.index = 0
  127.  
  128.  
  129.  
  130. class TabFrame(wx.Frame):
  131.     
  132.     def __init__(self, parent, pos = wx.DefaultPosition, **kwargs):
  133.         wx.Frame.__init__(self, parent, pos = pos, **kwargs)
  134.         self.winman = ImFrame.WinMan()
  135.         self.tabman = ImFrame.TabMan()
  136.         self.notebook = NoteBook(self, self, self.tabman, skinkey = 'Tabs')
  137.         self.mergetimer = None
  138.         self.notifiedtabs = oset()
  139.         self.titletimer = TitleBarTimer(self, self.notifiedtabs)
  140.         Bind = self.Bind
  141.         Bind(wx.EVT_MOVE, self.OnMove)
  142.         Bind(wx.EVT_SIZE, self.OnSize)
  143.         Bind(EVT_TAB_NOTIFIED, self.OnTabNotify)
  144.         sz = self.Sizer = wx.BoxSizer(wx.VERTICAL)
  145.         sz.Add(self.notebook, 1, wx.EXPAND)
  146.  
  147.     
  148.     def GetTabCount(self):
  149.         return self.notebook.GetTabCount()
  150.  
  151.     
  152.     def TabMan():
  153.         return ImFrame.WinMan().TabManager
  154.  
  155.     TabMan = staticmethod(TabMan)
  156.     
  157.     def WinMan():
  158.         
  159.         try:
  160.             return ImFrame._winmanager
  161.         except AttributeError:
  162.             ImFrame._winmanager = TabWindowManager((lambda pos, size = None: ImFrame(pos = pos, size = size)))
  163.             
  164.             def explodeAllWindows():
  165.                 for win in (lambda .0: for w in .0:
  166. if isinstance(w, ImFrame):
  167. wcontinue)(wx.GetTopLevelWindows()):
  168.                     win.notebook.Explode()
  169.                 
  170.  
  171.             profile.prefs.link(('messaging.tabs.enabled',), (lambda val: None if not val else None), callnow = False, obj = ImFrame._winmanager)
  172.             return ImFrame._winmanager
  173.  
  174.  
  175.     WinMan = staticmethod(WinMan)
  176.     
  177.     def AddTab(self, ctrl, focus = None):
  178.         return self.notebook.Add(ctrl, focus = focus)
  179.  
  180.     cycleTitle = prefprop('conversation_window.cycle_unread_ims')
  181.     shouldFlash = prefprop('conversation_window.notify_flash')
  182.     
  183.     def OnTabNotify(self, event):
  184.         tab = event.tab
  185.         if tab.notified:
  186.             self.notifiedtabs.add(tab)
  187.         elif tab in self.notifiedtabs:
  188.             self.notifiedtabs.remove(tab)
  189.             return None
  190.         else:
  191.             return None
  192.         if not self.cycleTitle:
  193.             if self.shouldFlash:
  194.                 Flash(self)
  195.             
  196.             return None
  197.         
  198.         if len(self.notifiedtabs) and not self.IsActive():
  199.             if not self.titletimer.IsRunning():
  200.                 self.titletimer.Start()
  201.             
  202.         elif self.titletimer.IsRunning():
  203.             self.titletimer.Stop()
  204.         
  205.  
  206.     
  207.     def OnMove(self, event):
  208.         event.Skip(True)
  209.         if pref('messaging.tabs.enabled', True):
  210.             mt = self.mergetimer
  211.             if mt is None:
  212.                 self.mergetimer = wx.CallLater(10, self.notebook.StartWindowDrag)
  213.             else:
  214.                 mt.Start(10)
  215.         
  216.         event.Skip(True)
  217.  
  218.     
  219.     def OnSize(self, event):
  220.         mt = self.mergetimer
  221.         if mt is not None:
  222.             mt.Stop()
  223.         
  224.         event.Skip(True)
  225.  
  226.  
  227.  
  228. class ImFrame(TabFrame):
  229.     WindowName = u'IM Window'
  230.     
  231.     def __init__(self, pos = None, size = None, startMinimized = False, posId = ''):
  232.         (wininfo, placement) = preLoadWindowPos(ImFrame.WindowName, uniqueId = posId, defaultPos = wx.Point(200, 200), defaultSize = wx.Size(410, 300))
  233.         wininfo['style'] |= wx.DEFAULT_FRAME_STYLE
  234.         setPos = pos is not None
  235.         setSize = size is not None
  236.         if setPos or setSize:
  237.             wininfo['style'] &= ~(wx.MAXIMIZE)
  238.         
  239.         if startMinimized:
  240.             wininfo['style'] |= wx.ICONIZE
  241.         
  242.         TabFrame.__init__(self, parent = None, name = ImFrame.WindowName, **wininfo)
  243.         if placement is not None:
  244.             if not setPos:
  245.                 pass
  246.             if not setSize:
  247.                 print 'im window placement', placement
  248.                 traceguard.__enter__()
  249.                 
  250.                 try:
  251.                     SetWindowPlacement = SetWindowPlacement
  252.                     import gui.toolbox
  253.                     SetWindowPlacement(self, placement)
  254.                     print self.Rect
  255.                 finally:
  256.                     pass
  257.  
  258.             
  259.         if setPos:
  260.             self.Position = pos
  261.         
  262.         if setSize:
  263.             self.Size = size
  264.         
  265.         self.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
  266.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  267.         self.posId = posId
  268.         self.EnsureInScreen()
  269.         if pos is not None:
  270.             wx.CallAfter(self.EnsureNotStacked)
  271.         
  272.         profile.prefs.link('conversation_window.always_on_top', self.on_always_on_top)
  273.         snap_pref(self)
  274.         self.SetMinSize(IMFRAME_MINSIZE)
  275.         self.iconizecallbacks = set()
  276.         Bind = self.Bind
  277.         Bind(wx.EVT_CLOSE, self.OnClose)
  278.         Bind(wx.EVT_ACTIVATE, self.OnActivate)
  279.         Bind(wx.EVT_ICONIZE, self.OnIconize)
  280.         memory_event()
  281.  
  282.     
  283.     def OnIconize(self, event):
  284.         event.Skip()
  285.         for callback in set(self.iconizecallbacks):
  286.             
  287.             try:
  288.                 callback()
  289.             continue
  290.             except PyDeadObjectError:
  291.                 self.iconizecallbacks.remove(callback)
  292.                 continue
  293.             
  294.  
  295.         
  296.  
  297.     
  298.     def AnyNotified(self):
  299.         return any((lambda .0: for iwin in .0:
  300. iwin.Tab.notified)(self))
  301.  
  302.     AnyNotified = property(AnyNotified)
  303.     
  304.     def OnActivate(self, e):
  305.         e.Skip()
  306.         if e.GetActive():
  307.             tab = self.notebook.ActiveTab
  308.             if tab is not None:
  309.                 tab.SetNotify(False)
  310.                 tab.page.Content.FocusTextCtrl()
  311.             
  312.         
  313.         if self.titletimer.IsRunning():
  314.             self.titletimer.Stop()
  315.         
  316.  
  317.     
  318.     def __iter__(self):
  319.         return iter((lambda .0: for p in .0:
  320. p.Content)(self.notebook.Pages()))
  321.  
  322.     
  323.     def __getitem__(self, n):
  324.         return self.notebook.Pages()[n].Content
  325.  
  326.     
  327.     def CloseTabIfNotLast(self):
  328.         if self.notebook.GetTabCount() > 1:
  329.             self.notebook.ActiveTab.CloseTab()
  330.         
  331.  
  332.     CloseTabIfNotLast = bind('ImFrame.Tabs.CloseIfNotLast')(CloseTabIfNotLast)
  333.     
  334.     def CloseActiveTab(self):
  335.         self.notebook.ActiveTab.CloseTab()
  336.  
  337.     CloseActiveTab = bind('ImFrame.Tabs.CloseActive')(CloseActiveTab)
  338.     
  339.     def NextTab(self):
  340.         self.notebook.NextTab()
  341.  
  342.     NextTab = bind('ImFrame.Tabs.NextTab')(NextTab)
  343.     
  344.     def PrevTab(self):
  345.         self.notebook.PrevTab()
  346.  
  347.     PrevTab = bind('ImFrame.Tabs.PrevTab')(PrevTab)
  348.     
  349.     def IncreaseTextSize(self):
  350.         self.ActiveMessageArea.IncreaseTextSize()
  351.  
  352.     IncreaseTextSize = bind('ImFrame.ChatWindow.IncreaseTextSize')(IncreaseTextSize)
  353.     
  354.     def DescreaseTextSize(self):
  355.         self.ActiveMessageArea.DecreaseTextSize()
  356.  
  357.     DescreaseTextSize = bind('ImFrame.ChatWindow.DecreaseTextSize')(DescreaseTextSize)
  358.     
  359.     def ResetTextSize(self):
  360.         self.ActiveMessageArea.ResetTextSize()
  361.  
  362.     ResetTextSize = bind('ImFrame.ChatWindow.ResetTextSize')(ResetTextSize)
  363.     
  364.     def ActiveMessageArea(self):
  365.         return self.notebook.ActiveTab.page.Content.message_area
  366.  
  367.     ActiveMessageArea = property(ActiveMessageArea)
  368.     
  369.     def IsTabDragging(self):
  370.         notebook = self.winman.wdt.notebook
  371.         return None if notebook else False
  372.  
  373.     
  374.     def OnClose(self, e):
  375.         tabcount = self.GetTabCount()
  376.         if e.CanVeto() and tabcount > 1 and pref(WARN_PREF, True):
  377.             
  378.             try:
  379.                 diag = _[2]
  380.                 diag.CenterOnParent()
  381.                 res = diag.ShowModal()
  382.                 if not diag.WarnMe:
  383.                     setpref(WARN_PREF, False)
  384.                 
  385.                 if res == wx.ID_CANCEL:
  386.                     return e.Veto()
  387.             finally:
  388.                 pass
  389.  
  390.         
  391.         self.Hide()
  392.         saveWindowPos(self, uniqueId = self.posId)
  393.         for page in self.notebook.Pages():
  394.             page.Children[0].on_close()
  395.         
  396.         self.tabman.UnRegister(self.notebook)
  397.         self.mergetimer = None
  398.         memory_event()
  399.         self.Destroy()
  400.  
  401.     
  402.     def __repr__(self):
  403.         return '<%s %s>' % (self.__class__.__name__, id(self))
  404.  
  405.     
  406.     def UpdateSkin(self):
  407.         wx.CallAfter(self.Layout)
  408.  
  409.     
  410.     def on_always_on_top(self, val):
  411.         self.OnTop = val
  412.  
  413.  
  414. from gui.input import add_class_context
  415. add_class_context(_('IM Windows'), 'ImFrame', cls = ImFrame)
  416.