<commit_before>import time, os, os.path
from distutils import spawn
from Tkinter import *
from RPi import GPIO
from random import randint
import USBDevice, Settings, Script, Output, Display, PhotoThread
#from PhotoThread import *

download_id = None

def quit(some_var):
	"""Beendet die App."""
	global root
	root.destroy()

def button_pressed(some_var=None):
	if Settings.WAIT_FOR_BUTTON_PRESS:
		Settings.WAIT_FOR_BUTTON_PRESS = False
		if Settings.ON_BUTTON_PRESS is not None:
			Output.debug("Button pressed. Running code")
			temp = Settings.ON_BUTTON_PRESS
			Settings.ON_BUTTON_PRESS = None
			cancel_run()
			temp()
		else:
			Output.debug("Button pressed, but Settings.ON_BUTTON_PRESS is None.")
	else:
		Output.debug("Button pressed, but we are not waiting for this event.")

def start_run(script):
	"""Starts a new run. Is called whenever someone pushes the button (when the script is waiting for it, of course)."""
	global filename_schema
	global download_id
	Settings.runs += 1
	download_id = ''.join(["%s" % randint(0, 9) for num in range(0, 8)])
	filename_schema = time.strftime("photos/%Y%m%d-%H%M%S---" + download_id + "---{}.jpg")
	Output.debug("start_run results: download_id=" + download_id + " filename_schema=" + filename_schema)
	script.next_step()

def cancel_run():
	try:
		Display.root().after_cancel(Settings.AFTER_ID)
	except Exception as e:
		pass
	Settings.AFTER_ID = None

def single_photo(some_var=None):
	cancel_run()
	Output.debug("single_photo started")
	call_photo_thread(1, is_temp_photo=True)
	Output.debug("call_photo_thread() returned")
	Display.root().after(500, show_single_photo)

def show_single_photo():
	if PhotoThread.photo_load_threads()[0].is_alive():
		Display.root().after(500, show_single_photo)
		return
	Display.show_single_photo()
	Output.debug("Display.show_single_photo() returned")
	Settings.WAIT_FOR_BUTTON_PRESS = True
	Settings.ON_BUTTON_PRESS = lambda: Settings.main_script.start()

def shutdown(some_var=None):
	os.system("sudo shutdown -h now")

def call_photo_thread(number, is_temp_photo=False):
	"""Tells PhotoThread to take a photo and waits for it to return."""<commit_msg>Small cleanup.<commit_after>import time, os, os.path
from distutils import spawn
from Tkinter import *
from RPi import GPIO
from random import randint
import USBDevice, Settings, Script, Output, Display, PhotoThread
#from PhotoThread import *

download_id = None

def quit(some_var):
	"""Beendet die App."""
	global root
	root.destroy()

def button_pressed(some_var=None):
	if Settings.WAIT_FOR_BUTTON_PRESS:
		Settings.WAIT_FOR_BUTTON_PRESS = False
		if Settings.ON_BUTTON_PRESS is not None:
			Output.debug("Button pressed. Running code")
			temp = Settings.ON_BUTTON_PRESS
			Settings.ON_BUTTON_PRESS = None
			cancel_run()
			temp()
		else:
			Output.debug("Button pressed, but Settings.ON_BUTTON_PRESS is None.")
	else:
		Output.debug("Button pressed, but we are not waiting for this event.")

def start_run(script):
	"""Starts a new run. Is called whenever someone pushes the button (when the script is waiting for it, of course)."""
	global filename_schema
	global download_id
	Settings.runs += 1
	download_id = ''.join(["%s" % randint(0, 9) for num in range(0, 8)])
	filename_schema = time.strftime("photos/%Y%m%d-%H%M%S---" + download_id + "---{}.jpg")
	Output.debug("start_run results: download_id=" + download_id + " filename_schema=" + filename_schema)
	script.next_step()

def cancel_run():
	try:
		Display.root().after_cancel(Settings.AFTER_ID)
	except Exception as e:
		pass
	Settings.AFTER_ID = None

def single_photo(some_var=None):
	cancel_run()
	Output.debug("single_photo started")
	call_photo_thread(1, is_temp_photo=True)
	Output.debug("call_photo_thread() returned")
	show_single_photo()

def show_single_photo():
	if PhotoThread.photo_load_threads()[0].is_alive():
		Output.debug("PLT is still running. Sleeping 0.5s before trying again.")
		Display.root().after(500, show_single_photo)
		return
	Display.show_single_photo()
	Output.debug("Display.show_single_photo() returned")
	Settings.WAIT_FOR_BUTTON_PRESS = True
	Settings.ON_BUTTON_PRESS = lambda: Settings.main_script.start()

def shutdown(some_var=None):
	os.system("sudo shutdown -h now")

def call_photo_thread(number, is_temp_photo=False):
	"""Tells PhotoThread to take a photo and waits for it to return."""
{'fraction_non_alphanumeric': 0.11672433679354094, 'fraction_numerical': 0.0057670126874279125, 'mean_word_length': 5.500749625187407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186335', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1431, 'n_words': 376}