Esempio n. 1
0
 def askYesNo(message):
     return MessageBox(message, title, 
                       MB_OK + MB_YESNO + MB_ICONQUESTION +
                       MB_SYSTEMMODAL) == 6
Esempio n. 2
0
 def errorDialog(message):
     MessageBox(message, title, MB_OK + MB_ICONERROR + MB_SYSTEMMODAL)
Esempio n. 3
0
 def askRetryCancel(message):
     return MessageBox(message, title, 
                       MB_OK + MB_RETRYCANCEL + MB_ICONEXCLAMATION 
                       + MB_SYSTEMMODAL) == 4
Esempio n. 4
0
    def compare_to_reference(self, ref_file_path: str) -> None:
        """ Compare the business plan to a reference file.

        Compare the business plan with the contents of a reference file. The
        results of the comparison are shown in a dialog box.

        When the business plan and the reference file are not identical, a
        detailed report is displayed in the dialog box, indicating:

        - Lines which have different values in the business plan and in the
          reference.

        - Lines from the business plan which are not in the reference.

        - Lines from the reference which are not in the business plan.

        The user is then given the option to overwrite the reference file with
        the contents of the business plan (this is the way a reference file is
        created in the first place). A renamed copy of the old reference
        file is kept as a backup.


        Arguments
        ---------

        ref_file_path: `str`
            Path to the reference file. """
        reference = pd.read_json(ref_file_path)
        if not reference.index.equals(self._df.index):
            raise ValueError("Index mismatch between business plan and "
                             "reference file")
        bp_not_equal_to_ref: List[str] = []
        missing_from_ref: List[str] = []
        missing_from_bp: List[str] = []
        for key, value in self._df.items():
            if key in reference:
                if not np.allclose(value, reference[key]):
                    bp_not_equal_to_ref.append(key)
            else:
                missing_from_ref.append(key)
        for key in reference:
            if key not in self._df:
                missing_from_bp.append(key)
        if bp_not_equal_to_ref or missing_from_ref or missing_from_bp:
            msg = ""
            if bp_not_equal_to_ref:
                lines = len(bp_not_equal_to_ref)
                plural = lines > 1
                msg += (f"{lines} line{'s' if plural else ''} of BP "
                        f"'{self.name}' {'are' if plural else 'is'} not equal "
                        f"to reference file '{ref_file_path}':\n" +
                        "".join(f"- {line}\n" for line in bp_not_equal_to_ref))
            if missing_from_ref:
                lines = len(missing_from_ref)
                plural = lines > 1
                msg += (f"\n{lines} line{'s' if plural else ''} of BP "
                        f"'{self.name}' {'are' if plural else 'is'} missing "
                        f"from reference file '{ref_file_path}':\n" +
                        "".join(f"- {line}\n" for line in missing_from_ref))
            if missing_from_bp:
                lines = len(missing_from_bp)
                plural = lines > 1
                msg += (f"\n{lines} line{'s' if plural else ''} of reference "
                        f"file '{ref_file_path}' {'are' if plural else 'is'} "
                        f"missing from BP '{self.name}':\n" +
                        "".join(f"- {line}\n" for line in missing_from_bp))
            msg += f"\n\nUpdate reference file '{ref_file_path}'?"
            if (MessageBox(msg, "Business plan", win32con.MB_YESNO
                           | win32con.MB_DEFBUTTON2) == win32con.IDYES):
                path = Path(ref_file_path)
                suffix = path.suffix
                date_time = (datetime.fromtimestamp(
                    path.stat().st_mtime).strftime('%Y %m %d %H %M %S'))
                path.rename(
                    Path(f'{path.with_suffix("")} {date_time}{suffix}'))
                self._df.to_json(ref_file_path)

        else:
            MessageBox(
                f"All {len(self._df.columns)} lines of BP "
                f"'{self.name}' are equal to reference file "
                f"'{ref_file_path}'", "Business plan")