Skip to content

Instantly share code, notes, and snippets.

import sys
import os
from PyQt5 import QtWidgets, QtGui
class SampleWidget(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(SampleWidget, self).__init__(*args, **kwargs)
import sys
from PyQt5 import QtWidgets, QtGui, QtCore
class CustomLabel(QtWidgets.QLabel):
def __init__(self, *args, **kwargs):
super(CustomLabel, self).__init__(*args, **kwargs)
self.start_point = QtCore.QPoint(0, 0) # This is x, y point, we will use Qpoint to represent it
self.end_point = QtCore.QPoint(0, 0) # The QPoint will only take two integers, QPointF for floating point
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
class ClickableLabel(QtWidgets.QLabel):
# you will have to specify how many arguments and the type of the argument(eg: bool, int, str), in
# our case we will use QPoint to pass mouse position.
# All your signals must be class level, not object level/instance level.
clicked = QtCore.pyqtSignal(QtCore.QPoint)
import sys
from PyQt5 import QtWidgets, QtCore
class CustomTimer(QtCore.QThread):
countDownUpdated = QtCore.pyqtSignal(int) # whenever the countdown changes this signal get emitted
def __init__(self, count_down, sleep=1000, *args, **kwargs):
super(CustomTimer, self).__init__(*args, **kwargs)
import sys
from PyQt5 import QtGui, QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
view = QtWidgets.QGraphicsView()
scene = QtWidgets.QGraphicsScene()
while True:
for event in event_queue:
if event == "quit":
break
elif event == "button_press":
update_button()
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QGridLayout
app = QApplication(sys.argv)
widget = QWidget()
grid_layout = QGridLayout()
label = QLabel("Sample label")
button = QPushButton("Button") # create an instance of QPushbutton
@PaulleDemon
PaulleDemon / PyPi Upload.md
Last active January 19, 2024 16:52
This is quick description to upload to PyPi
  • create setup.py file

Eg:

from setuptools import setup

with open("Readme.md", 'r') as f:
    long_description = f.read()

setup(
@PaulleDemon
PaulleDemon / FileTreeGenerator.py
Created August 5, 2022 06:37
walks through a specified directory listing all the files and folders in with indent.
# used to generate file overview
import os
ignore_dirs = ['.git']
ignore_files = ['.env']
def path_tree(root, inner=0):
for dir in os.listdir(root):
# print("DIR: ", root, dirs, files)
@PaulleDemon
PaulleDemon / firestore_validation.md
Last active November 14, 2023 15:17
Google Firestore data validation

This is a gist for data validation for cloud firestore nosql db.

Code for validation

The function takes 2 parameter a datastructure and data, the datastructure that contains all the validation fields such as minlength, default, required etc, it is as show in the Example datastructure. The data is the data passed by user that will be validated

def clean_data(data_structure, data, update=False):

    """