X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/65d48a2acf559325968922906da647b3a77eb016..ac9d5e9574b1bbc9cc86480cd30b4cd3e89f9a96:/wxPython/demo/ExpandoTextCtrl.py diff --git a/wxPython/demo/ExpandoTextCtrl.py b/wxPython/demo/ExpandoTextCtrl.py new file mode 100644 index 0000000000..0315a39e2f --- /dev/null +++ b/wxPython/demo/ExpandoTextCtrl.py @@ -0,0 +1,133 @@ + +import wx +from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED + +#---------------------------------------------------------------------- + +class TestFrame(wx.Frame): + def __init__(self, parent): + wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl") + self.pnl = p = wx.Panel(self) + self.eom = ExpandoTextCtrl(p, size=(250,-1), + value="This control will expand as you type") + self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom) + + # create some buttons and sizers to use in testing some + # features and also the layout + vBtnSizer = wx.BoxSizer(wx.VERTICAL) + + btn = wx.Button(p, -1, "Set MaxHeight") + self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn) + vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5) + + btn = wx.Button(p, -1, "Set Font") + self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn) + vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5) + + btn = wx.Button(p, -1, "Write Text") + self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn) + vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5) + + for x in range(5): + btn = wx.Button(p, -1, " ") + vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5) + + hBtnSizer = wx.BoxSizer(wx.HORIZONTAL) + for x in range(3): + btn = wx.Button(p, -1, " ") + hBtnSizer.Add(btn, 0, wx.ALL, 5) + + sizer = wx.BoxSizer(wx.HORIZONTAL) + col1 = wx.BoxSizer(wx.VERTICAL) + col1.Add(self.eom, 0, wx.ALL, 10) + col1.Add(hBtnSizer) + sizer.Add(col1) + sizer.Add(vBtnSizer) + p.SetSizer(sizer) + + # Put the panel in a sizer for the frame so we can use self.Fit() + frameSizer = wx.BoxSizer() + frameSizer.Add(p, 1, wx.EXPAND) + self.SetSizer(frameSizer) + + self.Fit() + + + def OnRefit(self, evt): + # The Expando control will redo the layout of the + # sizer it belongs to, but sometimes this may not be + # enough, so it will send us this event so we can do any + # other layout adjustments needed. In this case we'll + # just resize the frame to fit the new needs of the sizer. + self.Fit() + + def OnSetMaxHeight(self, evt): + mh = self.eom.GetMaxHeight() + dlg = wx.NumberEntryDialog(self, "", "Enter new max height:", + "MaxHeight", mh, -1, 1000) + if dlg.ShowModal() == wx.ID_OK: + self.eom.SetMaxHeight(dlg.GetValue()) + dlg.Destroy() + + + def OnSetFont(self, evt): + dlg = wx.FontDialog(self, wx.FontData()) + dlg.GetFontData().SetInitialFont(self.eom.GetFont()) + if dlg.ShowModal() == wx.ID_OK: + self.eom.SetFont(dlg.GetFontData().GetChosenFont()) + dlg.Destroy() + + + def OnWriteText(self, evt): + self.eom.WriteText("\nThis is a test... Only a test. If this had " + "been a real emergency you would have seen the " + "quick brown fox jump over the lazy dog.\n") + + +#---------------------------------------------------------------------- + +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1) + + b = wx.Button(self, -1, " Test ExpandoTextCtrl ", (50,50)) + self.Bind(wx.EVT_BUTTON, self.OnButton, b) + + + def OnButton(self, evt): + win = TestFrame(self) + win.Show(True) + + +#---------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + +#---------------------------------------------------------------------- + + + +overview = """
+