]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ExpandoTextCtrl.py
3 from wx
.lib
.expando
import ExpandoTextCtrl
, EVT_ETC_LAYOUT_NEEDED
5 #----------------------------------------------------------------------
7 class TestFrame(wx
.Frame
):
8 def __init__(self
, parent
, log
):
9 wx
.Frame
.__init
__(self
, parent
, title
="Test ExpandoTextCtrl")
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
)
16 # create some buttons and sizers to use in testing some
17 # features and also the layout
18 vBtnSizer
= wx
.BoxSizer(wx
.VERTICAL
)
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)
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)
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)
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)
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)
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)
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
)
49 hBtnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
51 btn
= wx
.Button(p
, -1, " ")
52 hBtnSizer
.Add(btn
, 0, wx
.ALL
, 5)
53 self
.Bind(wx
.EVT_BUTTON
, self
.OnOtherBtn
, btn
)
55 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
56 col1
= wx
.BoxSizer(wx
.VERTICAL
)
57 col1
.Add(self
.eom
, 0, wx
.ALL
, 10)
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
)
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.
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())
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())
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")
102 def OnAppendText(self
, evt
):
103 self
.eom
.AppendText("\nAppended text.")
105 def OnSetValue(self
, evt
):
106 self
.eom
.SetValue("A new value.")
108 def OnGetValue(self
, evt
):
109 self
.log
.write("-----------------\n" + self
.eom
.GetValue())
111 def OnOtherBtn(self
, evt
):
112 # just for testing...
113 #print self.eom.numLines,
114 self
.eom
._adjustCtrl
()
115 #print self.eom.numLines
117 #----------------------------------------------------------------------
119 class TestPanel(wx
.Panel
):
120 def __init__(self
, parent
, log
):
122 wx
.Panel
.__init
__(self
, parent
, -1)
124 b
= wx
.Button(self
, -1, " Test ExpandoTextCtrl ", (50,50))
125 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
128 def OnButton(self
, evt
):
129 self
.win
= TestFrame(self
, self
.log
)
133 #----------------------------------------------------------------------
135 def runTest(frame
, nb
, log
):
136 win
= TestPanel(nb
, log
)
139 #----------------------------------------------------------------------
143 overview
= """<html><body>
144 <h2><center>ExpandoTextCtrl</center></h2>
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.
159 if __name__
== '__main__':
162 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])