-
Notifications
You must be signed in to change notification settings - Fork 8
/
QDSpy_GUI_support.py
102 lines (84 loc) · 3.54 KB
/
QDSpy_GUI_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
QDSpy module - support routines for the GUI version of QDSpy
Copyright (c) 2013-2024 Thomas Euler
All rights reserved.
2024-06-19 - Ported from `PyQt5` to `PyQt6`
- Reformatted (using Ruff)
"""
# ---------------------------------------------------------------------
__author__ = "[email protected]"
import os
from datetime import datetime
from PyQt6 import QtCore, QtGui
import QDSpy_global as glo
# ---------------------------------------------------------------------
def getStimFileLists(_path):
""" Make a list of the stimulus files (including path) present in the
given path
"""
f = []
stimFNames = []
for dirpath, dirnames, filenames in os.walk(_path):
f.extend(filenames)
break
for fName in f:
if (os.path.splitext(fName)[1]).lower() == glo.QDSpy_stimFileExt:
fName = (os.path.splitext(os.path.basename(fName)))[0]
stimFNames.append(os.path.join(_path, fName))
return stimFNames
# ---------------------------------------------------------------------
def getFNameNoExt(_fName):
""" Extract just file name, no path nor extension
"""
return (os.path.splitext(os.path.basename(_fName)))[0]
# ---------------------------------------------------------------------
def getStimCompileState(_fName):
""" Check if pickle-file is current
"""
fName = os.path.splitext(_fName)[0]
try:
tStamp = os.path.getmtime(fName + glo.QDSpy_stimFileExt)
tPy = datetime.fromtimestamp(tStamp)
tStamp = os.path.getmtime(fName + glo.QDSpy_cPickleFileExt)
tPck = datetime.fromtimestamp(tStamp)
return tPck > tPy
except WindowsError:
pass
return False
# ---------------------------------------------------------------------
def getStimExists(_fName):
""" Check if stimulus file (.py) exists
"""
return os.path.isfile(_fName + glo.QDSpy_stimFileExt)
# ---------------------------------------------------------------------
def getShortText(_win, _txt, _widget):
metrics = QtGui.QFontMetrics(_win.font())
return metrics.elidedText(_txt, QtCore.Qt.TextElideMode.ElideRight, _widget.width())
# ---------------------------------------------------------------------
def getLEDGUIObjects(_this, _LED):
if (_LED["LEDIndex"] == 0) and (_LED["devIndex"] == 0):
return [_this.spinBoxLED1, _this.label_LED1, _this.pushButtonLED1]
elif (_LED["LEDIndex"] == 1) and (_LED["devIndex"] == 0):
return [_this.spinBoxLED2, _this.label_LED2, _this.pushButtonLED2]
elif (_LED["LEDIndex"] == 2) and (_LED["devIndex"] == 0):
return [_this.spinBoxLED3, _this.label_LED3, _this.pushButtonLED3]
elif (_LED["LEDIndex"] == 0) and (_LED["devIndex"] == 1):
return [_this.spinBoxLED4, _this.label_LED4, _this.pushButtonLED4]
elif (_LED["LEDIndex"] == 1) and (_LED["devIndex"] == 1):
return [_this.spinBoxLED5, _this.label_LED5, _this.pushButtonLED5]
elif (_LED["LEDIndex"] == 2) and (_LED["devIndex"] == 1):
return [_this.spinBoxLED6, _this.label_LED6, _this.pushButtonLED6]
else:
return [None] * 3
# ---------------------------------------------------------------------
def updateToggleButton(_btn, _txtList=["on", "off"]):
s = _btn.text().split("\n")
f = _btn.isChecked()
if len(s) == 1:
s = "{0}".format(_txtList[0] if f else _txtList[1])
else:
s = "{0}\n{1}".format(s[0], _txtList[0] if f else _txtList[1])
_btn.setText(s)
# ---------------------------------------------------------------------