]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ExpandoTextCtrl.py
handle starting out with multiple lines of text.
[wxWidgets.git] / wxPython / demo / ExpandoTextCtrl.py
1
2 import wx
3 from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
4
5 #----------------------------------------------------------------------
6
7 class TestFrame(wx.Frame):
8 def __init__(self, parent):
9 wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
10 self.pnl = p = wx.Panel(self)
11 self.eom = ExpandoTextCtrl(p, size=(250,-1),
12 value="This control will expand as you type")
13 self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)
14
15 # create some buttons and sizers to use in testing some
16 # features and also the layout
17 vBtnSizer = wx.BoxSizer(wx.VERTICAL)
18
19 btn = wx.Button(p, -1, "Set MaxHeight")
20 self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
21 vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
22
23 btn = wx.Button(p, -1, "Set Font")
24 self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
25 vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
26
27 btn = wx.Button(p, -1, "Write Text")
28 self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
29 vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
30
31 for x in range(5):
32 btn = wx.Button(p, -1, " ")
33 vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
34
35 hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
36 for x in range(3):
37 btn = wx.Button(p, -1, " ")
38 hBtnSizer.Add(btn, 0, wx.ALL, 5)
39
40 sizer = wx.BoxSizer(wx.HORIZONTAL)
41 col1 = wx.BoxSizer(wx.VERTICAL)
42 col1.Add(self.eom, 0, wx.ALL, 10)
43 col1.Add(hBtnSizer)
44 sizer.Add(col1)
45 sizer.Add(vBtnSizer)
46 p.SetSizer(sizer)
47
48 # Put the panel in a sizer for the frame so we can use self.Fit()
49 frameSizer = wx.BoxSizer()
50 frameSizer.Add(p, 1, wx.EXPAND)
51 self.SetSizer(frameSizer)
52
53 self.Fit()
54
55
56 def OnRefit(self, evt):
57 # The Expando control will redo the layout of the
58 # sizer it belongs to, but sometimes this may not be
59 # enough, so it will send us this event so we can do any
60 # other layout adjustments needed. In this case we'll
61 # just resize the frame to fit the new needs of the sizer.
62 self.Fit()
63
64 def OnSetMaxHeight(self, evt):
65 mh = self.eom.GetMaxHeight()
66 dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
67 "MaxHeight", mh, -1, 1000)
68 if dlg.ShowModal() == wx.ID_OK:
69 self.eom.SetMaxHeight(dlg.GetValue())
70 dlg.Destroy()
71
72
73 def OnSetFont(self, evt):
74 dlg = wx.FontDialog(self, wx.FontData())
75 dlg.GetFontData().SetInitialFont(self.eom.GetFont())
76 if dlg.ShowModal() == wx.ID_OK:
77 self.eom.SetFont(dlg.GetFontData().GetChosenFont())
78 dlg.Destroy()
79
80
81 def OnWriteText(self, evt):
82 self.eom.WriteText("\nThis is a test... Only a test. If this had "
83 "been a real emergency you would have seen the "
84 "quick brown fox jump over the lazy dog.\n")
85
86
87 #----------------------------------------------------------------------
88
89 class TestPanel(wx.Panel):
90 def __init__(self, parent, log):
91 self.log = log
92 wx.Panel.__init__(self, parent, -1)
93
94 b = wx.Button(self, -1, " Test ExpandoTextCtrl ", (50,50))
95 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
96
97
98 def OnButton(self, evt):
99 self.win = TestFrame(self)
100 self.win.Show(True)
101
102
103 #----------------------------------------------------------------------
104
105 def runTest(frame, nb, log):
106 win = TestPanel(nb, log)
107 return win
108
109 #----------------------------------------------------------------------
110
111
112
113 overview = """<html><body>
114 <h2><center>ExpandoTextCtrl</center></h2>
115
116 The ExpandoTextCtrl is a multi-line wx.TextCtrl that will
117 adjust its height on the fly as needed to accomodate the number of
118 lines needed to display the current content of the control. It is
119 assumed that the width of the control will be a fixed value and
120 that only the height will be adjusted automatically. If the
121 control is used in a sizer then the width should be set as part of
122 the initial or min size of the control.
123
124 </body></html>
125 """
126
127
128
129 if __name__ == '__main__':
130 import sys,os
131 import run
132 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
133