Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

indexable graphic attributes #78

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

Merged
merged 11 commits into from
Dec 23, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
warning if event handlers already registered or has weird argspec
  • Loading branch information
kushalkolar committed Dec 22, 2022
commit 22f72834da5fd3d66205c54b572676ca51ae18e3
12 changes: 11 additions & 1 deletion 12 fastplotlib/graphics/features/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC, abstractmethod
from inspect import getfullargspec
from warnings import warn
from typing import *

import numpy as np
Expand Down Expand Up @@ -63,6 +64,11 @@ def add_event_handler(self, handler: callable):
"""
if not callable(handler):
raise TypeError("event handler must be callable")

if handler in self._event_handlers:
warn(f"Event handler {handler} is already registered.")
return

self._event_handlers.append(handler)

#TODO: maybe this can be implemented right here in the base class
Expand All @@ -73,7 +79,11 @@ def _feature_changed(self, key: Union[int, slice, Tuple[slice]], new_data: Any):

def _call_event_handlers(self, event_data: FeatureEvent):
for func in self._event_handlers:
if len(getfullargspec(func).args) > 0:
try:
if len(getfullargspec(func).args) > 0:
func(event_data)
except:
warn(f"Event handler {func} has an unresolvable argspec, trying it anyways.")
func(event_data)
else:
func()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.