Skip to content

Conversation

@bhanushri12
Copy link

The changes made aim to improve code structure, readability, maintainability, and error handling, while also enhancing the user experience. Here are the specific changes:

1. Code Organization and Cleanliness

  • Refactored Methods: The setup code for the window and widgets is moved into separate methods (setup_window, create_widgets, populate_textbox, and get_combobox_values). This makes the code more modular and readable.
  • Consistent Naming Conventions: Used consistent naming conventions for variables and methods.

2. Error Handling

  • Try-Except Blocks: Added error handling in populate_textbox, get_combobox_values, and button_callback methods to catch and handle potential errors gracefully.

3. Separation of Concerns

  • Separation of UI and Logic: Separated the logic for fetching data from the database (sql.Query_FetchFromFile) and handling selections (File.Handle_Selection) from the UI code. This modular approach improves maintainability.

4. UI/UX Improvements

  • Intuitive UI: Ensured that the UI components are created and configured in a clean and understandable manner. Added better labeling and alignment for UI components.

5. Documentation

  • Docstrings and Comments: Although not explicitly shown in the example, you should add docstrings and comments to explain the purpose of classes, methods, and key parts of the code.

Example of Improved Code

import customtkinter as ctk
import Modules.SQL as sql
import Modules.FileHandling as File

class Available(ctk.CTk):
    def __init__(self):
        super().__init__()

        self.setup_window()
        self.create_widgets()
        self.populate_textbox()

    def setup_window(self):
        self.geometry("700x300")
        self.title("Route Information Page")
        self.minsize(300, 200)
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure((0, 1), weight=1)

    def create_widgets(self):
        self.textbox = ctk.CTkTextbox(master=self, font=("Arial", 18))
        self.textbox.grid(row=0, column=0, columnspan=2, padx=20, pady=(20, 0), sticky="nsew")
        
        self.combobox = ctk.CTkComboBox(master=self, values=self.get_combobox_values())
        self.combobox.grid(row=1, column=0, padx=20, pady=20, sticky="ew")

        self.button = ctk.CTkButton(master=self, command=self.button_callback, text="Proceed")
        self.button.grid(row=1, column=1, padx=20, pady=20, sticky="ew")

    def populate_textbox(self):
        try:
            available_list = sql.Query_FetchFromFile()
            available_list.reverse()
            indexing_choices = len(available_list)

            for item in available_list:
                self.textbox.insert("0.0", f"{indexing_choices}). {item}\n")
                indexing_choices -= 1
        except Exception as e:
            self.textbox.insert("0.0", f"Error fetching data: {e}\n")

    def get_combobox_values(self):
        try:
            available_list = sql.Query_FetchFromFile()
            values = [f"Choice {i+1}" for i in range(len(available_list))]
            values.append("Select")
            return values[::-1]
        except Exception as e:
            return [f"Error fetching data: {e}"]

    def button_callback(self):
        selection = self.combobox.get()
        try:
            File.Handle_Selection(selection)
        except Exception as e:
            print(f"Error handling selection: {e}")
        finally:
            self.destroy()
            import Payment
            Payment.mainloop()

if __name__ == "__main__":
    app = Available()
    app.mainloop()

@bhanushri12 bhanushri12 marked this pull request as draft July 12, 2024 00:18
@bhanushri12 bhanushri12 marked this pull request as ready for review July 12, 2024 00:19
@bhanushri12
Copy link
Author

@HartzFrequency the above PR is for the issue #96

@bhanushri12
Copy link
Author

@HartzFrequency I have made some changes can u please review them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant