def get_current_country(self): """ Returns name of current country """ details = Details() trip_countries_dict = self.sort_trips() for part in trip_countries_dict: details.add(trip_countries_dict[part][0], trip_countries_dict[part][1], trip_countries_dict[part][2]) current_country = details.current_country(self.current_date) print(current_country) return current_country
def find_trip_details(self): # calls the Details class from the trip module self.details = Details() # opens the config file that contains the users trip details file = open('config.txt', encoding='utf-8') self.home_country = file.readline().strip() self.root.ids.home_country.text = str(self.home_country) # displays the users trip order in a chronological list self.country_list = [] for line in file: parts = line.strip().split(',') print(parts) self.details.add(parts[0], parts[1], parts[2]) self.root.ids.country_selection.values = self.country_list self.country_list.append(parts[0]) file.close() return self.country_list
def build(self): self.trip_details = Details() # main window widget build self.title = "Foreign Exchange Calculator" self.root = Builder.load_file('gui.kv') Window.size = (500, 700) # text input disable self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True # status label - config file if not os.path.isfile('config.txt'): self.root.ids.status.text = "The config file cannot be loaded" return else: self.root.ids.status.text = "The config file successfully loaded" # retrieving home country file = open('config.txt', encoding='utf-8') home_country = file.readline() home_country = home_country.rstrip("\n") self.root.ids.home_country_label.text = home_country file.close() # retrieving values for the spinner file = open('config.txt', encoding='utf-8') country_names = file.readlines() file.close() del(country_names[0]) sorted_country_names = sorted(country_names) # removes date details from the country list a = -1 for countries in range(len(sorted_country_names)): a += 1 sorted_country_name = sorted_country_names[a] sorted_country_name_split = sorted_country_name.rstrip("\n").split(",") country_list_dictionary = currency.get_all_details(sorted_country_name_split[0]) country_name_codes = sorted(country_list_dictionary.keys()) self.root.ids.country_selection.values = country_name_codes # date self.root.ids.date.text = self.root.ids.date.text + time.strftime("%Y/%m/%d") # current location file = open('config.txt', encoding='utf-8') country_details = file.readlines() del(country_details[0]) current_time = time.strftime("%Y/%m/%d") b = -1 for i in range(len(country_details)): b += 1 country_details_separated = country_details[b] country_details_split = country_details_separated.rstrip("\n").split(",") self.trip_details.add(country_details_split[0], country_details_split[1], country_details_split[2]) self.current_location = self.trip_details.current_country(current_time) self.root.ids.current_destination_label.text += self.current_location return self.root
def __init__(self, **kwargs): super(CurrencyConverter, self).__init__(**kwargs) # Retrieve today's date using time builtin in format YYYY/MM/DD self.todays_date = time.strftime("%Y/%m/%d") # Retrieve current time using time builtin self.time = time.strftime('%H:%M:%S') self.forward_conversion_rate = -1 self.backward_conversion_rate = -1 self.details = Details() self.country_list = [] self.home_country = "" self.load_config() self.update_button_disabled = "" try: self.current_country = self.details.current_country(self.todays_date) self.home_currency = get_details(self.home_country)[1] # to retrieve code self.target_currency = get_details(self.current_country)[1] except Error: self.current_country = "Could not be found" self.target_country = self.current_country self.update_button_disabled = "True"
def __init__(self, **kwargs): super(CurrencyConvert, self).__init__(**kwargs) self.details = Details()
class CurrencyConvert(App): def __init__(self, **kwargs): super(CurrencyConvert, self).__init__(**kwargs) self.details = Details() # Creates the window and provides the basic information used in the start up of the program def build(self, ): Window.size = (350, 700) self.title = "Foreign Exchange Calculator" self.root = Builder.load_file('gui.kv') self.find_trip_details() # Sets the current date in the layout self.root.ids.current_date.text = 'Today is: \n' + str( datetime.date.today()).replace('-', '/') # sets the current location of the user in their trip self.root.ids.trip_location.text = ( 'Current Location: \n' + self.details.current_country( str(datetime.date.today()).replace('-', '/'))) return self.root def find_trip_details(self): # calls the Details class from the trip module self.details = Details() # opens the config file that contains the users trip details file = open('config.txt', encoding='utf-8') self.home_country = file.readline().strip() self.root.ids.home_country.text = str(self.home_country) # displays the users trip order in a chronological list self.country_list = [] for line in file: parts = line.strip().split(',') print(parts) self.details.add(parts[0], parts[1], parts[2]) self.root.ids.country_selection.values = self.country_list self.country_list.append(parts[0]) file.close() return self.country_list def get_currency_conversion(self, directions): # print(directions) # creates a dictionary from the currency module place_dictionary = get_all_details() # stores the user selection from the spinner gui spinner_location = self.root.ids.country_selection.text # print(spinner_location) location_currency = place_dictionary[spinner_location][1] home_currency = place_dictionary[self.home_country][1] # print(location_currency) # print(home_currency) # provides the status message and conversion amount in the gui # allows for back and forth conversion if directions == 'to home': value = convert(float(self.root.ids.target_amount.text), home_currency, location_currency) self.root.ids.home_amount.text = str(value) self.root.ids.status.text = location_currency + ' to ' + home_currency else: value = convert(float(self.root.ids.home_amount.text), location_currency, home_currency) self.root.ids.target_amount.text = str(value) self.root.ids.status.text = home_currency + ' to ' + location_currency # updates the conversion rate for the user def update_currency(self): self.root.update_currency.text = 'updated' + time.strftime('%X')
class CurrencyConverter(App): """ class variables """ current_state = StringProperty() home_state = StringProperty() country_names = ListProperty() status_text = StringProperty() update_button_disabled = StringProperty() def __init__(self, **kwargs): super(CurrencyConverter, self).__init__(**kwargs) # Retrieve today's date using time builtin in format YYYY/MM/DD self.todays_date = time.strftime("%Y/%m/%d") # Retrieve current time using time builtin self.time = time.strftime('%H:%M:%S') self.forward_conversion_rate = -1 self.backward_conversion_rate = -1 self.details = Details() self.country_list = [] self.home_country = "" self.load_config() self.update_button_disabled = "" try: self.current_country = self.details.current_country(self.todays_date) self.home_currency = get_details(self.home_country)[1] # to retrieve code self.target_currency = get_details(self.current_country)[1] except Error: self.current_country = "Could not be found" self.target_country = self.current_country self.update_button_disabled = "True" def build(self): self.title = "GUI" self.root = Builder.load_file('gui.kv') Window.size = (350, 700) # Set current state to current country (currently 1st country in list) self.current_state = "" # add values to the spinner self.root.ids.home_country_label.text = self.home_country return self.root """ load the config file and store the data """ def load_config(self): try: config_data = open("config.txt", mode='r', encoding="utf-8") self.home_country = config_data.readline().strip("\n") # Retrieve locations from config.txt file format: location,start_date,end_date self.details.locations = [] self.country_list = [] for line in config_data.readlines(): parts = line.strip().split(",") # add all details to locations self.details.locations.append(tuple(parts)) # checks country exists for key in get_all_details(): if parts[0] == key: # add only country names to country_list self.country_list.append(parts[0]) else: self.status_text = "Invalid trip details" config_data.close() self.status_text = "Config loaded\nsuccessfully" except FileNotFoundError: self.status_text = "Config could not\nbe loaded" # processing input from app separately """ takes location value and converts to value in home currency """ def convert_forward(self): try: amount = float(self.root.ids.current_country_input.text) end_amount = float(float(self.forward_conversion_rate)*amount) self.root.ids.home_country_input.text = str("%.3f" % end_amount) self.status_text = "{} ({}) to {} ({})".format(self.target_currency, self.get_symbol(self.target_country), self.home_currency, self.get_symbol(self.home_country)) return end_amount except ValueError: self.status_text = "Invalid Input" """ takes home value and converts to value in location """ def convert_backward(self): try: amount = float(self.root.ids.home_country_input.text) end_amount = float(float(self.backward_conversion_rate)*amount) self.root.ids.current_country_input.text = str("%.3f" % end_amount) self.status_text = "{} ({}) to {} ({})".format(self.home_currency, self.get_symbol(self.home_country), self.target_currency, self.get_symbol(self.target_country)) return end_amount except ValueError: self.status_text = "Invalid Input" """ retrieves the symbol for the currency from the currency_details file using the get_all_details() function """ def get_symbol(self, country): if country in get_all_details().keys(): symbol = get_all_details()[country][0][2] return symbol else: return None """ takes a country name and returns it's currency code using get_all_details """ def change_state(self, target_country): self.root.ids.current_country_input.readonly = False self.root.ids.home_country_input.readonly = False self.target_country = self.root.ids.country_spinner.text all_details = get_all_details() for country in all_details: if target_country == country: details = all_details[country] target_country_details = details[0] target_currency_new = target_country_details[1] # If the currency code has not changed, do not update if not target_currency_new == self.target_currency: self.target_currency = target_currency_new self.get_conversion_rate() return [self.target_currency, target_country_details[2]] """ retrieves the conversion rate from the internet """ def get_conversion_rate(self): self.forward_conversion_rate = convert(1, self.home_currency, self.target_currency) self.backward_conversion_rate = convert(1, self.target_currency, self.home_currency) def update_button_press(self): # activates the text input fields self.root.ids.current_country_input.readonly = False self.root.ids.home_country_input.readonly = False # On press of the update button retrieve fresh data from webpage self.get_conversion_rate() self.status_text = "Updated at\n" + self.time if self.root.ids.country_spinner.text == "": self.root.ids.country_spinner.text = self.current_country def current_trip_location(self): return "Current trip Location: \n" + self.current_country def todays_date_label(self): label = "Today is:" + "\n" + self.todays_date # format today's date for the gui return label
class ForeignExchangeCalculator(App): country_name_codes = "" def __init__(self, **kwargs): super().__init__(**kwargs) def build(self): self.trip_details = Details() # main window widget build self.title = "Foreign Exchange Calculator" self.root = Builder.load_file('gui.kv') Window.size = (500, 700) # text input disable self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True # status label - config file if not os.path.isfile('config.txt'): self.root.ids.status.text = "The config file cannot be loaded" return else: self.root.ids.status.text = "The config file successfully loaded" # retrieving home country file = open('config.txt', encoding='utf-8') home_country = file.readline() home_country = home_country.rstrip("\n") self.root.ids.home_country_label.text = home_country file.close() # retrieving values for the spinner file = open('config.txt', encoding='utf-8') country_names = file.readlines() file.close() del(country_names[0]) sorted_country_names = sorted(country_names) # removes date details from the country list a = -1 for countries in range(len(sorted_country_names)): a += 1 sorted_country_name = sorted_country_names[a] sorted_country_name_split = sorted_country_name.rstrip("\n").split(",") country_list_dictionary = currency.get_all_details(sorted_country_name_split[0]) country_name_codes = sorted(country_list_dictionary.keys()) self.root.ids.country_selection.values = country_name_codes # date self.root.ids.date.text = self.root.ids.date.text + time.strftime("%Y/%m/%d") # current location file = open('config.txt', encoding='utf-8') country_details = file.readlines() del(country_details[0]) current_time = time.strftime("%Y/%m/%d") b = -1 for i in range(len(country_details)): b += 1 country_details_separated = country_details[b] country_details_split = country_details_separated.rstrip("\n").split(",") self.trip_details.add(country_details_split[0], country_details_split[1], country_details_split[2]) self.current_location = self.trip_details.current_country(current_time) self.root.ids.current_destination_label.text += self.current_location return self.root def update_currency(self): # text input enable if self.root.ids.input_country_amount.disabled is True and self.root.ids.input_home_country_amount.disabled is True: self.root.ids.input_country_amount.disabled = False self.root.ids.input_home_country_amount.disabled = False self.root.ids.input_country_amount.text = '' self.root.ids.input_home_country_amount.text = '' return self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False # currency exchange self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text # spinner / home country name grabbing self.country1 = self.root.ids.home_country_label.text self.country2 = self.root.ids.country_selection.text # checks if spinner selection is blank if self.country2 is "": self.country2 = self.root.ids.country_selection.text = self.current_location # gets country details self.country_details1 = currency.get_details(self.country1) self.country_details2 = currency.get_details(self.country2) # checks to see if there was an inputted currency in the "home country" textbox, if there is no value, then it is assumed that the spinner country textbox has an inputted value. if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) print(self.amount2) self.amount2 = round(self.amount2, 3) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # checks to see if there was an inputted currency in the spinner country textbox, if there is no value, then it is assumed that the "home country" textbox has an inputted value. elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # is launched when a person presses enter def change_amount(self): self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) self.amount2 = round(self.amount2, 3) print(self.amount2) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) self.root.ids.status.text = "{}({}) -> {}({})".format(self.country_details2[1], self.country_details2[2], self.country_details1[1], self.country_details1[2]) elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) self.root.ids.status.text = "{}({}) -> {}({})".format(self.country_details1[1], self.country_details1[2], self.country_details2[1], self.country_details2[2]) # launched if somebody types into any textbox def clear_textinput(self): if self.root.ids.input_country_amount.focus is True: self.root.ids.input_home_country_amount.text = '' elif self.root.ids.input_home_country_amount.focus is True: self.root.ids.input_country_amount.text = ''
def build(self): self.trip_details = Details() # main window widget build self.title = "Foreign Exchange Calculator" self.root = Builder.load_file('gui.kv') Window.size = (500, 700) # text input disable self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True # status label - config file if not os.path.isfile('config.txt'): self.root.ids.status.text = "The config file cannot be loaded" return else: self.root.ids.status.text = "The config file successfully loaded" # retrieving home country file = open('config.txt', encoding='utf-8') home_country = file.readline() home_country = home_country.rstrip("\n") self.root.ids.home_country_label.text = home_country file.close() # retrieving values for the spinner file = open('config.txt', encoding='utf-8') country_names = file.readlines() file.close() del (country_names[0]) sorted_country_names = sorted(country_names) # removes date details from the country list a = -1 for countries in range(len(sorted_country_names)): a += 1 sorted_country_name = sorted_country_names[a] sorted_country_name_split = sorted_country_name.rstrip("\n").split( ",") country_list_dictionary = currency.get_all_details( sorted_country_name_split[0]) country_name_codes = sorted(country_list_dictionary.keys()) self.root.ids.country_selection.values = country_name_codes # date self.root.ids.date.text = self.root.ids.date.text + time.strftime( "%Y/%m/%d") # current location file = open('config.txt', encoding='utf-8') country_details = file.readlines() del (country_details[0]) current_time = time.strftime("%Y/%m/%d") b = -1 for i in range(len(country_details)): b += 1 country_details_separated = country_details[b] country_details_split = country_details_separated.rstrip( "\n").split(",") self.trip_details.add(country_details_split[0], country_details_split[1], country_details_split[2]) self.current_location = self.trip_details.current_country(current_time) self.root.ids.current_destination_label.text += self.current_location return self.root
class ForeignExchangeCalculator(App): country_name_codes = "" def __init__(self, **kwargs): super().__init__(**kwargs) def build(self): self.trip_details = Details() # main window widget build self.title = "Foreign Exchange Calculator" self.root = Builder.load_file('gui.kv') Window.size = (500, 700) # text input disable self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True # status label - config file if not os.path.isfile('config.txt'): self.root.ids.status.text = "The config file cannot be loaded" return else: self.root.ids.status.text = "The config file successfully loaded" # retrieving home country file = open('config.txt', encoding='utf-8') home_country = file.readline() home_country = home_country.rstrip("\n") self.root.ids.home_country_label.text = home_country file.close() # retrieving values for the spinner file = open('config.txt', encoding='utf-8') country_names = file.readlines() file.close() del (country_names[0]) sorted_country_names = sorted(country_names) # removes date details from the country list a = -1 for countries in range(len(sorted_country_names)): a += 1 sorted_country_name = sorted_country_names[a] sorted_country_name_split = sorted_country_name.rstrip("\n").split( ",") country_list_dictionary = currency.get_all_details( sorted_country_name_split[0]) country_name_codes = sorted(country_list_dictionary.keys()) self.root.ids.country_selection.values = country_name_codes # date self.root.ids.date.text = self.root.ids.date.text + time.strftime( "%Y/%m/%d") # current location file = open('config.txt', encoding='utf-8') country_details = file.readlines() del (country_details[0]) current_time = time.strftime("%Y/%m/%d") b = -1 for i in range(len(country_details)): b += 1 country_details_separated = country_details[b] country_details_split = country_details_separated.rstrip( "\n").split(",") self.trip_details.add(country_details_split[0], country_details_split[1], country_details_split[2]) self.current_location = self.trip_details.current_country(current_time) self.root.ids.current_destination_label.text += self.current_location return self.root def update_currency(self): # text input enable if self.root.ids.input_country_amount.disabled is True and self.root.ids.input_home_country_amount.disabled is True: self.root.ids.input_country_amount.disabled = False self.root.ids.input_home_country_amount.disabled = False self.root.ids.input_country_amount.text = '' self.root.ids.input_home_country_amount.text = '' return self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False # currency exchange self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text # spinner / home country name grabbing self.country1 = self.root.ids.home_country_label.text self.country2 = self.root.ids.country_selection.text # checks if spinner selection is blank if self.country2 is "": self.country2 = self.root.ids.country_selection.text = self.current_location # gets country details self.country_details1 = currency.get_details(self.country1) self.country_details2 = currency.get_details(self.country2) # checks to see if there was an inputted currency in the "home country" textbox, if there is no value, then it is assumed that the spinner country textbox has an inputted value. if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) print(self.amount2) self.amount2 = round(self.amount2, 3) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # checks to see if there was an inputted currency in the spinner country textbox, if there is no value, then it is assumed that the "home country" textbox has an inputted value. elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # is launched when a person presses enter def change_amount(self): self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) self.amount2 = round(self.amount2, 3) print(self.amount2) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) self.root.ids.status.text = "{}({}) -> {}({})".format( self.country_details2[1], self.country_details2[2], self.country_details1[1], self.country_details1[2]) elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) self.root.ids.status.text = "{}({}) -> {}({})".format( self.country_details1[1], self.country_details1[2], self.country_details2[1], self.country_details2[2]) # launched if somebody types into any textbox def clear_textinput(self): if self.root.ids.input_country_amount.focus is True: self.root.ids.input_home_country_amount.text = '' elif self.root.ids.input_home_country_amount.focus is True: self.root.ids.input_country_amount.text = ''