Page MenuHome

Python Console Drawing Refactor
AbandonedPublic

Authored by Harley Acheson (harley) on Mon, Nov 25, 2:11 AM.

Details

Summary

This might seem like a lot of changes for small result, but let me explain this a bit. What I really want to do is pretty up Info Editor. But it and the Python Console share drawing code. Specifically Python Console uses Info Editor's TextView code.

The way these two editors share code makes it difficult for them to vary as much as they really should, and make them both a little harder to read and follow. As a small example, both editors have separate CONSOLE_DRAW_MARGIN defines. And if you want to change the margin of the python console you must change both of these (or it doesn't display correctly) but also affects the Info editor. There many things like this in this code.

So this patch breaks that dependency so that these two editors can draw themselves any way they wish without affecting the other. I've tried to do it in a way that makes the least amount of change. But does make it much easier to read since many of the generic structures and pointers could instead have specific types. So in the end it is simpler and easier to read and maintain.

While I was in there I also made it so that the Python console has a margin that changes properly with user scale. And the cursor gets wider with scale too, as it is harder to see on high-dpi displays like Retina.

Diff Detail

Repository
rB Blender

Event Timeline

Campbell Barton (campbellbarton) requested changes to this revision.EditedMon, Nov 25, 5:47 PM

The purpose of TextView is to be able to display wrapped text without having to re-implement it each time.

This looks to loose this advantage, so some tweaks can be made, which I don't think is justified.

Some improvement to de-duplicate CONSOLE_DRAW_MARGIN define seems reasonable, but I don't think these minor changes require restructuring the code like this.

I'd rather see mockups of the changes you're proposing to make and see if they can be done without duplicating code for wrapped text drawing.

However this isn't so high priority either, I think it can be left as-is, unless there are areas where the py console aren't working well and need to be addressed.

This revision now requires changes to proceed.Mon, Nov 25, 5:47 PM

@Campbell Barton (campbellbarton) - I'd rather see mockups of the changes you're proposing to make and see if they can be done without duplicating code for wrapped text drawing.

Yes, I had meant to include the following link and information about that. Must have been tired. LOL

It started with me looking at this task about updating Info Editor: https://developer.blender.org/T68448

Had thoughts about doing something like the following:

And that is when I saw how (only) those two editors are so linked. When looking into how I could change Textview to support both it looked to turn into a mess. Differing vertical alignment, order, horizontal alignment. The need to only change text color for console, but adding (option) icon, icon color, icon background. And then they would probably want filtering added to Info too which also doesn't fit well there.

So my thought is that each could be more straight-forward if they each used their own drawing code. The thought anyway. LOL

Re: info editor, adding icon at start of each line and reversing the text drawing direction seems like something that the current text-view could support easily enough.
If there are other changes in the future... there may be some reason not to share code. For now I think sharing code is fine.
Suggest to do this in steps

  • First add buttons to display different kinds of reports (code for this is there, just not exposed in the UI)
  • Then reverse draw direction.
  • Then add callback for drawing something at the beginning of each line (an icon for eg).

This is what comes to mind, maybe it can be done differently, but think it can work.


Note that separating out info and console drawing could make sense in some cases, I just don't think the changes being proposed justify it.

Cleaned up the margin use in the textview code to simplify further work in this area:

@Campbell Barton (campbellbarton) - Thanks! Sounds like a plan.

Will abandon this revision as I don't have anything to play with in Console since you have fixed text insertion caret and margin scaling.