import sys
from PyQt5 import QtGui, QtCore, uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication
import random as r
import threading, time
from PyQt5.QtCore import pyqtSlot
from hotkeys import bind_hotkey_function
from PyQt5 import QtOpenGL
import OpenGL.GL as GL # python wrapping of OpenGL
from OpenGL import GLU # OpenGL Utility Library, extends OpenGL functionality
class GLWidget(QtOpenGL.QGLWidget):
def __init__(self, parent=None):
self.parent = parent
QtOpenGL.QGLWidget.__init__(self, parent)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
def initializeGL(self):
# GL.glEnable(GL.GL_ALPHA_TEST)
# GL.glEnable(GL.GL_DEPTH_TEST)
# GL.glEnable(GL.GL_COLOR_MATERIAL)
# GL.glEnable(GL.GL_LIGHTING)
# GL.glEnable(GL.GL_LIGHT0)
# GL.glEnable(GL.GL_BLEND)
# GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
self.qglClearColor(QtCore.QColor(0, 0, 255, 0))
GL.glClearColor(0, 0, 255, 0)
def resizeGL(self, w, h):
GL.glViewport(0, 0, w, h)
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
x = float(w) / h
GL.glFrustum(-x, x, -1.0, 1.0, 1.0, 10.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
def paintGL(self):
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
GL.glPushMatrix()
GL.glBegin(GL.GL_TRIANGLES)
GL.glColor3f(1.0, 0.0, 0.0, 0)
GL.glVertex3f(-1.0, 1.0, -3.0, 0)
GL.glColor3f(0.0, 1.0, 0.0, 0)
GL.glVertex3f(1.0, 1.0, -3.0, 0)
GL.glColor3f(0.0, 0.0, 1.0, 0)
GL.glVertex3f(0.0, -1.0, -3.0, 0)
GL.glEnd()
GL.glPopMatrix()
GL.glFlush()
class MainWindow(QMainWindow):
def __init__(self, screen_size):
QMainWindow.__init__(self)
self.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.FramelessWindowHint |
QtCore.Qt.X11BypassWindowManagerHint
#| QtCore.Qt.WindowTransparentForInput
)
self.size = size + QtCore.QSize(220, 32)
self.setGeometry(
QtWidgets.QStyle.alignedRect(
QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
self.size,
QtWidgets.qApp.desktop().availableGeometry()
))
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
self.updater = True
def update_widget():
pass
#while self.updater:
# time.sleep(.1)
# self.update()
self.update_thread = threading.Thread(target=update_widget)
self.update_thread.start()
self.exit_hotkey = bind_hotkey_function("Ctrl-M", self.close_shortcut_trigger)
from audio_noise import audio_noise_thread_executor
self.audio_noise_thread = audio_noise_thread_executor()
glWidget = GLWidget(self)
self.setCentralWidget(glWidget)
def mousePressEvent(self, event):
QtWidgets.qApp.quit()
self.updater = False
self.audio_noise_thread.data['do'] = False
self.exit_hotkey.data['do'] = False
def paintEvent(self, event):
try:
width, height = r.randint(20, 70), r.randint(20, 70)
qp = QtGui.QPainter(self)
for i in range(int(self.size.width() / width)):
for j in range(int(self.size.height() / height) + 1):
qp.setBrush(QtGui.QColor(r.randint(0, 255),r.randint(0, 255),r.randint(0, 255), 40))
if r.randint(0, 1) == 1:
qp.drawRect(i*width, j*height, width, height)
else:
qp.drawEllipse(i*width, j*height, width, height)
# for i in range(self.size.width()):
# for j in range(self.size.height()):
# pen = QtGui.QPen()
# pen.setWidth(5)
# pen.setColor(QtGui.QColor(r.randint(0, 255),r.randint(0, 255),r.randint(0, 255), 40))
# qp.setPen(pen)
# qp.setRenderHint(QtGui.QPainter.Antialiasing, True)
# qp.drawPoint(i, j)
# print(i, j)
except Exception as e:
print(e)
def close_shortcut_trigger(self):
print("CLOSE WINDOW!")
self.app.quit()
def gen_image_object(self):
pass
if __name__ == '__main__':
app = QApplication(sys.argv)
screen = app.primaryScreen()
print('Screen: %s' % screen.name())
size = screen.size()
print('Size: %d x %d' % (size.width(), size.height()))
rect = screen.availableGeometry()
print('Available: %d x %d' % (rect.width(), rect.height()))
mywindow = MainWindow(size)
mywindow.app = app
mywindow.show()
sys.exit(app.exec())