Notifications
Clear all

[Closed] focus on active viewport

Hello!
This thread appeared in this forum for not a single time, but nevertheless i can’t find the answer.
I can’t return focus on the viewport after executing some actions in my script (written on python). a clearFocus to my pyqt widget, use

try ( toolmode.commandmode = toolmode.commandmode); catch ()

(i found this tip here), so the focus should be on max, but the keyboard shortcuts doesn’t work no matter. the only way is middlemousebutton clicking the viewport. I used enableAccelerators, viewport.activeViewport – these things doesn’t help.
So what’s the solution? Or how can i emulate mouse clicking ? thank you

8 Replies

Python is not officially supported by MAX. If your problem caused by Python just don’t use it. If it’s not Python you can use .NET for example to simulate any button click (key press).

thank you, Denis!
of course simulating mouseclick is not very good solution (cause after clicking in pyqt application my mouse isn’t in max viewport). So maybe there is any internal command to force activate viewport …

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

there are a lot of ways to set focus to any window. But it seems like the focus is screwed up. If you don’t know why it was happened, how can you fix it? The focus goes in PyQt application, so you have to call something in that application to return the focus to MAX. If you make PyQt window a child of MAX you shouldn’t lose the focus at all.

  1. my PyQt widget is a child of Max, so it’s in “windows.getChildrenHWND #max
  2. i use clearFocus() to this widget, so the focus is not on it.
  3. i’m using blurpython, that isn’t currently(?) supported, so it’s may be some kind of bug, or i don’t know.
  4. everything is ok except the keyboard shortcuts =)
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0
  1. so, if the window closes the focus has to return to MAX
  2. i have no idea what clearFocus has to do. Is it something PyQt specific? Where is the focus after clearFocus called? (what GetFocus, GetActiveWindow, GetForegroundWindow say? )
  3. hopefully bluepython will never be supported by MAX.
  4. because the focus is not in MAX. That’s the question to know. Where is it?
  1. no! =) if i close the widget, the accelerators still not working. only by clicking the viewport.
  2. clearFocus is just the QWidget’s method… what i wanted to say – that my widget loose focus 100% after this.
    So, i think that this vanishing focus should be really on max, but nevertheless the hotkeys doesn’t work.

( 3) why do you think so about blurpython ? but this is off-topic )

now i’m trying to sendMessage to the viewport’s handle)

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

because I want to have fully integrated c# in MAX.

ok, i’ve solved it
don’t know why, but SendMessage WM_SETFOCUS doesn’t work for me, so i ‘implemented’ SetFocus from WinApi on c# (using Denis’ hints from this forum :), + enabling accelerators. (or in python it’s a pywin32 module, win32gui.SetFocus(hwnd) – just the same, ’cause my script is written on python, i prefer this). So if you suddenly use pyqt in max and have the same problems you are welcome =)
thank you, Denis!