refactor: implement UI code optimization and refactoring
This commit implements the comprehensive UI code refactoring plan to improve code quality, reduce duplication, and enhance maintainability. Phase 1: High Priority Improvements - Create BaseDialog class to eliminate window centering code duplication across ProgressDialog, DeleteProgressWindow, LoginDialog, and UserSelectionDialog (~30 lines of duplicate code removed) - Unify log color configuration with LogTheme class in gui/log_config.py - Create permission check decorators (@require_admin, @require_permission, @require_user_type, @handle_errors) - Update all dialog classes to use unified patterns Phase 2: Architecture Improvements - Create input validation framework (ValidationResult, Validator, ValidatedWidget classes) - Implement StateManager with observer pattern for component state sharing - Create unified ErrorHandler for consistent error handling - Extract CheckboxTreeview into reusable component New Modules: - gui/widgets/base_dialog.py - Base dialog class with modal setup and centering - gui/utils/decorators.py - Permission and error handling decorators - gui/utils/error_handler.py - Unified error handling with user-friendly messages - gui/utils/state_manager.py - State management with observer pattern - gui/utils/validators.py - Input validation framework - gui/material_validation/checkbox_treeview.py - Reusable checkbox table Modified Files: - gui/log_config.py - Added LogTheme class for centralized styling - gui/widgets/log_text.py - Use LogTheme.COLORS - gui/widgets/progress_dialog.py - Inherit from BaseDialog - gui/widgets/delete_progress_window.py - Inherit from BaseDialog, use LogTheme - gui/widgets/__init__.py - Add new exports, optional imports - gui/login_dialog.py - Use unified centering pattern - gui/user_selection_dialog.py - Use unified centering pattern - gui/material_validation_tab.py - Import CheckboxTreeview from new module Benefits: - Reduced code duplication by ~200 lines - Improved maintainability through centralized configuration - Better abstraction with 5 new reusable base classes - Enhanced type safety with type hints - Future-proof theming support via LogTheme Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,8 +6,26 @@ GUI 自定义组件模块
|
||||
|
||||
from .file_selector import FileSelector
|
||||
from .log_text import LogText
|
||||
from .production_id_input import ProductionIdInput
|
||||
try:
|
||||
from .production_id_input import ProductionIdInput
|
||||
_has_production_id_input = True
|
||||
except ImportError:
|
||||
# tklinenums may not be installed
|
||||
_has_production_id_input = False
|
||||
from .log_handler import GuiTextHandler
|
||||
from .delete_progress_window import DeleteProgressWindow
|
||||
from .base_dialog import BaseDialog
|
||||
from .progress_dialog import ProgressDialog
|
||||
|
||||
__all__ = ['FileSelector', 'LogText', 'ProductionIdInput', 'GuiTextHandler', 'DeleteProgressWindow']
|
||||
__all__ = [
|
||||
'FileSelector',
|
||||
'LogText',
|
||||
'GuiTextHandler',
|
||||
'DeleteProgressWindow',
|
||||
'BaseDialog',
|
||||
'ProgressDialog',
|
||||
]
|
||||
|
||||
# Add ProductionIdInput to __all__ only if it's available
|
||||
if _has_production_id_input:
|
||||
__all__.append('ProductionIdInput')
|
||||
|
||||
Reference in New Issue
Block a user