60
60
EVENT_SAVE_DB = 11
61
61
EVENT_EDIT_PROTECT_DB = 12
62
62
63
- # --------------------
64
- # PROMPT_SAVE Returns
65
- # --------------------
66
- PROMPT_DISCARDED = 0
67
- PROMPT_PROCEED = 1
68
- PROMPT_NONE = 2
69
-
70
- # ------------------------
71
- # RECORD SAVE RETURN TYPES
72
- # ------------------------
73
- SAVE_FAIL = 0 # Save failed due to callback
74
- SAVE_SUCCESS = 1 # Save was successful
75
- SAVE_NONE = 2 # There was nothing to save
76
-
77
- # --------------------
78
- # SEARCH RETURN VALUES
79
- # --------------------
80
- SEARCH_FAILED = 0 # No result was found
81
- SEARCH_RETURNED = 1 # A result was found
82
- SEARCH_ABORTED = 2 # The search was aborted, likely during a callback
83
- SEARCH_ENDED = 3 # We have reached the end of the search
63
+ # ----------------
64
+ # GENERIC BITMASKS
65
+ # ----------------
66
+ # Can be used with other bitmask values
67
+ SHOW_MESSAGE = 4096
68
+
69
+ # ---------------------------
70
+ # PROMPT_SAVE RETURN BITMASKS
71
+ # ---------------------------
72
+ PROMPT_SAVE_DISCARDED = 1
73
+ PROMPT_SAVE_PROCEED = 2
74
+ PROMPT_SAVE_NONE = 4
75
+
76
+ # ---------------------------
77
+ # RECORD SAVE RETURN BITMASKS
78
+ # ---------------------------
79
+ SAVE_FAIL = 1 # Save failed due to callback
80
+ SAVE_SUCCESS = 2 # Save was successful
81
+ SAVE_NONE = 4 # There was nothing to save
82
+
83
+ # ----------------------
84
+ # SEARCH RETURN BITMASKS
85
+ # ----------------------
86
+ SEARCH_FAILED = 1 # No result was found
87
+ SEARCH_RETURNED = 2 # A result was found
88
+ SEARCH_ABORTED = 4 # The search was aborted, likely during a callback
89
+ SEARCH_ENDED = 8 # We have reached the end of the search
84
90
85
91
86
92
def strip (string :str ) -> str :
@@ -535,7 +541,7 @@ def records_changed(self, recursive=True, column_name:str=None) -> bool:
535
541
return dirty
536
542
537
543
538
- def prompt_save (self , autosave = False ) -> Union [PROMPT_PROCEED , PROMPT_DISCARDED , PROMPT_NONE ]:
544
+ def prompt_save (self , autosave = False ) -> Union [PROMPT_SAVE_PROCEED , PROMPT_SAVE_DISCARDED , PROMPT_SAVE_NONE ]:
539
545
"""
540
546
Prompts the user if they want to save when changes are detected and the current record is about to change.
541
547
:param autosave: True to autosave when changes are found without prompting the user
@@ -546,7 +552,7 @@ def prompt_save(self, autosave=False) -> Union[PROMPT_PROCEED, PROMPT_DISCARDED,
546
552
# Return False if there is nothing to check or _prompt_save is False
547
553
# TODO: children too?
548
554
if self .current_index is None or self .rows == [] or self ._prompt_save is False :
549
- return PROMPT_NONE
555
+ return PROMPT_SAVE_NONE
550
556
551
557
# Check if any records have changed
552
558
changed = self .records_changed ()
@@ -558,12 +564,12 @@ def prompt_save(self, autosave=False) -> Union[PROMPT_PROCEED, PROMPT_DISCARDED,
558
564
if save_changes == 'Yes' :
559
565
# save this record
560
566
self .save_record_recursive ()
561
- return PROMPT_PROCEED
567
+ return PROMPT_SAVE_PROCEED
562
568
else :
563
569
self .rows .purge_virtual ()
564
- return PROMPT_DISCARDED
570
+ return PROMPT_SAVE_DISCARDED
565
571
else :
566
- return PROMPT_NONE
572
+ return PROMPT_SAVE_NONE
567
573
568
574
569
575
def requery (self , select_first = True , filtered = True , update = True , dependents = True ):
@@ -940,7 +946,7 @@ def save_record(self, display_message=True, update_elements=True):
940
946
941
947
if not self .records_changed ():
942
948
if display_message : sg .popup_quick_message ('There were no changes to save!' , keep_on_top = True )
943
- return SAVE_NONE
949
+ return SAVE_NONE + SHOW_MESSAGE
944
950
945
951
# check to see if cascading-fk has changed before we update database
946
952
fk_changed = False
@@ -955,13 +961,13 @@ def save_record(self, display_message=True, update_elements=True):
955
961
if self .transform is not None : self .transform (changed , TFORM_ENCODE )
956
962
957
963
if not self .driver .save_record (self .table ,self .get_current_pk (),self .pk_column ,changed ):
958
- return SAVE_FAIL
964
+ return SAVE_FAIL # Do not show the message in this case, since it's handled in the driver
959
965
960
966
# callback
961
967
if 'after_save' in self .callbacks .keys ():
962
968
if not self .callbacks ['after_save' ](self .frm , self .frm .window ):
963
969
self .driver .rollback ()
964
- return SAVE_FAIL
970
+ return SAVE_FAIL + SHOW_MESSAGE
965
971
966
972
# If we made it here, we can commit the changes
967
973
self .driver .commit ()
@@ -985,7 +991,7 @@ def save_record(self, display_message=True, update_elements=True):
985
991
logger .debug (f'Record Saved!' )
986
992
if display_message : sg .popup_quick_message ('Updates saved successfully!' ,keep_on_top = True )
987
993
988
- return SAVE_SUCCESS
994
+ return SAVE_SUCCESS + SHOW_MESSAGE
989
995
990
996
991
997
def save_record_recursive (self ):
@@ -1707,43 +1713,36 @@ def prompt_save(self, autosave=False) -> int:
1707
1713
if save_changes != 'Yes' :
1708
1714
# update the elements to erase any GUI changes, since we are choosing not to save
1709
1715
self .update_elements ()
1710
- return PROMPT_DISCARDED # We did have a change, regardless if the user chose not to save
1716
+ return PROMPT_SAVE_DISCARDED # We did have a change, regardless if the user chose not to save
1711
1717
self [q ].save_record (update_elements = False ) # Don't update elements yet, as there may be more saving to do yet
1712
1718
self .update_elements () # Now we are safe to update elements
1713
- return PROMPT_PROCEED if user_prompted else PROMPT_NONE
1719
+ return PROMPT_SAVE_PROCEED if user_prompted else PROMPT_SAVE_NONE
1714
1720
1715
1721
1716
1722
1717
1723
1718
1724
def save_records (self , cascade_only = False ):
1719
1725
logger .debug (f'Saving records in all queries...' )
1720
- msg = None
1721
- i = 0
1722
- tables = self .get_cascaded_relationships () if cascade_only else self .queries
1723
- last_index = len (self .queries ) - 1
1724
1726
1725
- successes = 0
1726
- failures = 0
1727
- no_actions = 0
1727
+ result = 0
1728
+ show_message = True
1729
+ tables = self . get_cascaded_relationships () if cascade_only else self . queries
1728
1730
for t in tables :
1729
1731
logger .debug (f'Saving records for table { t } ...' )
1730
- result = self [t ].save_record (False ,update_elements = False )
1731
- if result == SAVE_FAIL :
1732
- failures += 1
1733
- elif result == SAVE_SUCCESS :
1734
- successes += 1
1735
- elif result == SAVE_NONE :
1736
- no_actions += 1
1737
- logger .debug (f'Successes: { successes } , Failures: { failures } , No Actions: { no_actions } ' )
1738
-
1739
- if failures == 0 :
1740
- if successes == 0 :
1741
- sg .popup_quick_message ('There was nothing to update.' , keep_on_top = True )
1732
+ res = self [t ].save_record (False ,update_elements = False )
1733
+ if not res & SHOW_MESSAGE : show_message = False # Only one instance of not showing the message hides all
1734
+ result |= res
1735
+
1736
+ logger .debug (f'Success: { result & SAVE_SUCCESS } , Failure: { result & SAVE_FAIL } , No Action: { result & SAVE_NONE } ' )
1737
+
1738
+ if result & SAVE_FAIL :
1739
+ if show_message : sg .popup ('There was a problem saving some updates.' , keep_on_top = True )
1740
+ else :
1741
+ if result & SAVE_NONE :
1742
+ if show_message : sg .popup_quick_message ('There was nothing to update.' , keep_on_top = True )
1742
1743
else :
1743
- sg .popup_quick_message ('Updates saved successfully!' ,keep_on_top = True )
1744
+ if show_message : sg .popup_quick_message ('Updates saved successfully!' ,keep_on_top = True )
1744
1745
self .update_elements ()
1745
- else :
1746
- sg .popup ('There was a problem saving some updates.' , keep_on_top = True )
1747
1746
1748
1747
1749
1748
0 commit comments