Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@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 / test_traitsui_quamash.py
Last active February 22, 2020 13:31
An example of asynchronous programming with TraitsUI using QT5 backend with Quamash event loop to work with asyncio.
"""
This code was helpful,
https://stackoverflow.com/questions/32141623/pyqt5-and-asyncio-yield-from-never-finishes
"""
import os
import sys
import quamash
import asyncio
import traceback
import PyQt5
@danieljfarrell
danieljfarrell / environment.yml
Created January 11, 2019 16:41
Conda environment
name: asyncstuff
channels:
- defaults
- krisvanneste
- david_baddeley
- conda-forge
- danieljfarrell_teraview
- teraview
- pkgs/main
- pkgs/free
@danieljfarrell
danieljfarrell / parse_iso8601_badly.py
Created January 5, 2017 15:18
Cheap and cheerful parser for iso8601 with zero flexibility.
import datetime
import time
now = datetime.datetime.now()
now_iso = now.isoformat()
def parse_iso8601_badly(iso_str):
date_str, time_str = iso_str.split('T')
d = dict()
d.update(zip(['hour', 'minute', 'second'],
@danieljfarrell
danieljfarrell / tree_editor_multiple_selection.py
Created October 24, 2016 10:14
tree_editor_multiple_selection.py -- Example of a tree editor demonstrating multiple selection
# tree_editor.py -- Example of a tree editor
from traits.api \
import HasTraits, Str, Regex, List, Instance, Any, Property
from traitsui.api \
import TreeEditor, TreeNode, View, Item, VSplit, \
HGroup, Handler, Group, ModelView
from traitsui.menu \
import Menu, Action, Separator
from traitsui.wx.tree_editor \
@danieljfarrell
danieljfarrell / experimental_filtering.py
Created April 19, 2016 15:33
Experimental reference filtering.
def remove_reference_signal_with_experimental_reference_method_with_extended_FFT(
signal,
reference,
optical_delay_spacing,
ref_calibration=None):
"""Removes reference signal using extended FFT method."""
# transform reference signal to frequency domain
t_points = reference.shape[0]
ref_spec = np.fft.rfft(reference, reference.shape[0]*2)
signal_spec = np.fft.rfft(signal, signal.shape[0]*2)
@danieljfarrell
danieljfarrell / make_frequency_information.py
Created April 19, 2016 15:24
APS make_frequency_information function.
def make_frequency_information(self):
"""NB kUseNewFFTMethod = True for MATLAB algorithm."""
reference = self.measurement.reference
if len(reference) > 1:
dt = self.measurement.optical_delay_spacing
t_offset = self.measurement.optical_delay_offset
f_max = 1./(2*dt)
if kUseNewFFTMethod:
freq = np.linspace(0.0, f_max, len(reference) + 1)
else:
@danieljfarrell
danieljfarrell / run_test_robot.py
Created March 29, 2016 11:54
Reading/writing stdout/stdin
import os, psutil, subprocess
# Usage:
# This script MUST be run from the root of the
# teraview-test-robot directory for example using,
# python run_test_robot_cmd.py
def make_test_robot_process():
"""Creates the test robot process."""
REL_TEST_ROBOT_EXE = "bin\\Debug\\test-robot.exe"