File: textrepr.py

package info (click to toggle)
pype 2.9.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,200 kB
  • ctags: 1,468
  • sloc: python: 13,860; makefile: 8; sh: 7
file content (34 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34

'''
This software is licensed under the GPL (GNU General Public License) version 2
as it appears here: http://www.gnu.org/copyleft/gpl.html
It is also included with this archive as `gpl.txt <gpl.txt>`_.
'''


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))