Python [Canvas]: Detect Mouse Button NOT pressed - python

My question today is, that I'd like to know, if there's a way to detect a mouse button NOT pressed using canvas.bind().
I want to know that, because I want to save data while a button is pressed, and to stop saving data when the button is not pressed anymore.
I want to do this with the left mouse button / ''
If you don't know what I wan't to do; feel free to ask in the comments :/

Detect mouse press and release events. When one of those events occur, start or stop saving as appropriate.
canvas.bind("<Button-1>", start_saving)
canvas.bind("<ButtonRelease-1>", stop_saving)

Related

Is there a way to let Python differentiate clicks sent by the program and clicks sent by the user?

for some context, I'm trying to make a python program that left-clicks for you when the left mouse button is held down.
This is how it works: while True:
keystate = win32api.GetAsyncKeyState(0x02) or win32api.GetAsyncKeyState(0x01)
if left_clicker == 'true':
if keystate == win32api.GetAsyncKeyState(0x01):
ac()
if keystate == win32api.GetAsyncKeyState(0x02):
if right_clicker == 'true':
rightac()
The ac() loop clicks and then waits for a delay, and then repeats the loop. However, when I run the code, I hold down the mouse button, it clicks once, and then stops. The reason is the program reads the left click sent by Python and sees that the left mouse button has been released (which must happen upon click or the loop will run indefinitely regardless of how the user interacts with the mouse). So, is there any way I can let Python differentiate clicks sent by the program and directly by the user so it won't stop itself? The only workaround I have found is using a different button to trigger the loop, but that's not really what I'm trying to do. Please ask for clarification if needed
I have tried using Pynput and PyAutoGUI as the method for clicking the mouse, both had the same issue. I don't know of any other libraries that can click the mouse and I'm out of ideas on how to solve this.

Right clicking on plot to zoom in Bokeh

I recently started using Bokeh. Overall I am very satisfied. One thing I find annoying though is that it seems I can only play with the left mouse button and need to manually switch tools everytime I want to pan/zoom/etc... It would be great if I could pan with left mouse buttom and zoom in with right mouse button. Is there a way to automatically 'switch' to zoom tool whenever right mouse button held, and switch back when left mouse button held?
Thanks!

making Baxter do an action once

I just started working with the rethink robotics baxter.
In their example for responding to button controls they use event handlers (I think).
Example (from gripper_cuff_control.py):
self._open_io.state_changed.connect(self._open_action)
I want to be able to push a button and move the wrist a set amount, I can currently do that, but it happens twice (once for state_changed -> pushed and once for state_changed -> released)
What is the most elegant way to make it so that the action only happens once on when a button is pushed and released?
I couldn't find documentation on the API, but from this example it looks like the first parameter to the function will tell you whether the button was pressed or released.
def _open_action(self, value):
if value: #button was pressed
#do stuff here in response to button press
else: #button was released
#do stuff here in response to button release

Disable PyQt Arrow Key Focus

I have a very simple PyQt application with some buttons and a checkbox.
Right now pressing the arrow keys iterates focus over the buttons and the checkbox. I would like to override the arrow keys events and instead have it print which key you pressed, so pressing "right" would print "right" instead of changing the focus to the next component.
It looks like pressing the arrow keys generates a Paint QEvent and not a KeyPress event so they do not get caught.
Any help would be appreciated, thanks!
It is unclear as to exactly what you are trying to achieve, but without any additional information, I would try setting the focus policy of the buttons and checkboxes, e.g.:
button = QtGui.QPushButton('button1')
button.setFocusPolicy(QtCore.Qt.NoFocus)

How to change my wx.toolbar event?

I have a wx.toolbar with some buttons. One of the buttons makes pan left!
I want to click on the button and while I keep it pressed, the pan left is made.
For now I only saw that the wx.EVT_TOOL only works when mouse left is up.
Is there a way to do what I intend ?
In the toolbar button's event, you should be able to get the state of the mouse via wx.GetMouseState.
Alternatively, you can make your own toolbar with a panel and some wx.Buttons (or other button widgets).

Categories

Resources