tkinter forced indent - python

I am looking for help - I am updating my Tkinter wiki (http://sourceforge.net/projects/infolder/) trying to add to it some folding/outline capabilities.
For it to work I need to place in the text widget (the main window where all the action happens) some un-deletable symbol indicating folding (e.g. a small triangle image indicating hidden text lines).
Unfortunately I noticed from these Q&A's that undeletable stuff is not easy to create in Tkinter:
How can you mark a portion of a text widget as readonly?
unremovable text in tkinter
As a 2nd option, I could try to show folding levels by a forced indent, so that e.g. if I'm at a one-level deep, the start-of-line is not at column 1 but at column 5...
This is it possible in Tkinter, without too much work?
thanks for any help...

Your question says that undeleteable regions are "not easy", but you also show they are possible by linking to an answer that shows how. So, what question are you asking?
As for "forced indent", look at the lmargin1 and lmargin2 tag attributes.

Related

What is the difference between a Primitive, Control and Complex Control widget?

Qt supports custom paint events for drawing of widgets through QStyle.
However when using the QStyle you need to specify what type of element you're trying to draw,
i.e, if you want a control element you need to paint it by using QStyle.drawControl(CE_Example, style).
My question is, how is someone who is relatively new meant to understand which method to correctly call, or find which element to paint when I want to perform the actions myself, say for example I want to draw my SpinButton with purple up and down arrows. I tried to google and see if I could find an explanation but could not, so I was wondering if this is common terminology or if it was some jargon used by the Qt community.
Any advice for correctly traversing documentation or anything like that appreciated, maybe I have an incorrect approach.
I eventually found my answer traversing https://doc.qt.io/qt-5/qstyle.html#details
Primitive Element: A primitive element is a common GUI element, such as a checkbox indicator or button bevel.
Control Element: A control element is a part of a widget that performs some action or displays information to the user.
Complex Control: Complex controls have different behavior depending upon where the user clicks on them or which keys are pressed.

wxPython : change colour of a DataViewListCtrl item

I'm pretty new to building UIs, so I apologize if my question seems dumb in any way.
I'm currently building a small interface which aims at displaying a report depending on several entry parameters.
At first, I wanted the report to be shown through a wxListCtrl (LC_REPORT) but the problem I encountered is that I can't set the background or the font colour of a "Cell", I can only do it for the complete row. Maybe I'm mistaken tho.
Secondly, I found that I could show a report in a wxDataViewListCtrl, but I must admit I'm kind of lost within wxPython documentation (wxDataViewItem, wxDataViewItemAttr, etc).
Is there a way, once I built the report, to change some cells settings specifically?
You can definitely do what you want using the UltimateListCtrl widget. The wxPython demo even has an example of setting a single cell's background color to yellow. It looks like the items are of the following type: UltimateListItem. These have a _colour property that can be set.
The ObjectListView also might be a solution that is worth looking at: https://objectlistview-python-edition.readthedocs.io/en/latest/recipes.html#how-can-i-change-the-colours-of-a-row

wxpython bitmap adding textctrl/combobox top of it?

I was trying to find if its possible to add textctrl/combobox top of GenStaticBitmap in wxpython.
Did not find anything with the fast searches i did. Its not first in the priorities, but i feel like it would make the program usage better.
In this case i have screenshot taken from webpage and user can select inputbox and it should be textctrl over the bitmap positioned where it was selected. (i have it working already with textctrl positioned elsewhere).
# example something like this
self.staticbitmap = GenStaticBitmap(self.panel, self.bitmap)
text = wx.textctrl(self.panel)
# Have sizer position it here?
I can not give full code example.
Are you searching for something like a background bitmap (controls on top of a user-defined bitmap)?
Mike Driscoll has described a solution for this in his Blog.

Is there a way to make s tkinter widget lose focus?

That is, without doing focus_set on some other widget?
The original post ended with the sentence above, but it did not meet quality standards. These standards demand that the problem is described completely, including what one has tried. They insist on proper grammar too.
Well, it is not really a problem, just a question. I tried to find a widget method, say, focus_unset, that would do the trick. I didn't. My grammar is proper. Maybe the robotic police is confused with terms like focus_set?
No. Some widget must have focus. You can set focus to the root window if you don't have any other widgets that naturally accept keyboard input.

Select text over multiple TextCtrls in wxpython

So I currently have a ScrolledPanel that contains a number of TextCtrls that are placed in a vertical BoxSizer programmatically. The reason I'm doing this instead of just appending lines to one big scrolled TextCtrl is so that I can also add other controls in between the TextCtrl, such as images or stylized expand/contract folding stuff.
However, this particular implementation is causing a problem - namely that it is impossible for the user to select text across multiple TextCtrls. Is there a way to do this that will be fast, clean, idiomatic, and not especially kludgy? Is my best bet to write a pointer-location text selection algorithm that essentially reinvents the wheel for the text selection stuff of the underlying native libraries, or is there an easier way to embed other controls inside a multiline scrollable TextCtrl, or even select text across multiple TextCtrls natively?
I would stay away from trying to reimplement text selection controls if at all possible, since that is bound to turn very messy very fast. Another way you could tackle this issue would be to use a single multi-line textctrl widget with the other widgets tacked on over it. This is also messy, but less so.
You can place the other widgets over the textctrl simply by placing them directly over the same position as the textctrl, so long as the other widgets have the same parent as the textctrl. This should work, so long as you don't overlap with the vscrollbar (or, better yet, remove it entirely with style=wx.TE_NO_VSCROLLBAR).
The next thing you'll need to do is pre-fill and space your textctrl so that the user has control of text only right after the position of each widget. You should have each line of text with a different spacing setting, set with the spacing options of wx.TextAttr (the more generic versions of double-spacing, etc), which you calculate based on the particular widget spacing you've given your app. This is necessary to force the user to type only exactly where you want them to.
Next, you'll need to set up a binding to the textctrl newline character that recalculates the spacing needed for each line. Once you've figured out how to handle spacing, this shouldn't be too difficult.
Finally, after you select the text, just reset everything to the same spacing, or whatever else suits your fancy, so that you don't get awkward linebreaks when you paste it back in elsewhere.
I know this is a complicated answer, but it's a complicated issue you raised. This is, I believe, the most efficient way to solve it, and avoids all the bugs that would arise from completely overhauling the textctrl, but it does involve messing around with auto-correcting linebreaks and spacings, which can be a little tricky at first.

Categories

Resources