105 lines
4.8 KiB
Python
Executable file
105 lines
4.8 KiB
Python
Executable file
import os
|
|
|
|
from PyQt6.QtWidgets import QPushButton, QButtonGroup
|
|
from PyQt6.QtGui import QPixmap, QIcon
|
|
from PyQt6.QtCore import Qt
|
|
from PyQt6 import QtCore
|
|
|
|
from gui.v2.ui.pages.Page import Page
|
|
from gui.v2.ui.pages.location_page import LocationPage
|
|
|
|
|
|
class HidetorPage(Page):
|
|
def __init__(self, page_stack, main_window, parent=None):
|
|
super().__init__("HideTor", page_stack, main_window, parent)
|
|
self.selected_location_icon = None
|
|
self.connection_manager = main_window.connection_manager
|
|
self.update_status = main_window
|
|
self.button_next.clicked.connect(self.go_selected)
|
|
self.button_reverse.setVisible(True)
|
|
self.button_reverse.clicked.connect(self.reverse)
|
|
self.display.setGeometry(QtCore.QRect(5, 10, 390, 520))
|
|
self.title.setGeometry(395, 40, 380, 40)
|
|
self.title.setText("Pick a location")
|
|
|
|
if self.connection_manager.is_synced():
|
|
from gui.v2.actions.sync import generate_grid_positions
|
|
locs = self.connection_manager.get_location_list()
|
|
positions = generate_grid_positions(len(locs))
|
|
available = [(QPushButton, loc, positions[i]) for i, loc in enumerate(locs)]
|
|
self.create_interface_elements(available)
|
|
|
|
def create_interface_elements(self, available_locations):
|
|
self.buttonGroup = QButtonGroup(self)
|
|
self.buttons = []
|
|
|
|
for j, (object_type, icon_name, geometry) in enumerate(available_locations):
|
|
boton = object_type(self)
|
|
boton.setGeometry(*geometry)
|
|
boton.setIconSize(boton.size())
|
|
boton.setCheckable(True)
|
|
locations = self.connection_manager.get_location_info(icon_name)
|
|
if icon_name == 'my_14':
|
|
boton.setVisible(False)
|
|
if locations and not (hasattr(locations, 'is_proxy_capable') and locations.is_proxy_capable):
|
|
boton.setVisible(False)
|
|
icon_path = os.path.join(self.btn_path, f"button_{icon_name}.png")
|
|
boton.setIcon(QIcon(icon_path))
|
|
fallback_path = os.path.join(
|
|
self.btn_path, "default_location_button.png")
|
|
provider = locations.operator.name if locations and hasattr(
|
|
locations, 'operator') else None
|
|
if boton.icon().isNull():
|
|
if locations and hasattr(locations, 'country_name'):
|
|
location_name = locations.country_name
|
|
base_image = LocationPage.create_location_button_image(
|
|
location_name, fallback_path, provider)
|
|
boton.setIcon(QIcon(base_image))
|
|
else:
|
|
base_image = LocationPage.create_location_button_image(
|
|
'', fallback_path, provider)
|
|
boton.setIcon(QIcon(base_image))
|
|
else:
|
|
if locations and hasattr(locations, 'country_name'):
|
|
base_image = LocationPage.create_location_button_image(
|
|
f'{locations.country_code}_{locations.code}', fallback_path, provider, icon_path)
|
|
boton.setIcon(QIcon(base_image))
|
|
else:
|
|
base_image = LocationPage.create_location_button_image(
|
|
'', fallback_path, provider, icon_path)
|
|
boton.setIcon(QIcon(base_image))
|
|
self.buttons.append(boton)
|
|
self.buttonGroup.addButton(boton, j)
|
|
boton.location_icon_name = icon_name
|
|
boton.setCursor(QtCore.Qt.CursorShape.PointingHandCursor)
|
|
boton.clicked.connect(
|
|
lambda checked, loc=icon_name: self.show_location(loc))
|
|
|
|
def update_swarp_json(self):
|
|
inserted_data = {
|
|
"location": self.selected_location_icon,
|
|
"connection": "tor"
|
|
}
|
|
self.update_status.write_data(inserted_data)
|
|
|
|
def show_location(self, location):
|
|
tor_hide_img = f'hdtor_{location}'
|
|
self.display.setPixmap(QPixmap(os.path.join(self.btn_path, f"{tor_hide_img}.png")).scaled(
|
|
self.display.size(), Qt.AspectRatioMode.KeepAspectRatio))
|
|
self.selected_location_icon = location
|
|
self.button_next.setVisible(True)
|
|
self.update_swarp_json()
|
|
|
|
def reverse(self):
|
|
self.custom_window.navigator.navigate("protocol")
|
|
|
|
def go_selected(self):
|
|
self.custom_window.navigator.navigate("browser")
|
|
|
|
def show_location_verification(self, location_icon_name):
|
|
from gui.v2.ui.pages.location_verification_page import LocationVerificationPage
|
|
verification_page = LocationVerificationPage(
|
|
self.page_stack, self.update_status, location_icon_name, self)
|
|
self.page_stack.addWidget(verification_page)
|
|
self.page_stack.setCurrentIndex(
|
|
self.page_stack.indexOf(verification_page))
|