Advertisement
j0h

mouse-Highlighter

j0h
Oct 26th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # I was looking at a certain provissioning tool, and keeping track of all the lines was hard,
  3. # highlighting isnt an option, and theres a lot of stuff on the sceen.
  4. # this script is to help me keep track of the line I'm on.
  5.  
  6. # pip install PyQt5
  7.  
  8.  
  9. import sys
  10. from PyQt5 import QtCore, QtWidgets, QtGui
  11.  
  12. class HighlightLineOverlay(QtWidgets.QWidget):
  13.     def __init__(self):
  14.         super().__init__()
  15.  
  16.         # Set up the main window
  17.         self.setWindowFlags(
  18.             QtCore.Qt.FramelessWindowHint |
  19.             QtCore.Qt.WindowStaysOnTopHint |
  20.             QtCore.Qt.Tool |
  21.             QtCore.Qt.WindowTransparentForInput
  22.         )
  23.         self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
  24.  
  25.         # Set the overlay window to full screen
  26.         self.screen_width = QtWidgets.QApplication.primaryScreen().size().width()
  27.         self.screen_height = QtWidgets.QApplication.primaryScreen().size().height()
  28.         self.setGeometry(0, 0, self.screen_width, self.screen_height)
  29.  
  30.         # Create the highlight bar with semi-transparent color
  31.         self.bar_height = 15  # Adjust bar thickness here
  32.         self.bar_color = QtGui.QColor(255, 255, 0, 50)  # Yellow bar with transparency (150)
  33.         self.bar_y_position = 100  # Initial Y position
  34.         self.showFullScreen()
  35.  
  36.         # Set up a timer to update the bar position based on mouse Y coordinate
  37.         self.timer = QtCore.QTimer(self)
  38.         self.timer.timeout.connect(self.update_bar_position)
  39.         self.timer.start(20)  # Refresh rate
  40.  
  41.     def paintEvent(self, event):
  42.         # Draw the highlight bar
  43.         painter = QtGui.QPainter(self)
  44.         painter.setRenderHint(QtGui.QPainter.Antialiasing)
  45.         painter.setBrush(self.bar_color)
  46.         painter.setPen(QtCore.Qt.NoPen)
  47.         painter.drawRect(0, self.bar_y_position, self.screen_width, self.bar_height)
  48.  
  49.     def update_bar_position(self):
  50.         # Get the current mouse position
  51.         cursor_pos = QtGui.QCursor.pos()
  52.         # Update the bar's Y position to follow the mouse's Y coordinate
  53.         self.bar_y_position = cursor_pos.y()
  54.         self.update()  # Redraw the bar at the new position
  55.  
  56. if __name__ == "__main__":
  57.     app = QtWidgets.QApplication(sys.argv)
  58.     overlay = HighlightLineOverlay()
  59.     overlay.show()
  60.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement