Focus for UI that is used in 3d app - python-2.7

I have a UI that I have made which is to perform tasks within 3ds max. When I open the ui in Max via a python.ExecuteFile call in a toolbar maxscript, focus and keyboard entries are given to the ui elements, using the max command DisableAccelerators(), so that fields can be entered and then run via an execute button. If I click onto the main max window to do something before I have finished the input to the ui, the focus is lost and keyboard shortcuts are restored to max. If I then click on the UI again to continue editing/updating, the focus remains with Max and I cannot continue using the UI.
I am using PySide and have tried setting the UI window to have strong focus ( setFocusPolicy(Qt.StrongFocus) ), but this has not worked so far, so does anybody know what I need to research or look up to help me with this? I just need to understand how to shift focus back and forth between the App window and the UI I have created.
Thanks
I have been looking into mouse events to identify the window that I click on to run a function that sets a boolean if the right window name is returned, Would this be a good idea?

The following link should help. I doubt you'll be able to do your work with PySide, as the proposed solution assumes using a PyQt4 build supplied by Blur Studio as part of their 3ds Max tool set. That being said, PyQt4 and PySide are substantially similar, so unless there's a very specific reason why you need to use PySide over PyQt4, you should be fine.
http://area.autodesk.com/blogs/chris/pyqt-ui-in-3ds-max-2014-extension

Related

Trying to write a c++ console program to change a setting controlled by a windows checkbox

Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/

CWnd::SetRedraw(False) make mouse go throught window

So I have a MFC application which flick when we do some action.
So I figured I would set SetRedraw(false) and set it to true at the end of the function.
The application doesn't refresh anymore but if I click on it while SetRedraw(false), my cursor is not catched by my application, it goes throught it and set focus on the application below.
Anyone has some kind of idea how I could fix that.
I ended up using CWnd::LockWindowUpdate instead after some research.
It freezes the update but doesn't act if the window was transparent.

How to simulate a mouse click without interfering with actual mouse in Python

I've made a simple click bot to automatically play an android game on my Windows PC. It currently identifies when certain things change on the screen then moves the mouse and clicks the correct button.
Currently I am using the following win32api functions to achieve this:
Win32api.SetCursorPos(Position)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTDOWN,0,0)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTUP,0,0)
These work great however when I use the bot it takes over my computer's mouse and I basically have to let it run. Is there anyway I could simulate a click without it actually using my mouse, or is there a way I could isolate the bot on one of my other screens and be able to work freely on the other?
There is a lib specific for deal with user interaction components and periferics: pyautogui
Here, is a short and easy to try documentation for performing/simulating mouse click DOWN & UP
https://pyautogui.readthedocs.org/en/latest/mouse.html#the-mousedown-and-mouseup-functions

Adding custom controls to a console window

Is it possible to add custom controls to a console window? You can use GetConsoleWindow() to get the window's handle, and then add your own menu items or consume all its events. I can't find any examples of people adding extra controls though.
I am developing a small, high performance serial terminal app. It is a console application - RichTextBox is too slow and has issues that make it unsuitable for VT100 terminal emulation.
I want to add some little graphics to show the state of the serial control lines (RTS/CTS/DTR/RI etc.) and perhaps a capture on/off toggle button. Ideally I'd like to add them to the window title bar. Bitmaps are all that are required.
After lots of research I found that it isn't easy, or even possible really.
You can add controls to the window with CreateWindow(), but of course only in the client area which is taken up entirely by the console text box. However, you can at least create floating controls that way, which hover over the text to provide status info etc.
You can put controls in the window borders but only with some hacking on XP or a new API that was introduced with Vista. The problem with this API is that it requires you to draw your own program icon and title text, and the console window doesn't seem to cope with it very well.
You can't add your own menu items because the console window doesn't pass the messages.
In the end I used the function keys for everything and gave a status indication by changing the console window icon.

How to keep the window focus on new Toplevel() window in Tkinter?

I am currently writing a win32gui python27 application (I'm running win7). I am wondering if it is possible to create a new window from my mainloop() and KEEPING the focus on it, possibly by stopping the mainloop and deactivating the root window. In a sort of pseudo code example:
root=Tk()
#put in some widgets, such as statusbars, tkfileDialog widgets etc...
O=Toplevel()
OptionMenu(O) #wait for user to make his choices; btw: OptionMenu is a class...
tkFileDialog.askdirectory(...) #THEN interpret this line
Basically, I'd like to achieve what most of the widgets in tkfiledialog and tksimpledialog do:
To steal the focus from the main window (not just the console focus, the wm focus) and to resume the mainloop until AFTER everything in, for example, OptionMenu has been resolved. I hope I could make my goals clear to y'all, I just started Tkinter programming a couple of weeks ago and may confuse and misinterpret some concepts behind it....
That's all, folks!
The concept you are looking for is called a "grab". Tkinter supports grabs with several methods. For example, to set a local grab on a toplevel you would do my_window.grab_set(). A local grab is where this window grabs the focus from all other windows in your app, but only for your app.
You can also do a global grab, which effectively freezes your entire display except for your specific window. This is very dangerous since you can easily lock yourself out of your own computer if you have a bug in your code.
Grabs do not deactivate the mainloop function. This must be running for your window to process events. It simply redirects all events to the window that has the grab.
For more information, read about grab_set and other grab commands here: http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.grab_set-method
None of the above suggestions worked for me, on Mac OS El Capitan. But based on those hints, this does:
class Window(Tk.Toplevel):
...
def setActive(self):
self.lift()
self.focus_force()
self.grab_set()
self.grab_release()
...
grab.set() is much to aggressive for my needs and blocks normal window operations. This answer is to make one Tkinter Window pop up overtop of other Tkinter windows.
In my app I have a large window toplevel which calls a much smaller window top2 which initially appears on top of toplevel.
If user clicks within toplevel window it gains focus and smothers much smaller top2 window until toplevel window is dragged off of it.
The solution is to click the button in toplevel to launch top2 again. The top2 open function knows it is already running so simply lifts it to the top and gives it focus:
def play_items(self):
''' Play 1 or more songs in listbox.selection(). Define buttons:
Close, Pause, Prev, Next, Commercial and Intermission
'''
if self.top2_is_active is True:
self.top2.focus_force() # Get focus
self.top2.lift() # Raise in stacking order
root.update()
return # Don't want to start playing again