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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  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.             else:
  22.                 raise 
  23.         except:
  24.             attr in jseditor_commands
  25.  
  26.  
  27.     
  28.     def _execCommand(self, *a):
  29.         args = ', '.join((lambda .0: for arg in .0:
  30. jsrepr(arg))(a))
  31.         js = 'document.execCommand(%s);' % args
  32.         print js
  33.         return self.RunScript(js)
  34.  
  35.  
  36.  
  37. def jsrepr(o):
  38.     if isinstance(o, bool):
  39.         return str(o).lower()
  40.     elif isinstance(o, unicode):
  41.         return repr(o)[1:]
  42.     else:
  43.         return repr(o)
  44.  
  45. 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')
  46. if __name__ == '__main__':
  47.     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>'
  48.     
  49.     def Button(parent, text, callback, **kwargs):
  50.         button = wx.Button(parent, -1, text, **kwargs)
  51.         button.Bind((wx.EVT_BUTTON,), (lambda : callback()))
  52.         return button
  53.  
  54.     app = wx.PySimpleApp()
  55.     f = wx.Frame(None, title = 'WebKit Editor Test')
  56.     wdc = wx.WindowDC(f)
  57.     gc = wx.GraphicsContext.Create(wdc)
  58.     gc.SetFont(f.GetFont())
  59.     wdc.SetFont(f.GetFont())
  60.     print gc.GetTextExtent(' ')
  61.     print wdc.GetTextExtent(' ')
  62.     f.Sizer = fs = wx.BoxSizer(wx.VERTICAL)
  63.     editor = WebKitEditor(f)
  64.     editor.SetPageSource(empty_editable_doc)
  65.     editor.MakeEditable(True)
  66.     
  67.     button = lambda label, callback: Button(f, label, callback, style = wx.BU_EXACTFIT)
  68.     
  69.     def get_set_color(title, okfunc):
  70.         c = wx.GetColourFromUser(f, caption = title)
  71.         if c.IsOk():
  72.             okfunc(c.GetAsString(wx.C2S_HTML_SYNTAX))
  73.         
  74.  
  75.     editbuttons = [
  76.         ('B', editor.Bold),
  77.         ('I', editor.Italic),
  78.         ('U', editor.Underline),
  79.         ('A+', (lambda : editor.fontsize(16))),
  80.         ('A-', (lambda : editor.fontsize(11))),
  81.         ('bg', (lambda : get_set_color('Background Color', (lambda c: editor.BackColor(True, c)))
  82. )),
  83.         ('fg', (lambda : get_set_color('Foreground Color', (lambda c: editor.ForeColor(True, c)))
  84. ))]
  85.     bsizer = wx.BoxSizer(wx.HORIZONTAL)
  86.     for label, callback in editbuttons:
  87.         bsizer.Add(button(label, callback))
  88.     
  89.     fs.Add(bsizer, 0, wx.EXPAND)
  90.     fs.Add(editor, 1, wx.EXPAND)
  91.     panel = wx.Panel(f)
  92.     panel.Sizer = wx.BoxSizer(wx.HORIZONTAL)
  93.     panel.Sizer.AddSpacer((50, 50))
  94.     
  95.     def paint(e):
  96.         dc = wx.PaintDC(panel)
  97.         dc.SetFont(f.GetFont())
  98.         dc.DrawText('ggggggg', 0, 0)
  99.  
  100.     panel.Bind(wx.EVT_PAINT, paint)
  101.     fs.Add(panel, 0, wx.EXPAND)
  102.     wx.CallAfter(f.Show)
  103.     app.MainLoop()
  104.  
  105.