|
2 | 2 | Reusable GUI widgets for the application. |
3 | 3 | """ |
4 | 4 |
|
5 | | -# Import telegram_selector first using absolute import to ensure PyInstaller includes it |
6 | | -# Try multiple import strategies to ensure PyInstaller detects it |
7 | | -try: |
8 | | - from app.gui.widgets.telegram_selector import TelegramSelectorDialog |
9 | | -except ImportError: |
| 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.""" |
10 | 9 | try: |
11 | | - # Try relative import |
12 | | - from .telegram_selector import TelegramSelectorDialog |
| 10 | + from app.gui.widgets.telegram_selector import TelegramSelectorDialog |
| 11 | + return TelegramSelectorDialog |
13 | 12 | except ImportError: |
14 | | - # Last resort: try importing the module directly |
15 | | - import importlib |
16 | | - import sys |
17 | | - import os |
18 | | - # Get the directory of this file |
19 | | - widgets_dir = os.path.dirname(os.path.abspath(__file__)) |
20 | | - if widgets_dir not in sys.path: |
21 | | - sys.path.insert(0, widgets_dir) |
22 | 13 | try: |
23 | | - telegram_selector_module = importlib.import_module('telegram_selector') |
24 | | - TelegramSelectorDialog = telegram_selector_module.TelegramSelectorDialog |
| 14 | + from .telegram_selector import TelegramSelectorDialog |
| 15 | + return TelegramSelectorDialog |
25 | 16 | except ImportError: |
26 | | - # If all else fails, create a dummy class to prevent complete failure |
27 | | - class TelegramSelectorDialog: |
28 | | - def __init__(self, *args, **kwargs): |
29 | | - raise RuntimeError("TelegramSelectorDialog module not found. Please rebuild the executable with PyInstaller using main.spec") |
| 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() |
30 | 40 |
|
31 | 41 | from .account_widget import AccountWidget, AccountListWidget |
32 | 42 | from .campaign_widget import CampaignWidget, CampaignListWidget |
|
0 commit comments