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!
Related
Question: It seems that ButtonPress events on tkinter give the location of the click w/r to the top left corner of the window. However, when you click on a Button widget, a ButtonPress event occurs, but the x,y location values given are w/r to the top left corner of the Button. How can I get the ButtonPress event to occur at the location w/r to the top left corner of the window, not the button?
Details: I have a tkinter program that lets users draw on a picture (layout below), but only occurs below a certain y value. If you move the cursor below that threshold (aka below the picture and into an area that has instructions), no drawing functionality can occur. Drawing only occurs with clicks, so <Button-1> is bound to a class method that keeps track of where the click occurred and draws on the picture at that location:
self.root.bind('<Button-1>', self.addDot)
However, in the area that has instructions, there is an undo button. Clicking on it in theory should undo the last click's effect. Instead, if I click on it, it registers a <ButtonPress> event that has x and y values with respect to the top left corner of the button, not the window. I do not know how to differentiate when the x,y location of a button press occurs w/r to the window or the button, so the self.addDot function executes near the top left of the image. Everywhere else you click behaves as normal.
One caveat I have seen is that if I change the binding to be on the canvas, not the root, this strangely goes away and behaves as expected. Why is that?
Layout:
What I want to achieve:
I want to detect the situation when the user is dragging a file over the Kivy app window.
What I already know:
I know how to detect hovering mouse coursor over widgets (with on_mouse_pos), I also know how to detect if a file is dropped onto the window (with on_file_drop).
So, is it possible to see whether the cursor is hovering over the window and "holding" a file? Because then I want to display some prompt (eg. 'Drop HERE'). I hope you get the idea :)
I'm not really sure, because there's this thing with SDL2 (and probably even with old pygame) when the Window just pauses (try some animation or something) when you e.g. drag it with the window decoration (the thing where title and _ O X are). That is the behavior if you do something with the Window directly.
Although, the Window looks like it behaves normally (doesn't pause itself), when you drag file on top of it (I tried with examples/animation/animate.py), to do such thing you'd need to do either the hovering behavior + handling the collisions or bind to mouse_pos.
However, when binding to mouse_pos, it seems like the Window still isn't capable of handling the input from outside and at the same time get mouse properties correctly (I think it's similar to the behavior when you click & drag outside of the Window and Button remains pressed, but this is kind of inversed).
edited animate.py:
class TestApp(App):
def on_mouse_pos(self, win, args):
print args
...
def build(self):
...
from kivy.core.window import Window
Window.bind(mouse_pos=self.on_mouse_pos)
return button
Therefore if you can't get even mouse position when a mouse button is being held, I don't think such an action is possible. You can however make the areas where you want to drop the file already different (e.g. change background) when you'll expect a user to drop the file - a very dirty workaround from UI side for such a problem.
Side note: Kivy should be able to get most (if not all) SDL2 window events via Cython, therefore if you find such event in SDL2 that would make fetching mouse position possible, such action could be performed, feel free to make a feature request in kivy/kivy or make a pull request.
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.
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.
I have a PyQt GUI set up that has a selection of QPushButtons and a QLineEdit text box (among other things). The text box is set up so as to call a function upon returnPressed(). My problem is that when I click on the text box and put in text, one of the buttons becomes selected which means that when I press enter in the text box it activates both the button and the text box function.
Is there a way around this? Some way to stop any buttons from being selected while the text box is being edited?
The code is fairly long so I can't add it here but if there are any questions regarding layout or anything that may be relevant, please ask.
Thank you for any help you can offer
From your question and comments, I'm guessing that the buttons and line-edit are in a QDialog, and that the selection/highlighting occurs due to the default/autoDefault property of buttons.
Normally, these properties will be set to False, but in a QDialog they are automatically set to True. The button that is the current default gets an additional frame drawn around it (even when it doesn't have the keyboard focus), and is activated whenever the return key is pressed.
You can of course prevent this behaviour by simply doing:
button.setDefault(False)
button.setAutoDefault(False)
for each button in the dialog.