import os import json from PyQt5.
QtWidgets import ( QMainWindow, QFileDialog,
QMessageBox, QVBoxLayout, QWidget, QSplitter, QListWidget, QTextEdit, QAction,
QMenuBar, QLineEdit, QPushButton, QHBoxLayout, QLabel ) from [Link] import Qt,
QTimer from [Link] import Tag from [Link] import Session
class MainWindow(QMainWindow): def init(self): super().init() [Link]("NVivo
Clone") [Link](100, 100, 1000, 600)
[Link] = Session()
[Link] = 'light'
self.init_ui()
self.load_tags()
self.start_auto_save()
def init_ui(self):
self.text_edit = QTextEdit()
# Tag List and Search
self.search_bar = QLineEdit()
self.search_bar.setPlaceholderText("Search tags...")
self.search_bar.[Link](self.filter_tags)
self.tag_list = QListWidget()
self.tag_list.setMaximumWidth(200)
self.tag_list.[Link](self.apply_tag_to_selection)
self.refresh_tags_button = QPushButton("Refresh Tags")
self.refresh_tags_button.[Link](self.load_tags)
tag_layout = QVBoxLayout()
tag_layout.addWidget(QLabel("Tags"))
tag_layout.addWidget(self.search_bar)
tag_layout.addWidget(self.tag_list)
tag_layout.addWidget(self.refresh_tags_button)
tag_widget = QWidget()
tag_widget.setLayout(tag_layout)
splitter = QSplitter([Link])
[Link](tag_widget)
[Link](self.text_edit)
container = QWidget()
layout = QVBoxLayout()
[Link](splitter)
[Link](layout)
[Link](container)
self.create_menu()
def create_menu(self):
menubar = [Link]()
file_menu = [Link]("File")
open_action = QAction("Open", self)
open_action.[Link](self.open_file)
file_menu.addAction(open_action)
save_action = QAction("Save", self)
save_action.[Link](self.save_file)
file_menu.addAction(save_action)
export_action = QAction("Export Tags", self)
export_action.[Link](self.export_tags)
file_menu.addAction(export_action)
view_menu = [Link]("View")
toggle_theme_action = QAction("Toggle Theme", self)
toggle_theme_action.[Link](self.toggle_theme)
view_menu.addAction(toggle_theme_action)
help_menu = [Link]("Help")
about_action = QAction("About", self)
about_action.[Link](self.show_about)
help_menu.addAction(about_action)
def open_file(self):
path, _ = [Link](self, "Open Text File", "", "Text
Files (*.txt)")
if path:
with open(path, 'r', encoding='utf-8') as file:
self.text_edit.setPlainText([Link]())
def save_file(self):
path, _ = [Link](self, "Save Text File", "", "Text
Files (*.txt)")
if path:
with open(path, 'w', encoding='utf-8') as file:
[Link](self.text_edit.toPlainText())
def export_tags(self):
tags = [Link](Tag).all()
tag_data = [{'name': [Link], 'description': [Link]} for tag in
tags]
path, _ = [Link](self, "Export Tags", "", "JSON Files
(*.json)")
if path:
with open(path, 'w', encoding='utf-8') as file:
[Link](tag_data, file, indent=4)
def load_tags(self):
self.tag_list.clear()
tags = [Link](Tag).all()
self.current_tags = tags
for tag in tags:
self.tag_list.addItem([Link])
def filter_tags(self, text):
self.tag_list.clear()
for tag in self.current_tags:
if [Link]() in [Link]():
self.tag_list.addItem([Link])
def apply_tag_to_selection(self, item):
cursor = self.text_edit.textCursor()
if [Link]():
tag = [Link]()
selection = [Link]()
[Link](f'[{tag}:{selection}]')
def toggle_theme(self):
if [Link] == 'light':
[Link]("QTextEdit, QListWidget, QLineEdit { background-
color: #2b2b2b; color: #f0f0f0; } QPushButton { background-color: #444; color:
white; }")
[Link] = 'dark'
else:
[Link]("")
[Link] = 'light'
def show_about(self):
[Link](self, "About NVivo Clone", "NVivo Clone App\nBuilt
with Python and PyQt5\nDeveloped by Temwa")
def start_auto_save(self):
self.auto_save_timer = QTimer(self)
self.auto_save_timer.[Link](self.auto_save)
self.auto_save_timer.start(60000)
def auto_save(self):
auto_path = [Link]([Link](), '[Link]')
with open(auto_path, 'w', encoding='utf-8') as file:
[Link](self.text_edit.toPlainText())