#!/usr/bin/python3 """ this script is a simple GUI for managing Wireguard Tunnels """ import getpass import sys import tkinter as tk from tkinter import TclError from shared_libs.common_tools import ( LxTools, CryptoUtil, ConfigManager, ThemeManager, IconManager, ) from shared_libs.wp_app_config import AppConfig from ui.main_frame import MainFrame from ui.log_window import LogWindow from logger import app_logger class Wirepy(tk.Tk): """ Class Wirepy this is the Main Window of wirepy """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Hide the window initially self.withdraw() self.my_tool_tip = None self.x_width = AppConfig.UI_CONFIG["window_size"][0] self.y_height = AppConfig.UI_CONFIG["window_size"][1] # Set the window size self.geometry(f"{self.x_width}x{self.y_height}") self.resizable( AppConfig.UI_CONFIG["resizable_window"][0], AppConfig.UI_CONFIG["resizable_window"][1], ) self.minsize( AppConfig.UI_CONFIG["window_size"][0], AppConfig.UI_CONFIG["window_size"][1], ) self.title(AppConfig.UI_CONFIG["window_title"]) self.image_manager = IconManager() self.tk.call( "source", f"{AppConfig.SYSTEM_PATHS['tcl_path']}/water.tcl") ConfigManager.init(AppConfig.SETTINGS_FILE) theme = ConfigManager.get("theme") ThemeManager.change_theme(self, theme) # Try to set icon try: icon = self.image_manager.get_icon("vpn_small") if icon: self.iconphoto(True, icon) except Exception: pass self.log_window = LogWindow(self) app_logger.init_logger(self.log_window.log_message) # Add the widgets main_frame = MainFrame(self, image_manager=self.image_manager, toggle_log_window=self.toggle_log_window) main_frame.grid(sticky="nsew") self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) # Center the window on the primary monitor LxTools.center_window_cross_platform(self, self.x_width, self.y_height) # Now show the window after it has been positioned self.after(10, self.deiconify) def toggle_log_window(self): self.log_window.toggle() if __name__ == "__main__": AppConfig.ensure_directories() AppConfig.create_default_settings() LxTools.sigi(AppConfig.TEMP_DIR) CryptoUtil.decrypt(getpass.getuser()) window = Wirepy() """ the hidden files are hidden in Filedialog """ try: window.tk.call("tk_getOpenFile", "-foobarbaz") except TclError: pass window.tk.call("set", "::tk::dialog::file::showHiddenBtn", "0") window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0") window.mainloop() LxTools.clean_files(AppConfig.TEMP_DIR) sys.exit(0)