Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@danieljfarrell
danieljfarrell / treeview_test.py
Last active April 26, 2022 02:36 — forked from nbassler/treeview_test.py
PyQt5 TreeView with QAbstractItemModel
"""
Reworked code based on
http://trevorius.com/scrapbook/uncategorized/pyqt-custom-abstractitemmodel/
Adapted to Qt5 and fixed column/row bug.
TODO: handle changing data.
"""
import sys
@danieljfarrell
danieljfarrell / DoubleSlider.py
Created April 1, 2019 07:30 — forked from dennis-tra/DoubleSlider.py
PyQt - QSlider for float or double values + tests
from PyQt5.QtWidgets import QSlider
class DoubleSlider(QSlider):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.decimals = 5
self._max_int = 10 ** self.decimals
super().setMinimum(0)
@danieljfarrell
danieljfarrell / async_slot.py
Created March 20, 2019 12:44 — forked from ericfrederich/async_slot.py
Example of using an asyncio coroutine as a Qt slot
import math
import sys
import asyncio
from functools import partial, wraps
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout, QProgressBar, QErrorMessage
from PyQt5.QtCore import Qt
from quamash import QEventLoop
import traceback
@danieljfarrell
danieljfarrell / reset_timer.py
Created January 28, 2019 12:27 — forked from aeroaks/reset_timer.py
Reset Timer in Python
from threading import Thread, Event, Timer
import time
def TimerReset(*args, **kwargs):
""" Global function for Timer """
return _TimerReset(*args, **kwargs)
class _TimerReset(Thread):
"""Call a function after a specified number of seconds:
@danieljfarrell
danieljfarrell / addColumn_PyTables.py
Created September 4, 2015 15:17 — forked from swarbhanu/addColumn_PyTables.py
Example showing how to add a column in PyTables
from tables import *
# Isolated the copying logic
def append_column(table, group, name, column):
"""Returns a copy of `table` with an empty `column` appended named `name`."""
description = table.description._v_colObjects.copy()
description[name] = column
copy = Table(group, table.name+"_copy", description)
NSPoint ConstrainPointInsideRect(CGPoint freePoint, NSRect boundaryRect)
{
//NSPoint constrainedViewPoint = DFConstrainPointToRect(viewPoint, boundaryRect);
// Make sure the handle cannot be dragged outside of the plot range
if (NSPointInRect(freePoint, boundaryRect)) {
return freePoint;
}
NSPoint cp = freePoint;
@danieljfarrell
danieljfarrell / multipass_beer_lambert.py
Created June 11, 2012 08:06 — forked from guyer/multipass_beer_lambert.py
Fipy: Beer-Lambert law with multiple reflections
# http://matforge.org/wd15/blog
from __future__ import division
from fipy import *
# Grid things
N = 1000
D = 1
dx = D / N
m = Grid1D(nx=N+1, dx=dx) + [[-dx/2.]]
I_right = CellVariable(mesh=m, value=1., name='I_right') # Intensity along the positive direction