Skip to content

Instantly share code, notes, and snippets.

@saleph
saleph / centering.py
Last active August 8, 2022 05:20
[qt5] center a window on screen
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
@saleph
saleph / tetris.py
Created September 5, 2015 20:38
[qt5] tetris game - in one file
import sys, random
from PyQt5.QtWidgets import (QMainWindow, QFrame,
QDesktopWidget, QApplication)
from PyQt5.QtCore import Qt, QBasicTimer, pyqtSignal
from PyQt5.QtGui import QPainter, QColor
class Tetris(QMainWindow):
def __init__(self):
super().__init__()
@saleph
saleph / grid_layout.py
Created August 26, 2015 15:13
[qt5] grid layout - calculator skeleton
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import (QWidget, QGridLayout,
QPushButton, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
@saleph
saleph / msgbox.py
Last active November 3, 2019 13:09
[qt5] handling close event - msg box
__author__ = "tom"
import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
//sharedmemory.h
#ifndef SHAREDMEMORY_H
#define SHAREDMEMORY_H
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyAMA0"
@saleph
saleph / printfloat.c
Last active December 15, 2016 17:46
A function printing float to char* buffer without using %f. Excellent for arduino projects purpose. Fully SIGSEGV-prone. Enjoy!
#include <stdio.h>
/// Prints float to buffer without using %f (for microcontrollers purpose)
///
/// Usage:
/// char buffer[20];
/// printFloatToBuffer(buffer, 20, -3.1415, 3);
/// printf("%s", buffer);
///
void printFloatToBuffer(char *buffer, size_t bufferSize, float val, unsigned int precision) {
@saleph
saleph / CMakeLists.txt
Created October 14, 2016 09:33
cmake for boost tests
project(simple_tests)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_definitions(-DBOOST_TEST_DYN_LINK)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
@saleph
saleph / slider.py
Created September 5, 2015 08:16
[qt5] slider - volume contorl
import sys
from PyQt5.QtWidgets import (QWidget, QSlider,
QLabel, QApplication)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
class Example(QWidget):
def __init__(self):
super().__init__()
@saleph
saleph / closing.py
Last active March 25, 2016 18:34
[qt5] signals - quiting
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
class Example(QWidget):
def __init__(self):
super().__init__()