home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / gui / toast / toaststack.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  5.2 KB  |  143 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from wx import Point, RectPS, TOP, LEFT, BOTTOM, GetMousePosition
  6. from gui.toolbox import Monitor, alignment_to_string
  7. from gui.windowfx import move_smoothly
  8. from cgui import fadein
  9. from common import prefprop
  10. from logging import getLogger
  11. log = getLogger('popupstack')
  12.  
  13. def screenArea(monitor_n):
  14.     display_n = min(Monitor.GetCount() - 1, monitor_n)
  15.     return Monitor.All()[display_n].GetClientArea()
  16.  
  17. AVOID_MOUSE = False
  18. AVOID_MOUSE_PIXELS = 30
  19. valid_corners = frozenset((wx.TOP | wx.LEFT, wx.TOP | wx.RIGHT, wx.BOTTOM | wx.LEFT, wx.BOTTOM | wx.RIGHT))
  20.  
  21. class PopupStack(list):
  22.     
  23.     def __init__(self, monitor, position, padding = None, border = None):
  24.         self.monitor = monitor
  25.         self.corner = position
  26.         if padding is None:
  27.             padding = (0, 10)
  28.         
  29.         if border is None:
  30.             border = (10, 10)
  31.         
  32.         self.padding = Point(*padding)
  33.         self.border = Point(*border)
  34.         self.NextRect = None if TOP & self.corner else self.Up
  35.         self.OppositeRect = None if TOP & self.corner else self.Down
  36.  
  37.     
  38.     def __repr__(self):
  39.         return '<PopupStack %s monitor %d (%d popups)>' % (alignment_to_string(self.corner), self.monitor, len(self))
  40.  
  41.     
  42.     def ScreenRect(self):
  43.         return screenArea(self.monitor)
  44.  
  45.     ScreenRect = property(ScreenRect)
  46.     
  47.     def Up(self, prevRect, newSize, user_action):
  48.         border = self.border
  49.         padding = self.padding
  50.         if prevRect is None:
  51.             if LEFT & self.corner:
  52.                 pt = self.ScreenRect.BottomLeft + (border.x + padding.x, -(border.y))
  53.             else:
  54.                 pt = self.ScreenRect.BottomRight - (newSize.width + border.x + padding.x, border.y)
  55.         else:
  56.             pt = prevRect.TopLeft - Point(0, border.y + padding.y)
  57.         r = RectPS(pt - Point(0, newSize.height), newSize)
  58.         if AVOID_MOUSE and not user_action and r.Contains(GetMousePosition()):
  59.             r.y -= (r.Bottom - GetMousePosition().y) + AVOID_MOUSE_PIXELS
  60.         
  61.         return r
  62.  
  63.     
  64.     def Down(self, prevRect, newSize, user_action):
  65.         border = self.border
  66.         padding = self.padding
  67.         if prevRect is None:
  68.             if LEFT & self.corner:
  69.                 pt = self.ScreenRect.TopLeft + (border.x + padding.x, border.y)
  70.             else:
  71.                 pt = self.ScreenRect.TopRight - (newSize.width + border.x + padding.x, -(border.y))
  72.         else:
  73.             pt = prevRect.BottomLeft + Point(0, border.y + padding.y)
  74.         r = RectPS(pt, newSize)
  75.         if AVOID_MOUSE and not user_action and r.Contains(GetMousePosition()):
  76.             r.y += (GetMousePosition().y - r.y) + AVOID_MOUSE_PIXELS
  77.         
  78.         return r
  79.  
  80.     
  81.     def InitialPos(self, size):
  82.         return self.NextRect(None, size).Position
  83.  
  84.     
  85.     def Add(self, popup):
  86.         self.append(popup)
  87.         (popup, popup.OnClose) += (lambda userClose: self.Remove(popup, user_action = userClose))
  88.         self.DoPositions(popup)
  89.         popup._infader = fadein(popup, 0, popup.opacity_normal, 30)
  90.  
  91.     
  92.     def Remove(self, popup, user_action = False):
  93.         
  94.         try:
  95.             self.remove(popup)
  96.         except ValueError:
  97.             pass
  98.  
  99.         self.DoPositions(user_action = user_action)
  100.  
  101.     
  102.     def DoPositions(self, paging = None, user_action = False):
  103.         prevRect = None
  104.         for popup in self[:]:
  105.             
  106.             try:
  107.                 oldrect = popup.Rect
  108.             except wx.PyDeadObjectError:
  109.                 self.remove(popup)
  110.                 log.critical('dead Popup object in %r' % self)
  111.                 continue
  112.  
  113.             quick = False
  114.             desired = popup.DesiredSize
  115.             if popup.Hover or popup.has_focus:
  116.                 rect = RectPS(popup.Position, desired)
  117.                 if paging is popup and BOTTOM & self.corner:
  118.                     rect.y -= rect.height - oldrect.height
  119.                 
  120.             else:
  121.                 rect = self.NextRect(prevRect, desired, user_action = user_action)
  122.             popup._moved = True
  123.             self.SetPopupRect(popup, rect, quick = paging is popup)
  124.             prevRect = rect
  125.         
  126.  
  127.     slidetime = prefprop('notifications.popups.slide_ms', 140)
  128.     
  129.     def SetPopupRect(self, popup, rect, quick = False):
  130.         t = int(self.slidetime)
  131.         if t == 0:
  132.             quick = True
  133.         
  134.         oldrect = popup.Rect
  135.         if quick:
  136.             popup.SetRect(rect)
  137.         elif oldrect.Size != rect.Size:
  138.             popup.SetRect(wx.RectPS(oldrect.Position, rect.Size))
  139.         
  140.         move_smoothly(popup, rect.Position, time = t)
  141.  
  142.  
  143.