Skip to content

Commit 9d6b517

Browse files
macevhiczMHendricks
authored andcommitted
Move handleMenuHovered and connect to tab context menus
1 parent 19a4fef commit 9d6b517

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

preditor/gui/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import absolute_import
22

3+
import re
34
from functools import partial
45

56
from Qt.QtCore import Property
6-
from Qt.QtWidgets import QStackedWidget
7+
from Qt.QtGui import QCursor
8+
from Qt.QtWidgets import QStackedWidget, QToolTip
79

810
from .dialog import Dialog # noqa: F401
911
from .window import Window # noqa: F401
@@ -61,6 +63,23 @@ def _setattrCallback(callback, attrName, self, value):
6163
return Property(typ, fget=(lambda s: ga(s, name)), fset=(lambda s, v: sa(s, v)))
6264

6365

66+
def handleMenuHovered(action):
67+
"""Actions in QMenus which are not descendants of a QToolBar will not show
68+
their toolTips, because... Reasons?
69+
"""
70+
# Don't show if it's just the text of the action
71+
text = re.sub(r"(?<!&)&(?!&)", "", action.text())
72+
text = text.replace('...', '')
73+
74+
if text == action.toolTip():
75+
text = ''
76+
else:
77+
text = action.toolTip()
78+
79+
menu = action.parent()
80+
QToolTip.showText(QCursor.pos(), text, menu)
81+
82+
6483
def loadUi(filename, widget, uiname=''):
6584
"""use's Qt's uic loader to load dynamic interafces onto the inputed widget
6685

preditor/gui/drag_tab_bar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from preditor import osystem
2020

21+
from ..gui import handleMenuHovered
2122
from . import QtPropertyInit
2223

2324

@@ -364,6 +365,7 @@ def tab_menu(self, pos, popup=True):
364365
return
365366
menu = QMenu(self)
366367
menu.setFont(self.window().font())
368+
menu.hovered.connect(handleMenuHovered)
367369

368370
grouped_tab = self.parentWidget()
369371
workbox = grouped_tab.widget(self._context_menu_tab)

preditor/gui/loggerwindow.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
from pathlib import Path
1717

1818
import __main__
19-
import Qt as Qt_py
2019
from Qt import QtCompat, QtCore, QtWidgets
2120
from Qt.QtCore import QByteArray, QFileSystemWatcher, QObject, Qt, QTimer, Signal, Slot
22-
from Qt.QtGui import QCursor, QFont, QIcon, QKeySequence, QTextCursor
21+
from Qt.QtGui import QFont, QIcon, QKeySequence, QTextCursor
2322
from Qt.QtWidgets import (
2423
QApplication,
2524
QFontDialog,
@@ -45,7 +44,7 @@
4544
resourcePath,
4645
)
4746
from ..delayable_engine import DelayableEngine
48-
from ..gui import Dialog, Window, loadUi, tab_widget_for_tab
47+
from ..gui import Dialog, Window, handleMenuHovered, loadUi, tab_widget_for_tab
4948
from ..gui.fuzzy_search.fuzzy_search import FuzzySearch
5049
from ..gui.group_tab_widget.grouped_tab_models import GroupTabListItemModel
5150
from ..logging_config import LoggingConfig
@@ -210,7 +209,7 @@ def __init__(self, parent, name=None, run_workbox=False, standalone=False):
210209
action.setObjectName('uiCycleModeACT')
211210
action.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_M))
212211
action.triggered.connect(self.cycleCompleterMode)
213-
self.uiCompleterModeMENU.hovered.connect(self.handleMenuHovered)
212+
self.uiCompleterModeMENU.hovered.connect(handleMenuHovered)
214213

215214
# Workbox add/remove
216215
self.uiNewWorkboxACT.triggered.connect(
@@ -293,7 +292,7 @@ def __init__(self, parent, name=None, run_workbox=False, standalone=False):
293292
regEx = ".*"
294293
menus = self.findChildren(QtWidgets.QMenu, QtCore.QRegExp(regEx))
295294
for menu in menus:
296-
menu.hovered.connect(self.handleMenuHovered)
295+
menu.hovered.connect(handleMenuHovered)
297296

298297
# Preferences window
299298
self.uiClosePreferencesBTN.clicked.connect(self.update_workbox_stack)
@@ -809,23 +808,6 @@ def adjustFontSize(self, kind, delta):
809808
size += delta
810809
self.setGuiFont(newSize=size)
811810

812-
def handleMenuHovered(self, action):
813-
"""Qt4 doesn't have a ToolTipsVisible method, so we fake it"""
814-
# Don't show if it's just the text of the action
815-
text = re.sub(r"(?<!&)&(?!&)", "", action.text())
816-
text = text.replace('...', '')
817-
818-
if text == action.toolTip():
819-
text = ''
820-
else:
821-
text = action.toolTip()
822-
823-
if Qt_py.IsPyQt4:
824-
menu = action.parentWidget()
825-
else:
826-
menu = action.parent()
827-
QToolTip.showText(QCursor.pos(), text, menu)
828-
829811
def selectFont(
830812
self, origFont=None, monospace=False, proportional=False, doGui=False
831813
):

0 commit comments

Comments
 (0)