0

Having trouble finalizing a dynamic QMenu tree.
The structure and format is perfect, but what remains missing is the return of all branch names when triggering the end-action.

The only implement I have tried with ANY trend toward a solution is the use of self.sender(); which returns only the name of the end-action.

Before adding a ton of the lengthy code snips - starting by conceptualizing the question seemed best in case there is some (obvious) means I am over-looking.

Example; The ideal return based on the footer figure would be something along the lines of...

  • Top Image:

    'Single Results' - 'Head Results'

  • Middle Image:

    'Batch Results' - 'testBatch_vr3' - 'Run-1' - 'Budget Results'

  • Bottom Image:

    'Single Results' - 'testBatch_vr3' - 'Run-3' - 'Particle Tracks'

enter image description here

To the point;

How can all names in a multi-leveled set of QMenus be retrieved when triggering end-action?

Katalpa
  • 159
  • 2
  • 9

1 Answers1

0

The following complex bits resolved my problem. It might be a bit obscure way to go about it (hovered signal from menu to search for dictionary menu entry) - but it works well for now.

# checks batch processing folder for existing directories and publishes the contents 
# into the batch results menu comboBox
def populateBatchResults(self):
    self.batchMenuDict = {}
    self.runMenuDict = {}
    self.runBatchResultsPopup.clear()
    self.batchDirNamesMenu.clear()
    batchModDir = self.estabBatchModelDir()
    for batch in os.listdir(batchModDir):
        fullBatchDir = batchModDir+str(batch)
        if os.path.isdir(fullBatchDir):
            self.batchMenuDict[batch] = QMenu(self.iface.mainWindow())
            self.batchMenuDict[batch].setTitle(str(batch))
            self.runBatchResultsPopup.addMenu(self.batchMenuDict[batch])
        for run in os.listdir(fullBatchDir):
            fullRunDir = fullBatchDir+'\\'+str(run)
            if os.path.isdir(fullRunDir):
                self.runMenuDict[run] = QMenu(self.iface.mainWindow())
                self.runMenuDict[run].setTitle(str(run))
                self.batchMenuDict[batch].addMenu(self.runMenuDict[run])
                self.runMenuDict[run].hovered.connect(self.assertBatchMenuSelection)

# get all current cursor hovered menu names
def assertBatchMenuSelection(self):
    self.selectedBatch = self.runBatchResultsPopup.activeAction().text()
    self.selectedRun = self.batchMenuDict.get(self.selectedBatch).activeAction().text()
    self.selectedAction = self.runMenuDict.get(self.selectedRun).activeAction().text()
Katalpa
  • 159
  • 2
  • 9