PyQt5应用程序在所有肉桂/侏儒工作区中都可见

时间:2018-01-11 09:58:33

标签: python pyqt5

我正在尝试在pyqt5中编写的应用程序始终在所有cinnamon/gnome个虚拟工作空间中可见。
示例: 'conky'
但调查QDesktopApplicationQWindowQScreen似乎并不正确。请问任何地址?

修改:我已经在Keep a application window always on current desktop on linux and mac看到了答案,这是一个C ++答案,但我的问题是关于pyQt5。似乎方向是使用一种C ++包装器。

1 个答案:

答案 0 :(得分:0)

在以下代码中,可以在所有工作空间中显示一个简单的文本框。 这可以使用python-ewmh包将_NET_WM_DESKTOP提示设置为0xffffffff。

"""
  example.py

  simple widget on bottom level visible in all workspaces
"""


import sys
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from ewmh import EWMH


class Panel(QtWidgets.QWidget):
    """ main panel """

    def __init__(self):
        super(Panel, self).__init__()

        # panel size and position
        self.setFixedSize(300, 200)                     # width, height
        self.move(100, 100)                             # x, y

        # panel flags
        flags = QtCore.Qt.FramelessWindowHint           # no border and no title bar
        flags |= QtCore.Qt.WindowStaysOnBottomHint      # always on bottom level
        flags |= QtCore.Qt.Tool                         # no icon on taskbar
        self.setWindowFlags(flags)

        # panel style
        self.setWindowOpacity(0.8)                      # 0=transparent; 1=opaque
        self.setStyleSheet("background-color:#334455;padding: 0;margin: 0;")

        # text label
        txt = QtWidgets.QLabel(self)
        txt.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
        txt.setStyleSheet("background:transparent;color:#000000;font:40px;padding:0;margin:0;")
        txt.setText('Hello world!')

        # vertical layout
        v_layout = QtWidgets.QVBoxLayout()
        v_layout.setContentsMargins(2, 2, 2, 2)
        v_layout.setSpacing(0)
        v_layout.addWidget(txt)
        self.setLayout(v_layout)

        # show the panel
        self.show()

        # show the panel in all workspaces
        # (taken from ewmh documentation)
        ewmh = EWMH()
        all_wins = ewmh.getClientList()
        wins = filter(lambda w: w.get_wm_class()[1] == 'example.py', all_wins)
        for w in wins:
            ewmh.setWmDesktop(w, 0xffffffff)
        ewmh.display.flush()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    p = Panel()
    sys.exit(app.exec_())