home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / gui / browser / webkit / webkiteditor.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  6.0 KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. import wx.webview as wx
  6. from functools import partial
  7.  
  8. class WebKitEditor(wx.webview.WebView):
  9.     
  10.     def __init__(self, parent):
  11.         wx.webview.WebView.__init__(self, parent)
  12.  
  13.     
  14.     def __getattr__(self, attr):
  15.         
  16.         try:
  17.             return object.__getattribute__(self, attr)
  18.         except AttributeError:
  19.             if attr in jseditor_commands:
  20.                 return partial(self._execCommand, attr)
  21.             raise 
  22.         except:
  23.             attr in jseditor_commands
  24.  
  25.  
  26.     
  27.     def _execCommand(self, *a):
  28.         args = ', '.join((lambda .0: for arg in .0:
  29. jsrepr(arg))(a))
  30.         js = 'document.execCommand(%s);' % args
  31.         print js
  32.         return self.RunScript(js)
  33.  
  34.  
  35.  
  36. def jsrepr(o):
  37.     if isinstance(o, bool):
  38.         return str(o).lower()
  39.     if isinstance(o, unicode):
  40.         return repr(o)[1:]
  41.     return repr(o)
  42.  
  43. jseditor_commands = ('BackColor', 'Bold', 'Copy', 'CreateLink', 'Cut', 'Delete', 'FindString', 'FontName', 'FontSize', 'FontSizeDelta', 'ForeColor', 'FormatBlock', 'ForwardDelete', 'HiliteColor', 'Indent', 'InsertHorizontalRule', 'InsertHTML', 'InsertImage', 'InsertLineBreak', 'InsertOrderedList', 'InsertParagraph', 'InsertNewlineInQuotedContent', 'InsertText', 'InsertUnorderedList', 'Italic', 'JustifyCenter', 'JustifyFull', 'JustifyLeft', 'JustifyNone', 'JustifyRight', 'Outdent', 'Paste', 'PasteAndMatchStyle', 'Print', 'Redo', 'RemoveFormat', 'SelectAll', 'Strikethrough', 'Subscript', 'Superscript', 'Transpose', 'Underline', 'Undo', 'Unlink', 'Unselect')
  44. if __name__ == '__main__':
  45.     empty_editable_doc = '<html>\n    <head>\n    <style>\n    body {\n        /* width: 100%; */\n        word-wrap:  break-word;\n        font-family: arial;\n    }\n    </style>\n    </head>\n    <body>\n    </body>\n</html>'
  46.     
  47.     def Button(parent, text, callback, **kwargs):
  48.         button = wx.Button(parent, -1, text, **kwargs)
  49.         button.Bind((wx.EVT_BUTTON,), (lambda : callback()))
  50.         return button
  51.  
  52.     app = wx.PySimpleApp()
  53.     f = wx.Frame(None, title = 'WebKit Editor Test')
  54.     wdc = wx.WindowDC(f)
  55.     gc = wx.GraphicsContext.Create(wdc)
  56.     gc.SetFont(f.GetFont())
  57.     wdc.SetFont(f.GetFont())
  58.     print gc.GetTextExtent(' ')
  59.     print wdc.GetTextExtent(' ')
  60.     f.Sizer = fs = wx.BoxSizer(wx.VERTICAL)
  61.     editor = WebKitEditor(f)
  62.     editor.SetPageSource(empty_editable_doc)
  63.     editor.MakeEditable(True)
  64.     
  65.     button = lambda label, callback: Button(f, label, callback, style = wx.BU_EXACTFIT)
  66.     
  67.     def get_set_color(title, okfunc):
  68.         c = wx.GetColourFromUser(f, caption = title)
  69.         if c.IsOk():
  70.             okfunc(c.GetAsString(wx.C2S_HTML_SYNTAX))
  71.         
  72.  
  73.     editbuttons = [
  74.         ('B', editor.Bold),
  75.         ('I', editor.Italic),
  76.         ('U', editor.Underline),
  77.         ('A+', (lambda : editor.fontsize(16))),
  78.         ('A-', (lambda : editor.fontsize(11))),
  79.         ('bg', (lambda : get_set_color('Background Color', (lambda c: editor.BackColor(True, c)))
  80. )),
  81.         ('fg', (lambda : get_set_color('Foreground Color', (lambda c: editor.ForeColor(True, c)))
  82. ))]
  83.     bsizer = wx.BoxSizer(wx.HORIZONTAL)
  84.     for label, callback in editbuttons:
  85.         bsizer.Add(button(label, callback))
  86.     
  87.     fs.Add(bsizer, 0, wx.EXPAND)
  88.     fs.Add(editor, 1, wx.EXPAND)
  89.     panel = wx.Panel(f)
  90.     panel.Sizer = wx.BoxSizer(wx.HORIZONTAL)
  91.     panel.Sizer.AddSpacer((50, 50))
  92.     
  93.     def paint(e):
  94.         dc = wx.PaintDC(panel)
  95.         dc.SetFont(f.GetFont())
  96.         dc.DrawText('ggggggg', 0, 0)
  97.  
  98.     panel.Bind(wx.EVT_PAINT, paint)
  99.     fs.Add(panel, 0, wx.EXPAND)
  100.     wx.CallAfter(f.Show)
  101.     app.MainLoop()
  102.  
  103.