How to change the state of a PopupSwitchMenuItem in gnome extension - gnome-shell-extensions

I am working with a gnome extension which has a toggle switch on its panel popup menu.
I have bound a keyboard shortcut to the same setting, so I want to change the state of the toggle to reflect what happens with the keyboard shortcut.
the toggle comes from code like this:
let toggle = new PopupSwitchMenuItem(desc, active);
and I can save a reference to toggle so that is known to the code that handles the short cut.
But I don't know how to change the state.
I hoped toggle.set_state(true) might work, but whatever object toggle is, it does not support set_state()

Right, well I found a the correct javascript libary.
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js
and from there, this works:
toggle._switch.state = true;
EDIT: Better solution from Gnome dev Florian Müllner
ie toggle.setToggleState(bool)
It’s setToggleState(), see https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js#L419
https://discourse.gnome.org/t/newbie-shell-extension-coder-how-to-i-set-the-state-of-a-switch-created-with-popupswitchmenuitem/3370?u=tim_richardson

Related

How to set a mouse button combo as a hotkey?

Since I remapped XButton1 and XButton2 to ctrl+shift+tab and ctrl+tab
I wanted to set the right mouse button + XButton1/2 combos as forward&backward.
It works, but I don't have right click now...
I tried writing it as {RButton&XButton1}, needless to say that didn't help, but back/forward still works.
XButton1::Send ^+{Tab}
XButton2::Send ^{Tab}
RButton&XButton1::Send !{Left}
RButton&XButton2::Send !{Right}
I expect the right mouse button to work still as it is intended.
The prefix key in a custom combination (in this case RButton) loses its native function,
unless you add
RButton:: Send {RButton}

How to hide mouse cursor in Qt Application?

qApp->setOverrideCursor() method works successfully, if I want to hide mouse cursor, except one condition. If I add a dialog that is modal, and while it is shown, if the cursor is out of dialog's borders, it is shown again. Have you got any idea about the problem?
It does not matter how the solution for hiding mouse cursor is; whether by Qt or at the operating system level. My operating system is Windows 7.
You cannot hide the mouse cursor when it leaves your window (or dialog-window), because it is then handled by the window-manager of your OS. A workaround would be to constrain the mouse to your window/dialog, so it cannot leave. You will either need to look through the MSDN to find the specific windows functions to do it, or do it like in kshegunov's code example on the Qt-forums: https://forum.qt.io/topic/61832/restrict-mouse-cursor-movement/12

PyQt5 QMenu no focus on exec_()

I have an already fully functioning app, with a custom widget that opens a custom QMenu when clicked, by calling exec_():
menu.exec_(QPoint)
I recently migrated from PyQt4->PyQt5 and noticed that the focusOutEvent method I was overriding was no longer responsive. I already have a fix, which works just fine:
menu.setFocus() #calling this prior to exec_()
Nevertheless, I would like to understand what exactly is different after the Qt migration, that I had to manually set the focus in order to keep desired functionality.
The menu is set to have StrongFocus.
Another apparent issue that might be related is that the setting of the cursor to hand fails to change back to regular cursor when the cursor leaves the menu rect.
Thank you! =)

Be notified of a click on Taskbar Icon

Looking for a solution to a hidden window - either a windows event that occurs when the TaskBar Icon is clicked.
or alternatively, a way to remove the TaskBar Icon. The Tray Icon is easily hidden - that is not the problem.
There is a sample script on the AutoHotkey's Website called Minimize Window to Tray
The script itself uses the hotkey Win+H to hide the active window. Win+U then shows the last hidden window. If this is not the functionality you are going for, I'm sure you can take a look at the script and pick out what you need. Hope this helps you out.
I've a possible answer to detecting a Click on the TaskBar Icon - but I'm concerned it will differ for each version of Windows. Using OnMessage(Wm_Activate := 0x06, "testmessage") - then MouseGetPos to get the Window name, I can eliminate all but 'MSTaskListWClass1' the name of the Icon I want. But I suspect that the name is only valid for Win7.

How to make Qt widgets do not react on mouse click

I need on my form ordinary widgets (e.g. buttons) do not react on mouse clicks but NOT to be disabled (it change look to grayed one -- not good).
I wonder is there some neat small hack for this?
You could stick in an event filter and filter out the mouse events before passing the remaining events on for processing, but I'm not sure that not giving the user a visual clue that certain elements are effectively disabled is such a good idea.
You could try using style sheets to control how the disabled mode of the buttons in your form get styled. Unfortunately I'm not sure exactly how to do that but you could have a look at the style sheet docs to get you started.

Resources