[Idle-dev] IDLE Line numbering initial plan

Tal Einat taleinat at gmail.com
Mon Jun 16 00:06:21 CEST 2014


On Sun, Jun 15, 2014 at 5:50 PM, Saimadhav Heblikar
<saimadhavheblikar at gmail.com> wrote:
> Hi,
>
> An open issue for this topic[1].
>
> This email details how I want to add line numbering to IDLE. The mock is at
> [2]
>
> This will be only added to EditorWindow and OutputWindow.
>
> The tk.Text class will be replaced by a Text class which inherits from
> tk.Text as in the mock(line 50). Basically, a virtual event called
> <<changed>> is going to be generated when the following actions take
> place:
> insert, delete, replace, when 'insert' is changed, the window moves etc.
> The Text object will intercept this call, trigger <<changed>>. It will
> propagate the original call, as well.
> The line number canvas will be at the left of the text area. It will
> be redrawn, whenever the above events take place.

I'm guessing this is based largely on the code here, right?
http://stackoverflow.com/questions/16369470/tkinter-adding-line-number-to-text-widget

That does look like a very robust approach.

> I was worried about memory usage due to constant redrawing, but the
> memory never increased beyond 5.3 MiB. This is good, given a text
> widget on its own takes 5.0 MiB.
> Processor usage was same in both cases.
>
> As far as details like background, color of text etc are concerned,
> they will be added to config-highlight.def.
>
> There will be a menu option to toggle the line numbering canvas
> on-off. Would something like the "Code Context" option in "Options"
> menu be good?

I think it would be more natural for this setting to be under the
"General" tab in the config dialog.

> The open issue[1] says it should be enabled by default. That to me
> seems like the right way to do it. But if we were to do it as an
> extension, will the existing extension mechanism allow it?(Especially
> the tk.Text overriding part). Could someone familiar with the
> mechanism could fill me in on it?

There's no need to implement this as an extension. Doing so would be
unwise, I think, considering that this will be messing around under
the hood with the Text widget.

> Should the linenumbering related code go into a new class and the Text
> widget be imported from there, or should it be added into EditorWindow
> itself?(LineNumber canvas, the interception mechansim etc)

You should use separate classes, but they do not necessarily have to
be in a separate file. IDLE already has too many code files around.

In this case, however, I think you should put these in a new file.
This code could be useful for other projects as well, and it will be
easier for them to find the code an reuse it if it is in a file of its
own.


Other notes and questions:

1) If you'd like to allow separate configuration of the text and
background colors for the line numbers, you will eventually have to
add those to the "highlighting" tab of the config dialog as well. This
could be left until after we have a satisfactory initial working
version though.

2) Will this support non-standard line heights in the text widget,
such as those inserted by the Squeezer extension? If so, how? If this
makes the implementation slower or more complex then it can be left
out.

3) If this event is going to be triggered for every change in the Text
widget, I'm more concerned about performance than memory. I'd like for
us to test the effect this has on weak computers, e.g. Raspberry Pi.

These are all quite minor notes. Overall I think you're on to a good
approach. I really like that you thought in advance of possible ill
effects, such as memory usage, and went on to check those before
beginning. I think you're about ready to get started on this, and I'll
be excited to see your progress!

Good night,
- Tal Einat


More information about the IDLE-dev mailing list