Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
app funcionality issue
#1
ok so i'm building a reminder app for a client. So far i have one application that is booted by the user that the user can use to create reminders (send date, contact information, name, reminder description and send method are amongs my elements. Send method is defined by a drop down menu selection. My problem is with that function. I set the clicked variable to the dropdown menu and are retreving it. So far everything works as it should. I check if the clicked variable value is SMS and i assign the send method to SMS, otherwise the clicked value is Email. The problem is that no matter what my dropdown selection is the send method is always set to EMAIL!!!! can't figure out why. my relevant code follows

first i trigger this function by clicking the button
def save_info(self):
        saved_data = self.read_csv_file(self.CSV_FILE)
        send_date = self.send_date_ent.get()

        if not self.check_date(send_date):
            return

        name = self.name_ent.get().title()
        desc = self.description_ent.get()
        phone_number = self.phone_ent.get()


        if not self.check_alphabetical(name) or not self.check_alphabetical(desc):
            self.show_error(title="Error",
                                 message="Name or task description contains invalid characters. Please enter only alphabetical characters and spaces.")
            return

        have_email_address = self.var2.get() == 1
        to_email_address = self.email_ent.get() if have_email_address else " not provided"
        if self.clicked=="SMS":
            if len(phone_number) != 11 or not phone_number.isdigit():
                self.show_error(title="Error",
                                message="Invalid phone number. Please enter a valid 11-digit UK phone number starting with 0.")
                return
            send_method="SMS"

        else:
            if have_email_address and not self.verify_email(to_email_address):
                self.show_error(title="Invalid Email",
                                message="The email address you entered does not exist. Please enter a valid email address.")
                return
            send_method="Email"



        recurring = self.var1.get() == 1
        end_date = self.end_date_ent.get() if recurring else ""

        if recurring and not self.check_date(end_date):
            self.show_error(title="OOOOOOps",message="End date is not in the right format,\nPlease enter a date in DD-MM-YYYY format!!")
            return

        self.process_save_info(saved_data, name, send_date, send_method, desc, phone_number, to_email_address, have_email_address,
                               end_date, recurring)
as you can see in the final line of that code i call another function. The latter function follows

    def process_save_info(self, saved_data, name, send_date, send_method, desc, phone_number, to_email_address, have_email_address, end_date, recurring):
        '''this function is meant to aid the save info function
        if the reminder is recurring then the list of send dates is generated.
        if an email address is provided then it is saved along with all the other information
        as long as the user presses yes on the prompt.'''
        send_status=[]
        if recurring:

            frequency = simpledialog.askinteger(title="Task Frequency", prompt="How many days should the task occur?")
            start_date_index = self.dates_list_starting_from_today.index(send_date)
            end_date_index = self.dates_list_starting_from_today.index(end_date)
            send_dates = self.dates_list_starting_from_today[start_date_index:end_date_index:frequency]
            for date in send_dates:
                send_status.append("No")
        else:
            send_dates = send_date
            send_status.append("No")

        entry = {
            "name": name, "send date": send_dates, "send_method":send_method, "send status":send_status, "description": desc, "phone number": phone_number,
            "email address": to_email_address, "recurring": recurring, "have email address": have_email_address
        }
        if entry["send_method"]=="SMS":
            if messagebox.askyesno(title="Save Information", message=f"{name}? will be reminded to {desc} on {send_dates}\n"
                                                                     f"Their phone number is {phone_number}\n"
                                                                     f"\nWe will be sending this reminder via {entry['send_method']}!"):
                saved_data.append(entry)
                self.save_csv_file(self.CSV_FILE, saved_data)
                self.clear_widget_entries()
                messagebox.showinfo(title="Congratulations!!!!",message="Way to go!!\nYou have successfully saved this reminder!\n")
        else:
            if messagebox.askyesno(title="Save Information", message=f"{name} will be reminded to {desc} on {send_dates}\n"
                                                                     f"Their email address is {to_email_address}\n"
                                                                     f"\nWe will be sending this reminder via {entry['send_method']}!"):
                saved_data.append(entry)
                self.save_csv_file(self.CSV_FILE, saved_data)
                self.clear_widget_entries()
                messagebox.showinfo(title="Congratulations!!!!",message="Way to go!!\nYou have successfully saved this reminder!\n")
my code seems to be constructed right but whether i select SMS or Email in the dropdown menu, the result is always Email. Please help if possible
Reply
#2
I don't think you posted the relevant code.

My guess is that self.clicked never equals "SMS". There is no way for me to tell why because you didn't include the code that sets self.clicked. Verify the value for self.clicked is "SMS" or "Email".

Another guess is that you are not posting the code that you are running. This looks very much like it simulates reading a dictionary from a json file or maybe a database query.
    entry = {
        "name": name, "send date": send_dates, "send_method":send_method, "send status":send_status, "description": desc, "phone number": phone_number,
        "email address": to_email_address, "recurring": recurring, "have email address": have_email_address
    }
If so, do you see "SMS" in your json file or database?
Reply
#3
(Jan-29-2025, 04:17 PM)deanhystad Wrote: I don't think you posted the relevant code.

My guess is that self.clicked never equals "SMS". There is no way for me to tell why because you didn't include the code that sets self.clicked. Verify the value for self.clicked is "SMS" or "Email".

Another guess is that you are not posting the code that you are running. This looks very much like it simulates reading a dictionary from a json file or maybe a database query.
    entry = {
        "name": name, "send date": send_dates, "send_method":send_method, "send status":send_status, "description": desc, "phone number": phone_number,
        "email address": to_email_address, "recurring": recurring, "have email address": have_email_address
    }
If so, do you see "SMS" in your json file or database?

mate.. two things... thanks a lot.... aaaaaand chiiiiiill dude.. i added the relevant code in my initial post. if you check line of 20 (i think) of the code of the first code snippet i posted in my thread you will see that i am checking for self.clicked=="SMS".. i can post the snippet from the code that setups the GUI or just the whole fricking thing if you want to see how it looks/works
now about the dictionary, you will see it was from the second code snippet that is the function that runs as soon as the end of the first function (1st code snippet i posted) .. the last function running has a ridiculous amount of positional arguments (just cause i couldn't be arsed to make them keyword [honestly if i was to do them, i'd do them alphabetically.. it's too much of a hussle though]).. anyway i digress.. i am creating the dictionary in order to append it to the csv file that saves all of the users data. i am currently working on making the software to auto delete past reminders .. that way when the user chooses to show all of the saved reminders, they won't be flooded with 1000000 of past reminders..

aaaaanywho. thanks for helping again .. can't wait to hear back
Reply
#4
This is not the code I'm interested in:
        if self.clicked=="SMS":
            if len(phone_number) != 11 or not phone_number.isdigit():
If self.clicked is not "SMS", then the code falls through and chooses "Email". I think that is what's happening, but I don't think that is the problem. I think the problem is where self.clicked is set. You say this happens when you make a dropdown menu selection. You did not post that code.

If I was debugging the code I would set a breakpoint on line 20 and verify that self.clicked says "SMS" when you selected "SMS" in your dropdown. I would also verify that type(self.clicked) is str. My guess is self.clicked is not "SMS" and problably not "Email" either. I cannot guess what it might be because you did not post that code. I don't even know what you are using for the GUI. Are you using tkinter? is self.clicked a StringVar? maybe you should check if self.clicked.get() == "SMS"?
Reply
#5
(Jan-29-2025, 08:39 PM)deanhystad Wrote: This is not the code I'm interested in:
        if self.clicked=="SMS":
            if len(phone_number) != 11 or not phone_number.isdigit():
If self.clicked is not "SMS", then the code falls through and chooses "Email". I think that is what's happening, but I don't think that is the problem. I think the problem is where self.clicked is set. You say this happens when you make a dropdown menu selection. You did not post that code.

If I was debugging the code I would set a breakpoint on line 20 and verify that self.clicked says "SMS" when you selected "SMS" in your dropdown. I would also verify that type(self.clicked) is str. My guess is self.clicked is not "SMS" and problably not "Email" either. I cannot guess what it might be because you did not post that code. I don't even know what you are using for the GUI. Are you using tkinter? is self.clicked a StringVar? maybe you should check if self.clicked.get() == "SMS"?
you were right! sorry just saw this comment. The problem was that i was missing .get() from my self.clicked statement. mentioning this in case anyone has the same kind of problem. stupid oversight on my part
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020