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

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