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.
Related
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.
As the title suggests I wonder if it is possible to set the length of a line in python scripts when someone uses Qt Creator as an IDE, in order to get rid of this annoying warning:
I found at least how to hide these annotations (for Mac Os users): First method is to go with the mouse on the top-left corner of the screen and to sequentially click Qt Creator->Preferences. Immediately the Preferences Dialog Window will appear inside the Qt Creator working window. There, have to go to Text Editor in the left panel and in the right panel associated with Text Editor, in the horizontal tabs have to click on Display tab. Scroll down and uncheck Line annotations. The second and the third methods imply to place the mouse over one particular annotation (second method) or over one of the small yellow triangles which are shown in the left column of the "lines numbers column" (third method) and in both cases after one or two seconds will appear a floater and inside that floater with blue letters will be the "Annotation settings" message. Clicking on that message will open the same Preferences Window like in first case. And there will be repeated the procedure described in the first case.
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.
I am having trouble setting a default button for a gtk table in a window.
It is a 4x3 table, and I want to set the center button to be the default.
I have the center button set as default, but it is not behaving correctly when I move it with the arrow keys.
Please check out my code at: http://dpaste.com/3M36W8X
The center button is set as default button at line 118 At lines 189 and 190, if I switch "self.window.show()" with "self.table.show()" the buttons behave correctly, but I can't default a button.
The way it is set now, the center button is set as default initially, but as soon as I move with the arrow keys, it acts as though there wasn't a default key to begin with.
Please let me know if I can describe this problem better!
I am having a problem with GtkSourceView used from Python.
Two major problems:
1) When a user types text into the GtkSourceView, and types past the bottom of the visible text, the GtkSourceView does not autoscroll to the users cursor.
This wouldnt be so bad, except:
2) The arrow keys, page up and page down keys, do not cause the GtkSourceView to scroll either.
The mouse scrollbar does work on the GtkSourceView.
Does anyone have knowledge/experience of this?
My code is here http://launchpad.net/kabikaboo
Ok I just figured this out.
I was adding the GtkSourceView2 into a GtkScrolledWindow.
Only, it was adding a ViewPort first via ScrolledWindow.add_with_viewport().
This disables part of the scrolling behavior via keyboard.
Instead, use ScrolledWindow.add(), and the ViewPort is skipped and the GtkAdjustments take care of the scrolling!