import os from PyQt6.QtWidgets import QPushButton, QLabel, QButtonGroup from PyQt6.QtGui import QPixmap, QIcon from PyQt6 import QtCore from gui.v2.ui.pages.Page import Page class WireGuardPage(Page): browser_label_created = False def __init__(self, page_stack, main_window, parent=None): super().__init__("Wireguard", page_stack, main_window, parent) self.buttonGroup = QButtonGroup(self) self.btn_path = main_window.btn_path self.update_status = main_window self.buttons = [] self.selected_protocol = None self.selected_protocol_icon = None self.button_back.setVisible(True) self.button_go.clicked.connect(self.go_selected) self.additional_labels = [] self.title.setGeometry(585, 40, 185, 40) self.title.setText("Pick a Protocol") self.sudo_warning = QLabel("Requires Sudo", self) self.sudo_warning.setGeometry(165, 90, 300, 40) self.sudo_warning.setStyleSheet(""" font-size: 24px; font-weight: bold; color: cyan; """) self.sudo_warning.setVisible(False) self.create_interface_elements() def create_interface_elements(self): for j, (object_type, icon_name, page_name, geometry) in enumerate([ (QPushButton, "system-wide", "location", (585, 90, 185, 75)), (QPushButton, "browser-only", "location", (585, 90+30+75+30+75, 185, 75)), (QLabel, None, None, (570, 170, 210, 105)), (QLabel, None, None, (570, 385, 210, 115)) ]): if object_type == QPushButton: boton = object_type(self) boton.setGeometry(*geometry) boton.setIconSize(boton.size()) boton.setCheckable(True) boton.setIcon( QIcon(os.path.join(self.btn_path, f"{icon_name}.png"))) self.buttons.append(boton) self.buttonGroup.addButton(boton, j) boton.clicked.connect( lambda _, name=page_name, protocol=icon_name: self.show_protocol(name, protocol)) elif object_type == QLabel: label = object_type(self) label.setGeometry(*geometry) label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) label.setWordWrap(True) if geometry == (570, 170, 210, 105): text1 = "VPN for the whole PC\n(€1/month - 1 location)" label.setText(text1) elif geometry == (570, 385, 210, 115): text2 = "1 Profile.\n1 Country.\nIsolated VPN for just the browser\n(1€/month)" label.setText(text2) def update_swarp_json(self): inserted_data = { "protocol": "wireguard", "connection": self.selected_protocol_icon } self.update_status.write_data(inserted_data) def show_protocol(self, page_name, protocol): if protocol == "browser-only": self.sudo_warning.setVisible(False) else: self.sudo_warning.setVisible(True) self.protocol_chosen = protocol self.selected_protocol_icon = protocol self.selected_page_name = page_name self.button_go.setVisible(True) self.update_swarp_json() for label in self.additional_labels: label.deleteLater() self.additional_labels.clear() if protocol == "system-wide": label_principal = QLabel(self) label_principal.setGeometry(0, 60, 540, 460) pixmap = QPixmap(os.path.join(self.btn_path, "wireguard.png")) label_principal.setPixmap(pixmap) label_principal.show() label_principal.setScaledContents(True) label_principal.lower() self.additional_labels.append(label_principal) if protocol == "browser-only": label_principal = QLabel(self) label_principal.setGeometry(0, 80, 530, 380) pixmap = QPixmap(os.path.join(self.btn_path, "wireguard.png")) label_principal.setPixmap(pixmap) label_principal.show() label_principal.setScaledContents(True) label_principal.show() self.additional_labels.append(label_principal) label_background = QLabel(self) label_background.setGeometry(0, 60, 540, 460) pixmap = QPixmap(os.path.join(self.btn_path, "browser only.png")) label_background.setPixmap(pixmap) label_background.show() label_background.setScaledContents(True) label_background.lower() self.additional_labels.append(label_background) def go_selected(self): if self.selected_page_name: self.custom_window.navigator.navigate("location") self.display.clear() for boton in self.buttons: boton.setChecked(False) self.button_go.setVisible(False) def reverse(self): self.display.clear() for boton in self.buttons: boton.setChecked(False) self.button_go.setVisible(False) self.custom_window.navigator.navigate("protocol")