Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.12.2 #542

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
---------

8.12.2
------
* bugfix: rollback skipping of bpod initialization (possible source of integer overflow)
* removal of dead code

8.12.1
------
* bugfix: remember ability for setting the status LED
Expand Down
2 changes: 1 addition & 1 deletion iblrig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 3) Check CI and eventually wet lab test
# 4) Pull request to iblrigv8
# 5) git tag the release in accordance to the version number below (after merge!)
__version__ = '8.12.1'
__version__ = '8.12.2'

# The following method call will try to get post-release information (i.e. the number of commits since the last tagged
# release corresponding to the one above), plus information about the state of the local repository (dirty/broken)
Expand Down
5 changes: 2 additions & 3 deletions iblrig/base_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

import iblrig
import iblrig.path_helper
from iblutil.spacer import Spacer
from iblutil.util import Bunch, setup_logger
from iblrig.hardware import Bpod, MyRotaryEncoder, sound_device_factory, SOFTCODE
import iblrig.frame2TTL as frame2TTL
import iblrig.sound as sound
import iblrig.spacer
import iblrig.alyx
import iblrig.graphic as graph
import ibllib.io.session_params as ses_params
Expand Down Expand Up @@ -699,8 +699,7 @@ def softcode_handler(code):
def send_spacers(self):
self.logger.info("Starting task by sending a spacer signal on BNC1")
sma = StateMachine(self.bpod)
spacer = iblrig.spacer.Spacer()
spacer.add_spacer_states(sma, next_state="exit")
Spacer().add_spacer_states(sma, next_state="exit")
self.bpod.send_state_machine(sma)
self.bpod.run_state_machine(sma) # Locks until state machine 'exit' is reached
return self.bpod.session.current_trial.export()
Expand Down
179 changes: 0 additions & 179 deletions iblrig/graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
Popup and string input prompts
"""
import tkinter as tk
from tkinter import messagebox
from tkinter import simpledialog


def popup(title, msg):
root = tk.Tk()
root.withdraw()
messagebox.showinfo(title, msg)
root.quit()


def numinput(title, prompt, default=None, minval=None, maxval=None, nullable=False, askint=False):
root = tk.Tk()
root.withdraw()
Expand All @@ -36,174 +28,3 @@ def numinput(title, prompt, default=None, minval=None, maxval=None, nullable=Fal
askint=askint,
)
return ans


def strinput(title, prompt, default="COM", nullable=False):
"""
Example:
>>> strinput("RIG CONFIG", "Insert RE com port:", default="COM")
"""
import tkinter as tk
from tkinter import simpledialog

root = tk.Tk()
root.withdraw()
ans = simpledialog.askstring(title, prompt, initialvalue=default)
if (ans is None or ans == "" or ans == default) and not nullable:
return strinput(title, prompt, default=default, nullable=nullable)
else:
return ans


def login(
title="Enter Credentials", default_username=None, default_passwd=None, add_fields=None,
):
"""
Dialog box prompting for username and password.

:param title: Window title
:param default_username: default field for username
:param default_passwd: default field for password
:param add_fields: list of new fields to be added to the dialog
:return:
"""

class Toto:
def __init__(
self, root, default_username=None, default_passwd=None, title=None, add_fields=None,
):
self.add_fields = add_fields or []
self.var1 = tk.StringVar()
self.root = root
# self.root.geometry('300x160')
self.root.title(title)
# frame for window margin
self.parent = tk.Frame(self.root, padx=10, pady=10)
self.parent.pack(fill=tk.BOTH, expand=True)
# entrys with not shown text
self.add_entries = []
for fname in self.add_fields:
self.add_entries.extend([self.make_entry(self.parent, fname + ":", 42, show="")])

self.user = self.make_entry(
self.parent, "User name:", 42, show="", default=default_username
)
self.password = self.make_entry(
self.parent, "Password:", 42, show="*", default=default_passwd
)
# button to attempt to login
self.button = tk.Button(
self.parent, borderwidth=4, text="Login", width=42, pady=8, command=self.get_value,
)
self.button.pack(side=tk.BOTTOM)
self.user.focus_set()
self.USR = None
self.MDP = None
self.root.bind("<Return>", self.push_enter)
# do not reproduce vim behaviour
self.root.protocol("WM_DELETE_WINDOW", self.cancel_login)

def make_entry(self, _, caption, width=None, default="", **options):
tk.Label(self.parent, text=caption).pack(side=tk.TOP)
entry = tk.Entry(self.parent, **options)
if width:
entry.config(width=width)
entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
if default:
entry.insert(0, default)
return entry

def push_enter(self, _):
self.get_value()

def get_value(self):
self.USR = self.user.get()
self.MDP = self.password.get()
self.ADD = []
for entry in self.add_entries:
self.ADD.extend([entry.get()])
self.root.destroy()
self.root.quit()

def cancel_login(self):
self.USR = None
self.MDP = None
self.ADD = []
for entry in self.add_entries:
self.ADD.extend([None])
self.root.destroy()
self.root.quit()

root = tk.Tk()
toto = Toto(
root,
title=title,
default_passwd=default_passwd,
default_username=default_username,
add_fields=add_fields,
)
root.mainloop()
return [toto.USR] + [toto.MDP] + toto.ADD


def multi_input(title="Enter Credentials", add_fields=None, defaults=None):
class Toto:
def __init__(self, root, title=None, add_fields=None, defaults=None):
self.fields_to_add = add_fields or []
if defaults is None or len(defaults) != len(add_fields):
self.defaults = [None for x in self.fields_to_add]
else:
self.defaults = defaults
self.var1 = tk.StringVar()
self.root = root
# self.root.geometry('300x160')
self.root.title(title)
# frame for window margin
self.parent = tk.Frame(self.root, padx=10, pady=10)
self.parent.pack(fill=tk.BOTH, expand=True)
# entrys with not shown text
self.add_entries = []
for fname, fdef in zip(self.fields_to_add, self.defaults):
self.add_entries.extend(
[self.make_entry(self.parent, fname + ":", 42, show="", default=fdef)]
)
# button to attempt to login
self.button = tk.Button(
self.parent, borderwidth=4, text="Submit", width=42, pady=8, command=self.get_value,
)
self.button.pack(side=tk.BOTTOM)
self.root.bind("<Return>", self.push_enter)
# do not reproduce vim behaviour
self.root.protocol("WM_DELETE_WINDOW", self.cancel_login)

def make_entry(self, _, caption, width=None, default="", **options):
tk.Label(self.parent, text=caption).pack(side=tk.TOP)
entry = tk.Entry(self.parent, **options)
if width:
entry.config(width=width)
entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
if default:
entry.insert(0, default)
return entry

def push_enter(self, _):
self.get_value()

def get_value(self):
self.ADD = []
for entry in self.add_entries:
self.ADD.extend([entry.get()])
self.root.destroy()
self.root.quit()

def cancel_login(self):
self.ADD = []
for entry in self.add_entries:
self.ADD.extend([None])
self.root.destroy()
self.root.quit()

root = tk.Tk()
toto = Toto(root, title=title, add_fields=add_fields, defaults=defaults)
root.mainloop()
return toto.ADD
9 changes: 5 additions & 4 deletions iblrig/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def __new__(cls, *args, **kwargs):
return instance

def __init__(self, *args, **kwargs):
# skip initialization if it has already been performed before
if self._is_initialized:
return
# # skip initialization if it has already been performed before
# if self._is_initialized:
# return

# try to instantiate once for nothing
try:
Expand Down Expand Up @@ -191,7 +191,8 @@ def set_status_led(self, state: bool) -> bool:
return True
except serial.SerialException:
pass
self._arcom.serial_object.flush()
self._arcom.serial_object.reset_input_buffer()
self._arcom.serial_object.reset_output_buffer()
log.error('Bpod device does not support control of the status LED. Please update firmware.')
return False

Expand Down
Loading