ClinicianFOCUS / FreeScribe

A medical scribe capable of creating SOAP notes running Whisper and Kobold based on conversation with a patient
GNU General Public License v3.0
0 stars 0 forks source link

**issue (complexity):** Consider extracting a reusable TwoColumnFrame component to handle the settings UI layout. #29

Open ItsSimko opened 2 days ago

ItsSimko commented 2 days ago
          **issue (complexity):** Consider extracting a reusable TwoColumnFrame component to handle the settings UI layout.

The settings UI layout code could be simplified by extracting a reusable two-column frame component. This would reduce duplication and complexity while maintaining the same functionality. Here's an example approach:

class TwoColumnFrame(ttk.Frame):
    def __init__(self, parent):
        super().__init__(parent)
        self.left_frame = ttk.Frame(self)
        self.right_frame = ttk.Frame(self)
        self.left_frame.grid(row=0, column=0, padx=10, pady=5, sticky="nw")
        self.right_frame.grid(row=0, column=1, padx=10, pady=5, sticky="nw")
        self.left_row = 0
        self.right_row = 0

    def add_setting(self, name, widget_creator):
        # Add to shorter column
        target = self.left_frame if self.left_row <= self.right_row else self.right_frame
        row = self.left_row if target == self.left_frame else self.right_row

        tk.Label(target, text=f"{name}:").grid(row=row, column=0, padx=0, pady=5, sticky="w")
        widget = widget_creator(target)
        widget.grid(row=row, column=1, padx=0, pady=5, sticky="w")

        if target == self.left_frame:
            self.left_row += 1
        else:
            self.right_row += 1
        return widget

# Usage example:
def create_llm_settings(self):
    frame = TwoColumnFrame(self.llm_settings_frame)
    frame.pack(expand=True, fill="both")

    # Add settings more concisely
    self.llm_preset = frame.add_setting("LLM Preset", 
        lambda parent: ttk.Combobox(parent, values=preset_options, width=15))
    self.api_key = frame.add_setting("OpenAI API Key",
        lambda parent: tk.Entry(parent, width=25))
    # etc

This approach:

  1. Encapsulates column management logic
  2. Eliminates manual row tracking
  3. Automatically balances settings between columns
  4. Makes settings creation more declarative
  5. Reduces code duplication across different settings sections

_Originally posted by @sourcery-ai[bot] in https://github.com/ClinicianFOCUS/FreeScribe/pull/28#discussion_r1822592732_