Skip to content

Commit c50e1ef

Browse files
committed
fix: Simplify telegram_selector import to direct import for PyInstaller
- Remove complex lazy import logic from __init__.py - Use direct import at top level so PyInstaller can detect it - Remove problematic hidden imports that PyInstaller can't resolve - Keep module in hiddenimports as backup - Build completed successfully
1 parent 1e97f9f commit c50e1ef

1 file changed

Lines changed: 3 additions & 35 deletions

File tree

app/gui/widgets/__init__.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,9 @@
22
Reusable GUI widgets for the application.
33
"""
44

5-
# Lazy import function for TelegramSelectorDialog to avoid import errors at module level
6-
# This allows PyInstaller to include the module even if it's not directly imported
7-
def _get_telegram_selector_dialog():
8-
"""Lazy import function for TelegramSelectorDialog."""
9-
try:
10-
from app.gui.widgets.telegram_selector import TelegramSelectorDialog
11-
return TelegramSelectorDialog
12-
except ImportError:
13-
try:
14-
from .telegram_selector import TelegramSelectorDialog
15-
return TelegramSelectorDialog
16-
except ImportError:
17-
import importlib
18-
import sys
19-
import os
20-
# Get the directory of this file
21-
widgets_dir = os.path.dirname(os.path.abspath(__file__))
22-
if widgets_dir not in sys.path:
23-
sys.path.insert(0, widgets_dir)
24-
try:
25-
telegram_selector_module = importlib.import_module('telegram_selector')
26-
return telegram_selector_module.TelegramSelectorDialog
27-
except ImportError:
28-
# If all else fails, create a dummy class
29-
class TelegramSelectorDialog:
30-
def __init__(self, *args, **kwargs):
31-
raise RuntimeError("TelegramSelectorDialog module not found. Please rebuild the executable with PyInstaller using main.spec")
32-
return TelegramSelectorDialog
33-
34-
# Import it immediately to ensure PyInstaller sees it, but use the function for lazy loading
35-
try:
36-
from app.gui.widgets.telegram_selector import TelegramSelectorDialog
37-
except ImportError:
38-
# If import fails, use lazy loader
39-
TelegramSelectorDialog = _get_telegram_selector_dialog()
5+
# Import telegram_selector FIRST using absolute import to ensure PyInstaller includes it
6+
# This MUST be at the top level, not in a try-except, so PyInstaller can detect it
7+
from app.gui.widgets.telegram_selector import TelegramSelectorDialog
408

419
from .account_widget import AccountWidget, AccountListWidget
4210
from .campaign_widget import CampaignWidget, CampaignListWidget

0 commit comments

Comments
 (0)