Skip to content

Instantly share code, notes, and snippets.

View MaurizioB's full-sized avatar

MaurizioB

View GitHub Profile
@MaurizioB
MaurizioB / miditokeypress
Created January 4, 2018 23:22
Simple MIDI note to keyboard event
#!/usr/bin/env python2.7
from mididings import *
config(
client_name='MidiKeyPress',
in_ports = [('Mixer', 'USB Midi 4i4o:.*MIDI 1')],
out_ports = 0,
)
@MaurizioB
MaurizioB / mididingsSceneCallback.py
Created February 9, 2018 17:56
Mididings scene switch callback
#!/usr/bin/env python
'''
Two alternatives for scene switch callback.
1. Using a custom made Hook() object, which responds only *after* a scene
change has been made. This means that if a scene switch request contains
a non existing scene/subscene, nothing happens.
2. Rewriting the private Engine.scene_switch_callback function, which
intercepts scene switch requests and can do some further actions before
the change is actually made.
@MaurizioB
MaurizioB / midi_timings.py
Created August 30, 2018 23:20
Timing of MIDI events in seconds
#!/usr/bin/env python2.7
import sys
import midi
def getTempoMap(pattern, maxTick=None):
#create a first tempo (default to 120, if there is no tempo event)
tempoMap = [[0, .5 / pattern.resolution]]
lastTick = 0
for track in pattern:
'''
Different ways to doSomething(row, column) based on the clicked button
'''
class GuiBase(QtWidgets.QWidget):
def doSomething(self, row, column):
print(row, column)
'''
@MaurizioB
MaurizioB / slices.py
Last active May 27, 2020 00:13
Equally slice splitt a list based on step
def getSlices(l, step):
# stepCount, rest = divmod(len(l) - 1, step)
rest = (len(l) - 1) % step
if not rest:
return l[::step]
stepCount = len(l) // (rest + 1)
indexes = [0]
maxIndex = len(l)
i = 0
# maybe done = step for short/odd lists?
@MaurizioB
MaurizioB / grabtest.py
Created June 13, 2020 17:17
Click based screen grab workaround for systems not supporting Qt mouseGrab()
from PyQt5 import QtCore, QtGui, QtWidgets
class FakeCursor(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.ToolTip)
self.setFixedSize(16, 16)
path = QtGui.QPainterPath()
path.moveTo(0, 8)
@MaurizioB
MaurizioB / pianokbmap.json
Created February 10, 2021 20:53
Qt piano keyboard
{
"be": {
"basic": {
"name": "Belgian",
"include": ["latin","level3.ralt_switch"],
"keys": {
"0": {
"0": "w",
"6": ",",
"7": ";",
@MaurizioB
MaurizioB / simpledial.py
Last active June 11, 2021 13:57
Simple QDial subclass with paint event override
from PyQt5 import QtCore, QtGui, QtWidgets
class SimpleDial(QtWidgets.QDial):
def paintEvent(self, event):
# create a QStyleOption for the dial, and initialize it with the basic properties
# that will be used for the configuration of the painter
opt = QtWidgets.QStyleOptionSlider()
self.initStyleOption(opt)
# construct a QRectF that uses the minimum between width and height,
@MaurizioB
MaurizioB / movecolumntest.py
Created June 12, 2021 00:21
QAbstractTableModel item selection odd behavior when moving columns
try:
from PySide2 import QtCore, QtWidgets
print(QtCore.__version__)
except:
from PyQt5 import QtCore, QtWidgets
print(QtCore.QT_VERSION_STR)
class Model(QtCore.QAbstractTableModel):
def __init__(self,):
super().__init__()
@MaurizioB
MaurizioB / gist:faedf525b4beb8910d3d25ebff66b984
Created July 17, 2021 16:22
QPushButton with embedded QLabel
from PyQt5 import QtWidgets
import sys
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
mainLayout = QtWidgets.QGridLayout(window)
labels = []
for r in range(3):
for c in range(4):
button = QtWidgets.QPushButton()