Problem with lines numbers width in wx.stc.StyledTextCtrl

Hi everyone!

Thanks for the existence of this group where we can find help, that’s nice and great!

I’m trying to configure a StyledTextCtrl (from the wx.stc) and I can’t manage to control the width of the element on the left where lines numbers are displayed. I’ve tried many things, looked for help on Google, but nothing I did gave me the answer…

Here a screenshot:

As you can see, the space for numbers is too narrow, and when there’s many line in the control numbers are hidden on the left behind the border… :confused:

And here is the concerned portion of code:

self.SetProperty(“fold”, “1”)
self.SetProperty(“fold.html”, “1”)
self.SetMargins(0, 0)
self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
self.SetMarginSensitive(2, True)
self.SetMarginWidth(2, 12)

``

I also attach my entire file for you to see the code in context! And by the way, while you may read and inspect my script, I need help for another problem: despite what I wrote in my code the indentation guides don’t appear… Can you tell me how to fix that?

Your help we’ll be greatly appreciated as I’m struggling since yesterday with these problems… Big thanks in advance!

editor.py (2.93 KB)

try (untested):

         self.SetMarginWidth(1, 25)

if your post runnable samples you will get tested suggestions.

HTH

Niki

···

On 13.07.2016 13:02, stephane catalanotto wrote:

*Hi everyone!*

Thanks for the existence of this group where we can find help, that's
nice and great!

I'm trying to configure a StyledTextCtrl (from the wx.stc) and I can't
manage to control the width of the element on the left where lines
numbers are displayed. I've tried many things, looked for help on
Google, but nothing I did gave me the answer...

_Here a screenshot_:

<https://lh3.googleusercontent.com/-0_t4O2lL0fg/V4YOxfJwjXI/AAAAAAAABMQ/gfb5yhw1fbs3fYzeW2I-xAfTclB48IiDACLcB/s1600/Capture-2.png&gt;

As you can see, the space for numbers is too narrow, and when there's
many line in the control numbers are hidden on the left behind the
border... :confused:

_And here is the concerned portion of code_:

>
self.SetProperty("fold","1")
self.SetProperty("fold.html","1")
self.SetMargins(0,0)
self.SetMarginType(1,wx.stc.STC_MARGIN_NUMBER)
self.SetMarginMask(2,stc.STC_MASK_FOLDERS)
self.SetMarginSensitive(2,True)
self.SetMarginWidth(2,12)

Hi Niki, thanks for the reply! :slight_smile:

I’ve tried what you propose, but it doesn’t change a thing…

Iattach a runnable sample as you have suggested to me!

I’ve forgot to mention that I use wxPython 3 (with Python 2.7).

Thanks again!!

runnable_sample.py (3.2 KB)

···

Le jeudi 14 juillet 2016 09:33:59 UTC+2, niki a écrit :

try (untested):

     self.SetMarginWidth(1, 25)

if your post runnable samples you will get tested suggestions.

HTH

Niki

Hi,

I am also trying to update it in a dynamic way something like catching text changed event and binding to a function to set line number margin with again.

But if you want to make it wider and not change it again you can try changing the line in your code runnable_sample.py below

from

self.SetMarginWidth(2, 12)

to

self.SetMarginWidth(1, 50)

and if you make it

self.SetMarginWidth(1, 100) you will get a wider line number area


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

On Thursday, July 14, 2016 at 5:01:33 PM UTC+1, stephane catalanotto wrote:
> 
> Le jeudi 14 juillet 2016 09:33:59 UTC+2, niki a écrit :
> > try (untested):
> > 
> > 
> > 
> >          self.SetMarginWidth(1, 25)
> > 
> > 
> > 
> > if your post runnable samples you will get tested suggestions.
> > 
> > 
> > 
> > HTH
> > 
> > 
> > 
> > Niki
> > 
> 
> 
> Hi Niki, thanks for the reply! :)
> 
> I've tried what you propose, but it doesn't change a thing...
> 
> Iattach a runnable sample as you have suggested to me!
> 
> I've forgot to mention that I use wxPython 3 (with Python 2.7).
> 
> Thanks again!!

</details>

Hi Emre, thanks for the reply!

I’m gonna try what you suggested to me, it sounds good!

I’ll try and I’ll be back to tell how it works for me. But I’ll do it later, because for the moment I don’t have really the motivation to do coding; let me explain: I’m french and as you may have heard it, we have been hit by another attack. It happened during national day, july the 14th, in city of Nice (southern France, near where I live). My mind and my heart are not totally at coding for the moment, I need 3 or 4 days to wail…

All right problem solved!

I just had to do this:

self.SetMarginWidth(1, 50) # set the width for line number
self.SetMarginWidth(2, 12) # set the width for folding control

``

In fact I didn’t realised that the 1st param of SetMarginWidth designates the column concerned by the 2nd param… First one is the line numbers column, and the second is for the folding controls.

Now everything works the way it has to…

As Emre raised the question of dynamic width, I will probably modify the code so that the line numbers adapts itself according to number of lines, indeed there’s no need to have a width of 50px when there’s only a few lines.

Long live wxPython, and long live WxPython users! :slight_smile: (yes I’m happy, some may say it doesn’t take much to make me happy…).

I’ve just read again the doc and I would have had the answer if only I would have read with attention; the doc says:

SetMarginWidth(self ,

margin ,
pixelWidth)
Set the width of a margin to a width expressed in pixels.

Parameters:
**margin**

(type=int)

**pixelWidth**

(type=int)

https://www.wxpython.org/docs/api/wx.stc.StyledTextCtrl-class.html#SetMarginWidth

Last question: how to mark the discussion as solved?

I’ve looked everywhere on the page to find an option to edit the initial message, but I can’t find it!