Fixed height of the text widget for document object previews
This commit is contained in:
parent
9967b4dab3
commit
aee0069136
|
@ -5,7 +5,8 @@ from PySide import QtGui
|
||||||
from PySide import QtCore
|
from PySide import QtCore
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from SearchTools import SearchTools; from importlib import reload; reload(SearchTools)
|
# Reload with:
|
||||||
|
import SearchTools; from importlib import reload; reload(SearchTools)
|
||||||
|
|
||||||
|
|
||||||
TODO for this project:
|
TODO for this project:
|
||||||
|
@ -45,6 +46,7 @@ class SafeViewer(QtGui.QWidget):
|
||||||
|
|
||||||
self.setLayout(QtGui.QVBoxLayout())
|
self.setLayout(QtGui.QVBoxLayout())
|
||||||
self.layout().addWidget(self.private_widget)
|
self.layout().addWidget(self.private_widget)
|
||||||
|
self.layout().setContentsMargins(0,0,0,0)
|
||||||
|
|
||||||
def fin(slf):
|
def fin(slf):
|
||||||
slf.finalizer()
|
slf.finalizer()
|
||||||
|
@ -168,7 +170,7 @@ if not hasattr(App, '_SearchTools3DViewer'):
|
||||||
|
|
||||||
import pivy
|
import pivy
|
||||||
class DocumentObjectToolTipWidget(QtGui.QWidget):
|
class DocumentObjectToolTipWidget(QtGui.QWidget):
|
||||||
def __init__(self, nfo):
|
def __init__(self, nfo, setParent):
|
||||||
super(DocumentObjectToolTipWidget, self).__init__()
|
super(DocumentObjectToolTipWidget, self).__init__()
|
||||||
html = '<p>' + nfo['toolTip']['label'] + '</p><p><code>App.getDocument(' + repr(str(nfo['toolTip']['docName'])) + ').getObject(' + repr(str(nfo['toolTip']['name'])) + ')</code></p>'
|
html = '<p>' + nfo['toolTip']['label'] + '</p><p><code>App.getDocument(' + repr(str(nfo['toolTip']['docName'])) + ').getObject(' + repr(str(nfo['toolTip']['name'])) + ')</code></p>'
|
||||||
description = QtGui.QTextEdit()
|
description = QtGui.QTextEdit()
|
||||||
|
@ -201,6 +203,8 @@ class DocumentObjectToolTipWidget(QtGui.QWidget):
|
||||||
# finalizing the object, we remove the parent ourselves.
|
# finalizing the object, we remove the parent ourselves.
|
||||||
oldParent = self.preview.parent()
|
oldParent = self.preview.parent()
|
||||||
lay = QtGui.QVBoxLayout()
|
lay = QtGui.QVBoxLayout()
|
||||||
|
lay.setContentsMargins(0,0,0,0)
|
||||||
|
lay.setSpacing(0)
|
||||||
self.setLayout(lay)
|
self.setLayout(lay)
|
||||||
lay.addWidget(description)
|
lay.addWidget(description)
|
||||||
lay.addWidget(self.preview)
|
lay.addWidget(self.preview)
|
||||||
|
@ -209,11 +213,17 @@ class DocumentObjectToolTipWidget(QtGui.QWidget):
|
||||||
oldParent.setParent(None)
|
oldParent.setParent(None)
|
||||||
|
|
||||||
# Tried hiding/detaching the preview to prevent it from disappearing when changing its contents
|
# Tried hiding/detaching the preview to prevent it from disappearing when changing its contents
|
||||||
self.preview.viewer.stopAnimating()
|
#self.preview.viewer.stopAnimating()
|
||||||
self.preview.viewer.getViewer().setSceneGraph(obj.ViewObject.RootNode)
|
self.preview.viewer.getViewer().setSceneGraph(obj.ViewObject.RootNode)
|
||||||
self.preview.viewer.setCameraOrientation(App.Rotation(1,1,0, 0.2))
|
self.preview.viewer.setCameraOrientation(App.Rotation(1,1,0, 0.2))
|
||||||
self.preview.viewer.fitAll()
|
self.preview.viewer.fitAll()
|
||||||
|
|
||||||
|
setParent(self)
|
||||||
|
# Let the GUI recompute the side of the description based on its horizontal size.
|
||||||
|
FreeCADGui.updateGui()
|
||||||
|
siz = description.document().size().toSize()
|
||||||
|
description.setFixedHeight(siz.height() + 5)
|
||||||
|
|
||||||
def finalizer(self):
|
def finalizer(self):
|
||||||
#self.preview.finalizer()
|
#self.preview.finalizer()
|
||||||
# Detach the widget so that it may be reused without getting deleted
|
# Detach the widget so that it may be reused without getting deleted
|
||||||
|
@ -226,15 +236,15 @@ def easyToolTipWidget(html):
|
||||||
foo.setAlignment(QtCore.Qt.AlignTop)
|
foo.setAlignment(QtCore.Qt.AlignTop)
|
||||||
foo.setText(html)
|
foo.setText(html)
|
||||||
return foo
|
return foo
|
||||||
def refreshToolsToolTip(nfo):
|
def refreshToolsToolTip(nfo, setParent):
|
||||||
return easyToolTipWidget(iconToHTML(genericToolIcon) + '<p>Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.</p>')
|
return easyToolTipWidget(iconToHTML(genericToolIcon) + '<p>Load all workbenches to refresh this list of tools. This may take a minute, depending on the number of installed workbenches.</p>')
|
||||||
def toolbarToolTip(nfo):
|
def toolbarToolTip(nfo, setParent):
|
||||||
return easyToolTipWidget('<p>Display toolbar ' + nfo['toolTip'] + '</p><p>This toolbar appears in the following workbenches: <ul>' + ''.join(['<li>' + iconToHTML(QtGui.QIcon(FreeCADGui.listWorkbenches()[wb].Icon)) + wb + '</li>' for wb in nfo['action']['workbenches']]) + '</ul></p>')
|
return easyToolTipWidget('<p>Display toolbar ' + nfo['toolTip'] + '</p><p>This toolbar appears in the following workbenches: <ul>' + ''.join(['<li>' + iconToHTML(QtGui.QIcon(FreeCADGui.listWorkbenches()[wb].Icon)) + wb + '</li>' for wb in nfo['action']['workbenches']]) + '</ul></p>')
|
||||||
def subToolToolTip(nfo):
|
def subToolToolTip(nfo, setParent):
|
||||||
return easyToolTipWidget(iconToHTML(nfo['icon'], 32) + '<p>' + nfo['toolTip'] + '</p>')
|
return easyToolTipWidget(iconToHTML(nfo['icon'], 32) + '<p>' + nfo['toolTip'] + '</p>')
|
||||||
def documentObjectToolTip(nfo):
|
def documentObjectToolTip(nfo, setParent):
|
||||||
return DocumentObjectToolTipWidget(nfo)
|
return DocumentObjectToolTipWidget(nfo, setParent)
|
||||||
def documentToolTip(nfo):
|
def documentToolTip(nfo, setParent):
|
||||||
return easyToolTipWidget('<p>' + nfo['toolTip']['label'] + '</p><p><code>App.getDocument(' + repr(str(nfo['toolTip']['name'])) + ')</code></p><p><img src="data:image/png;base64,.............."></p>')
|
return easyToolTipWidget('<p>' + nfo['toolTip']['label'] + '</p><p><code>App.getDocument(' + repr(str(nfo['toolTip']['name'])) + ')</code></p><p><img src="data:image/png;base64,.............."></p>')
|
||||||
toolTipHandlers = {
|
toolTipHandlers = {
|
||||||
'refreshTools': refreshToolsToolTip,
|
'refreshTools': refreshToolsToolTip,
|
||||||
|
@ -311,7 +321,7 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
self.showList()
|
self.showList()
|
||||||
super(SearchBox, self).focusInEvent(qFocusEvent)
|
super(SearchBox, self).focusInEvent(qFocusEvent)
|
||||||
def focusOutEvent(self, qFocusEvent):
|
def focusOutEvent(self, qFocusEvent):
|
||||||
self.hideList()
|
#self.hideList()
|
||||||
super(SearchBox, self).focusOutEvent(qFocusEvent)
|
super(SearchBox, self).focusOutEvent(qFocusEvent)
|
||||||
def keyPressEvent(self, qKeyEvent):
|
def keyPressEvent(self, qKeyEvent):
|
||||||
key = qKeyEvent.key()
|
key = qKeyEvent.key()
|
||||||
|
@ -477,24 +487,30 @@ class SearchBox(QtGui.QLineEdit):
|
||||||
#TODO: used to be: nfo['action'] = json.loads(nfo['action'])
|
#TODO: used to be: nfo['action'] = json.loads(nfo['action'])
|
||||||
#while len(self.extraInfo.children()) > 0:
|
#while len(self.extraInfo.children()) > 0:
|
||||||
# self.extraInfo.children()[0].setParent(None)
|
# self.extraInfo.children()[0].setParent(None)
|
||||||
w = self.extraInfo.layout().takeAt(0)
|
# This is a hack to allow some widgets to set the parent and recompute their size
|
||||||
toolTipWidget = toolTipHandlers[nfo['action']['handler']](nfo)
|
# during their construction.
|
||||||
while w:
|
parentIsSet = False
|
||||||
if hasattr(w.widget(), 'finalizer'):
|
def setParent(toolTipWidget):
|
||||||
# The 3D viewer segfaults very easily if it is used after being destroyed, and some Python/C++ interop seems to overzealously destroys some widgets, including this one, too soon?
|
nonlocal parentIsSet
|
||||||
# Ensuring that we properly detacth the 3D viewer widget before discarding its parent seems to avoid these crashes.
|
parentIsSet = True
|
||||||
#print('FINALIZER')
|
|
||||||
w.widget().finalizer()
|
|
||||||
if w.widget() is not None:
|
|
||||||
w.widget().hide() # hide before detaching, or we have widgets floating as their own window that appear for a split second in some cases.
|
|
||||||
w.widget().setParent(None)
|
|
||||||
w = self.extraInfo.layout().takeAt(0)
|
w = self.extraInfo.layout().takeAt(0)
|
||||||
self.extraInfo.layout().addWidget(toolTipWidget)
|
while w:
|
||||||
global toto
|
if hasattr(w.widget(), 'finalizer'):
|
||||||
toto = self.extraInfo
|
# The 3D viewer segfaults very easily if it is used after being destroyed, and some Python/C++ interop seems to overzealously destroys some widgets, including this one, too soon?
|
||||||
#toolTipHTML = toolTipHandlers[nfo['action']['handler']](nfo)
|
# Ensuring that we properly detacth the 3D viewer widget before discarding its parent seems to avoid these crashes.
|
||||||
#self.extraInfo.setText(toolTipHTML)
|
#print('FINALIZER')
|
||||||
self.setFloatingWidgetsGeometry()
|
w.widget().finalizer()
|
||||||
|
if w.widget() is not None:
|
||||||
|
w.widget().hide() # hide before detaching, or we have widgets floating as their own window that appear for a split second in some cases.
|
||||||
|
w.widget().setParent(None)
|
||||||
|
w = self.extraInfo.layout().takeAt(0)
|
||||||
|
self.extraInfo.layout().addWidget(toolTipWidget)
|
||||||
|
#toolTipHTML = toolTipHandlers[nfo['action']['handler']](nfo)
|
||||||
|
#self.extraInfo.setText(toolTipHTML)
|
||||||
|
self.setFloatingWidgetsGeometry()
|
||||||
|
toolTipWidget = toolTipHandlers[nfo['action']['handler']](nfo, setParent)
|
||||||
|
if not parentIsSet:
|
||||||
|
setParent(toolTipWidget)
|
||||||
if self.pendingExtraInfo is not None:
|
if self.pendingExtraInfo is not None:
|
||||||
index = self.pendingExtraInfo
|
index = self.pendingExtraInfo
|
||||||
self.pendingExtraInfo = None
|
self.pendingExtraInfo = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user