MultiTaskBattery 1.4.4__tar.gz → 1.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/__init__.py +1 -1
  2. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/gamepad.py +31 -18
  3. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/PKG-INFO +1 -1
  4. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/PKG-INFO +1 -1
  5. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/LICENSE +0 -0
  6. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/battery.py +0 -0
  7. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/experiment_block.py +0 -0
  8. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/fetch.py +0 -0
  9. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/screen.py +0 -0
  10. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/task_blocks.py +0 -0
  11. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/task_details.json +0 -0
  12. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/task_file.py +0 -0
  13. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/task_table.tsv +0 -0
  14. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/ttl_clock.py +0 -0
  15. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery/utils.py +0 -0
  16. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/SOURCES.txt +0 -0
  17. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/dependency_links.txt +0 -0
  18. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/entry_points.txt +0 -0
  19. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/requires.txt +0 -0
  20. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/MultiTaskBattery.egg-info/top_level.txt +0 -0
  21. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/README.md +0 -0
  22. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/pyproject.toml +0 -0
  23. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/setup.cfg +0 -0
  24. {multitaskbattery-1.4.4 → multitaskbattery-1.4.5}/tests/test_tasks.py +0 -0
@@ -6,4 +6,4 @@ import os
6
6
  # PsychoPy imports pygame when it is installed (MTB needs it for gamepads): hide its banner
7
7
  os.environ.setdefault('PYGAME_HIDE_SUPPORT_PROMPT', '1')
8
8
 
9
- __version__ = "1.4.4"
9
+ __version__ = "1.4.5"
@@ -9,11 +9,12 @@ in the same order::
9
9
  A press of X then counts as the key '1', Y as '2', and so on, wherever MTB reads a
10
10
  response. The keyboard keeps working. Without ``gamepad_buttons`` nothing changes.
11
11
 
12
- A button is a name (A, B, X, Y, START, LEFTSHOULDER, DPAD_UP, ...) for a pad SDL
13
- knows (Xbox, PlayStation, 8BitDo). A pad SDL does not know is taken to be a Current
14
- Designs GMPD3 (on a 932 in joystick mode): its face buttons answer to A, B, X and Y,
15
- by where they sit on an Xbox pad. For any other pad, give raw
16
- button numbers instead, e.g. [0, 1, 2, 3].
12
+ A button is a name (A, B, X, Y, START, LEFTSHOULDER, LEFTTRIGGER, DPAD_UP, ...) for a
13
+ pad SDL knows (Xbox, PlayStation, 8BitDo); a trigger counts as pressed once pulled past
14
+ half way. A pad SDL does not know is taken to be a Current Designs GMPD3 (on a 932 in
15
+ joystick mode): its face buttons answer to A, B, X and Y and its index-finger buttons
16
+ to LEFTTRIGGER and RIGHTTRIGGER, by where they sit on an Xbox pad. For any other pad,
17
+ give raw button numbers instead, e.g. [0, 1, 2, 3].
17
18
 
18
19
  The pad is polled, not buffered: a press counts when MTB looks for responses, and
19
20
  presses made while it is not looking are dropped, as event.clearEvents() drops keys.
@@ -22,14 +23,18 @@ import os
22
23
 
23
24
  from psychopy import event, core
24
25
 
25
- _keys = {} # button -> response key
26
- _held = set() # buttons down at the last poll
26
+ _keys = {} # ('button' or 'axis', number) -> response key
27
+ _held = set() # entries of _keys down at the last poll
27
28
  _pad = None # the opened pygame controller or joystick
28
29
  _named = False # True: buttons are SDL names, False: raw numbers
29
30
 
30
- # Current Designs GMPD3 (932 in joystick mode): SDL's raw button number of each face
31
- # button, named by where it sits on an Xbox pad.
32
- GMPD3_BUTTONS = {'Y': 0, 'B': 1, 'X': 2, 'A': 4}
31
+ # Current Designs GMPD3 (932 in joystick mode): SDL's raw button number of each button,
32
+ # named by where it sits on an Xbox pad (its triggers are plain buttons)
33
+ GMPD3_BUTTONS = {'Y': 0, 'B': 1, 'X': 2, 'LEFTTRIGGER': 3, 'A': 4, 'RIGHTTRIGGER': 5}
34
+
35
+ # Triggers on a pad SDL knows are axes (0 released to 32767 fully pulled)
36
+ TRIGGERS = {'LEFTTRIGGER': 'CONTROLLER_AXIS_TRIGGERLEFT', 'RIGHTTRIGGER': 'CONTROLLER_AXIS_TRIGGERRIGHT'}
37
+ TRIGGER_DOWN = 16384 # pulled past half way counts as pressed
33
38
 
34
39
 
35
40
  def setup(const):
@@ -52,32 +57,34 @@ def setup(const):
52
57
  controller.init()
53
58
  _named = all(isinstance(b, str) for b in buttons)
54
59
  names = [b.upper() for b in buttons] if _named else []
55
- unknown = [b for b in names if not hasattr(pygame, f'CONTROLLER_BUTTON_{b}')]
60
+ unknown = [b for b in names if b not in TRIGGERS and not hasattr(pygame, f'CONTROLLER_BUTTON_{b}')]
56
61
  if unknown:
57
62
  raise ValueError(f"Unknown gamepad button(s) {unknown}: use A, B, X, Y, START, BACK, "
58
- f"LEFTSHOULDER, RIGHTSHOULDER, DPAD_UP, DPAD_DOWN, DPAD_LEFT or DPAD_RIGHT.")
63
+ f"LEFTSHOULDER, RIGHTSHOULDER, LEFTTRIGGER, RIGHTTRIGGER, DPAD_UP, DPAD_DOWN, "
64
+ f"DPAD_LEFT or DPAD_RIGHT.")
59
65
  if pygame.joystick.get_count() == 0:
60
66
  raise RuntimeError("gamepad_buttons is set in constants.py but no gamepad is plugged in. "
61
67
  "Plug it in, or remove gamepad_buttons to use the keyboard only.")
62
68
 
63
69
  if _named and controller.is_controller(0):
64
70
  _pad = controller.Controller(0)
65
- ids = [getattr(pygame, f'CONTROLLER_BUTTON_{b}') for b in names]
71
+ ids = [('axis', getattr(pygame, TRIGGERS[b])) if b in TRIGGERS
72
+ else ('button', getattr(pygame, f'CONTROLLER_BUTTON_{b}')) for b in names]
66
73
  elif _named:
67
74
  # no SDL names: read it as a GMPD3, whose raw buttons sit where an Xbox pad's do
68
75
  name = pygame.joystick.Joystick(0).get_name()
69
76
  missing = [b for b in names if b not in GMPD3_BUTTONS]
70
77
  if missing:
71
78
  raise RuntimeError(f"The gamepad '{name}' has no SDL button names and is read as a "
72
- f"Current Designs GMPD3, which has only A, B, X and Y, not {missing}. "
79
+ f"Current Designs GMPD3, which has only A, B, X, Y, LEFTTRIGGER and RIGHTTRIGGER, not {missing}. "
73
80
  f"For another pad, give its raw button numbers instead, e.g. [0, 1, 2, 3].")
74
81
  _pad = pygame.joystick.Joystick(0)
75
82
  _named = False
76
- ids = [GMPD3_BUTTONS[b] for b in names]
83
+ ids = [('button', GMPD3_BUTTONS[b]) for b in names]
77
84
  print(f"Gamepad '{name}' has no SDL button names: reading it as a Current Designs GMPD3.")
78
85
  elif all(isinstance(b, int) for b in buttons):
79
86
  _pad = pygame.joystick.Joystick(0)
80
- ids = list(buttons)
87
+ ids = [('button', b) for b in buttons]
81
88
  else:
82
89
  raise ValueError("gamepad_buttons must be all names (e.g. ['X', 'Y', 'A', 'B']) "
83
90
  "or all numbers (e.g. [0, 1, 2, 3]), not a mix.")
@@ -96,11 +103,17 @@ def close():
96
103
  _held.clear()
97
104
 
98
105
 
106
+ def _is_down(control):
107
+ """True while this ('button' or 'axis', number) is pressed."""
108
+ kind, n = control
109
+ return _pad.get_axis(n) > TRIGGER_DOWN if kind == 'axis' else bool(_pad.get_button(n))
110
+
111
+
99
112
  def _poll():
100
113
  """Returns the response keys of the buttons pressed since the last poll."""
101
114
  import pygame
102
115
  pygame.event.pump()
103
- down = {b for b in _keys if _pad.get_button(b)}
116
+ down = {b for b in _keys if _is_down(b)}
104
117
  pressed = down - _held
105
118
  _held.clear()
106
119
  _held.update(down)
@@ -141,4 +154,4 @@ def is_held(key):
141
154
  return False
142
155
  import pygame
143
156
  pygame.event.pump()
144
- return any(_pad.get_button(b) for b, k in _keys.items() if k == key)
157
+ return any(_is_down(b) for b, k in _keys.items() if k == key)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MultiTaskBattery
3
- Version: 1.4.4
3
+ Version: 1.4.5
4
4
  Summary: A flexible Python toolbox for running multi-domain cognitive and motor tasks during fMRI sessions, built on PsychoPy.
5
5
  Author: Diedrichsenlab
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MultiTaskBattery
3
- Version: 1.4.4
3
+ Version: 1.4.5
4
4
  Summary: A flexible Python toolbox for running multi-domain cognitive and motor tasks during fMRI sessions, built on PsychoPy.
5
5
  Author: Diedrichsenlab
6
6
  License-Expression: MIT