PYQT5 Simulating Window Menu MacOS - python-3.x

I'm attempting to simulate the native MacOS "Window" menu in PYQT5. I am able to cycle through open windows via my menu and indicate the active window by setting its checked state to True.
I would like to also simulate the MacOS HID icon assigned when a window is minimized like this:
However, the closest I have been able to come is with a QIcon, which isn't quite right (the icon isn't quite right either, but I can live with that).
bring = self.view_menu.addAction('&Bring to Front', self.foo)
bring.setIcon(QtGui.QIcon("diamond.png"))
Is it possible to have the QIcon displayed in the left menu column (aligned with the checkmark) or otherwise display a diamond for an action item like MacOS? I didn't see any parms for the QIcon class that appeared to do this.

Related

PYQT change clearButton in QLineEdit (w/wht Qt Designer)

Since I updated python from 3.8 to 3.10 (with Linux Ubuntu 22.04), clear button in QlineEdit widget has become an ugly red cross. It was before a nice dark kind of rectangular button with a small cross inside.
I wish I could switch back to the previous clear button without having to create a custom button, because the red cross is kind of disturbing as it seems to indicate an error in what you write in the QLineEdit widget.
Is there a way to do that in Qt Designer or programmatically?
It seems a bit unlikely that just updating Python would affect the icon.
The update probably involved other packages along with it (or they need rebuilding, they were uninstalled due to incompatibilities, etc), so I'd suggest to check that first.
In any case, you can set the icon using a specific stylesheet you could set for the top level window or even the application, so that it will be used for any QLineEdit with the clear button enabled:
QLineEdit > QToolButton {
qproperty-icon: url(/path/to/icon.png);
}
Note that this will override all icons of QLineEdit, including those used for custom actions, so in that case you must explicitly set the object name of the button and use the proper selector in the QSS:
# this assumes that the clearButtonEnabled property is already set,
# otherwise it will crash
lineEdit.findChild(QToolButton).setObjectName('clearButton')
lineEdit.setStyleSheet('''
QLineEdit > QToolButton#clearButton {
qproperty-icon: url(/path/to/icon.png);
}
''')
Also, see this related answer for other alternatives.

Change taskbar menu in Tauri

I'm using Tauri and would like to change the menu items shown when clicking my application in the taskbar using the right mouse button (Windows/Linux) or double click (MacOS).
For example Firefox shows "Open a New Window" and music players often show "Play/Pause" or "Next track" buttons. How to do that with Tauri?
I'm aware of SystemTrayMenu in Tauri, but that only seems to affect the system tray, not the task bar.
(What I mean by "taskbar": the line of application icons that you click to open them, and that usually indicate which ones are running. I think MacOS calls it Dock, in Windows it's at the bottom between start button and clock, and Linux isn't very homogeneous but in Ubuntu it's vertically on the left by default. I do not mean the system tray of usually smaller icons that are almost always next to the clock, that are usually more like background services. I.e. I mean where your browser usually shown up, not where your VPN usually shows up.)
Tauri does not support this at the moment (2022-06-27). You may file a feature request.

Python 3 tkinter checkbutton dialog with different background colors

The app is a canvas-based app. For a certain box on the gui, when the user clicks it, I bring up a checkbutton dialog. The dialog contains a color coded gif image at the top. Below that are 48 checkbuttons arranged in groups of 4. Each group of four corresponds to a color in the gif image. So I set the background color of each checkbutton to its corresponding color in the gif image. This helps the user select the appropriate button. The colors are just rgb strings like "#00cc00", etc.
My problem is, when I run on Linux, the background colors of the checkbuttons do not appear unless I mouse over the checkbuttons. Otherwise they just have a gray background. When I run on Windows from MobaXterm, it works like a charm. The background colors appear immediately. However, the target platform is Linux.
I've tried the following: Using ttk and not using ttk. Forcing a dialog update, forcing a "do-nothing" mouse enter event. None of this has worked though. The python 3 version is anaconda 3.7.6 with tkinter 8.6.10.
I found a solution. For each checkbutton, I bind events Enter and Leave to a callback that does nothing, just returns. Then, after the dialog is created, I call event_generate first to Enter then to Leave the checkbutton.
This appears to solve the issue, and the dialog works correctly as well.
Though, if someone has a more elegant solution, I would like to see that as well.

PyAutoGui - locate doesn't see the right-click menu

I have the code below that basically identify the small chrome icon in the windows toolbar, right-click on it using pyautogui and then it should locate the "New Window" option. The problem I face is that, even if I take a screenshot after the right-click, the small menu doesn't show up, making it impossible to locate the "New Window" option.
# this part works
chrome_small_icon = r"C:\Users\chrome_small_icon.png"
elem = pyautogui.locateOnScreen(chrome_small_icon)
elem_center = pyautogui.center(elem)
pyautogui.click(elem_center, duration=0.5, button="right")
time.sleep(0.5)
im_after_right_click = pyautogui.screenshot()
# this part finds zero element, reason being, the right-click menu is like a ghost...
chrome_new_window = r"C:\Users\new_window_text.png"
elements = pyautogui.locateAllOnScreen(chrome_new_window)
does anybody have any suggestion about how to locate elements inside the menu that appears when we right click on an element?
Thanks
EDIT
it seems this issue happens only if I right click on the windows toolbar. It does work if I right click on other locations of the screen.
Instead of trying to locate the new window text use the keyboard to select the new window option. I just ran the following code on MacOS and I was successfully able to open a new Chrome window:
import pyautogui
import time
pyautogui.rightClick(pyautogui.center(pyautogui.locateOnScreen('chrome.png')))
#chrome.png is an image of the chrome icon
pyautogui.typewrite('new window')
pyautogui.press('enter')

With Qt under Gnome 3, Xfce and Unity a full screen window with a child window doesn't stay on top

I have a full screen application based on Qt. Full screen applications should always be on top because otherwise part of the window will be obstructed. I want the frameless full screen window to have child windows (special dialogs, ..). These child windows should be shown on top of the full screen window. Not much sense in showing them below.
A short, self contained example is:
from PySide import QtGui, QtCore
app = QtGui.QApplication([])
window = QtGui.QWidget(f=QtCore.Qt.WindowStaysOnTopHint)
child_window = QtGui.QWidget(window, f=QtCore.Qt.Window)
child_window.resize(400, 300)
layout = QtGui.QVBoxLayout(window)
exit = QtGui.QPushButton('Exit')
exit.clicked.connect(app.exit)
layout.addWidget(exit)
create = QtGui.QPushButton('Create child window')
create.clicked.connect(child_window.show)
layout.addWidget(create)
layout.addStretch()
window.showFullScreen()
app.exec_()
It's written in Python and tested on Python 3.X + PySide 1.2.2 (Qt 4.8) + Ubuntu 14.04 (Unity desktop) or Windows 7. However transformation to C++ Qt (or PyQt) should be straightforward.
The observation is that on Windows everything is as described at the beginning. The Qt.WindowsStaysOnTopHint is not necessary, while on Ubuntu it is.
On Ubuntu I see that initially the full screen main window is on top of everything but as soon as a child dialog window is created the usual desktop decorations (top and left bars) are shown above the full screen main window obstructing part of the view! As soon as the child window is closed the full screen window is on top again.
Question is now if there is anything that can be done to have a full screen window which is on top plus child windows on Ubuntu and with Qt?
The different behavior between Windows and Linux is also not satisfying because OS specific code should be avoided if possible.
Later:
Using the overview of available desktop environment on Ubuntu I installed several environments and tested them.
KDE, Lubuntu (Lxde?) and Openbox work as expected (and equally to Windows). The main window stays on top when shown full screen and child windows are displayed above.
However for Gnome-Shell (Gnome 3), Xfce, Unity and Awesome the desktop decoration stays on top of full screen mode windows of children windows are displayed also. Xfce and Unity behave exactly equal, Gnome and Awesome have even some small additional problems.
Did you tried thing which documentation suggests?
Qt::WindowStaysOnTopHint 0x00040000 Informs the window system that the window should stay on top of all other windows. Note that on
some window managers on X11 you also have to pass
Qt::X11BypassWindowManagerHint for this flag to work correctly.
Another thing why you want other window to be a child if it you what to be under a parent?

Resources