示例#1
0
class TimerUi:
    """View"""
    def __init__(self, app):
        self.time_label = Label(app.root,
                                textvariable=app.time,
                                anchor=CENTER,
                                foreground='black',
                                background='lightgray',
                                font=('Helvetica', 60))
        self.time_label.pack(fill=BOTH, expand=True)

        validate_command = (app.root.register(self.check), '%P')
        self.entry = Spinbox(app.root,
                             from_=1,
                             to=MAX_COUNT,
                             textvariable=app.count_start,
                             validate='all',
                             validatecommand=validate_command)
        self.entry.pack(fill=X)
        self.entry.focus()

        buttons_frame = Frame(app.root)
        buttons_frame.pack(fill=X)
        self.start_button = Button(buttons_frame,
                                   text='Start',
                                   command=app.start_timer)
        self.stop_button = Button(buttons_frame,
                                  text='Stop',
                                  state=DISABLED,
                                  command=app.stop_timer)
        self.start_button.pack(side=LEFT, fill=X, expand=True)
        self.stop_button.pack(side=RIGHT, fill=X, expand=True)

    def check(self, new_val):
        return new_val.isdigit() and 1 <= int(new_val) <= MAX_COUNT

    def state_started(self):
        self.stop_button.config(state=NORMAL)
        self.start_button.config(state=DISABLED)
        self.entry.config(state=DISABLED)
        self.time_label.config(foreground='white', background='red')

    def state_stopped(self):
        self.stop_button.config(state=DISABLED)
        self.start_button.config(state=NORMAL)
        self.entry.config(state=NORMAL)
        self.time_label.config(foreground='black', background='lightgray')
示例#2
0
    def initialize_settings_ui(self):
        # Initializes resamples field
        resamples_label = Label(self, text="Resamples (affects recognition accuracy)")
        resamples_label.place(y=12.5, x=12.5)
        resamples_text = tk.StringVar()
        resamples_text.set(self.settings["resamples"])
        resamples_spin = Spinbox(self, from_=1, to=10, textvariable=resamples_text)
        resamples_spin.config(command=partial(self.save_settings, "resamples", lambda: int(resamples_text.get())))
        resamples_spin.place(y=37.5, x=12.5)
        separator1 = Separator(self, orient='horizontal')
        separator1.place(y=62.5, x=12.5, width=375, height=1)

        # Initializes tolerance field
        tolerance_label = Label(self, text="Face matching tolerance (lower is more strict)")
        tolerance_label.place(y=68.75, x=12.5)
        tolerance_text = tk.StringVar()
        tolerance_text.set(self.settings["tolerance"])
        tolerance_spin = Spinbox(self, from_=0, to=1, increment=0.1, textvariable=tolerance_text)
        tolerance_spin.config(command=partial(self.save_settings, "tolerance", lambda: float(tolerance_text.get())))
        tolerance_spin.place(y=93.75, x=12.5)
        separator2 = Separator(self, orient='horizontal')
        separator2.place(y=118.75, x=12.5, width=375, height=1)

        # Initializes track period field
        track_period_label = Label(self, text="Track period (the number of frames between each recognition)")
        track_period_label.place(y=125, x=12.5)
        track_period_text = tk.StringVar()
        track_period_text.set(self.settings["track_period"])
        track_period_spin = Spinbox(self, from_=1, to=30, textvariable=track_period_text)
        track_period_spin.config(command=partial(self.save_settings, "track_period", lambda: int(track_period_text.get())))
        track_period_spin.place(y=150, x=12.5)
        separator3 = Separator(self, orient='horizontal')
        separator3.place(y=175, x=12.5, width=375, height=1)

        # Initializes blur method field
        blur_method_label = Label(self, text="Blur method")
        blur_method_label.place(y=181.25, x=12.5)
        blur_method_text = tk.StringVar()
        blur_method_text.set(self.settings["blur_method"])
        blur_method_menu = Combobox(self, textvariable=blur_method_text, values=("pixelate", "blur", "blacken"))
        blur_method_text.trace('w', partial(self.save_settings, "blur_method", lambda: blur_method_text.get()))
        blur_method_menu.place(y=206.25, x=12.5)
        separator4 = Separator(self, orient='horizontal')
        separator4.place(y=231.25, x=12.5, width=375, height=1)

        # Initializes blur intensity field
        blur_intensity_label = Label(self, text="Blur intensity (filter size)")
        blur_intensity_label.place(y=237.5, x=12.5)
        blur_intensity_text = tk.StringVar()
        blur_intensity_text.set(self.settings["blur_intensity"])
        blur_intensity_spin = Spinbox(self, from_=1, to=30, textvariable=blur_intensity_text)
        blur_intensity_spin.config(command=partial(self.save_settings, "blur_intensity", lambda: int(blur_intensity_text.get())))
        blur_intensity_spin.place(y=262.5, x=12.5)
        separator5 = Separator(self, orient='horizontal')
        separator5.place(y=287.5, x=12.5, width=375, height=1)

        # Initializes display output field
        display_output_flag = tk.IntVar()
        display_output_flag.set(self.settings["display_output"])
        display_output_checkbox = tk.Checkbutton(self, text='Display output', variable=display_output_flag, onvalue=1, offvalue=0)
        display_output_checkbox.config(command=partial(self.save_settings, "display_output", lambda: display_output_flag.get()))
        display_output_checkbox.place(y=293.75, x=12.5)