@@ -655,28 +655,73 @@ def Define_Diary_Slim_Texts(self):
655
655
if self .File .Exist (dictionary ["Files" ]["Data" ]) == True :
656
656
dictionary .update (self .JSON .To_Python (dictionary ["Files" ]["Data" ]))
657
657
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
+
658
697
# Define the language text files
659
698
for language in self .languages ["small" ]:
660
699
# Get the full language
661
700
full_language = self .languages ["full" ][language ]
662
701
663
702
# Define and create the language text file
664
703
dictionary ["Files" ][language ] = dictionary ["Folders" ]["root" ] + full_language + ".txt"
665
- self .File .Create (dictionary ["Files" ][language ])
666
704
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" ]
669
713
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 ] += "..."
673
717
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" ]
676
721
677
- dictionary ["Files" ].pop ("Data" )
722
+ dictionary ["Files" ].pop ("Data" )
678
723
679
- dictionary ["Files" ]["Data" ] = file
724
+ dictionary ["Files" ]["Data" ] = file
680
725
681
726
# If the "Item" key is inside the text dictionary
682
727
if "Item" in dictionary :
@@ -727,11 +772,88 @@ def Define_Diary_Slim_Texts(self):
727
772
728
773
self .diary_slim ["Texts" ]["Options" ][self .user_language ].append (language_text )
729
774
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
+
730
781
# Make a copy of the "Texts" dictionary
731
782
texts_copy = deepcopy (self .diary_slim ["Texts" ])
732
783
733
784
# Remove the "Options" key
734
785
texts_copy .pop ("Options" )
735
786
736
787
# 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
0 commit comments