Prevent segault when doing right-click actions on the extra info panel

This commit is contained in:
Suzanne Soy 2021-10-16 20:15:33 +01:00
parent 004dd3edfd
commit d862be5f40
3 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import os
import FreeCAD as App
import FreeCADGui
from PySide import QtGui
import Serialize
@ -48,10 +49,12 @@ def getAllParams():
return [getParamGroups('UserParameter', 'User parameter')]
def paramGroupAction(nfo):
print(repr(nfo))
FreeCADGui.runCommand('Std_DlgParameter',0)
# TODO: find a way to select the desired group in the parameter dialog once it opens
def paramAction(nfo):
print(repr(nfo))
FreeCADGui.runCommand('Std_DlgParameter',0)
# TODO: find a way to select the desired parameter in the parameter dialog once it opens
getters = {
'Boolean' : 'GetBool',

View File

@ -47,7 +47,7 @@ def subToolAction(nfo):
print('Tool ' + toolPath + ' not found, was it offered by an extension that is no longer present?')
def toolbarToolTip(nfo, setParent):
return '<p>Display toolbar ' + nfo['toolTip'] + '</p><p>This toolbar appears in the following workbenches: <ul>' + ''.join(['<li>' + Serialize.iconToHTML(QtGui.QIcon(FreeCADGui.listWorkbenches()[wb].Icon)) + wb + '</li>' for wb in nfo['action']['workbenches']]) + '</ul></p>'
return '<p>Show the ' + nfo['text'] + ' toolbar</p><p>This toolbar appears in the following workbenches: <ul>' + ''.join(['<li>' + Serialize.iconToHTML(QtGui.QIcon(FreeCADGui.listWorkbenches()[wb].Icon)) + wb + '</li>' for wb in nfo['action']['workbenches']]) + '</ul></p>'
def subToolToolTip(nfo, setParent):
return Serialize.iconToHTML(nfo['icon'], 32) + '<p>' + nfo['toolTip'] + '</p>'

View File

@ -72,6 +72,7 @@ class SearchBox(QtGui.QLineEdit):
self.extraInfo.layout().setContentsMargins(0,0,0,0)
self.setExtraInfoIsActive = False
self.pendingExtraInfo = None
self.currentExtraInfo = None
# Connect signals and slots
self.listView.clicked.connect(lambda x: self.selectResult('select', x))
self.listView.selectionModel().selectionChanged.connect(self.onSelectionChanged)
@ -241,6 +242,7 @@ class SearchBox(QtGui.QLineEdit):
addGroups(group['subitems'], depth+1)
addGroups(filterGroups(self.itemGroups))
self.proxyModel.setSourceModel(self.mdl)
self.currentExtraInfo = None # Unset this so that the ExtraInfo can be updated
# TODO: try to find the already-highlighted item
nbRows = self.listView.model().rowCount()
if nbRows > 0:
@ -303,6 +305,11 @@ class SearchBox(QtGui.QLineEdit):
@staticmethod
def setExtraInfo(self, index):
if self.currentExtraInfo == (index.row(), index.column(), index.model()):
# avoid useless updates of the extra info window; this also prevents segfaults when the widget
# is replaced when selecting an option from the right-click context menu
return
self.currentExtraInfo = (index.row(), index.column(), index.model())
# TODO: use an atomic swap or mutex if possible
if self.setExtraInfoIsActive:
self.pendingExtraInfo = index