""" Created by Team 17 - Tech 4 """ from configparser import NoOptionError from re import S import pyodbc from typing import Text from kivy import utils from kivy.app import App from kivy.properties import ObjectProperty, ListProperty, StringProperty from kivy.uix.behaviors import button from kivy.uix.boxlayout import BoxLayout from kivy.uix.gridlayout import GridLayout from kivy.uix.button import Button from kivy.uix.layout import Layout from kivy.uix.label import Label from kivy.uix.screenmanager import Screen from kivy.uix.textinput import TextInput from kivy.uix.image import Image from kivy.lang import Builder, builder from kivy.core.window import Window from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition from kivy.uix.widget import Widget from kivy.clock import Clock from kivy.uix.dropdown import DropDown # # SQL SERVER CONNECTION # cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};" # "Server=localhost;" # "Database=master;" # "Trusted_Connection=yes;") # Background color App Window.clearcolor= utils.get_color_from_hex('#012E28') # Set window size for testing purpose, should be removed before compiling the App Window.size = (360,600) # Screen Manager Manages the different screens class MyScreenManager(ScreenManager): def __init__(self, **kwargs): super(MyScreenManager, self).__init__(**kwargs) #Switching from loading screen to Screen_1(HomePage) in 4 seconds Clock.schedule_once(self.screen_switch_one, 4) def screen_switch_one(self, *args): """ functies voor de transitioning van Loadingscreen naar Screen_1 """ self.current = 'Screen_1' def switch_screen_to_Screen_1(self, *args): """ Switches to Screen_1 from whatever screen your currently at """ self.current = 'Screen_1' def switch_screen_to_Screen_2(self, *args): """ Switches to Screen_2 from whatever screen your currently at """ self.current = 'Screen_2' # creates the Hot Items Grid for task in range(1,15): # Populates the Gallery grid with a test product for Hot Items page self.children[0].lastgridscreen2.add_widget(Image(source="D:\Studies\Coding\Python Programming\VsCode\Kivy\AppDev\PriceCharm\Images\Markant Bruine Bonen 700g Pot Hollandse.jpg", size_hint= (None,None), width= 150, height = 200, keep_ratio = False)) def switch_screen_to_Screen_3(self, *args): """ Switches to Screen_3 from whatever screen your currently at """ self.current = 'Screen_3' # creates the Gallery Grid for task in range(1,15): # Populates the Gallery grid with a test product for Hot Items page self.children[0].lastgridscreen3.add_widget(Image(source="D:\Studies\Coding\Python Programming\VsCode\Kivy\AppDev\PriceCharm\Images\Markant Bruine Bonen 700g Pot Hollandse.jpg", size_hint= (None,None), width= 150, height = 200, keep_ratio = False)) def submit_btn(self): """ submit_btn function will take textinputs alongside the image uploaded and will store them in variables for later use """ # Defining and Initializing variables for use in Backend regarding Database storage ## takes the input in the TextInputBox below Shop label and stores into shopName Variable shopName = self.current_screen.children[0].children[2].children[0].text ## takes the input in the TextInputBox below Shop label and stores into shopName Variable productName = self.current_screen.children[0].children[1].children[0].text ## takes the input in the TextInputBox below Shop label and stores into shopName Variable productPrice = self.current_screen.children[0].children[0].children[1].text print("Shop Name: ", shopName) print("Product Name: ", productName) print("Price is: ", productPrice) class LoadingImage(Screen): pass class Screen1(Screen): # For no add names in shop_list. THESE ARE CASE SENSITIVE choicesfile = StringProperty() # declaring the file variable shop_list = ["Anding", "Choi's", "Tulip", "Soengie", "Lins", "Leiding", "anding", "choi's", "tulip", "soengie", "lins", "leiding"] product_list = ["aardapelen", "suiker", "blom", "melkpoeder", "uien", "knoflook", "spijsolie"] def __init__(self, **kwargs): super(Screen1, self).__init__(**kwargs) self.choicesfile = kwargs.pop('choicesfile', '') #this is for a file for the inputs incase we need one self.chosen_list = kwargs.pop('chosen_list', []) #for the input list self.bind(choicesfile = self.load_choices) # method for autocomplete for shop input def fill_Shop_input(self, instance, value): """ Feeds the content inputted from Shop TextInputBox to auto_input() method for shop Recommendation and Autocompletion """ #path for different textInput self.text_Box = self.children[0].children[2].children[0] #Use a common variabel for autocomplete method self.chosen_list = self.shop_list #Use self. to include it as class member self.load_choices() self.dropdown = None self.auto_input(instance, value) # method for autocomplete for Product input def fill_Product_input(self, instance, value): """ Feeds the content inputted from Product TextInputBox to auto_input() method for Product Recommendation and Autocompletion """ self.text_Box = self.children[0].children[1].children[0] self.chosen_list = self.product_list self.load_choices() self.auto_input(instance, value) def load_choices(self): # als er een file is Doe de volgende if self.choicesfile: with open(self.choicesfile) as fd: for line in fd: #plaats de values van file in de chosen_list self.chosen_list.append(line.strip('\n')) self.values = [] """ stay open dropdown, i don't really know of dit mee moet def open_dropdown(self, *args): if self.dropdown: self.dropdown.open(self.text_Box) """ def keyboard_on_key_down(self, window, keycode, text, modifiers): #standard method with its own arguments van TextInput class if self.text_Box.suggestion_text and keycode[0] == ord('\r'): #Als enter gedrukt wordt , kies 1e suggestie self.text_Box.suggestion_text = ' ' #setting suggestion_text to '' screws everything self.text_Box.text = self.values[0] if self.dropdown: self.dropdown.dismiss() self.dropdown = None else: super(Chooser, self).keyboard_on_key_down(window, keycode, text, modifiers) # method for autocomplete def auto_input(self, instance, value): """ This Function reads user input, compares it to the information provided in the database regarding to product and shop names and recommends this autocompletion to the user in the TextInputBox """ if self.dropdown: self.dropdown.dismiss() self.dropdown = None if self.text_Box.text == '': return values = [] for addr in self.chosen_list: if addr.startswith(self.text_Box.text): values.append(addr) self.values = values if len(values) > 0: if len(self.text_Box.text) < len(self.values[0]): self.text_Box.suggestion_text = self.values[0][len(self.text_Box.text):] else: self.text_Box.suggestion_text = '' self.dropdown = DropDown() for val in self.values: self.dropdown.add_widget(Button(text=val, size_hint = (None,None), width = 340, height = 50, on_release = self.do_choose)) self.dropdown.open(self.text_Box) def do_choose(self, butt): self.text_Box.text = butt.text if self.dropdown: self.dropdown.dismiss() self.dropdown = None class Screen2(Screen): pass class Screen3(Screen): pass class MainApp(App): #create Screenmanager for screens global sm sm = MyScreenManager() def build(self): """ Adds the screen widgets to the Screen Manager Object """ sm.add_widget(LoadingImage(name = "LoadingImage")) sm.add_widget(Screen1(name = "Screen_1")) sm.add_widget(Screen2()) sm.add_widget(Screen3()) # Displays the App title/Name in the window bar self.title="Test" return sm if __name__ == "__main__": MainApp().run()