how to expand the height of stc automatically?

hi

I want to expand the height of stc automatically according to the text
size(length?) of stc.
how can I do this?

···

------------------------------------

this |
is |
text! |
........... |
............... |

-------------------------------------

Wonjun, Choi

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

Type in the control to see it auto-expand.

do you mean SetMaxHeight method?

it seems like stc has not this.

···

2011/10/31 DevPlayer devplayer@gmail.com

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

Type in the control to see it auto-expand.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

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, self.GetId())
            evt.SetEventObject(self)
            evt.height = height
            evt.numLines = numLines
            self.GetEventHandler().ProcessEvent(evt)

I want to use stc not expando
How can I do this?

···

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 &gt; self\.maxHeight\):
            \# The size is changing\.\.\.  if the control is not in a
            \# sizer then we just want to change the size and
            \# that&#39;s it, the programmer will need to deal with
            \# potential layout issues\.  If it is being managed by
            \# a sizer then we&#39;ll change the min size setting and
            \# then try to do a layout\.  In either case we&#39;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)

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,

self.GetId())

            evt.SetEventObject(self)
            evt.height = height
            evt.numLines = numLines
            self.GetEventHandler().ProcessEvent(evt)

I want to use stc not expando

How can I do this?

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

···

2011/10/31 Wonjun, Choi wonjunchoi001@gmail.com

On 10월31일, 오전11시28분, 최원준 wonjunchoi...@gmail.com wrote:

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.

I think stc needs the event like self.Bind(wx.EVT_TEXT, self.OnTextChanged)

but it seems like there is no event like this in stc.

···

2011/10/31 DevPlayer devplayer@gmail.com

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.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I think I have to make the function like below. but the method in stc might be different.
am I right? please suggest anything.

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))
            # 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)
···

2011/10/31 최원준 wonjunchoi001@gmail.com

2011/10/31 DevPlayer devplayer@gmail.com

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.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I think stc needs the event like self.Bind(wx.EVT_TEXT, self.OnTextChanged)

but it seems like there is no event like this in stc.

EVT_STC_MODIFIED

···

On 10/31/11 1:38 AM, 최원준 wrote:

I think stc needs the event like self.Bind(wx.EVT_TEXT,
self.OnTextChanged)
but it seems like there is no event like this in stc.

--
Robin Dunn
Software Craftsman

Add similar functionality to your STC class.

···

On 10/30/11 9:20 PM, Wonjun, Choi wrote:

I want to use stc not expando
How can I do this?

--
Robin Dunn
Software Craftsman

what is the event in stc instead of EVT_ETC_LAYOUT_NEEDED in textctrl?

ps. please unban me in wxpython(my nickname is maum)

don’t I need below code?

            # send notification that layout is needed
            evt = wx.PyCommandEvent(st.StyledTextEvent, self.GetId())
            evt.SetEventObject(self)
            evt.height = height
            evt.numLines = numLines
            self.GetEventHandler().ProcessEvent(evt)

I just didn’t use this function . and this code works well.
I don’t know why but it works.
thank you

btw when I load the text file in here. can I set the height according to the text length?

···

2011/11/1 최원준 wonjunchoi001@gmail.com

don’t I need below code?

            # send notification that layout is needed

evt = wx.PyCommandEvent(st.StyledTextEvent, self.GetId())

            evt.SetEventObject(self)

            evt.height = height

            evt.numLines = numLines
            self.GetEventHandler().ProcessEvent(evt)

I just didn’t use this function . and this code works well.
I don’t know why but it works.
thank you

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.

···

On 10/31/11 5:39 PM, 최원준 wrote:

--
Robin Dunn
Software Craftsman

ok.

and when I load some string in stc, I want to expand the height of stc according to the text height

so I tested like this. but it didn’t work

    Totalline = self.GetLineCount()
    self.maxHeight = 0
    for line in range(Totalline):
        self.maxHeight += self.TextHeight(line)
···

2011/11/1 Robin Dunn robin@alldunn.com

On 10/31/11 5:39 PM, 최원준 wrote:

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.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I don’t know how to get the max line of stc

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

it seems like self.GetCharHeight() method is not working. the value of this is 17 always.
so I changed manually. it works

height = numLines * 20 #charHeight

# ......................

help(wx.Frame.GetCharHeight)

Help on method GetCharHeight in module wx._core:

GetCharHeight(*args, **kwargs) unbound wx._windows.Frame method
    GetCharHeight(self) -> int

    Get the (average) character size for the current font.
# ......................

Note the word (average). Meaning 17 is the average height, not the
maximum height.