Exemplo n.º 1
0
 def convert_to_home(
     self
 ):  # First of three conversion functions, to convert from the destination to the home currency.
     try:  # Tries this block of code first, but should a Value Error appear it will act out the except ValueError code
         country_details = (
             currency.get_all_details()
         )  # runs get_all_details in the currency.py file to obtain country codes in a dictionary
         amount = float(
             self.root.ids.input_location.text
         )  # Sets the current text as a float in the location/destination text field
         home_currency = self.root.ids.country_name.text  # obtains the country name from the GUI
         home_currency = country_details[home_currency]  # uses the name as a key on the already obtained dictionary
         home_currency_code = home_currency[1]  # Gets the country code from the result
         target_currency = (
             self.root.ids.spinner.text
         )  # Does the same as previous 3 lines, but for the target currency
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(
             amount, target_currency_code, home_currency_code
         )  # runs the convert function in currency.py
         self.status_update(
             target_currency[2].strip("\n"), target_currency_code, home_currency[2].strip("\n"), home_currency_code
         )  # Sets the status to show the conversion and the updated time
         self.root.ids.input_home.text = (
             converted_number
         )  # shows in the GUI text field that the currency was not entered what the conversion is
     except ValueError:  # Runs if a value error appears in the above code
         self.root.ids.input_home.text = "-1"  # this will be shown as the 'conversion' should a value error arise
         self.root.ids.status.text = "Error in Conversion"  # this is shown in the status.
Exemplo n.º 2
0
 def convert_to_home(
     self
 ):  #First of three conversion functions, to convert from the destination to the home currency.
     try:  #Tries this block of code first, but should a Value Error appear it will act out the except ValueError code
         country_details = currency.get_all_details(
         )  #runs get_all_details in the currency.py file to obtain country codes in a dictionary
         amount = float(
             self.root.ids.input_location.text
         )  #Sets the current text as a float in the location/destination text field
         home_currency = self.root.ids.country_name.text  #obtains the country name from the GUI
         home_currency = country_details[
             home_currency]  #uses the name as a key on the already obtained dictionary
         home_currency_code = home_currency[
             1]  #Gets the country code from the result
         target_currency = self.root.ids.spinner.text  #Does the same as previous 3 lines, but for the target currency
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(
             amount, target_currency_code,
             home_currency_code)  #runs the convert function in currency.py
         self.status_update(
             target_currency[2].strip('\n'), target_currency_code,
             home_currency[2].strip('\n'), home_currency_code
         )  #Sets the status to show the conversion and the updated time
         self.root.ids.input_home.text = converted_number  #shows in the GUI text field that the currency was not entered what the conversion is
     except ValueError:  #Runs if a value error appears in the above code
         self.root.ids.input_home.text = "-1"  #this will be shown as the 'conversion' should a value error arise
         self.root.ids.status.text = "Error in Conversion"  #this is shown in the status.
Exemplo n.º 3
0
    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 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]]
Exemplo n.º 5
0
 def convert_to_location(self):  # Same as previous function except inversed
     try:
         country_details = currency.get_all_details()
         amount = float(self.root.ids.input_home.text)
         home_currency = self.root.ids.country_name.text
         home_currency = country_details[home_currency]
         home_currency_code = home_currency[1]
         target_currency = self.root.ids.spinner.text
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(amount, home_currency_code, target_currency_code)
         self.root.ids.input_location.text = converted_number
         self.status_update(
             home_currency[2].strip("\n"), home_currency_code, target_currency[2].strip("\n"), target_currency_code
         )
     except ValueError:
         self.root.ids.input_location.text = "-1"
         self.root.ids.status.text = "Error in Conversion"
 def get_country_details(self):
     """ Retrieves country details for home/travel """
     travel_country = self.travel_country
     home_country = self.home_country
     country_details_dict = get_all_details()
     # Find currency code/symbol for home/travel country
     for parts in country_details_dict:
         if travel_country == parts:
             # If currency symbol is the same, and list not blank, return "Same"
             if self.travel_details and country_details_dict[parts][2] == self.travel_details[2]:
                 self.update_indicator = False
             self.travel_details = country_details_dict[parts]
         if home_country == parts:
             self.home_details = country_details_dict[parts]
     # If either list is blank, display error
     if not self.travel_details or not self.home_details:
         self.toggle_inputs_disabled(True)
         self.root.ids.status_label.text = "Invalid Name!"
Exemplo n.º 7
0
 def convert_to_location(self):  #Same as previous function except inversed
     try:
         country_details = currency.get_all_details()
         amount = float(self.root.ids.input_home.text)
         home_currency = self.root.ids.country_name.text
         home_currency = country_details[home_currency]
         home_currency_code = home_currency[1]
         target_currency = self.root.ids.spinner.text
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(amount, home_currency_code,
                                             target_currency_code)
         self.root.ids.input_location.text = converted_number
         self.status_update(home_currency[2].strip('\n'),
                            home_currency_code,
                            target_currency[2].strip('\n'),
                            target_currency_code)
     except ValueError:
         self.root.ids.input_location.text = "-1"
         self.root.ids.status.text = "Error in Conversion"
Exemplo n.º 8
0
Arquivo: app.py Projeto: cfitz25/Kivy
    def on_start(self):
        number = 0
        # checks if config could be loaded
        try:
            # gets details for the Destination dictionary
            self.Destinations = currency.get_all_details()

            # loads data from congig file and checks if its valid or not
            files = open(File_name, "r", encoding="utf-8")
            try:
                for line in files:
                    number += 1
                    # if not first line add data to current_trip object, else is first line, add data to home_country
                    if number > 1:
                        parts = line.strip().split(',')
                        self.current_trip.add(parts[0], parts[1], parts[2])
                    else:
                        self.home_country = line.strip()
                self.root.ids.status_window.text = "Config Load Succesful"

            except:
                self.root.ids.status_window.text = "Config File Invalid Details"
            # update currency data, labels and spinner for start
            self.currency_update()
            self.cdate = time.strftime("%Y-%m-%d")
            self.current_country = self.current_trip.current_country(self.cdate)
            self.root.ids.country_select.text = self.current_country
            self.root.ids.country_select.values = self.current_trip.location
            self.root.ids.home_country.text = self.home_country
            self.root.ids.date_label.text = "Todays date is: \n" + str(self.cdate)
        except:
            self.app_can_run = False
            self.root.ids.status_window.text = "Config Load Failed"
        # check if spinner is empty and if so disable spinner
        if self.root.ids.country_select.text == "?":
            self.root.ids.country_amount.background_color = Colour
            self.root.ids.home_amount.background_color = Colour
            self.root.ids.country_amount.readonly = True
            self.root.ids.home_amount.readonly = True
        # make the current country label equal the current country
        self.root.ids.country_selected.text = "Current Trip Location: " + self.current_country
Exemplo n.º 9
0
 def conversion_rates(
     self
 ):  # Same as the first conversion function, however always defaults to only converting 1 in the selected currency for the conversion rate rather than an actual conversion
     try:
         country_details = currency.get_all_details()
         amount = float("1")
         home_currency = self.root.ids.country_name.text
         home_currency = country_details[home_currency]
         home_currency_code = home_currency[1]
         target_currency = self.root.ids.spinner.text
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(amount, target_currency_code, home_currency_code)
         self.status_update(
             target_currency[2].strip("\n"), target_currency_code, home_currency[2].strip("\n"), home_currency_code
         )
         self.root.ids.input_home.text = converted_number
         self.root.ids.input_location.text = "1"
     except ValueError:
         self.root.ids.input_home.text = "-1"
         self.root.ids.status.text = "Error in Conversion"
 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"
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 def conversion_rates(
     self
 ):  #Same as the first conversion function, however always defaults to only converting 1 in the selected currency for the conversion rate rather than an actual conversion
     try:
         country_details = currency.get_all_details()
         amount = float("1")
         home_currency = self.root.ids.country_name.text
         home_currency = country_details[home_currency]
         home_currency_code = home_currency[1]
         target_currency = self.root.ids.spinner.text
         target_currency = country_details[target_currency]
         target_currency_code = target_currency[1]
         converted_number = currency.convert(amount, target_currency_code,
                                             home_currency_code)
         self.status_update(target_currency[2].strip('\n'),
                            target_currency_code,
                            home_currency[2].strip('\n'),
                            home_currency_code)
         self.root.ids.input_home.text = converted_number
         self.root.ids.input_location.text = "1"
     except ValueError:
         self.root.ids.input_home.text = "-1"
         self.root.ids.status.text = "Error in Conversion"
 def get_symbol(self, country):
     if country in get_all_details().keys():
         symbol = get_all_details()[country][0][2]
         return symbol
     else:
         return None
Exemplo n.º 14
0
 def __init__(self):
     super().__init__()
     self.trip_details = currency.get_all_details()
Exemplo n.º 15
0
    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