-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyside6_fix.py
More file actions
67 lines (56 loc) · 2.56 KB
/
pyside6_fix.py
File metadata and controls
67 lines (56 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
PySide6互換性修正モジュール
PySide6のQEventとイベント処理に関連する互換性の問題を修正するためのモジュールです。
アプリケーション起動時に自動的に適用されます。
"""
import sys
import logging
from PySide6.QtCore import QEvent
# オリジナルの初期化メソッドを保存
original_init = QEvent.__init__
def patched_init(self, *args, **kwargs):
"""
QEvent初期化の修正版
intで直接初期化しようとした場合、適切なQEvent.Typeに変換します
"""
try:
# オリジナルの初期化を試みる
original_init(self, *args, **kwargs)
except TypeError as e:
# 整数が渡された場合、QEvent.Typeに変換する
if len(args) == 1 and isinstance(args[0], int):
try:
# QEvent.Typeとして再初期化
event_type = QEvent.Type(args[0])
original_init(self, event_type)
except Exception as conv_error:
logging.error(f"PySide6 QEvent初期化パッチ適用中にエラー: {conv_error}")
raise
else:
# その他のエラーはそのまま伝播
raise
def apply_patches():
"""パッチを適用します"""
# QEvent.__init__をパッチ適用
QEvent.__init__ = patched_init
logging.info("PySide6 QEvent互換性パッチが適用されました")
# PyInstallerの一時ディレクトリエラー抑制
if getattr(sys, 'frozen', False):
try:
import os
import warnings
import ctypes
# 警告の抑制
warnings.filterwarnings("ignore", message=".*temporary directory.*")
warnings.filterwarnings("ignore", message=".*Temp_.*")
# Windows環境でのエラーダイアログ抑制
if os.name == 'nt':
try:
# SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX
ctypes.windll.kernel32.SetErrorMode(0x0001 | 0x8000)
logging.info("Windows エラーダイアログ抑制が適用されました")
except Exception as e:
logging.warning(f"Windows エラーダイアログ抑制の適用に失敗: {e}")
logging.info("PyInstaller一時ディレクトリエラー抑制パッチが適用されました")
except Exception as e:
logging.warning(f"一時ディレクトリエラー抑制パッチの適用に失敗: {e}")