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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from gui.uberwidgets.formattedinput2.formattingbar import FormattingBar
  5. from gui.uberwidgets.formattedinput2.fontutil import StorageToFont, StyleToStorage
  6. import wx
  7. import config
  8. import cgui
  9. from gui.uberwidgets.formattedinput2.FormattedExpandoTextCtrl import FormattedExpandoTextCtrl, FormattedTextCtrl, EVT_ETC_LAYOUT_NEEDED
  10. wxMSW = 'wxMSW' in wx.PlatformInfo
  11. if wxMSW:
  12.     from gui.toolbox import set_rich_layoutdirection
  13.  
  14. import logging
  15. log = logging.getLogger('formattedinput')
  16.  
  17. class FormattedInput(cgui.SimplePanel):
  18.     
  19.     def __init__(self, parent, value = '', autosize = True, formatOptions = None, multiFormat = True, showFormattingBar = True, format = None, rtl = False, skin = None, validator = wx.DefaultValidator):
  20.         cgui.SimplePanel.__init__(self, parent)
  21.         self.skin = skin
  22.         self.formatOptions = formatOptions
  23.         sizer = self.Sizer = wx.BoxSizer(wx.VERTICAL)
  24.         if autosize:
  25.             tc = self.tc = FormattedExpandoTextCtrl(self, value = value, multiFormat = multiFormat, validator = validator)
  26.             tc.SetMaxHeight(100)
  27.         else:
  28.             tc = self.tc = FormattedTextCtrl(self, value = value, multiFormat = multiFormat, validator = validator)
  29.         if config.platform == 'mac':
  30.             self.tc.MacCheckSpelling(True)
  31.         
  32.         if format is not None:
  33.             if isinstance(format, wx.TextAttr):
  34.                 tc.SetFormat_Single(format)
  35.             else:
  36.                 (font, fgc, bgc) = StorageToFont(format)
  37.                 tc.SetFormat_Single(wx.TextAttr(wx.Color(*fgc), wx.Color(*bgc), font))
  38.         
  39.         tc.Bind(wx.EVT_KEY_DOWN, self.OnKey)
  40.         self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnExpandEvent)
  41.         self.fbar = None
  42.         inputsizer = self.inputsizer = wx.BoxSizer(wx.HORIZONTAL)
  43.         inputsizer.Add(tc, 1, wx.EXPAND)
  44.         sizer.Add(inputsizer, 1, wx.EXPAND)
  45.         if showFormattingBar:
  46.             self.CreatFormattingBar()
  47.         
  48.         self.SetFormattedValue = self.tc.SetFormattedValue
  49.         self.GetFormattedValue = self.tc.GetFormattedValue
  50.  
  51.     
  52.     def OnKey(self, event):
  53.         ctrlIsDown = event.Modifiers == wx.MOD_CONTROL
  54.         return event.Skip()
  55.  
  56.     
  57.     def OnExpandEvent(self, event):
  58.         height = None if self.FormattingBarIsShown() else 0 + self.tc.MinSize.height
  59.         self.MinSize = wx.Size(-1, height)
  60.         wx.CallAfter(self.Layout)
  61.  
  62.     
  63.     def FormattingBarIsShown(self):
  64.         if self.fbar is not None:
  65.             pass
  66.         return self.fbar.IsShown()
  67.  
  68.     
  69.     def CreatFormattingBar(self):
  70.         fbar = self.fbar = FormattingBar(self, self.tc, self.skin, self.formatOptions)
  71.         self.Sizer.Insert(0, fbar, 0, wx.EXPAND)
  72.         wx.CallAfter(fbar.UpdateDisplay)
  73.  
  74.     
  75.     def ShowFormattingBar(self, show = True):
  76.         hasFBar = self.fbar is not None
  77.         if hasFBar:
  78.             self.fbar.Show(show)
  79.         elif show:
  80.             self.CreatFormattingBar()
  81.         
  82.         self.tc.ForceExpandEvent()
  83.  
  84.     
  85.     def DoUpdateSkin(self, skin):
  86.         self.formattingbar.SetSkinKey(self._skinkey)
  87.  
  88.     
  89.     def Clear(self):
  90.         tc = self.tc
  91.         if 'wxMSW' in wx.PlatformInfo:
  92.             textattr = tc.GetFormat()
  93.             alignment = cgui.GetRichEditParagraphAlignment(tc)
  94.             tc.Clear()
  95.             if cgui.GetRichEditParagraphAlignment(tc) != alignment:
  96.                 cgui.SetRichEditParagraphAlignment(tc, alignment)
  97.             
  98.             tc.SetFormat(textattr)
  99.         else:
  100.             tc.Clear()
  101.  
  102.     
  103.     def __repr__(self):
  104.         
  105.         try:
  106.             return '<%s under %r>' % (self.__class__.__name__, self.Parent)
  107.         except Exception:
  108.             return object.__repr__(self)
  109.  
  110.  
  111.     
  112.     def GetValue(self):
  113.         return self.tc.GetValue()
  114.  
  115.     
  116.     def SetValue(self, value):
  117.         return self.tc.SetValue(value)
  118.  
  119.     Value = property(GetValue, SetValue)
  120.     
  121.     def SetFocus(self):
  122.         self.tc.SetFocus()
  123.  
  124.     
  125.     def ShowModalFontDialog(self, e = None):
  126.         diag = wx.FontDialog(self, self.FontData)
  127.         if wx.ID_OK == diag.ShowModal():
  128.             font_data = diag.GetFontData()
  129.             font = font_data.GetChosenFont()
  130.             color = font_data.GetColour()
  131.             tc = self.tc
  132.             attrs = tc.GetDefaultStyle()
  133.             if color.IsOk():
  134.                 attrs.SetTextColour(color)
  135.             
  136.             if font.IsOk():
  137.                 attrs.SetFont(font)
  138.             
  139.             tc.SetDefaultStyle(attrs)
  140.             tc.Refresh()
  141.             tc.SetFocus()
  142.         
  143.  
  144.     
  145.     def CreateFontButton(self, parent, label = _('Set Font...')):
  146.         font_button = wx.Button(parent, -1, label)
  147.         font_button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
  148.         font_button.Bind(wx.EVT_BUTTON, self.ShowModalFontDialog)
  149.         return font_button
  150.  
  151.     
  152.     def FontData(self):
  153.         d = wx.FontData()
  154.         tc = self.tc
  155.         d.SetInitialFont(tc.GetFont())
  156.         d.SetColour(tc.GetForegroundColour())
  157.         return d
  158.  
  159.     FontData = property(FontData)
  160.     
  161.     def Format(self):
  162.         return StyleToStorage(self.tc.GetDefaultStyle())
  163.  
  164.     Format = property(Format)
  165.  
  166.