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)
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
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
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()
-
-
-