Skip to content

Commit ded982c

Browse files
committed
In the "Diary_Slim" module, I made the following changes:
I added the function of text states, with texts containing multiple states. And on each state written in the Diary Slim, it defines the next state to be written. Like washing clothes, the first state is washing the clothes, the second is hanging them out, and the third is picking up the clothes from the line. I also added the function of additional information. For example, when taking a shower, the program asks if the user did their eyebrows and shaved. If the user answers yes, additional information will be added to the text to be written, with text formatting. If not, execution will continue normally and the text to be written will be the first, without additional information.
1 parent f2c3c07 commit ded982c

File tree

4 files changed

+186
-21
lines changed

4 files changed

+186
-21
lines changed

Module Files/Food_Time/Times.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"Will be hungry": 3
1111
},
1212
"Ate": {
13-
"Object": "2024-04-09 04:39:12-03:00",
13+
"Object": "2024-04-09 17:44:16-03:00",
1414
"Time": 0,
15-
"Time text": "04:39",
15+
"Time text": "17:44",
1616
"Unit": {
1717
"en": "hours",
1818
"pt": "horas"
@@ -23,9 +23,9 @@
2323
}
2424
},
2525
"Can drink water": {
26-
"Object": "2024-04-09 05:19:12-03:00",
26+
"Object": "2024-04-09 18:24:16-03:00",
2727
"Time": 40,
28-
"Time text": "05:19",
28+
"Time text": "18:24",
2929
"Unit": {
3030
"en": "minutes",
3131
"pt": "minutos"
@@ -36,9 +36,9 @@
3636
}
3737
},
3838
"Will be hungry": {
39-
"Object": "2024-04-09 07:39:12-03:00",
39+
"Object": "2024-04-09 20:44:16-03:00",
4040
"Time": 3,
41-
"Time text": "07:39",
41+
"Time text": "20:44",
4242
"Unit": {
4343
"en": "hours",
4444
"pt": "horas"

Modules/Diary_Slim/Diary_Slim/__init__.py

Lines changed: 133 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,28 +655,73 @@ def Define_Diary_Slim_Texts(self):
655655
if self.File.Exist(dictionary["Files"]["Data"]) == True:
656656
dictionary.update(self.JSON.To_Python(dictionary["Files"]["Data"]))
657657

658+
# Else, remove the key
659+
else:
660+
dictionary["Files"].pop("Data")
661+
662+
# ----- #
663+
664+
# Manage the text "States"
665+
666+
# Define the text "States.json" file
667+
dictionary["Files"]["States"] = dictionary["Folders"]["root"] + "States.json"
668+
669+
# Read the "States.json" file if it exists
670+
if self.File.Exist(dictionary["Files"]["States"]) == True:
671+
dictionary["States"] = self.JSON.To_Python(dictionary["Files"]["States"])
672+
673+
# Get the list of state dictionaries
674+
states = list(dictionary["States"]["Dictionary"].values())
675+
676+
# If the current state is empty, get the first state
677+
if dictionary["States"]["Current state"] == {}:
678+
dictionary["States"]["Current state"] = states[0]
679+
680+
# Update the "States.json" file
681+
self.JSON.Edit(dictionary["Files"]["States"], dictionary["States"])
682+
683+
# Iterate through the small languages list
684+
for language in self.languages["small"]:
685+
# Define the state name
686+
dictionary["Texts"][language] = dictionary["States"]["Names"][language]
687+
688+
# Add the current state
689+
dictionary["Texts"][language] += " (" + dictionary["States"]["Current state"][language] + ")"
690+
691+
# Else, remove the key
692+
else:
693+
dictionary["Files"].pop("States")
694+
695+
# ----- #
696+
658697
# Define the language text files
659698
for language in self.languages["small"]:
660699
# Get the full language
661700
full_language = self.languages["full"][language]
662701

663702
# Define and create the language text file
664703
dictionary["Files"][language] = dictionary["Folders"]["root"] + full_language + ".txt"
665-
self.File.Create(dictionary["Files"][language])
666704

667-
# Read the language text file and add its contents to the "Texts" dictionary
668-
dictionary["Texts"][language] = self.File.Contents(dictionary["Files"][language])["string"]
705+
# If the "States" key is not inside the "Text" dictionary, create the file
706+
if "States" not in dictionary:
707+
self.File.Create(dictionary["Files"][language])
708+
709+
# If the language file exists
710+
if self.File.Exist(dictionary["Files"][language]) == True:
711+
# Read the language text file and add its contents to the "Texts" dictionary
712+
dictionary["Texts"][language] = self.File.Contents(dictionary["Files"][language])["string"]
669713

670-
# Add "..." (three dots) if the "Item" key is present inside the "Data" dictionary
671-
if "Item" in dictionary:
672-
dictionary["Texts"][language] += "..."
714+
# Add "..." (three dots) if the "Item" key is present inside the "Data" dictionary
715+
if "Item" in dictionary:
716+
dictionary["Texts"][language] += "..."
673717

674-
# Move the "Data" file key to the end
675-
file = dictionary["Files"]["Data"]
718+
if "Data" in dictionary["Files"]:
719+
# Move the "Data" file key to the end if the key is present
720+
file = dictionary["Files"]["Data"]
676721

677-
dictionary["Files"].pop("Data")
722+
dictionary["Files"].pop("Data")
678723

679-
dictionary["Files"]["Data"] = file
724+
dictionary["Files"]["Data"] = file
680725

681726
# If the "Item" key is inside the text dictionary
682727
if "Item" in dictionary:
@@ -727,11 +772,88 @@ def Define_Diary_Slim_Texts(self):
727772

728773
self.diary_slim["Texts"]["Options"][self.user_language].append(language_text)
729774

775+
# Iterate through the keys inside the Diary Slim Texts dictionary
776+
for key in self.diary_slim["Texts"]["Dictionary"].copy():
777+
# If the key is not inside the "List" list, remove it
778+
if key not in self.diary_slim["Texts"]["List"]:
779+
self.diary_slim["Texts"]["Dictionary"].pop(key)
780+
730781
# Make a copy of the "Texts" dictionary
731782
texts_copy = deepcopy(self.diary_slim["Texts"])
732783

733784
# Remove the "Options" key
734785
texts_copy.pop("Options")
735786

736787
# Update the "Texts.json" file with the updated Diary Slim "Texts" dictionary
737-
self.JSON.Edit(self.diary_slim["Folders"]["Data"]["Texts"]["Texts"], texts_copy)
788+
self.JSON.Edit(self.diary_slim["Folders"]["Data"]["Texts"]["Texts"], texts_copy)
789+
790+
def Next_State(self, dictionary):
791+
# Define the states variable for easier typing
792+
states = dictionary["States"]
793+
794+
# Get the list of state dictionaries
795+
states_list = list(states["Dictionary"].values())
796+
797+
# Get the index of the next state
798+
index = states_list.index(states["Current state"]) + 1
799+
800+
# If the index is the last one, define the index as the first one
801+
if index == len(states_list):
802+
index = 0
803+
804+
# Define the next state
805+
states["Current state"] = states_list[index]
806+
807+
# Update the "States.json" file
808+
self.JSON.Edit(dictionary["Files"]["States"], states)
809+
810+
def Define_Additional_Information(self, dictionary, text_to_write = None):
811+
# Define the text variable for easier typing
812+
text = dictionary["Text"]
813+
814+
# Define the additional information variable for easier typing
815+
additional_information = text["Additional information"]
816+
817+
# Ask the question and get the user answer
818+
user_answer = self.Input.Yes_Or_No(additional_information["Question"][self.user_language])
819+
820+
# Define the list of booleans
821+
booleans = [
822+
True,
823+
False
824+
]
825+
826+
# If the "text to write" parameter is None
827+
if text_to_write == None:
828+
text_to_write = dictionary["Text to write"]
829+
830+
# Iterate through the "Yes" and "No" list
831+
i = 0
832+
for answer in ["Yes", "No"]:
833+
# Get the boolean
834+
boolean = booleans[i]
835+
836+
# If the answer dictionary exists
837+
if answer in additional_information:
838+
# Define the answer dictionary for easier typing
839+
answer_dictionary = additional_information[answer]
840+
841+
# If the answer is the same as the boolean
842+
# And the "[Answer]" ([Boolean]) option is inside the "Additional information" dictionary
843+
# And the "Continue" key is not inside the "[Answer]" dictionary
844+
if (
845+
user_answer == boolean and
846+
answer in additional_information and
847+
"Continue" not in answer_dictionary
848+
):
849+
# If the "Format" key is inside the "[Answer]" dictionary
850+
if "Format" in answer_dictionary:
851+
# Define the format variable for easier typing
852+
format = answer_dictionary["Format"][self.user_language]
853+
854+
# Format the format text with the text to write
855+
text_to_write = format.replace("{Text}", text_to_write)
856+
857+
i += 1
858+
859+
return text_to_write

Modules/Diary_Slim/Write_On_Diary_Slim/__init__.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def Select_The_Text(self):
106106
# Define the "Text to write" as the language text
107107
self.dictionary["Text to write"] = self.dictionary["Text"]["Texts"][self.user_language]
108108

109+
# If the "States" key is inside the "Text" dictionary
110+
if "States" in self.dictionary["Text"]:
111+
# Get the current state
112+
self.dictionary["Text to write"] = self.dictionary["Text"]["States"]["Current state"][self.user_language]
113+
109114
# If the option is the "[Multi-selection]" one
110115
if option == "[Multi-selection]":
111116
# Change the "Multi-selection" mode to activated
@@ -114,6 +119,18 @@ def Select_The_Text(self):
114119
# Run this method again to run it with the "Multi-selection" mode activated
115120
self.Select_The_Text()
116121

122+
# If the "Multi-selection" mode is deactivated
123+
if self.states["Multi-selection"] == False:
124+
# If the "States" key is inside the "Text" dictionary
125+
if "States" in self.dictionary["Text"]:
126+
# Change the current state to the next state
127+
self.Next_State(self.dictionary["Text"])
128+
129+
# If the "Additional information" key is inside the "Text" dictionary
130+
if "Additional information" in self.dictionary["Text"]:
131+
# Define the additional information and update the text to write
132+
self.dictionary["Text to write"] = self.Define_Additional_Information(self.dictionary)
133+
117134
def Multi_Selection(self):
118135
# Add the "[Finish selection]" text to the list of options
119136
parameters["options"].append("[Finish selection]")
@@ -139,24 +156,31 @@ def Multi_Selection(self):
139156
print()
140157
print(self.separators["5"])
141158

142-
# Show the "List:" text
159+
# If the list of texts is not empty
143160
if texts != []:
161+
# Show the "List:" text
144162
print()
145163
print(self.JSON.Language.language_texts["list, title()"] + ":")
146164

147-
# Show the list
165+
# Show the list of texts
148166
print("[")
149167

168+
# Iterate through the texts in the list
150169
for text in texts:
170+
# Make a backup of the text
151171
text_backup = text
152172

173+
# Add one tab to the text
153174
text = text.replace("\n", "\n\t")
154175

176+
# Show the text with a tab and quotes around it
155177
print("\t" + '"' + text + '"')
156178

179+
# If the text backup is not the last one, show a space separator
157180
if text_backup != texts[-1]:
158181
print()
159182

183+
# Show the end of the list
160184
print("]")
161185

162186
# Ask the user to select the Diary Slim text
@@ -167,13 +191,31 @@ def Multi_Selection(self):
167191
# Define the "Text" dictionary inside the root dictionary
168192
self.dictionary["Text"] = self.diary_slim["Texts"]["Dictionary"][option]
169193

194+
# Remove the selected text from the parameters dictionary
195+
parameters["options"].remove(option)
196+
parameters["language_options"].remove(self.dictionary["Text"]["Texts"][self.user_language])
197+
170198
# Add two line breaks if the text is not the first one
171199
if texts != []:
172200
self.dictionary["Text to write"] += "\n\n"
173201

174-
# Add the language text to the "Text to write" string
202+
# Define the language text
175203
language_text = self.dictionary["Text"]["Texts"][self.user_language]
176204

205+
# If the "States" key is inside the "Text" dictionary
206+
if "States" in self.dictionary["Text"]:
207+
# Get the current state
208+
language_text = self.dictionary["Text"]["States"]["Current state"][self.user_language]
209+
210+
# Change the current state to the next state
211+
self.Next_State(self.dictionary["Text"])
212+
213+
# If the "Additional information" key is inside the "Text" dictionary
214+
if "Additional information" in self.dictionary["Text"]:
215+
# Define the additional information and update the text to write
216+
language_text = self.Define_Additional_Information(self.dictionary, language_text)
217+
218+
# Add the language text to the "Text to write" string
177219
self.dictionary["Text to write"] += language_text
178220

179221
# Add a period to the end of the text if it is not present
@@ -184,7 +226,7 @@ def Multi_Selection(self):
184226
language_text = language_text.replace("\n", "\n")
185227

186228
# Add the language text to the texts list
187-
texts.append(language_text)
229+
texts.append(language_text)
188230

189231
def Define_Item_Variables(self):
190232
# Remove the "..." (three dots) text if it is present inside the text

Modules/Utility/Input/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def Select(self, options, language_options = None, show_text = None, select_text
6363

6464
if (
6565
"\n" in option and
66+
len(text) >= 2 and
6667
text[-2] + text[-1] != "\n\n"
6768
):
6869
text += "\n"

0 commit comments

Comments
 (0)