diff --git a/src/PrivacyNoticeDialog.py b/src/PrivacyNoticeDialog.py index dc74b7c..d70fe78 100644 --- a/src/PrivacyNoticeDialog.py +++ b/src/PrivacyNoticeDialog.py @@ -6,6 +6,19 @@ import getpass import subprocess import re import logging +import os +import sys + +def get_resource_path(relative_path): + """Get absolute path to resource, works for dev and for PyInstaller""" + try: + # PyInstaller creates a temp folder and stores path in _MEIPASS + base_path = sys._MEIPASS + except Exception: + base_path = os.path.abspath(".") + + return os.path.join(base_path, relative_path) + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) @@ -17,10 +30,11 @@ class PrivacyNoticeDialog(wx.Dialog): # Calculate optimal dialog size based on screen size screen_width, screen_height = wx.DisplaySize() - self.max_width = min(700, screen_width * 0.75) + self.max_width = min(400, screen_width * 0.55) self.max_height = min(700, screen_height * 0.8) self.SetMinSize((450, 400)) + self.SetIcon(wx.Icon(get_resource_path("icon.ico"), wx.BITMAP_TYPE_ICO)) self.SetSize((self.max_width, self.max_height)) # Create main sizer @@ -29,11 +43,22 @@ class PrivacyNoticeDialog(wx.Dialog): # Create header with icon and title header_sizer = wx.BoxSizer(wx.HORIZONTAL) - # Add info icon - info_icon = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_MESSAGE_BOX, (32, 32)) - icon_ctrl = wx.StaticBitmap(self, -1, info_icon) + icon_path = get_resource_path("icon.ico") + + # Load as wx.Bitmap + custom_bitmap = wx.Bitmap(icon_path, wx.BITMAP_TYPE_ICO) + + # Convert to wx.Image to scale + custom_image = custom_bitmap.ConvertToImage() + resized_image = custom_image.Scale(64, 64, wx.IMAGE_QUALITY_HIGH) + + # Convert back to wx.Bitmap + resized_icon = wx.Bitmap(resized_image) + + # Show in StaticBitmap + icon_ctrl = wx.StaticBitmap(self, -1, resized_icon) header_sizer.Add(icon_ctrl, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 10) - + # Add title title_text = wx.StaticText(self, label="Privacy and System Information") title_font = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) @@ -104,16 +129,24 @@ class PrivacyNoticeDialog(wx.Dialog): f"wxPython Version: {system_info['wx_version']}" ) - info_text = wx.StaticText(self.scrolled_win, label=info_details) - scrolled_sizer.Add(info_text, 0, wx.ALL | wx.EXPAND, 10) + self.info_text = wx.StaticText(self.scrolled_win, label=info_details) + scrolled_sizer.Add(self.info_text, 0, wx.ALL | wx.EXPAND, 10) self.scrolled_win.SetSizer(scrolled_sizer) main_sizer.Add(self.scrolled_win, 1, wx.EXPAND | wx.ALL, 5) - # Add OK button + # Add OK button with auto-sizing ok_btn = wx.Button(self, wx.ID_OK, "I Understand and Continue") ok_btn.SetDefault() - ok_btn.SetMinSize((160, 35)) + + # Calculate button size based on text content + btn_dc = wx.ClientDC(ok_btn) + btn_dc.SetFont(ok_btn.GetFont()) + btn_text_width, btn_text_height = btn_dc.GetTextExtent(ok_btn.GetLabel()) + btn_width = max(160, btn_text_width + 40) # Minimum 160, or text width + padding + btn_height = max(35, btn_text_height + 16) # Minimum 35, or text height + padding + + ok_btn.SetMinSize((btn_width, btn_height)) btn_sizer = wx.BoxSizer(wx.HORIZONTAL) btn_sizer.AddStretchSpacer() @@ -131,9 +164,69 @@ class PrivacyNoticeDialog(wx.Dialog): self.Bind(wx.EVT_BUTTON, self.on_ok, ok_btn) self.Bind(wx.EVT_SIZE, self.on_resize) - # Fit the dialog to content - self.Fit() - self.adjust_to_screen() + # Fit the dialog to content with proper text wrapping + self.auto_adjust_layout() + + def auto_adjust_layout(self): + """Automatically adjust the layout to fit text content nicely""" + try: + # Calculate optimal dialog size based on content + screen_width, screen_height = wx.DisplaySize() + + # Get text dimensions to determine optimal width + temp_dc = wx.ClientDC(self) + temp_dc.SetFont(self.body_text.GetFont()) + + # Calculate maximum text width needed + max_text_width = 0 + + # Check body text lines + body_lines = self.body_text.GetLabel().split('\n') + for line in body_lines: + line_width, _ = temp_dc.GetTextExtent(line) + max_text_width = max(max_text_width, line_width) + + # Check system info lines + info_lines = self.info_text.GetLabel().split('\n') + for line in info_lines: + line_width, _ = temp_dc.GetTextExtent(line) + max_text_width = max(max_text_width, line_width) + + # Calculate optimal dialog width + optimal_width = min(max_text_width + 100, self.max_width) # Text width + margins + optimal_width = max(450, optimal_width) # Don't go below minimum + + # Set initial size + self.SetSize((optimal_width, self.max_height)) + + # Wrap text to fit the calculated width + self.body_text.Wrap(optimal_width - 60) + self.info_text.Wrap(optimal_width - 60) + + # Fit the scrolled window to content + self.scrolled_win.FitInside() + + # Calculate optimal height based on content + self.Layout() + self.Fit() + + # Get the total content height + content_height = self.scrolled_win.GetSizer().GetMinSize().height + dialog_height = min(content_height + 150, self.max_height) # Content height + header/footer + + # Set final size + self.SetSize((optimal_width, dialog_height)) + self.Layout() + self.scrolled_win.FitInside() + + # Ensure we don't exceed screen bounds + self.adjust_to_screen() + + except Exception as e: + logger.error(f"Error in auto_adjust_layout: {e}") + # Fallback: use default sizing + self.Fit() + self.adjust_to_screen() def get_system_info(self): """Gather comprehensive system information with improved processor detection""" @@ -374,18 +467,16 @@ class PrivacyNoticeDialog(wx.Dialog): final_height = min(current_size.height, screen_height - 40) self.SetSize(final_width, final_height) - self.body_text.Wrap(final_width - 60) - self.Layout() - self.scrolled_win.FitInside() self.CentreOnParent() def on_resize(self, event): """Handle dialog resize to re-wrap text appropriately""" try: - if hasattr(self, 'body_text'): + if hasattr(self, 'body_text') and hasattr(self, 'info_text'): new_width = self.GetSize().width - 60 if new_width > 200: self.body_text.Wrap(new_width) + self.info_text.Wrap(new_width) self.scrolled_win.Layout() self.scrolled_win.FitInside() except Exception as e: diff --git a/src/main.py b/src/main.py index 7aee8a5..79858dd 100644 --- a/src/main.py +++ b/src/main.py @@ -1255,8 +1255,27 @@ COMMANDS (type /help in chat for full list): logger.error(f"Error during close: {e}") self.Destroy() +if os.name == 'nt': + import ctypes + + def enable_high_dpi(): + try: + ctypes.windll.shcore.SetProcessDpiAwareness(1) + except: + try: + ctypes.windll.user32.SetProcessDPIAware() + except: + pass +else: + pass + + if __name__ == "__main__": try: + if os.name == 'nt': + enable_high_dpi() + else: + pass app = wx.App() frame = IRCFrame() frame.SetIcon(wx.Icon(get_resource_path("icon.ico"), wx.BITMAP_TYPE_ICO))