PyQt custom dock tooltip for ubuntu

Viewed 24

I work with PyQt5 and PyDM in a few ubuntu and debian distributions and i need a way of setting tooltips for the application icon on the ubuntu bar as show in the image:

enter image description here

I need to do this via python code. The way im calling the application seems to be the reason why the tooltip text in the image is set to "testing" but i its still not in python code.

I have a .ui file named example.ui. I call it in a pydm/python script named example.py:

#!/usr/local/bin/pydm

from pydm import Display
from os import path

class Main(Display):

    def __init__(self, parent=None, args=None, macros=None):
        super(Main, self).__init__(parent=parent, args=args, macros=None)
        self.pushButton.clicked.connect(self.blah)

    def blah(self):
        print("BLAH")

    def ui_filename(self):
        return "example.ui"

    def ui_filepath(self):
        # Return the full path to the UI file
        return path.join("./", "example.ui")

finallly, i have a .sh script called init.sh:

#!/bin/bash

pydm -m "MY_MACRO=Example" example.py testing

If i change "testing" in the init.sh file, the tooltip also changes accordingly but, as i said, i want to do this via the .py file.

If it helps, i know Qt MainWindow is accessible via

QApplication.instance().main_window

For example, you can do:

QApplication.instance().main_window.setMaximumSize(some_number,some_number)

But i found nothing in QApplication documentation about application tooltips.

1 Answers

Python receives information from the command line in the form of *args and **kwargs. In this case, *args. 'testing' is an example of an arg. --input='testing' is an example of a kwarg (keyword argument).

Change this line:

def __init__(self, parent=None, args=None, macros=None):

To this:

def __init__(self, parent=None, args=['testing'], macros=None):

For more information, look into the __init__() 'dunder' method and the 'Display' object code that's being imported from pydm:

PyDM Display Object Code

Answer:

#!/usr/local/bin/pydm

from pydm import Display
from os import path

class Main(Display):

    def __init__(self, parent=None, args=['testing'], macros=None):
        super(Main, self).__init__(parent=parent, args=args, macros=None)
        self.pushButton.clicked.connect(self.blah)

    def blah(self):
        print("BLAH")

    def ui_filename(self):
        return "example.ui"

    def ui_filepath(self):
        # Return the full path to the UI file
        return path.join("./", "example.ui")

Related