]>
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
):
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
)
15 # create some buttons and sizers to use in testing some
16 # features and also the layout
17 vBtnSizer
= wx
.BoxSizer(wx
.VERTICAL
)
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)
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)
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)
32 btn
= wx
.Button(p
, -1, " ")
33 vBtnSizer
.Add(btn
, 0, wx
.ALL|wx
.EXPAND
, 5)
35 hBtnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
37 btn
= wx
.Button(p
, -1, " ")
38 hBtnSizer
.Add(btn
, 0, wx
.ALL
, 5)
40 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
41 col1
= wx
.BoxSizer(wx
.VERTICAL
)
42 col1
.Add(self
.eom
, 0, wx
.ALL
, 10)
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
)
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.
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())
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())
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")
87 #----------------------------------------------------------------------
89 class TestPanel(wx
.Panel
):
90 def __init__(self
, parent
, log
):
92 wx
.Panel
.__init
__(self
, parent
, -1)
94 b
= wx
.Button(self
, -1, " Test ExpandoTextCtrl ", (50,50))
95 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
98 def OnButton(self
, evt
):
99 self
.win
= TestFrame(self
)
103 #----------------------------------------------------------------------
105 def runTest(frame
, nb
, log
):
106 win
= TestPanel(nb
, log
)
109 #----------------------------------------------------------------------
113 overview
= """<html><body>
114 <h2><center>ExpandoTextCtrl</center></h2>
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.
129 if __name__
== '__main__':
132 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])