Exemple #1
0
def importMD(item):
    # Input file
    filename, _ = QtWidgets.QFileDialog().getOpenFileName(
        None, "Attach File", "./", "Markdown(*.md)")
    if filename == "":
        return

    # Creating file in our app
    randomString = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
    directory = "./Application/notes/"
    path = directory + randomString
    if (not os.path.exists(directory)):
        os.makedirs(directory)
    shutil.copyfile(filename, path)

    # Encrypt file
    userInfo = readUserInfo()
    txt = readText(path)
    aes = AEScipher(str(userInfo[1]), currentNote, txt=txt, encrypt=True)
    txt = aes.Encrypt()
    if (not isinstance(txt, bytes)):
        txt = bytes(txt)
    with open(path, 'wb') as file:
        file.write(txt)
        file.seek(0)
    print("Encrypting after importing")

    # Add to JSON
    info = QtCore.QFileInfo(filename)
    newdict = {}
    newdict["name"] = info.fileName()[:-len("." + info.suffix())]
    newdict["expanded"] = {}
    newdict["expanded"]["path"] = path
    newdict["expanded"]["randomString"] = randomString
    deets = itemVal(item)
    if item.parent() is None:
        deets[2]["Uncategorized"][randomString] = newdict
    else:
        deets[1][deets[0]]["expanded"][randomString] = newdict

    saveUpdatedJson(deets[2])

    # Update treeWidget
    newItem = QtWidgets.QTreeWidgetItem()
    newItem.setText(0, newdict["name"])
    newItem.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable
                     | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap(":/icons/Icons/16x16/document_light.png"),
                   QtGui.QIcon.Normal, QtGui.QIcon.Off)
    newItem.setIcon(0, icon)
    item.addChild(newItem)
    item.setExpanded(True)
    item.treeWidget().setCurrentItem(newItem)
Exemple #2
0
def addNotebook(window, check):
    # input name
    if check:
        item = window.ui.treeWidget.topLevelItem(0)
    else:
        item = window.ui.treeWidget.currentItem()
    text, ok = QtWidgets.QInputDialog().getText(
        window,
        "Groot",
        "Enter the name for new notebook - ",
        flags=QtCore.Qt.Dialog)
    if ok is True:
        if str(text) != "":
            name = str(text)
        else:
            name = "Untitled"
    else:
        return

    deets = treeHandling.itemVal(item)

    # Make changes to fileStructure
    randomString = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
    newdict = {}
    newdict["name"] = name
    newdict["expanded"] = {}
    if (item.parent() is None):
        deets[1][deets[0]][randomString] = newdict
    else:
        deets[1][deets[0]]["expanded"][randomString] = newdict

    treeHandling.saveUpdatedJson(deets[2])

    # Update treeWidget
    newItem = QtWidgets.QTreeWidgetItem()
    newItem.setText(0, name)
    newItem.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable
                     | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap(":/icons/Icons/16x16/subfolder_light.png"),
                   QtGui.QIcon.Normal, QtGui.QIcon.Off)
    newItem.setIcon(0, icon)
    item.addChild(newItem)
    item.setExpanded(True)
    item.treeWidget().setCurrentItem(newItem)
Exemple #3
0
def deleteNote(item, plainTextEdit, filename):
    toBeDlt = treeHandling.itemVal(item)
    # Notes to be deleted
    notesToBeDeleted = pathContainedNotes(toBeDlt[1][toBeDlt[0]]["expanded"])
    if (currentNote._details["path"] in notesToBeDeleted):
        loadFileName("No Note Selected", filename)
        currentNote.closeFile()
        currentNote._open = False
        plainTextEdit.clear()

    # removed from tree
    item.parent().removeChild(item)
    for note in notesToBeDeleted:
        os.remove(note)
    # all files deleted
    del toBeDlt[1][toBeDlt[0]]
    # Updated dictionary
    treeHandling.saveUpdatedJson(toBeDlt[2])
Exemple #4
0
def attachFile(window):
    te = window.ui.plainTextEdit
    if currentNote._open == False:
        msg = QtWidgets.QMessageBox(
            QtWidgets.QMessageBox.Information, "Groot",
            "Cannot attach images when no note is currently loaded",
            QtWidgets.QMessageBox.Ok)
        msg.setParent(window, QtCore.Qt.Window)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/Icons/32x32/attention.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        msg.setWindowIcon(icon)
        msg.exec_()
        return
    filename, _ = QtWidgets.QFileDialog().getOpenFileName(
        None, "Attach File", "./")
    # print(filename)
    if filename == "":
        return
    randomString = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
    if (not os.path.exists("./Application/atch")):
        os.makedirs("./Application/atch")
    destination = shutil.copyfile(filename,
                                  "./Application/atch/" + randomString)
    # print(destination)
    te.insertPlainText("![fileName](" + destination + ")")
    item = currentNote._item
    deets = itemVal(item)
    temp = deets[1][deets[0]]["expanded"]
    if "atchfiles" in temp: pass
    else:
        temp["atchfiles"] = []
    # print("Attaching file")
    temp["atchfiles"] += [destination]
    saveUpdatedJson(deets[2])

    for _ in range(len("fileName](" + destination + ")")):
        te.moveCursor(QtGui.QTextCursor.Left)
    for _ in range(len("filename")):
        te.moveCursor(QtGui.QTextCursor.Right, QtGui.QTextCursor.KeepAnchor)
    te.setFocus()
Exemple #5
0
def addNote(item, _plainTextEdit, window):
    # input name
    text, ok = QtWidgets.QInputDialog().getText(
        window,
        "Groot",
        "Enter the name for new note - ",
        flags=QtCore.Qt.Dialog)
    if ok is True:
        if str(text) != "":
            name = str(text)
        else:
            name = "Untitled"
    else:
        return

    deets = treeHandling.itemVal(item)
    randomString = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
    path = "./Application/notes/"
    filename = randomString

    # create notes folder if not exists
    if (not os.path.exists(path)):
        os.makedirs(path)

    # Creating file
    open(os.path.join(path, filename), 'a').close()
    # open(path,'a').close()

    # encrypt file
    if (window.encryptAll == True):
        userInfo = Application.modules.userLogin.readUserInfo()
        aes = AEScipher(str(userInfo[1]), currentNote, txt="", encrypt=True)
        txt = aes.Encrypt()
        if (not isinstance(txt, bytes)):
            print("here")
            txt = bytes(txt, encoding='utf8')
        with open(path + filename, 'wb') as file:
            file.write(txt)
            file.seek(0)
        print("Encrypted in add note method")

    # Add to JSON
    newdict = {}
    newdict["name"] = name
    newdict["expanded"] = {}
    newdict["expanded"]["path"] = path + filename
    newdict["expanded"]["randomString"] = randomString
    if item is item.treeWidget().topLevelItem(1):
        deets[2]["Uncategorized"][randomString] = newdict
    else:
        deets[1][deets[0]]["expanded"][randomString] = newdict
    treeHandling.saveUpdatedJson(deets[2])

    # Update treeWidget
    newItem = QtWidgets.QTreeWidgetItem()
    newItem.setText(0, name)
    newItem.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable
                     | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap(":/icons/Icons/16x16/document_light.png"),
                   QtGui.QIcon.Normal, QtGui.QIcon.Off)
    newItem.setIcon(0, icon)
    item.addChild(newItem)
    item.setExpanded(True)
    item.treeWidget().setCurrentItem(newItem)
    # Focus on plainTextEdit
    _plainTextEdit.setFocus()
Exemple #6
0
def renameNote(item, col):
    deets = treeHandling.itemVal(item)
    dic = deets[1][deets[0]]
    dic["name"] = item.text(0)
    treeHandling.saveUpdatedJson(deets[2])