home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / uberwidgets / UberEmotiBox.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  6.5 KB  |  183 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import os.path as os
  6. import math
  7. import wx
  8. from gui import skin
  9. from gui.skin.skinobjects import Margins
  10. from gui.toolbox.imagefx import wxbitmap_in_square
  11. from gui.toolbox import Monitor, AutoDC
  12. from wx import TextCtrl
  13. UberEmotiBase = wx.PopupTransientWindow
  14.  
  15. class UberEmotiBox(UberEmotiBase):
  16.     
  17.     def __init__(self, parent, emoticons, textctrl, maxwidth = 7, minwidth = 4):
  18.         UberEmotiBase.__init__(self, parent, style = wx.NO_BORDER)
  19.         self.maxwidth = maxwidth
  20.         self.minwidth = minwidth
  21.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  22.         self.SetExtraStyle(wx.WS_EX_PROCESS_IDLE)
  23.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  24.         self.UpdateSkin()
  25.         self.SetTextCtrl(textctrl)
  26.         if emoticons != getattr(self, 'emoticons', None):
  27.             self.emoticons = emoticons
  28.             self.DestroyChildren()
  29.             (self.pemoticons, pwidth, pheight) = self.Arrange(self, emoticons)
  30.         
  31.         self.lesssize = (pwidth, pheight)
  32.         self.SetSize(self.lesssize)
  33.  
  34.     
  35.     def SetTextCtrl(self, textctrl):
  36.         self.textctrl = textctrl
  37.  
  38.     
  39.     def UpdateSkin(self):
  40.         skin_elements = [
  41.             ('padding', 'padding', (lambda : wx.Point(3, 3))),
  42.             ('margins', 'margins', skin.ZeroMargins),
  43.             ('esize', 'emoticonsize', 19),
  44.             ('espace', 'emoticonspace', 23),
  45.             ('bg', 'backgrounds.window', None)]
  46.         for attr, skinattr, default in skin_elements:
  47.             setattr(self, attr, skin.get('emotibox.' + skinattr, default))
  48.         
  49.  
  50.     
  51.     def Arrange(self, parent, emots):
  52.         width = round(math.sqrt(len(emots)))
  53.         if width < self.minwidth:
  54.             width = self.minwidth
  55.         
  56.         if width > self.maxwidth:
  57.             width = self.maxwidth
  58.         
  59.         size = self.espace
  60.         padding = self.padding
  61.         margins = self.margins
  62.         cx = padding.x + margins.left
  63.         cy = padding.y + margins.top
  64.         emoticons = []
  65.         count = 0
  66.         for emot in emots:
  67.             emoticons.append(Emoticon(parent, emot, (cx, cy)))
  68.             cx += size + padding.x
  69.             count += 1
  70.             if count == width:
  71.                 cx = padding.x
  72.                 cy += size + padding.y
  73.                 count = 0
  74.                 continue
  75.         
  76.         if cx != padding.x:
  77.             cy += size + padding.y
  78.         
  79.         across = width * (size + padding.x) + padding.x + margins.x
  80.         cy += margins.bottom
  81.         if cy < across:
  82.             cy = across
  83.         
  84.         return (emoticons, across, cy)
  85.  
  86.     
  87.     def OnPaint(self, event):
  88.         dc = AutoDC(self)
  89.         self.bg.Draw(dc, self.ClientRect)
  90.  
  91.     
  92.     def Display(self, rect):
  93.         pos = rect.BottomLeft
  94.         newrect = wx.RectPS(pos, self.Size)
  95.         screenrect = Monitor.GetFromRect(newrect).ClientArea
  96.         if newrect.bottom > screenrect.bottom:
  97.             pos.y -= rect.height + self.Size.height
  98.         
  99.         if newrect.right > screenrect.right:
  100.             pos.x += rect.width - self.Size.width
  101.         
  102.         self.SetPosition(pos)
  103.         self.Popup()
  104.  
  105.  
  106.  
  107. class Emoticon(wx.Window):
  108.     
  109.     def __init__(self, parent, emot, pos):
  110.         wx.Window.__init__(self, parent, pos = pos)
  111.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  112.         events = [
  113.             (wx.EVT_PAINT, self.OnPaint),
  114.             (wx.EVT_ENTER_WINDOW, self.OnMouseInOrOut),
  115.             (wx.EVT_LEAVE_WINDOW, self.OnMouseInOrOut),
  116.             (wx.EVT_LEFT_UP, self.OnLeftUp)]
  117.         for evt, meth in events:
  118.             self.Bind(evt, meth)
  119.         
  120.         (imgpath, self.keys) = emot
  121.         self.SetToolTipString('   '.join(self.keys))
  122.         self.emote = None
  123.         
  124.         try:
  125.             bitmap = wx.Bitmap(imgpath)
  126.             if bitmap.Ok():
  127.                 self.emote = bitmap
  128.         except Exception:
  129.             print_exc = print_exc
  130.             import traceback
  131.             print_exc()
  132.  
  133.         self.UpdateSkin()
  134.  
  135.     
  136.     def UpdateSkin(self):
  137.         size = skin.get('emotibox.emoticonspace', 24)
  138.         self.Size = wx.Size(size, size)
  139.         esize = skin.get('emotibox.maxemoticonsize', 16)
  140.         self.normalbg = skin.get('emotibox.backgrounds.emoticon', None)
  141.         self.hoverbg = skin.get('emotibox.backgrounds.hover', None)
  142.         emote = self.emote
  143.         if emote is not None:
  144.             self.bitmap = emote.ResizedSmaller(esize)
  145.         else:
  146.             self.bitmap = None
  147.  
  148.     
  149.     def OnPaint(self, event):
  150.         dc = wx.AutoBufferedPaintDC(self)
  151.         rect = wx.RectS(self.Size)
  152.         if wx.FindWindowAtPointer() is self:
  153.             self.hoverbg.Draw(dc, rect)
  154.         else:
  155.             self.normalbg.Draw(dc, rect)
  156.         (W, H) = self.GetSize()
  157.         (w, h) = self.bitmap.GetSize()
  158.         if self.bitmap is not None:
  159.             dc.DrawBitmap(self.bitmap, W / 2 - w / 2, H / 2 - h / 2, True)
  160.         
  161.  
  162.     
  163.     def OnMouseInOrOut(self, event):
  164.         event.Skip()
  165.         self.Refresh()
  166.  
  167.     
  168.     def OnLeftUp(self, event):
  169.         import hooks
  170.         hooks.notify('digsby.statistics.emoticons.chosen')
  171.         textctrl = self.Parent.textctrl
  172.         ip = textctrl.InsertionPoint
  173.         if ip != 0 and textctrl.Value[ip - 1] and textctrl.Value[ip - 1] != ' ':
  174.             textctrl.WriteText(' ')
  175.         
  176.         textctrl.WriteText(''.join([
  177.             self.keys[0],
  178.             ' ']))
  179.         self.Parent.Dismiss()
  180.         self.Parent.textctrl.SetFocus()
  181.  
  182.  
  183.