X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ac9d5e9574b1bbc9cc86480cd30b4cd3e89f9a96..66dae888d1b46d754469d990a2bbc957163f0bad:/wxPython/wx/lib/expando.py diff --git a/wxPython/wx/lib/expando.py b/wxPython/wx/lib/expando.py index 754595687e..a66112b37f 100644 --- a/wxPython/wx/lib/expando.py +++ b/wxPython/wx/lib/expando.py @@ -64,9 +64,11 @@ class ExpandoTextCtrl(wx.TextCtrl): style, validator, name) # save some basic metrics self.extraHeight = self.defaultHeight - self.GetCharHeight() - self.numLines = self.GetNumberOfLines() + self.numLines = 1 self.maxHeight = -1 - + if value: + wx.CallAfter(self._adjustCtrl) + self.Bind(wx.EVT_TEXT, self.OnTextChanged) @@ -88,7 +90,21 @@ class ExpandoTextCtrl(wx.TextCtrl): wx.TextCtrl.SetFont(self, font) self.numLines = -1 self._adjustCtrl() - + + def WriteText(self, text): + # work around a bug of a lack of a EVT_TEXT when calling + # WriteText on wxMac + wx.TextCtrl.WriteText(self, text) + self._adjustCtrl() + + def AppendText(self, text): + # Instead of using wx.TextCtrl.AppendText append and set the + # insertion point ourselves. This works around a bug on wxMSW + # where it scrolls the old text out of view, and since there + # is no scrollbar there is no way to get back to it. + self.SetValue(self.GetValue() + text) + self.SetInsertionPointEnd() + def OnTextChanged(self, evt): # check if any adjustments are needed on every text update @@ -177,7 +193,7 @@ class ExpandoTextCtrl(wx.TextCtrl): while idx < len(pte): if line[idx] == ' ': spc = idx - if pte[idx] - start > width - _sbw: + if pte[idx] - start > width: # we've reached the max width, add a new line count += 1 # did we see a space? if so restart the count at that pos @@ -190,99 +206,3 @@ class ExpandoTextCtrl(wx.TextCtrl): return count #--------------------------------------------------------------------------- - - -if __name__ == '__main__': - print wx.VERSION - - class TestFrame(wx.Frame): - def __init__(self): - wx.Frame.__init__(self, None, title="Testing...") - self.pnl = p = wx.Panel(self) - self.eom = ExpandoTextCtrl(p, pos=(25,25), size=(250,-1)) - 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, "Set Value") - self.Bind(wx.EVT_BUTTON, self.OnSetValue, 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 OnSetValue(self, evt): - self.eom.SetValue("This 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.") - - - app = wx.App(False) - frm = TestFrame() - frm.Show() - #import wx.py - #shell = wx.py.shell.ShellFrame(frm, size=(500,300), - # locals={'wx':wx, 'frm':frm}) - #shell.Show() - frm.Raise() - app.MainLoop() - - -