import os import re def fix_pyside6_syntax(filepath): """Исправляет устаревший синтаксис PySide6""" with open(filepath, 'r', encoding='utf-8') as f: content = f.read() # Замены replacements = [ (r'Qt\.Horizontal', 'Qt.Orientation.Horizontal'), (r'Qt\.Vertical', 'Qt.Orientation.Vertical'), (r'Qt\.LeftButton', 'Qt.MouseButton.LeftButton'), (r'Qt\.RightButton', 'Qt.MouseButton.RightButton'), (r'Qt\.MiddleButton', 'Qt.MouseButton.MiddleButton'), (r'self\.RenderHint\.', 'QPainter.RenderHint.'), (r'Qt\.KeepAspectRatio', 'Qt.AspectRatioMode.KeepAspectRatio'), (r'Qt\.IgnoreAspectRatio', 'Qt.AspectRatioMode.IgnoreAspectRatio'), (r'Qt\.ScrollBarAsNeeded', 'Qt.ScrollBarPolicy.ScrollBarAsNeeded'), (r'Qt\.ScrollBarAlwaysOff', 'Qt.ScrollBarPolicy.ScrollBarAlwaysOff'), (r'Qt\.ScrollBarAlwaysOn', 'Qt.ScrollBarPolicy.ScrollBarAlwaysOn'), (r'Qt\.black', 'Qt.GlobalColor.black'), (r'Qt\.white', 'Qt.GlobalColor.white'), (r'Qt\.red', 'Qt.GlobalColor.red'), (r'Qt\.green', 'Qt.GlobalColor.green'), (r'Qt\.blue', 'Qt.GlobalColor.blue'), (r'Qt\.yellow', 'Qt.GlobalColor.yellow'), (r'Qt\.gray', 'Qt.GlobalColor.gray'), (r'Qt\.darkGray', 'Qt.GlobalColor.darkGray'), (r'Qt\.lightGray', 'Qt.GlobalColor.lightGray'), (r'Qt\.transparent', 'Qt.GlobalColor.transparent'), ] for old, new in replacements: content = re.sub(old, new, content) # Добавляем импорт QPainter если нужно if 'QPainter' not in content and any('RenderHint' in content for _ in []): if 'from PySide6.QtGui import' in content: content = content.replace( 'from PySide6.QtGui import', 'from PySide6.QtGui import QPainter, ' ) else: content = 'from PySide6.QtGui import QPainter\n' + content with open(filepath, 'w', encoding='utf-8') as f: f.write(content) print(f"Fixed: {filepath}") # Проходим по всем файлам for root, dirs, files in os.walk('.'): for file in files: if file.endswith('.py'): filepath = os.path.join(root, file) try: fix_pyside6_syntax(filepath) except Exception as e: print(f"Error fixing {filepath}: {e}") print("Done!")