Skip to content

Commit

Permalink
ENH: ignore all middle-click mouse relase events
Browse files Browse the repository at this point in the history
Do this to avoid middle-click pasting clipboard contents into
PyDMLineEdits. This seems like cleaner way to do it than before.
  • Loading branch information
nstelter-slac committed May 7, 2024
1 parent aa4e2df commit 9abbc25
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions pydm/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,11 @@ def eventFilter(self, obj, event):
"""
# Override the eventFilter to capture all middle mouse button events,
# and show a tooltip if needed.
# We capture the release event (instead of press event) to prevent clipboard contents
# from getting paste into PyDMLineEdits, since paste happens at mouse release.
if event.type() == QEvent.MouseButtonRelease:
if event.type() == QEvent.MouseButtonPress:
if event.button() == Qt.MiddleButton:
channels_method = getattr(self, "channels", None)
if channels_method is None:
return
channels = channels_method()
if channels:
self.show_address_tooltip(event)
return True
else:
# return and run default behavior middle-click paste if PyDMLineEdit
# is not connected to channel, so you can still paste the middle-click
# clipboard into edits intended for text entry.
return False
self.show_address_tooltip(event)
return True

return False

def show_address_tooltip(self, event):
Expand Down Expand Up @@ -242,10 +231,17 @@ def show_address_tooltip(self, event):
# Mode Selection is only valid for X11.
mode = clipboard.Selection

# currText = clipboard.text()
# print ("!! curr clip text: ", currText)

clipboard.setText(clipboard_text, mode=mode)
# print ("!! trying to set clip to: ", clipboard_text)
event = QEvent(QEvent.Clipboard)
self.app.sendEvent(clipboard, event)

# currText = clipboard.text()
# print ("!! after clip text: ", currText)

def opacity(self):
"""
Float value between 0 and 1 representing the opacity of the widget
Expand Down

0 comments on commit 9abbc25

Please sign in to comment.