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