home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / uberwidgets / formattedinput2 / formattingbar.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  11.3 KB  |  237 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from gui.prototypes.fontdropdown import FontDropDown
  5. from gui.uberwidgets.UberButton import UberButton
  6. from gui.uberwidgets.simplemenu import SimpleMenu, SimpleMenuItem
  7. from gui.uberwidgets.UberEmotiBox import UberEmotiBox
  8. from gui.uberwidgets.formattedinput2.fromattedinputevents import EVT_TEXT_FORMAT_CHANGED
  9. import sys
  10. import wx
  11. import config
  12. if config.platform == 'win':
  13.     from cgui import EVT_SELECTION_CHANGED
  14.  
  15. from gui.uberwidgets.formattedinput2.toolbar import ToolBar, ToolBarSkinDefaults
  16. from gui.prototypes.newskinmodule import NewSkinModule, SkinProxy
  17. from common import setpref, pref
  18. DEFAULT_SIZES = [
  19.     8,
  20.     10,
  21.     12,
  22.     14,
  23.     18,
  24.     24,
  25.     36]
  26. FormattingBarSkinDefaults = {
  27.     'toolbarskin': (lambda : pass),
  28.     'iconsize': (lambda : 15),
  29.     'fontdropdownwidth': (lambda : 100),
  30.     'sizedropdownwidth': (lambda : 33),
  31.     'icons.bold': (lambda : wx.EmptyBitmap(1, 1)),
  32.     'icons.italic': (lambda : wx.EmptyBitmap(1, 1)),
  33.     'icons.underline': (lambda : wx.EmptyBitmap(1, 1)),
  34.     'icons.foregroundcolor': (lambda : wx.EmptyBitmap(1, 1)),
  35.     'icons.backgroundcolor': (lambda : wx.EmptyBitmap(1, 1)),
  36.     'icons.emote': (lambda : wx.EmptyBitmap(1, 1)) }
  37.  
  38. class FormattingBar(ToolBar, NewSkinModule):
  39.     initover = False
  40.     
  41.     def __init__(self, parent, textctrl, skinkey, formatOptions):
  42.         ToolBar.__init__(self, parent, skinkey = None, alignment = wx.ALIGN_LEFT)
  43.         self.SetSkinKey(skinkey, FormattingBarSkinDefaults)
  44.         self.textctrl = textctrl
  45.         if sys.platform.startswith('win'):
  46.             textctrl.Bind(EVT_SELECTION_CHANGED, self.OnCursorMove)
  47.         
  48.         textctrl.Bind(EVT_TEXT_FORMAT_CHANGED, self.OnCursorMove)
  49.         self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
  50.         self.fontdd = FontDropDown(self, skinkey = self.skinTB['buttonskin'])
  51.         self.fontdd.SetMenuSkinKey(self.skinTB['menuskin'])
  52.         self.fontdd.Bind(wx.EVT_COMMAND_CHOICE_SELECTED, self.OnFontSelected)
  53.         icons = self.icons
  54.         self.msize = SimpleMenu(self, self.skinTB['menuskin'], maxheight = 10)
  55.         self.msize.SetItems(self.GenSizeItems(DEFAULT_SIZES))
  56.         self.bsize = UberButton(self, -1, '10', menu = self.msize, type = 'menu')
  57.         self.bsize.SetStaticWidth(self.skinFB['sizedropdownwidth'])
  58.         self.msize.SetWidth(self.skinFB['sizedropdownwidth'])
  59.         self.bbold = UberButton(self, -1, icon = icons['bold'], type = 'toggle')
  60.         self.bbold.Bind(wx.EVT_TOGGLEBUTTON, self.OnBoldButton)
  61.         self.bitalic = UberButton(self, -1, icon = icons['italic'], type = 'toggle')
  62.         self.bitalic.Bind(wx.EVT_TOGGLEBUTTON, self.OnItalicButton)
  63.         self.bunderline = UberButton(self, -1, icon = icons['underline'], type = 'toggle')
  64.         self.bunderline.Bind(wx.EVT_TOGGLEBUTTON, self.OnUnderlineButton)
  65.         self.bcolor = UberButton(self, -1, icon = icons['foregroundcolor'])
  66.         self.bcolor.Bind(wx.EVT_BUTTON, self.OnColorButton)
  67.         self.bbgcolor = UberButton(self, -1, icon = icons['backgroundcolor'])
  68.         self.bbgcolor.Bind(wx.EVT_BUTTON, self.OnBGColorButton)
  69.         self.bemote = UberButton(self, -1, icon = icons['emote'])
  70.         self.bemote.Bind(wx.EVT_BUTTON, self.OnEmoteButton)
  71.         self.AddMany([
  72.             self.fontdd,
  73.             self.bsize,
  74.             self.bbold,
  75.             self.bitalic,
  76.             self.bunderline,
  77.             self.bcolor,
  78.             self.bbgcolor,
  79.             self.bemote])
  80.         self.initover = True
  81.         self.EnableFormattingButtons(formatOptions)
  82.         self.UpdateDisplay()
  83.  
  84.     
  85.     def OnContextMenu(self, event):
  86.         UMenu = UMenu
  87.         import gui.uberwidgets.umenu
  88.         m = UMenu(self)
  89.         m.AddItem(_('Hide Formatting Bar'), callback = (lambda : wx.CallAfter(setpref, 'messaging.show_formatting_bar', False)))
  90.         m.PopupMenu()
  91.  
  92.     
  93.     def OnFontSelected(self, event):
  94.         self.textctrl.ApplyStyle(facename = self.fontdd.GetClientData(self.fontdd.GetSelection()).GetFaceName())
  95.  
  96.     
  97.     def OnSizeSelected(self, item):
  98.         self.bsize.label = str(item.id)
  99.         self.textctrl.ApplyStyle(pointsize = item.id)
  100.  
  101.     
  102.     def OnBoldButton(self, event):
  103.         self.textctrl.ApplyStyle(bold = event.EventObject.IsActive())
  104.  
  105.     
  106.     def OnItalicButton(self, event):
  107.         self.textctrl.ApplyStyle(italic = event.EventObject.IsActive())
  108.  
  109.     
  110.     def OnUnderlineButton(self, event):
  111.         self.textctrl.ApplyStyle(underline = event.EventObject.IsActive())
  112.  
  113.     
  114.     def OnColorButton(self, event):
  115.         oldtextcolor = self.textctrl.GetFormat().GetTextColour()
  116.         self.textctrl.ApplyStyle(textcolor = wx.GetColourFromUser(self, oldtextcolor, _('Choose a foreground color')))
  117.  
  118.     
  119.     def OnBGColorButton(self, event):
  120.         oldbgcolor = self.textctrl.GetFormat().GetTextColour()
  121.         self.textctrl.ApplyStyle(bgcolor = wx.GetColourFromUser(self, oldbgcolor, _('Choose a background color')))
  122.  
  123.     
  124.     def OnEmoteButton(self, event):
  125.         self.DisplayEmotibox(self.bemote.ScreenRect)
  126.  
  127.     
  128.     def DisplayEmotibox(self, rect):
  129.         import hooks
  130.         hooks.notify('digsby.statistics.emoticons.box_viewed')
  131.         ebox = self.GetEmotibox()
  132.         ebox.Display(rect)
  133.  
  134.     
  135.     def GetEmotibox(self):
  136.         b = None
  137.         old_name = getattr(self, '_emotipack_name', None)
  138.         new_name = pref('appearance.conversations.emoticons.pack', type = unicode, default = u'default')
  139.         self._emotipack_name = new_name
  140.         
  141.         try:
  142.             b = self.__class__.emotibox
  143.             if not wx.IsDestroyed(b):
  144.                 if old_name != new_name:
  145.                     b.Destroy()
  146.                 elif b.Parent is not self:
  147.                     b.Reparent(self)
  148.                 
  149.         except AttributeError:
  150.             pass
  151.  
  152.         if b is None or wx.IsDestroyed(b):
  153.             get_emoticon_bitmaps = get_emoticon_bitmaps
  154.             import gui.imwin.emoticons
  155.             b = self.__class__.emotibox = UberEmotiBox(self, get_emoticon_bitmaps(self._emotipack_name), self.textctrl, maxwidth = 12)
  156.         else:
  157.             b.SetTextCtrl(self.textctrl)
  158.         return b
  159.  
  160.     
  161.     def OnCursorMove(self, event):
  162.         event.Skip()
  163.         wx.CallAfter(self.UpdateDisplay)
  164.  
  165.     
  166.     def UpdateDisplay(self):
  167.         if wx.IsDestroyed(self.textctrl):
  168.             return None
  169.         selection = self.textctrl.GetSelection()
  170.         if selection[0] != selection[1]:
  171.             return None
  172.         textattr = self.textctrl.GetFormat()
  173.         font = textattr.GetFont()
  174.         facename = font.GetFaceName()
  175.         self.fontdd.SetSelection(self.fontdd.FindString(facename, False))
  176.         self.bsize.SetLabel(str(font.GetPointSize()))
  177.         self.bbold.Active(font.GetWeight() == wx.FONTWEIGHT_BOLD)
  178.         self.bitalic.Active(font.GetStyle() == wx.FONTSTYLE_ITALIC)
  179.         self.bunderline.Active(font.GetUnderlined())
  180.  
  181.     
  182.     def EnableFormattingButtons(self, enabledict):
  183.         if enabledict is None:
  184.             return None
  185.         default = enabledict is None if 'default' in enabledict else True
  186.         buttons = [
  187.             ('size', self.bsize),
  188.             ('bold', self.bbold),
  189.             ('italic', self.bitalic),
  190.             ('underline', self.bunderline),
  191.             ('color', self.bcolor),
  192.             ('bgcolor', self.bbgcolor),
  193.             ('emote', self.bemote)]
  194.         for key, button in buttons:
  195.             None(button.Enable if key in enabledict else default)
  196.         
  197.  
  198.     
  199.     def GenSizeItems(self, sizes = DEFAULT_SIZES):
  200.         return [ SimpleMenuItem([
  201.             str(size)], id = size, method = self.OnSizeSelected) for size in sizes ]
  202.  
  203.     
  204.     def DoUpdateSkin(self, skin):
  205.         self.skinFB = skin
  206.         ToolBar.DoUpdateSkin(self, SkinProxy(skin['toolbarskin'], ToolBarSkinDefaults))
  207.         icons = self.icons = { }
  208.         icons['bold'] = skin['icons.bold']
  209.         icons['italic'] = skin['icons.italic']
  210.         icons['underline'] = skin['icons.underline']
  211.         icons['foregroundcolor'] = skin['icons.foregroundcolor']
  212.         icons['backgroundcolor'] = skin['icons.backgroundcolor']
  213.         icons['emote'] = skin['icons.emote']
  214.         iconsize = skin['iconsize']
  215.         for key in icons:
  216.             if icons[key] is not None:
  217.                 icons[key] = icons[key].Resized(iconsize)
  218.                 continue
  219.         
  220.         if self.initover:
  221.             self.bsize.SetStaticWidth(skin['sizedropdownwidth'])
  222.             self.msize.SetWidth(skin['sizedropdownwidth'])
  223.             self.bbold.SetIcon(icons['bold'])
  224.             self.bitalic.SetIcon(icons['italic'])
  225.             self.bunderline.SetIcon(icons['underline'])
  226.             self.bcolor.SetIcon(icons['foregroundcolor'])
  227.             self.bbgcolor.SetIcon(icons['backgroundcolor'])
  228.             self.bemote.SetIcon(icons['emote'])
  229.         
  230.  
  231.     
  232.     def GetSkinProxy(self):
  233.         if hasattr(self, 'skinFB'):
  234.             return self.skinFB
  235.  
  236.  
  237.