예제 #1
0
 def fail():
     """
     Failure pop-up for reminder
     """
     dialog_rem_error = DialogBuilder(self.app, "Error")
     dialog_rem_error.setTitleText("Failed to remove reminder")
     dialog_buttons = QDialogButtonBox(QDialogButtonBox.Ok)
     dialog_rem_error.addButtonBox(dialog_buttons)
     dialog_rem_error.show()
예제 #2
0
def ensureDirectory(app, path: str):
    """
    This will ensure that the directory we are saving the embedding files into exists.
    :param app: reference to the application
    :param path: path to the directory
    :return: Returns true on success and false otherwise
    """
    # if the path doesnt exist make the directory
    if not os.path.exists(path):
        try:
            os.mkdir(path)
            logging.info("Created WordEmbeddings directory")
            return True
        except OSError as e:
            logging.exception(e)
            logging.error("Failed to create directory")
            return False
    # if it does exist prompt the user to clear the directory
    else:
        logging.info("Download path directory already exists!")

        # create the dialog to warn the user the dir will be cleared
        clear_dialog = DialogBuilder(
            app, "Download directory WordEmbeddings already exists...",
            "Would you like to clear the contents and proceed?",
            "Cancel will stop the download.")
        button_box = QDialogButtonBox(QDialogButtonBox.Cancel
                                      | QDialogButtonBox.Yes)
        clear_dialog.addButtonBox(button_box)

        # clear the directory if selected by the user
        if clear_dialog.exec():
            logging.info("User chose to remove all contents")
            files = glob.glob(os.path.abspath(os.path.join(path, '*')))
            for f in files:
                try:
                    os.remove(f)
                    logging.debug("Removed: %s", f)
                except OSError as e:
                    dialog_fail = DialogBuilder(
                        app, "Removing contents failed\nPermission denied")
                    dialog_fail.show()
                    logging.exception(e)
                    logging.error("Error occured removing directory contents")
                    return False
            return True

        logging.info("User chose not to clear directory. Exiting download")
        return False
예제 #3
0
def onEncryptionAction(app, file_manager):
    """
    this will determine what will be encrypted or decrypted based off user input
    :param app: reference to the main application object
    :param file_manager: reference to the file manager object
    :return: Returns nothing
    """

    # Helper Functions
    def onEncryptBtnClicked(button):
        """
        """
        encryptionDialogHandler(app, file_manager, button)

    def onDecryptBtnClicked(button):
        """
        """
        decryptionDialogHandler(app, file_manager, button)

    # Check whether the encryptor already exists
    if file_manager.encryptor is None:
        # To encrypt workspace
        logging.info("Encryptor NOT initialized")
        dialog_encryptor = DialogBuilder(
            app, "Crypto - Encrypt",
            "Would you like to Encrypt all files in the workspace?",
            "Please proceed with caution.")
        buttons = QDialogButtonBox(QDialogButtonBox.Cancel
                                   | QDialogButtonBox.Yes)
        buttons.clicked.connect(onEncryptBtnClicked)
        dialog_encryptor.addButtonBox(buttons)
        dialog_encryptor.show()
    else:
        # To decrypt workspace
        logging.info("Encryptor already initialized")
        dialog_encryptor = DialogBuilder(
            app, "Crypto - Decrypt",
            "Would you like to Decrypt all files in the workspace!",
            "Please proceed with caution.")
        buttons = QDialogButtonBox(QDialogButtonBox.Cancel
                                   | QDialogButtonBox.Yes)
        buttons.clicked.connect(onDecryptBtnClicked)
        dialog_encryptor.addButtonBox(buttons)
        dialog_encryptor.show()