AI Coding in Practice: Generating Error-Free GUI Tools
This article explores how to turn a vague requirement into a working desktop GUI tool using AI coding assistants, using a batch audio-video extraction utility as the case study. It breaks requirements into verifiable layers, shows key implementation patterns for background execution, progress queues, duplicate-name handling, dependency checks, and format whitelists, and provides a reusable prompt structure, follow-up validation questions, and an acceptance checklist for reliable delivery.
1. Background: Why “It Generates” Is Not the Same as “It Ships”
AI coding tools keep expanding their reach, from single-line completion to full modules and even small runnable applications in one shot. But in real engineering work, developers care about three simpler questions: does the code pass syntax and compilation checks on the first try; does the core functionality cover the requirements; and is it reliable on error paths and interaction.
Desktop GUI tools are a good example. They look simple, but they concentrate three typical difficulties:
- Many requirement dimensions: format support, import/export, layout, and status feedback all exist at once, so items are easy to miss.
- Sensitivity to the concurrency model: if a long-running task runs on the main thread, the UI freezes. This is the most common pitfall in beginner-generated solutions.
- Complex error paths: missing files, unsupported encodings, duplicate output names, and missing external dependencies all need explicit handling.
This article uses a “batch audio-video extraction tool” as the case study to discuss how to turn a fuzzy requirement into a high-quality, runnable implementation, and provides a reusable prompt structure and acceptance checklist.
2. Requirement Breakdown: Turning “Tedious” into Verifiable Items
High-quality generation starts with requirements that can be judged. It helps to split requirements into four layers, each independently verifiable.
- Functional layer
- Accept input in common video container formats;
- Support output in common audio formats;
- Provide a complete workflow: file import list, output format settings, run, and exit.
- Interaction layer
- Clear layout regions: controls, list, parameters, and feedback;
- Every long-running operation must show progress and status.
- Robustness layer
- Validate input paths and enforce a format whitelist;
- Define a duplicate output-name policy and check external dependency availability;
- A failed item must not stop the whole task; log errors one by one.
- Non-functional layer
- The UI stays responsive during conversion;
- The structure is layered so new formats and parameters can be added later.
The most critical item here is “no UI freeze.” It is essentially a requirement on the concurrency model: the GUI main loop must stay responsive, while time-consuming encoding/decoding and file I/O must run in the background and report progress back in a thread-safe way.
3. Key Implementation Points and Sample Code
1. Background Execution with Queue-Based Progress
A common approach: the main thread handles only the UI and scheduling, a worker thread executes tasks, progress is sent back through a queue, and the main thread polls on a timer and refreshes widgets. The structure looks like this (illustrative only, not a full project):
import queueimport threadingtask_q = queue.Queue()progress_q = queue.Queue()def worker():while True:item = task_q.get()if item is None:breaksrc, dst, fmt = item# Call an external transcoding capability or library to do the conversionprogress_q.put(("progress", src, 100))task_q.task_done()def poll_progress():while not progress_q.empty():kind, src, val = progress_q.get_nowait()# Update the progress bar and status bar on the main threadroot.after(100, poll_progress) # Pseudocode: poll on a timer
The key point: do not manipulate UI widgets directly inside callbacks. Post state changes to a queue and let the main thread consume them, avoiding the uncertainty of cross-thread UI updates.
2. Duplicate Output Names and Dependency Checks
A safer engineering strategy is “check first, then execute”:
- Create the output directory if it does not exist;
- Append a sequence number to duplicate file names to avoid overwriting;
- At startup, check whether the external transcoding component is available, and show a clear message instead of a stack trace if it is missing.
def unique_path(dir_path, base, ext):candidate = os.path.join(dir_path, f"{base}.{ext}")i = 1while os.path.exists(candidate):candidate = os.path.join(dir_path, f"{base}_{i}.{ext}")i += 1return candidate
3. Recursive Scanning and Format Whitelist
Batch tools usually need to walk a directory recursively and filter with a whitelist so unrelated files do not end up in the queue:
VIDEO_EXT = {".mp4", ".mkv", ".mov", ".avi", ".flv", ".wmv"}AUDIO_EXT = {".mp3", ".wav", ".aac", ".flac", ".m4a"}def collect_files(root_dir):for cur, _, files in os.walk(root_dir):for name in files:ext = os.path.splitext(name)[1].lower()if ext in VIDEO_EXT or ext in AUDIO_EXT:yield os.path.join(cur, name)
4. Prompt Structure: How to Keep the Model from Missing Items
In practice, generation quality depends heavily on how structured the prompt is. A four-part structure is recommended:
- Role and goal: state clearly that the goal is “a runnable desktop batch conversion tool.”
- Constraint list: language and GUI framework, required widgets and features, concurrency and responsiveness requirements.
- Acceptance criteria: passes syntax checks, zero errors, no UI freeze, clear messages on errors.
- Output format: full code first, then feature notes and usage steps.
Writing “no freeze” as a verifiable acceptance item rather than an adjective makes the model more likely to produce a background-execution plus queue-based progress design, instead of putting time-consuming logic on the main thread.
5. Follow-Up and Second Validation: From “It Runs” to “It Works Well”
After generation, three rounds of follow-up validation are recommended:
- Path semantics: where is the default output directory? Can users customize it?
- Failure recovery: does a mid-way failure affect later tasks? Can errors be traced to a specific file?
- Maintainability: is format support extensible? Are parameters decoupled from the UI?
If the model gives consistent, actionable answers to these questions, it shows its understanding of the context is coherent, rather than “happening to assemble code that compiles.”
6. Acceptance Checklist (Reusable)
- Passes syntax and compilation checks on the first try;
- Complete loop of import, settings, run, and exit;
- UI stays interactive during conversion, with visible progress and status;
- Duplicate names do not overwrite; missing dependencies produce a message;
- A single failure does not block the whole task;
- Recursive directory scanning and format whitelist work.
7. Conclusion
The value of AI coding is not replacing developers with text that “looks like code,” but turning structured requirements quickly into a verifiable, iterable engineering starting point. Writing requirements as a checklist, writing experience as acceptance items, and writing concurrency and error handling as hard constraints is the key to stable, usable generation results. For enterprise scenarios, combining these with common capabilities such as cloud builds, logging services, and monitoring alerts can extend “one-time generation” into a sustainable delivery workflow.
