Tkinter text widget search and show - python

i was able to create a text widget with a search, and highlight every finding. The only thing i miss is a button like "Next" which jumps to the next finding.
So far i was not even able to show (jump) to the first finding.
I can move the cursor there, but i cant move the screen.
The text widget has a huge ammount of text, and i use a scrollbars if that can help.
Is there any way to move the screen or scrollbar to the curzor? Or to a tag? Or to a finding?
Thanks, Gábor

You can call the yview methods to scroll the widget by a particular amount. However, for this specific use case the text widget has the see method, which arranges for a given index to be visible.
From the official tcl/tk documentation (upon which Tkinter is built):
[see] Adjusts the view in the window so that the character given by
index is completely visible. If index is already visible then the
command does nothing. If index is a short distance out of view, the
command adjusts the view just enough to make index visible at the edge
of the window. If index is far out of view, then the command centers
index in the window.

Related

Anchor button at the bottom of the screen in Dear PyGui

I'm writing a file management and config file editing app in Python 3.10 with Dear PyGui as the GUI library. I would like to place a group at the bottom of the window so it:
Stays at the same place when the rest of the content in the window changes
Stays at the same place relative to the lower left (or right) screen corner when the user changes the size of the viewport
I know how to do 1, I can just use pos=(10, dpg.get_viewport_height()-75).
I don't know how to do 2. The above seems to do it upon launch and if you don't resize the viewport, but it doesn't actually anchor them to that relative spot as the window size changes:
To anchor the group to the bottom, you need to update its position on the window resize. Dear PyGui has a callback that fires every time the window is resized: dpg.set_viewport_resize_callback(update) where update is a function that, in this case, runs dpg.set_item_pos("bottom_buttons", (10, dpg.get_viewport_height()-75)). This will keep the buttons positioned at the bottom of the screen.
There might be a better way to do this, and doing it this way might have consequences for overlapping content later on, but it's the easiest way to implement it that I have tried.

PyQt4: How do I place an object in front of another object?

For better understanding, I brought you a edited picture.
In general, is it possible to place a widget in front of another widget?
For example, on the picture above, you can see a QProgressBar placed in front of QTreeView.
Imagine a situation in which all records are loaded into QTreeView. During this process, the user should be informed how far the loading process is. I know that you can also place the QProgressBar above or below the QTreeView. But I wondered if it's also possible to place the QProgressBar in front of QTreeView?
Yeah it is possible to place a widget in front of another widget.
First of all drag a widget(Suppose a QTreeView) in a main window.
Then right click on the QTreeView and then click on Layout Alignment.
Then choose the alignment left or right and after that drag the another widget(Suppose QProgressBar) in front of your first widget.

How to set scrollbar initial position at right end in wx.Listbox using wxpython?

I am using the Listbox Widget to display a list of files uploaded by the users and wx.HSCROLL style is used. When the string of file names are wider than the size of the listbox, horizontal scrollbar appears as expected. However, I am having trouble in setting the scrollbar auto-rolling to the right end using SetScrollPos method. The following command was used:
self.dropfile_listBox.SetScrollPos(wx.HORIZONTAL,self.dropfile_listBox.GetScrollRange(wx.HORIZONTAL))
But apparently it did not set the scrollbar position correctly. Any comments about this issue are appreciated!
If we assume that you are using UltimateListCrtl from your posted code
try:
self.dropfile_listBox.SetScrollPos(wx.HORIZONTAL,self.dropfile_listBox.GetScrollRange(wx.HORIZONTAL),refresh=True)
which redraws the scroll bar

Tkinter: How to set the default new Text insert focus coordinates

When moving the text insert off the screen such that new text comes onto the screen (as well as the text insert), how do I get the text insert to be focused on at a specified x,y coordinate instead of the middle of the screen? For instance, when I'm using pagedown, I would like it to focus on the text insert at the bottom of the screen (instead of the center). When I'm using pageup, I would like it to focus on the text insert at the top of the screen (instead of the center).
For clarification, the default behavior is that when pressing pageup or pagedown, the text insert is in the middle of the screen after the insert moves. I would like it to be at the top and bottom respectively (where possible, considering that pageup/pagedown does not always have an entire page to traverse). Any ideas on how to do this? I don't see any built-in methods for the purpose. Text.see(myIndex) allows for no x,y coordinates as far as the documentation says.
The cursor indicates the insert position or the text 'insert' mark within the text. With Win7, 2.7.8 (tk 8.5.15) and 3.4.2 (tk 8.6.1), I see the following behavior.
If the cursor is visible, PageUp/Down move both the cursor and the text Up/Down a page, so the cursor appears to stay still, with the text moving under it.
If the cursor in not visible, because of scrolling, PageUP/Down move the page and put the cursor ('insert' mark) at the upper left corner of the page. (This is different from what you describe and may depend on the system or Python or tk version.)
You could try the following. Intercept PageUp and PageDown key events. Assuming your code gets the event first, use the return from scrollbar.get to calculate the top and bottom visible lines, use text.mark_set('insert', 'lineno.0') to make the cursor visible where you want it, and let the event propagate to move the text.

Scrolling in QScrollArea pyqt

How can I auto scroll for the scroll area? For example, when there is a new update instead of the view of the scroll area staying the same, I want to go down with the new text. Think of it as in a CMD console, when you type a command it autoscroll with the output.
I was just going to respond to the other answer, but I just didn't know the best way to phrase it in the space allotted.
QScrollArea's are very useful widgets to use when designing custom PyQt widgets - I use them often. Things like rollout widgets, card widgets, anything where you could be displaying multiple sub-widgets with the need for scrolling can be a very useful utility. I don't agree with the idea that a QScrollArea isn't much use on its own.
The QTextEdit answer solves the problem the developer was facing - but only because it so happens the question is really about that. If you're trying to scroll a text edit, go with that answer.
However, if you are searching for an answer to the actual question and come across this thread, then the way to scroll down a QScrollArea is by actually modifying the scrollbar's value.
area = QScrollArea(parent)
vbar = area.verticalScrollBar()
vbar.setValue(vbar.maximum())
If you want to scroll to particular areas or anything (like implementing the ensureCursorVisible) then you want to take the location on the area's widget that you want to scroll to, figure out the percentage of the height of it, and apply that value to the vertical scrollbar. (Pseudocode)
Use QTextEdit.moveCursor to set the location you want to scroll to, and then use QTextEdit.ensureCursorVisible to scroll to it:
textedit.moveCursor(QtGui.QTextCursor.End)
textedit.ensureCursorVisible()

Categories