PythonQT, QMenu update QActions

83 Views Asked by At

I've got the following code which was working well before I updated utils._DATA twice. Utils._DATA is dictionary.

class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
    def __init__(self, icon, parent=None):
        super(SystemTrayIcon, self).__init__(parent)

        self.parent = parent
        QtWidgets.QSystemTrayIcon.__init__(self, icon, self.parent)
        self.menu = QtWidgets.QMenu(parent)

        self.actions = {}

        self.Update()

    def Update(self):
        self.menu.clear()
        self.actions.clear()
        for key in utils._DATA:
            self.actions[key] = self.menu.addAction(key)
            self.actions[key].triggered.connect(partial(utils.copy, key))

        self.setContextMenu(self.menu)

But if I call self.Update() after editing utils._DATA (second, third time etc), QActions exist but do nothing.

How can I update QMenu with working QActions in it?

Utils.copy is next:

def copy(identificator):
    try:
        clipboard.copy(_DATA[identificator])
        return 0
    except:
        raise Exception('Cannot copy to clipboard')

I'm updating like _DATA = load(), where load() read specific file and convert it to dict. So in simple form it's

_DATA[file.readline()] = some_string

Update data works good, even QActions in my QMenu updating good, but their trigger does nothing!

0

There are 0 best solutions below