<commit_before># TkApplication class.  Brings together the Tk GUI functionality, the Scheduler and the BrickPi wrapper.
# Applications using the BrickPi derive from this, implementing appropriate functionality.


import Tkinter as tk

from BrickPiWrapper import *
from Motor import *


# TODO: How to stop two coroutines running at once on the same port?

# Main application class.  I'm not usually keen on multiple inheritance, but it makes using it much simpler.


class TkApplication(BrickPiWrapper):

    # Parameter: Configuration, e.g. {PORT_1: TYPE_SENSOR_ULTRASONIC_CONT } as passed to BrickPiWrapper
    def __init__(self, sensorConfiguration):
        BrickPiWrapper.__init__(self, sensorConfiguration )
        self.root = tk.Tk()
        self.root.geometry('300x200')
        self.pidSetting = PIDSetting()
        self.label = tk.Label(text="BrickPi")
        self.label.pack()
        self.timerTick()
        self.root.bind('<KeyPress>', self.onKeyPress)

        self.addUpdateCoroutine( self.updaterCoroutine() )

    # The main loop for the application - call this after initialisation.  Returns on exit.
    def mainloop(self):
        self.root.mainloop()

    # Private: Does all the coroutine processing, every 20ms or so.
    def timerTick(self):<commit_msg>CW: Refactored arbitrary TkApplication initialization into separate method.<commit_after># TkApplication class.  Brings together the Tk GUI functionality, the Scheduler and the BrickPi wrapper.
# Applications using the BrickPi derive from this, implementing appropriate functionality.


import Tkinter as tk

from BrickPiWrapper import *
from Motor import *


# TODO: How to stop two coroutines running at once on the same port?

# Main application class.  I'm not usually keen on multiple inheritance, but it makes using it much simpler.


class TkApplication(BrickPiWrapper):

    # Parameter: Configuration, e.g. {PORT_1: TYPE_SENSOR_ULTRASONIC_CONT } as passed to BrickPiWrapper
    def __init__(self, sensorConfiguration):
        BrickPiWrapper.__init__(self, sensorConfiguration )
        self.root = tk.Tk()

        self.doInitialization()

        self.pidSetting = PIDSetting()
        self.timerTick()
        self.addUpdateCoroutine( self.updaterCoroutine() )

    # Default initialization function with a simple window - override if you want something different
    def doInitialization(self):
        self.root.geometry('300x200')
        self.label = tk.Label(text="BrickPi")
        self.label.pack()
        self.root.bind('<KeyPress>', self.onKeyPress)


    # The main loop for the application - call this after initialisation.  Returns on exit.
    def mainloop(self):
        self.root.mainloop()

    # Private: Does all the coroutine processing, every 20ms or so.
    def timerTick(self):
{'fraction_non_alphanumeric': 0.07733619763694952, 'fraction_numerical': 0.00644468313641246, 'mean_word_length': 3.5357142857142856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1655503', 'n_tokens_mistral': 799, 'n_tokens_neox': 770, 'n_words': 266}