Focus-follows-mouse in wxPython? - python

I'm developing an application that contains a number of panes. See the screenshot:
The left settings pane is a wx.ScrolledPanel that contains a number of wx.Panels.
The top events pane is a wx.grid.Grid.
The bottom data pane is a wx.Panel that contains a wx.grid.Grid.
The middle plot pane is a wx.Panel containing an enthought chaco plot.
The right detector pane is a wx.Panel.
I would like to implement focus follows mouse so that when I move my mouse over the plot I can immediately zoom in or out using my scroll wheel without first clicking on the plot to give it the focus.
Similarly when I move my mouse over the left settings , the top events or the bottom data panes I would like to be able to immediately scroll the window using the scroll wheel without first clicking on the window.
Currently I defined a function:
def focusFollowsMouse(window):
window.Bind(wx.EVT_ENTER_WINDOW, lambda event: window.SetFocus())
I would like to apply this function only on the four top-level panes: plot, settings, events and data.
However I need to call this function for each sub-panel or control in each of the top-level panes to get this to work. For example I need to apply this function individually to the Measurement Settings, Analysis Parameters, View Settings etc. panels.
Most likely the EVT_ENTER_WINDOW event is not propagated to parent windows.
Is there a way to get this to work without applying focusFollowsMouse to each and every sub-panel or control?
Thanks

This is Windows' behaviour - it works as you expect under GTK. Personally, I'd leave your app as it is, for consistency with other Windows applications, and install WizMouse

Related

Qt Creator - How to get rid of "line too long" warning in python scripts

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.

Kivy Navigation Control

I was wondering whether it is possible to make a Navigation control just like the one in GIMP using the kivy framework in python
Navigation Control: This is a small cross-shaped button at the lower right corner of the image display. Click and hold (do not release the mouse button) on the navigation control to display the Navigation Preview. The Navigation Preview has a miniature view of the image with the displayed area outlined. Use the Navigation Preview to quickly pan to a different part of the image—move the mouse while keeping the button pressed. The Navigation Window is often the most convenient way to quickly navigate around a large image with only a small portion displayed. (See Navigation Dialog for other ways to access the Navigation Window). (If your mouse has a middle-button, click-drag with it to pan across the image).
Refer to point 11 on this link : https://docs.gimp.org/2.10/en/gimp-image-window.html
And : https://docs.gimp.org/2.10/en/gimp-navigation-dialog.html

Is it possible to see if the file is being dragged over the window in Kivy, Python?

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.

wxPython scrollbar doesn't stick

I've been playing with this cookbook example to make a scrollable matplotlib plot with wxPython. However, when I run this code on my Windows 7 machine at work, the scrollbar doesn't seem to work properly. In particular, if I click and drag it to a position, it does update the plot, but then the scrollbar moves back its starting position, instead of staying put. I'm curious if anyone has an idea what's going on here. FWIW, this code worked fine when I ran it on my Linux Mint 14 machine at home.
Right now, I'm trying to fix it by using a wx.ScrolledWindow or a wx.lib.scrolledpanel instead of adding the scrollbar directly to the canvas as in the example. I was also considering using a slider instead of a scrollbar
Thanks
From Programing Windows, Fifth Edition (emphasis mine)...
When you use scroll bars within your program, you share responsibility
with Windows for maintaining the scroll bars and updating the position
of the scroll bar thumb. These are Windows' responsibilities for
scroll bars:
Handle all processing of mouse messages to the scroll bar.
Provide a reverse-video "flash" when the user clicks the scroll bar.
Move the thumb as the user drags the thumb within the scroll bar.
Send scroll bar messages to the window procedure of the window containing the scroll bar.
These are the responsibilities of your program:
Initialize the range and position of the scroll bar.
Process the scroll bar messages to the window procedure.
Update the position of the scroll bar thumb.
Change the contents of the client area in response to a change in the scroll bar.
...so somewhere in OnScrollEvt() method, you'll need call SetScrollPos() with something like...
self.canvas.SetScrollPos(wx.HORIZONTAL, event.GetPosition(), True)

Can you auto hide frames/dialogs using wxPython?

I would like to create an application that has 3-4 frames (or windows) where each frame is attached/positioned to a side of the screen (like a task bar). When a frame is inactive I would like it to auto hide (just like the Windows task bar does; or the dock in OSX). When I move my mouse pointer to the position on the edge of the screen where the frame is hidden, I would like it to come back into focus.
The application is written in Python (using wxPython for the basic GUI aspects). Does anyone know how to do this in Python? I'm guessing it's probably OS dependent? If so, I'd like to focus on Windows first.
I don't do GUI programming very often so my apologies if this makes no sense at all.
As far as I know, there's nothing built in for this.
When the window is hidden, do you want it completely invisible or can a border of a few pixels be showing? That would be an easy way to get a mouse hover event. Otherwise you might have to use something like pyHook to get system-wide mouse events to know when to expand your window.
The events EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW might also be useful here to know when the user has entered/left the window so you can expand/collapse it.
Expanding/collapsing can just be done by showing/hiding windows or resizing them. Standard window functions, nothing fancy.
By the way, you might want to use wx.ClientDisplayRect to figure out where to position your window. That will give you a rectangle of the desktop that does NOT include the task bar or any other toolbars the user has, assuming you want to avoid overlapping with those things.
Personally, I would combine the EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW that FogleBird mentioned with a wx.Timer. Then whenever it the frame or dialog is inactive for x seconds, you would just call its Hide() method.
I think you could easily just make a window that is the same size as the desktop then do some while looping for an inactivity variable based on mouse position, then thread off a timer for loop for the 4 inactivity variables. I'd personally design it so that when they reach 0 from 15, they change size and position to become tabular and create a button on them to reactivate. lots of technical work on this one, but easily done if you figure it out

Categories