Skip to content

Refactor: split monolithic main.py into core/, widgets/, ui/ packages#1

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-compatibility-structure
Draft

Refactor: split monolithic main.py into core/, widgets/, ui/ packages#1
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-compatibility-structure

Conversation

Copy link

Copilot AI commented Mar 9, 2026

main.py was a 1598-line monolith mixing executor logic, terminal widget, dynamic param UI, script discovery, and the main window. This refactor splits responsibilities into focused modules while preserving 100% backward compatibility with all existing task scripts.

New structure

Module Responsibility
core/i18n.py Shared UI_TEXTS singleton; load_ui_texts() mutates it in-place so all modules share one dict
core/utils.py resource_path() — PyInstaller-compatible path resolver
core/executor.py ScriptExecutor(QThread) — QProcess, output decoding, [PROGRESS] parsing, send_input/terminate
core/script_registry.py scan(), parse_params(), extract_docstring()
widgets/terminal.py EnhancedTerminalWidget
widgets/dynamic_params.py DynamicParamsWidgetbuild_ui(params, lang) / build_args() / clear()
ui/main_window.py ScriptGUI(QMainWindow)
main.py 62-line launcher

Parameter parsing — backward-compatible --gui-schema extension

parse_params() tries --gui-schema first (returns structured JSON); falls back to the original --help regex heuristic for legacy scripts:

# New scripts can emit JSON schema:
# python script.py --gui-schema  →  [{"name": "--sort", "type": "choice", ...}]
#
# Old scripts unchanged — --help regex fallback fires automatically
params = registry.parse_params(script_path)   # transparent to caller

Bugs fixed

  • self.progress_label = None assigned twice in __init__ — duplicate removed
  • self.run_button.setText(lang['run_button']) called twice in _update_ui_language — duplicate removed
  • _refresh_scripts: was enabling the Stop button (wrong) and _clear_dynamic_params_ui() was unreachable inside a comment — both corrected
  • _on_script_finished: statusBar().showMessage(...) was inside an inline comment and never executed — fixed
  • Dead monkey-patch in _dynamic_params_resize_event (line 646 in original was unreachable) — replaced by DynamicParamsWidget.resizeEvent override
  • _get_union_of_marked_items() extracted as a helper, eliminating duplicated selected+checked union logic in _on_remove_button_clicked and keyPressEvent

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 9, 2026 12:15
Co-authored-by: UltraAce258 <174670272+UltraAce258@users.noreply.github.com>
… remove local import, extract timeout constant

Co-authored-by: UltraAce258 <174670272+UltraAce258@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor main.py for compatibility and reduced redundancy Refactor: split monolithic main.py into core/, widgets/, ui/ packages Mar 9, 2026
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.

2 participants