Workaround some platform differences
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -5,8 +5,9 @@ from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class TestFrame(wx.Frame):
|
class TestFrame(wx.Frame):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent, log):
|
||||||
wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
|
wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
|
||||||
|
self.log = log
|
||||||
self.pnl = p = wx.Panel(self)
|
self.pnl = p = wx.Panel(self)
|
||||||
self.eom = ExpandoTextCtrl(p, size=(250,-1),
|
self.eom = ExpandoTextCtrl(p, size=(250,-1),
|
||||||
value="This control will expand as you type")
|
value="This control will expand as you type")
|
||||||
@@ -28,14 +29,28 @@ class TestFrame(wx.Frame):
|
|||||||
self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
|
self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
|
||||||
vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
|
vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
|
||||||
|
|
||||||
for x in range(5):
|
btn = wx.Button(p, -1, "Append Text")
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnAppendText, 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)
|
||||||
|
|
||||||
|
btn = wx.Button(p, -1, "Get Value")
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnGetValue, btn)
|
||||||
|
vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
|
||||||
|
|
||||||
|
for x in range(3):
|
||||||
btn = wx.Button(p, -1, " ")
|
btn = wx.Button(p, -1, " ")
|
||||||
vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
|
vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)
|
||||||
|
|
||||||
hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
for x in range(3):
|
for x in range(3):
|
||||||
btn = wx.Button(p, -1, " ")
|
btn = wx.Button(p, -1, " ")
|
||||||
hBtnSizer.Add(btn, 0, wx.ALL, 5)
|
hBtnSizer.Add(btn, 0, wx.ALL, 5)
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)
|
||||||
|
|
||||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
col1 = wx.BoxSizer(wx.VERTICAL)
|
col1 = wx.BoxSizer(wx.VERTICAL)
|
||||||
@@ -61,6 +76,7 @@ class TestFrame(wx.Frame):
|
|||||||
# just resize the frame to fit the new needs of the sizer.
|
# just resize the frame to fit the new needs of the sizer.
|
||||||
self.Fit()
|
self.Fit()
|
||||||
|
|
||||||
|
|
||||||
def OnSetMaxHeight(self, evt):
|
def OnSetMaxHeight(self, evt):
|
||||||
mh = self.eom.GetMaxHeight()
|
mh = self.eom.GetMaxHeight()
|
||||||
dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
|
dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
|
||||||
@@ -83,7 +99,21 @@ class TestFrame(wx.Frame):
|
|||||||
"been a real emergency you would have seen the "
|
"been a real emergency you would have seen the "
|
||||||
"quick brown fox jump over the lazy dog.\n")
|
"quick brown fox jump over the lazy dog.\n")
|
||||||
|
|
||||||
|
def OnAppendText(self, evt):
|
||||||
|
self.eom.AppendText("\nAppended text.")
|
||||||
|
|
||||||
|
def OnSetValue(self, evt):
|
||||||
|
self.eom.SetValue("A new value.")
|
||||||
|
|
||||||
|
def OnGetValue(self, evt):
|
||||||
|
self.log.write("-----------------\n" + self.eom.GetValue())
|
||||||
|
|
||||||
|
def OnOtherBtn(self, evt):
|
||||||
|
# just for testing...
|
||||||
|
#print self.eom.numLines,
|
||||||
|
self.eom._adjustCtrl()
|
||||||
|
#print self.eom.numLines
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class TestPanel(wx.Panel):
|
class TestPanel(wx.Panel):
|
||||||
@@ -96,7 +126,7 @@ class TestPanel(wx.Panel):
|
|||||||
|
|
||||||
|
|
||||||
def OnButton(self, evt):
|
def OnButton(self, evt):
|
||||||
self.win = TestFrame(self)
|
self.win = TestFrame(self, self.log)
|
||||||
self.win.Show(True)
|
self.win.Show(True)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -90,7 +90,21 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
|||||||
wx.TextCtrl.SetFont(self, font)
|
wx.TextCtrl.SetFont(self, font)
|
||||||
self.numLines = -1
|
self.numLines = -1
|
||||||
self._adjustCtrl()
|
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):
|
def OnTextChanged(self, evt):
|
||||||
# check if any adjustments are needed on every text update
|
# check if any adjustments are needed on every text update
|
||||||
|
Reference in New Issue
Block a user