import kivy
import [Link] as kyProps
from [Link] import App
from [Link] import FloatLayout
from [Link] import Builder
from [Link] import Config
import time
import os
import shutil
from [Link] import Window
from [Link] import NumericProperty,StringProperty
from [Link] import Widget
from tkinter import filedialog
from [Link] import Clock
from model_api import load_model,predict_model_test,stop_model,predict_model
# ai model object
model = None
# loading kv language file
Builder.load_file('[Link]')
# disbaling touch screen emulation on mouse
[Link]("input","mouse","mouse,disable_multitouch")
class MyProgressBar(Widget):
set_value = NumericProperty(0)
# custom layout to hold all UI elements using a KV file for UI elements
class MyFloatLayout(FloatLayout):
progress_bar_value = NumericProperty(0)
error_file = StringProperty("")
# method for when start button is pressed
def start_press(self):
[Link].progress_bar_background.set_value += 10
if([Link].progress_bar_background.set_value > 100):
[Link].progress_bar_background.set_value = 0
self.progress_bar_value = [Link].progress_bar_background.set_value
# global model
# method for when stop button is pressed
def stop_press(self):
stop_model()
# # method for when change grade key button is pressed
# def change_key_button(self):
# key_file = [Link].grade_key_image.source
# # using tkinter to create a field dialog so it looks like default system
file explorer
# new_key_file = [Link](initialdir="/",
# title = "Select a new grade key",
# filetypes=(("PNG","*.png"),
# ("JPG","*.jpg"),
# ("JPEG","*.jpeg"),
# ("HEIC","*.heic"),
# ("All Files","*.*")))
# if(new_key_file is None):
# pass
# elif not (new_key_file.[Link](('.png','.jpg','.jpeg','.heic'))):
# self.error_file = 'TechTutor only accepts .png .jpeg .jpg or .heic
files'
# else:
# self.error_file = ''
# key_file = new_key_file.name
# [Link].grade_key_image.source = key_file
# method for when pause button is pressed
def pause_press(self):
print("here")
# Change Account Info
#==================================================================================
==
# Opens a file explorer to select a json file
# Saves the file to src/config_files and then saves the path to the config file
as well
def select_json_file(self):
# Open file dialog for JSON file selection
json_file = [Link](
initialdir="/",
title="Select configuration file",
filetypes=(("JSON files", "*.json"), ("All Files", "*.*"))
)
if json_file is None:
return # User cancelled the file selection
elif not json_file.[Link]('.json'):
self.error_file = 'Only .json files are accepted for configuration'
else:
self.error_file = ''
# Save the selected JSON file path to a configuration file
self.save_json_file(json_file.name)
# Save the JSON file to a designated folder and return its new path
def save_json_file(self, file_path):
config_dir = 'src/config_files'
[Link](config_dir, exist_ok=True)
file_name = [Link](file_path)
destination_path = [Link](config_dir, file_name)
try:
[Link](file_path, destination_path)
print(f"JSON file saved to: {destination_path}")
self.save_config(destination_path)
except Exception as e:
print(f"Failed to save JSON file: {e}")
return None
# Save the path of the saved JSON file to json_config.txt
def save_config(self, file_path):
config_file_path = 'src/json_config.txt'
try:
with open(config_file_path, 'w') as config_file:
config_file.write(file_path)
print(f"Configuration file path saved to {config_file_path}:
{file_path}")
self.load_config()
except Exception as e:
print(f"Failed to save configuration file: {e}")
# Read and return the saved configuration path from json_config.txt
def load_config(self):
config_file_path = 'src/json_config.txt'
try:
with open(config_file_path, 'r') as config_file:
file_path = config_file.read().strip()
print(f"Loaded file path from config: {file_path}")
return file_path
except FileNotFoundError:
print("Configuration file not found.")
return None
# Method to save the sheet ID entered in the text box
def save_sheet_id(self):
sheet_id = [Link].sheet_id_input.text
temp = sheet_id.split("/")
print(temp)
sheet_id = temp[5]
print(sheet_id)
file_path = './sheet_id.txt'
try:
# Open the file in append mode to add new IDs on new lines
with open(file_path, 'w') as file:
[Link](sheet_id) # Add a newline after each ID
print(sheet_id)
self.error_file = "Sheet ID saved successfully!"
# Clear the message after 2 seconds
Clock.schedule_once(self.clear_message, 2)
except Exception as e:
self.error_file = f"Error saving Sheet ID: {e}"
def clear_message(self, *args):
self.error_file = "" # Clears the success message
#==================================================================================
==
# main call loop for kivy to make application window
class TechTutorApp(App):
set_value = 5
def build(self):
# setting window background to white
[Link] = (49/255,51/255,56/255,1)
return MyFloatLayout()
# global model
# model = load_model("./model_test1.pt")
if __name__ == '__main__':
TechTutorApp().run()