Skip to content

Commit 01cc4e3

Browse files
macevhiczMHendricks
authored andcommitted
Retain orig cursor pos if clicking hyperlink
1 parent fcc1145 commit 01cc4e3

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

preditor/gui/console.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ def __init__(self, parent):
135135
self.addAction(self.uiClearToLastPromptACT)
136136

137137
self.x = 0
138-
self.clickPos = None
139-
self.anchor = None
138+
self.mousePressPos = None
140139

141140
# Make sure console cursor is visible. It can get it's width set to 0 with
142141
# unusual(ie not 100%) os display scaling.
@@ -220,30 +219,47 @@ def setConsoleFont(self, font):
220219
if origPercent is not None:
221220
self.doubleSingleShotSetScrollValue(origPercent)
222221

222+
def mouseMoveEvent(self, event):
223+
"""Overload of mousePressEvent to change mouse pointer to indicate it is
224+
over a clickable error hyperlink.
225+
"""
226+
if self.anchorAt(event.pos()):
227+
QApplication.setOverrideCursor(Qt.CursorShape.PointingHandCursor)
228+
else:
229+
QApplication.restoreOverrideCursor()
230+
return super().mouseMoveEvent(event)
231+
223232
def mousePressEvent(self, event):
224233
"""Overload of mousePressEvent to capture click position, so on release, we can
225234
check release position. If it's the same (ie user clicked vs click-drag to
226235
select text), we check if user clicked an error hyperlink.
227236
"""
228-
self.clickPos = event.pos()
229-
self.anchor = self.anchorAt(event.pos())
230-
if self.anchor:
231-
QApplication.setOverrideCursor(Qt.CursorShape.PointingHandCursor)
232-
return super(ConsolePrEdit, self).mousePressEvent(event)
237+
left = event.button() == Qt.MouseButton.LeftButton
238+
anchor = self.anchorAt(event.pos())
239+
self.mousePressPos = event.pos()
240+
241+
if left and anchor:
242+
event.ignore()
243+
return
244+
245+
return super().mousePressEvent(event)
233246

234247
def mouseReleaseEvent(self, event):
235248
"""Overload of mouseReleaseEvent to capture if user has left clicked... Check if
236249
click position is the same as release position, if so, call errorHyperlink.
237250
"""
238-
samePos = event.pos() == self.clickPos
251+
samePos = event.pos() == self.mousePressPos
239252
left = event.button() == Qt.MouseButton.LeftButton
240-
if samePos and left and self.anchor:
241-
self.errorHyperlink()
253+
anchor = self.anchorAt(event.pos())
254+
255+
if samePos and left and anchor:
256+
self.errorHyperlink(anchor)
257+
self.mousePressPos = None
242258

243-
self.clickPos = None
244-
self.anchor = None
245259
QApplication.restoreOverrideCursor()
246-
return super(ConsolePrEdit, self).mouseReleaseEvent(event)
260+
ret = super(ConsolePrEdit, self).mouseReleaseEvent(event)
261+
262+
return ret
247263

248264
def keyReleaseEvent(self, event):
249265
"""Override of keyReleaseEvent to determine when to end navigation of
@@ -254,7 +270,7 @@ def keyReleaseEvent(self, event):
254270
else:
255271
event.ignore()
256272

257-
def errorHyperlink(self):
273+
def errorHyperlink(self, anchor):
258274
"""Determine if chosen line is an error traceback file-info line, if so, parse
259275
the filepath and line number, and attempt to open the module file in the user's
260276
chosen text editor at the relevant line, using specified Command Prompt pattern.
@@ -267,13 +283,13 @@ def errorHyperlink(self):
267283
doHyperlink = (
268284
hasattr(window, 'uiErrorHyperlinksCHK')
269285
and window.uiErrorHyperlinksCHK.isChecked()
270-
and self.anchor
286+
and anchor
271287
)
272288
if not doHyperlink:
273289
return
274290

275291
# info is a comma separated string, in the form: "filename, workboxIdx, lineNum"
276-
info = self.anchor.split(', ')
292+
info = anchor.split(', ')
277293
modulePath = info[0]
278294
workboxName = info[1]
279295
lineNum = info[2]

0 commit comments

Comments
 (0)