Serch and update dictionaries with pyqt6

#5
by inshaA - opened

๐Ÿ˜ƒ: ๐ŸŒ€ GUI creation with PyQt6 for searching words in text files using JSON dictionaries
๐Ÿ’ป Create GUI for finding words in text files using JSON dictionaries
I have a few Dictionaries saved in a folder as json files, These dictionaries are just a set of word splits extracted from a text file, where the words are set as keys and values are left blank, I fill some of these values with the corrected words and the others which don't need corrections are left as blank values,

These dictionaries contain duplicate words set as keys because I am not sorting these words to remove duplicates, and these duplicates are present in the current dictionary as well as the other dictionaries,

Now what I am looking for is, if I double clicked a key and select a word from any of these dictionaries, it should search for that word in the text files and print the entire line where the word is being used,
Create a GUI for the same with PyQt6 dark mode, Where in the upper most section it has a button to upload the dictionary and a button to run this script to find the selected word, just below that button in the middle section is a text box which displays the uploaded json file with 70% of total space covered and in the bottom section a text box to display the results of the found words sentances, how to do this with python 10.5?
๐Ÿค–: Creating a GUI with PyQt6 for your specific use case involves several steps. Here's a basic outline to help you get started:

  1. Install PyQt6:
pip install PyQt6
  1. Import necessary libraries:
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QTextEdit, QVBoxLayout, QWidget, QPlainTextEdit
from PyQt6.QtCore import QFile, QJsonDocument, QJsonObject, QJsonArray, QJsonParseError
from PyQt6.QtGui import QJsonModel, QStandardItemModel, QStandardItem
import json
  1. Create a custom class for the main window:
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        # Set dark theme
        self.setStyleSheet("background-color: #323232; color: #ffffff")

        # Create widgets
        self.upload_button = QPushButton("Upload Dictionary", self)
        self.run_button = QPushButton("Find Word", self)
        self.dictionary_text_edit = QTextEdit(self)
        self.dictionary_text_edit.setReadOnly(True)
        self.result_text_edit = QPlainTextEdit(self)

        # Layout
        layout = QVBoxLayout()
        layout.addWidget(self.upload_button)
        layout.addWidget(self.run_button)
        layout.addWidget(self.dictionary_text_edit, stretch=3)
        layout.addWidget(self.result_text_edit, stretch=1)

        central_widget = QWidget()
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

        # Connections
        self.upload_button.clicked.connect(self.loadDictionary)
        self.run_button.clicked.connect(self.findWord)

    def loadDictionary(self):
        file_path, _ = QFileDialog.getOpenFileName(self, "Open Dictionary", "", "JSON Files (*.json)")
        if file_path:
            with open(file_path, 'r') as f:
                content = f.read()
                self.dictionary_text_edit.setText(content)

    def findWord(self):
        # Implement the logic to find the word in text files and display the result
        pass
  1. Run the application:
def main():
    app = QApplication(sys.argv)

    window = MainWindow()
    window.show()

    sys.exit(app.exec())
  1. Call the main function at the end of your script.

This code sets up the basic GUI structure with a dark theme, including buttons for uploading a dictionary and finding a word, as well as text boxes for displaying the dictionary and search results. You'll need to implement the findWord method to parse the JSON data, search for the selected word in text files, and display the results in the result_text_edit widget. This may involve reading text files, parsing JSON, and using string manipulation functions to find the desired lines.

Please note that the provided code is a starting point and does not include error handling or the actual functionality to search for words in text files. You will need to extend it according to your specific requirements.

Sign up or log in to comment