Run the wxPyDemo
...\wxPython2.8 Docs and Demos\demo\demo.pyw
or
...\wxPython2.9 Docs and Demos\demo\demo.pyw
In the "wxPython Overview" TreeCtrl on the left
expand "Recent Additions/Updates" or where ever and look for:
ExpandoTextCtrl
self.Bind(wx.EVT_TEXT, self.OnTextChanged)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnTextChanged(self, evt):
# check if any adjustments are needed on every text update
self._adjustCtrl()
evt.Skip()
def OnSize(self, evt):
# The number of lines needed can change when the ctrl is resized too.
self._adjustCtrl()
evt.Skip()
def _adjustCtrl(self):
# if the current number of lines is different than before
# then recalculate the size needed and readjust
numLines = self.GetLineCount()
if numLines != self.numLines:
self.numLines = numLines
charHeight = self.GetCharHeight()
height = numLines * charHeight + self.extraHeight
if not (self.maxHeight != -1 and height > self.maxHeight):
# The size is changing... if the control is not in a
# sizer then we just want to change the size and
# that's it, the programmer will need to deal with
# potential layout issues. If it is being managed by
# a sizer then we'll change the min size setting and
# then try to do a layout. In either case we'll also
# send an event so the parent can handle any special
# layout issues that it wants to deal with.
if self.GetContainingSizer() is not None:
mw, mh = self.GetMinSize()
self.SetMinSize((mw, height))
if self.GetParent().GetSizer() is not None:
self.GetParent().Layout()
else:
self.GetContainingSizer().Layout()
else:
self.SetSize((-1, height))
# send notification that layout is needed
evt = wx.PyCommandEvent(wx.EVT_ETC_LAYOUT_NEEDED, self.GetId())
evt.SetEventObject(self)
evt.height = height
evt.numLines = numLines
self.GetEventHandler().ProcessEvent(evt)
On 10월31일, 오전11시28분, 최원준 <wonjunchoi...@gmail.com> wrote:
or do you mean below function?
self\.Bind\(wx\.EVT\_TEXT, self\.OnTextChanged\)
self\.Bind\(wx\.EVT\_SIZE, self\.OnSize\)
def OnTextChanged\(self, evt\):
\# check if any adjustments are needed on every text update
self\.\_adjustCtrl\(\)
evt\.Skip\(\)
def OnSize\(self, evt\):
\# The number of lines needed can change when the ctrl is resized
too.
self._adjustCtrl()
evt.Skip()
def \_adjustCtrl\(self\):
\# if the current number of lines is different than before
\# then recalculate the size needed and readjust
numLines = self\.GetLineCount\(\)
if numLines \!= self\.numLines:
self\.numLines = numLines
charHeight = self\.GetCharHeight\(\)
height = numLines \* charHeight \+ self\.extraHeight
if not \(self\.maxHeight \!= \-1 and height > self\.maxHeight\):
\# The size is changing\.\.\. if the control is not in a
\# sizer then we just want to change the size and
\# that's it, the programmer will need to deal with
\# potential layout issues\. If it is being managed by
\# a sizer then we'll change the min size setting and
\# then try to do a layout\. In either case we'll also
\# send an event so the parent can handle any special
\# layout issues that it wants to deal with\.
if self\.GetContainingSizer\(\) is not None:
mw, mh = self\.GetMinSize\(\)
self\.SetMinSize\(\(mw, height\)\)
if self\.GetParent\(\)\.GetSizer\(\) is not None:
self\.GetParent\(\)\.Layout\(\)
else:
self\.GetContainingSizer\(\)\.Layout\(\)
else:
self\.SetSize\(\(\-1, height\)\)
\# send notification that layout is needed
evt = wx\.PyCommandEvent\(wx\.EVT\_ETC\_LAYOUT\_NEEDED,
Additionally, in your self._adjustCtrl() you will need to account for
when STC line wrapping is on and off, STC margins, spacing borders
between widgets, if you use any, scrollbars, font and font size
changes (try CTRL+MOUSEWHEEL), and the like, which all can effect the
length and number of lines to show.
Instead of self.GetParent.GetSize() you may need
self.GetParent.GetVirtualSize()
It looks to me like your doing what I would do. Other then that is all
I can suggest about your question so far.
what is the event in stc instead of EVT_ETC_LAYOUT_NEEDED in textctrl?
You need to create your own event type just like the expando module does. Or you could probably just reuse that one
ps. please unban me in wxpython(my nickname is maum)
It's been unbanned for about 10 hours now. Please don't flood the channel (or this list) anymore, including useless re-asking of the same questions over and over.
what is the event in stc instead of EVT_ETC_LAYOUT_NEEDED in textctrl?
You need to create your own event type just like the expando module does. Or you could probably just reuse that one
ps. please unban me in wxpython(my nickname is maum)
It’s been unbanned for about 10 hours now. Please don’t flood the channel (or this list) anymore, including useless re-asking of the same questions over and over.
Totalline = self.GetLineCount()
self.maxHeight = 0
for line in range(0, Totalline):
self.maxHeight += self.TextHeight(line)
self.SetMinSize((-1, Totalline * self.maxHeight))
if self.GetParent().GetSizer() is not None:
self.GetParent().Layout()
else:
self.GetContainingSizer().Layout()
I did like this. am I right?
this code expands strangely.
self.Bind(st.EVT_STC_MODIFIED, self.OnTextChanged)
def OnTextChanged(self, evt):
# check if any adjustments are needed on every text update
self._adjustCtrl()
evt.Skip()
def _adjustCtrl(self):
numLines = self.GetLineCount()
if numLines != self.numLines:
self.numLines = numLines
charHeight = self.GetCharHeight()
height = numLines * charHeight
if not (self.maxHeight != -1 and height > self.maxHeight):
if self.GetContainingSizer() is not None:
mw, mh = self.GetMinSize()
self.SetMinSize((mw, height))
if self.GetParent().GetSizer() is not None:
self.GetParent().Layout()
else:
self.GetContainingSizer().Layout()
else:
self.SetSize((-1, height))