MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / _TimerPeriodic

Class _TimerPeriodic

PySimpleGUI/PySimpleGUI.py:9711–9804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9709# ------------------------------------------------------------------------- #
9710
9711class _TimerPeriodic:
9712 id_counter = 1
9713 # Dictionary containing the active timers. Format is {id : _TimerPeriodic object}
9714 active_timers = {} # type: dict[int , _TimerPeriodic]
9715
9716 def __init__(self, window, frequency_ms, key=EVENT_TIMER, repeating=True):
9717 """
9718 :param window: The window to send events to
9719 :type window: Window
9720 :param frequency_ms: How often to send events in milliseconds
9721 :type frequency_ms: int
9722 :param repeating: If True then the timer will run, repeatedly sending events, until stopped
9723 :type repeating: bool
9724 """
9725 self.window = window
9726 self.frequency_ms = frequency_ms
9727 self.repeating = repeating
9728 self.key = key
9729 self.id = _TimerPeriodic.id_counter
9730 _TimerPeriodic.id_counter += 1
9731 self.start()
9732
9733 @classmethod
9734 def stop_timer_with_id(cls, timer_id):
9735 """
9736 Not user callable!
9737 :return: A simple counter that makes each container element unique
9738 :rtype:
9739 """
9740 timer = cls.active_timers.get(timer_id, None)
9741 if timer is not None:
9742 timer.stop()
9743
9744 @classmethod
9745 def stop_all_timers_for_window(cls, window):
9746 """
9747 Stops all timers for a given window
9748 :param window: The window to stop timers for
9749 :type window: Window
9750 """
9751 for timer in _TimerPeriodic.active_timers.values():
9752 if timer.window == window:
9753 timer.running = False
9754
9755 @classmethod
9756 def get_all_timers_for_window(cls, window):
9757 """
9758 Returns a list of timer IDs for a given window
9759 :param window: The window to find timers for
9760 :type window: Window
9761 :return: List of timer IDs for the window
9762 :rtype: List[int]
9763 """
9764 timers = []
9765 for timer in _TimerPeriodic.active_timers.values():
9766 if timer.window == window:
9767 timers.append(timer.id)
9768

Callers 1

timer_startMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected