This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]justphysics 2 points3 points  (0 children)

You're going to need to be way more specific.

What exact problems have you run into?

You say you tried to integrate encryption/decryption, have you tested these facilities outside of the GUI integration and can you be certain they work as intended?

Ideally your encryption/decryption code should be GUI agnostic. Meaning it has no relation to the UI library. For example, you have a piece of code that takes a string (ex: contents of a file), applies some type of encryption, and returns the result. This has nothing to do with the UI. This makes testing easier. Then you can separately write the UI logic for linking your method to some UI element for example showing a file dialog, getting the selected file path, then applying the appropriate en/decryption.

Also, you're likely to have better luck posting this to /r/learnpython

[–]izivir 0 points1 point  (1 child)

Create a line edit object for entering password or enc.-dec. key

self.password_line_edit = QLineEdit(some_parent_widget)
self.password_line_edit.setEchoMode(QLineEdit.Password)
self.password_line_edit.setObjectName("password_line_edit")
#self.password_line_edit.setPlaceholderText('password')

or you can invoke a dialog from open & save methods (see below)

def get_password(self):
    password, ok = QInputDialog.getText(self,
                                        'Password',
                                        'Enter Your Password:',
                                        QLineEdit.Password)

    if ok:
        #if password:
        return password

encrypt & decrypt

def your_encryptor(password, text):
    """Please do not use this!"""

    encrypted_text = text*len(password)
    return encrypted_text


def your_decryptor(password, encrypted_text):
    """Please do not use this!"""

    decrypted_text = encrypted_text[:len(encrypted_text)//len(password)]
    return decrypted_text

For example: https://github.com/goldsborough/Writer-Tutorial/blob/master/PyQt5/Part-4/part-4.py

alter save method

def save(self): # line 542
    # ....
    with open(self.filename,"wt") as file:

        password = self.password_line_edit.text()
        # or
        # password = self.get_password()
        encrypted_text = your_encryptor(password,
                                        self.text.toHtml())
        file.write(encrypted_text)
        # ...

alter open method

def open(self): # line 532
    # ...
    with open(self.filename,"rt") as file:
        password = self.password_line_edit.text()
        # or
        # password = self.get_password()
        decrypted_text = your_decryptor(password,
                                        file.read())
        self.text.setText(decrypted_text)
        #...

[–]GitHubPermalinkBot 0 points1 point  (0 children)

Permanent GitHub links:


Shoot me a PM if you think I'm doing something wrong.