3030from matplotlib .cbook import is_sequence_of_strings
3131import matplotlib .lines as mlines
3232
33+ import warnings
34+
3335
3436class BlockingInput (object ):
3537 """
@@ -38,8 +40,8 @@ class BlockingInput(object):
3840 """
3941 def __init__ (self , fig , eventslist = ()):
4042 self .fig = fig
41- assert is_sequence_of_strings (
42- eventslist ), "Requires a sequence of event name strings"
43+ if not is_sequence_of_strings (eventslist ):
44+ raise ValueError ( "Requires a sequence of event name strings" )
4345 self .eventslist = eventslist
4446
4547 def on_event (self , event ):
@@ -95,7 +97,8 @@ def __call__(self, n=1, timeout=30):
9597 Blocking call to retrieve n events
9698 """
9799
98- assert isinstance (n , int ), "Requires an integer argument"
100+ if not isinstance (n , int ):
101+ raise ValueError ("Requires an integer argument" )
99102 self .n = n
100103
101104 self .events = []
@@ -146,9 +149,9 @@ def post_event(self):
146149 """
147150 This will be called to process events
148151 """
149- assert len (self .events ) > 0 , "No events yet"
150-
151- if self .events [- 1 ].name == 'key_press_event' :
152+ if len (self .events ) <= 0 :
153+ warnings . warn ( "No events yet" )
154+ elif self .events [- 1 ].name == 'key_press_event' :
152155 self .key_event ()
153156 else :
154157 self .mouse_event ()
@@ -359,9 +362,10 @@ def post_event(self):
359362 """
360363 Determines if it is a key event
361364 """
362- assert len (self .events ) > 0 , "No events yet"
363-
364- self .keyormouse = self .events [- 1 ].name == 'key_press_event'
365+ if len (self .events ) <= 0 :
366+ warnings .warn ("No events yet" )
367+ else :
368+ self .keyormouse = self .events [- 1 ].name == 'key_press_event'
365369
366370 def __call__ (self , timeout = 30 ):
367371 """
0 commit comments