CSSG-Labs / PyNote

Text Editor Written in Python
GNU General Public License v3.0
3 stars 4 forks source link

Add messagebox prompts for "new" and "open" functions to save work. #33

Closed PatrickBruso closed 2 years ago

PatrickBruso commented 2 years ago

While I think that the CustomPrompt class will be very useful in the future when additional features are added that will need custom prompt windows, I don't think we necessarily need to use it at this point. I was testing out the messagebox feature of tkinter and that would seem to take care of the issue as it currently stands. For example, when calling the new function, one could immediately test whether the text is changed, and if so, prompt the user with a messagebox tkinter.messagebox.askyesnocancel("Question", "Save changes?")

The return values of that messagebox can be used to determine the logical flow within the new function:

def new(self):
    if self.text_is_changed():
        answer = tkinter.messagebox.askyesnocancel("Question", "Save changes?")
        if answer:
            self.save()
        elif not answer:
            self.file_location = None
            self.text.delete("1.0", "end")
            self.saved_text = ""
        else:
            pass
    else:
        self.file_location = None
        self.text.delete("1.0", "end")
        self.saved_text = ""

This would make the code considerably less complex than using the CustomPrompt class and, as far as I can tell (and please correct me if wrong), would allow for the same functionality that we would want (i.e., clicking "yes" saves the text, clicking "no" does not save, and clicking "cancel" escapes out of the entire new function and does not change the window).

AdamLaine commented 2 years ago

@PatrickBruso Funnily enough, while creating CustomPrompt I didn't see particularly this function, I saw only askyesno type without cancelling. Anyway, being a little biased towards my function I am not the best person to answer this question, however, you are right, from a certain point of view your option is less complex, but at the same time less customizable, so one is constrained with what is given and the functionality remains almost the same. In my PR #34 I gave an example of how to use mine and you can derive possible advantages of my approach. If you ask me to remove CustomPrompt and use your approach I'll update the PR

mrHeavenli commented 2 years ago

Messagebox is better suited for the quit prompt, but I think we should leave the CustomPrompt class in just in case. Let's just change the quit prompt to use messagebox and keep CustomPrompt for future usage.

PatrickBruso commented 2 years ago

@SamReiCooper I don't have an issue with the CustomPrompt and I think it's very useful to have for more advanced features (for example, a Font prompt that has options for fonts, styles, sizes, colors, effects, etc.).

I just think it's better to use the messagebox for applications in which the CustomPrompt class would provide no additional necessary functionality, because it's simpler code, easier for people to follow, and is a built in tkinter module that people will be familiar with. But it only works for simple yes-no-cancel prompts like saving changes or quitting the application.

PatrickBruso commented 2 years ago

I will be adding messagebox prompts for the "new" and "open" functions.