Advertisement
shh_algo_PY

Smart Notes, Part 1 (Dec 2022)

Dec 10th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. from PyQt5.QtCore import Qt
  2. from PyQt5.QtWidgets import (
  3.     QApplication, QWidget, QPushButton,
  4.     QLabel, QListWidget, QLineEdit,
  5.     QTextEdit, QInputDialog, QHBoxLayout,
  6.     QVBoxLayout, QFormLayout)
  7.  
  8. import json
  9.  
  10. app = QApplication([])
  11.  
  12. #==========================================#
  13. '''Notes in json'''
  14.  
  15. notes = {
  16.     "Welcome!" : {
  17.         "text" : "This is the best note taking app in the world!",
  18.         "tags" : ["good", "instructions"]
  19.     }
  20. }
  21.  
  22. with open("notes_data.json", "w") as file:
  23.     json.dump(notes, file, ensure_ascii=False)
  24. #==========================================#
  25.  
  26. '''Application interface'''
  27. # Application window parameters
  28. notes_win = QWidget()
  29. notes_win.setWindowTitle('Smart Notes')
  30. notes_win.resize(900, 600)
  31.  
  32. # Application window widgets
  33. # List widget: List of notes
  34. list_notes = QListWidget()
  35. list_notes_label = QLabel('List of notes')
  36.  
  37. # Buttons under the list of notes
  38. button_note_create = QPushButton('Create note')
  39. button_note_del = QPushButton('Delete note')
  40. button_note_save = QPushButton('Save note')
  41.  
  42. # Creates a field to insert tags
  43. field_tag = QLineEdit('') # Creates a blank field
  44. field_tag.setPlaceholderText('Enter tag...') # Text prompt inside the field
  45. field_text = QTextEdit() # Field for entering text
  46.  
  47. # Buttons for all the tags
  48. button_add = QPushButton('Add to note')
  49. button_del = QPushButton('Untag from note')
  50. button_search = QPushButton('Search notes by tag')
  51.  
  52. # List widget: List of tags
  53. list_tags = QListWidget()
  54. list_tags_label = QLabel('List of tags')
  55.  
  56. # Arranging widgets by layout
  57. layout_notes = QHBoxLayout()
  58. col_1 = QVBoxLayout()
  59. col_1.addWidget(field_text)
  60.  
  61. col_2 = QVBoxLayout()
  62. col_2.addWidget(list_notes_label)
  63. col_2.addWidget(list_notes)
  64. row_1 = QHBoxLayout()
  65. row_1.addWidget(button_note_create)
  66. row_1.addWidget(button_note_del)
  67. row_2 = QHBoxLayout()
  68. row_2.addWidget(button_note_save)
  69. col_2.addLayout(row_1)
  70. col_2.addLayout(row_2)
  71.  
  72. col_2.addWidget(list_tags_label)
  73. col_2.addWidget(list_tags)
  74. col_2.addWidget(field_tag)
  75. row_3 = QHBoxLayout()
  76. row_3.addWidget(button_add)
  77. row_3.addWidget(button_del)
  78. row_4 = QHBoxLayout()
  79. row_4.addWidget(button_search)
  80.  
  81. col_2.addLayout(row_3)
  82. col_2.addLayout(row_4)
  83.  
  84. layout_notes.addLayout(col_1, stretch = 2)
  85. layout_notes.addLayout(col_2, stretch = 1)
  86. notes_win.setLayout(layout_notes)
  87.  
  88. #==========================================#
  89.  
  90. '''Application functionality'''
  91. def show_note():
  92.     key = list_notes.selectedItems()[0].text()
  93.     print(key)
  94.     field_text.setText(notes[key]["text"])
  95.     list_tags.clear()
  96.     list_tags.addItems(notes[key]["tags"])
  97.  
  98. list_notes.itemClicked.connect(show_note)
  99.  
  100. with open("notes_data.json", "r") as file:
  101.     notes = json.load(file)
  102.  
  103. list_notes.addItems(notes)
  104.  
  105. #==========================================#
  106.  
  107. # Run the application
  108. notes_win.show()
  109. app.exec_()
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement