File: textrepr.py

package info (click to toggle)
pype 2.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 832 kB
  • ctags: 953
  • sloc: python: 9,007; makefile: 54
file content (27 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

import wx

class TextRepr(wx.Panel):
    def __init__(self, parent, root):
        wx.Panel.__init__(self, parent, -1)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(wx.StaticText(self, -1, "Enter your text here:"))
        self.inp = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_TAB|wx.TE_MULTILINE|wx.TE_RICH2)
        sizer.Add(self.inp, 1, wx.TOP|wx.EXPAND, 5)
        sizer.Add(wx.StaticText(self, -1, "Python repr() of that text (including quotes, u prefix, etc.):"), 0, wx.TOP, 5)
        self.out = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE|wx.TE_RICH2|wx.TE_READONLY)
        sizer.Add(self.out, 1, wx.TOP|wx.EXPAND, 5)
        
        self.inp.Bind(wx.EVT_TEXT, self.OnChar)
        
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
    
    def OnChar(self, e):
        txt = self.inp.GetValue()
        try:
            txt = str(txt)
        except:
            pass
        self.out.SetValue(repr(txt))