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
Example #2
0
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 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 = ''
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 = ''