Added larger resolutions / custom resolutions

This commit is contained in:
Your Name 2025-07-29 16:28:35 +01:00
parent 89e6bfd086
commit 393087954d
9 changed files with 259 additions and 24 deletions

View file

@ -1959,7 +1959,7 @@ class ConnectionManager:
self._is_synced = False
self._is_profile_being_enabled = {}
self.profile_button_objects = {}
self.available_resolutions = ['800x600', '1024x760', '1152x1080', '1280x1024', '1920x1080', '2560x1440', '2560x1600', '1920x1440', '1792x1344', '2048x1152']
self._location_list = []
self._browser_list = []
@ -1969,8 +1969,15 @@ class ConnectionManager:
def set_profile_button_objects(self, profile_id, profile_button_objects):
self.profile_button_objects[profile_id] = profile_button_objects
def get_available_resolutions(self, profile_id):
profile = ProfileController.get(profile_id)
if profile and hasattr(profile, 'resolution') and profile.resolution:
self.available_resolutions.append(profile.resolution)
return self.available_resolutions
def add_custom_resolution(self, resolution):
self.available_resolutions.append(resolution)
def add_connected_profile(self, profile_id):
self._connected_profiles.add(profile_id)
@ -3355,28 +3362,209 @@ class ScreenPage(Page):
self.selected_dimentions_icon = None
self.button_back.setVisible(True)
self.title.setGeometry(585, 40, 200, 40); self.title.setText("Pick a Resolution")
self.display.setGeometry(QtCore.QRect(5, 50, 580, 435))#relacion 4:3
self.display.setGeometry(QtCore.QRect(5, 50, 580, 435))
self.showing_larger_resolutions = False
self.larger_resolution_buttons = []
self.create_interface_elements()
def create_interface_elements(self):
self.buttonGroup = QButtonGroup(self)
self.buttons = []
for j, (object_type, icon_name, geometry) in enumerate([
(QPushButton, "800x600", (585, 90, 185, 75)),
(QPushButton, "1024x760", (585, 170, 185, 75)),
(QPushButton, "1152x1080", (585, 250, 185, 75)),
(QPushButton, "1280x1024", (585, 330, 185, 75)),
(QPushButton, "1920x1080", (585, 410, 185, 75))
(QPushButton, "800x600", (595, 90, 180, 70)),
(QPushButton, "1024x760", (595, 170, 180, 70)),
(QPushButton, "1152x1080", (595, 250, 180, 70)),
(QPushButton, "1280x1024", (595, 330, 180, 70)),
(QPushButton, "1920x1080", (595, 410, 180, 70))
]):
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}_button.png")))
boton.setIcon(QIcon(self.create_resolution_button_image(icon_name)))
self.buttons.append(boton)
self.buttonGroup.addButton(boton, j)
boton.clicked.connect(lambda _, dimentions=icon_name: self.show_dimentions(dimentions))
boton.clicked.connect(lambda _, dimentions=icon_name: self.on_standard_resolution_clicked(dimentions))
self.larger_resolutions_button = QPushButton(self)
self.larger_resolutions_button.setGeometry(100, 450, 185, 50)
self.larger_resolutions_button.setIconSize(self.larger_resolutions_button.size())
self.larger_resolutions_button.setIcon(QIcon(self.create_resolution_button_image("Larger Resolutions")))
self.larger_resolutions_button.clicked.connect(self.show_larger_resolutions)
self.custom_resolution_button = QPushButton(self)
self.custom_resolution_button.setGeometry(300, 450, 195, 50)
self.custom_resolution_button.setIconSize(self.custom_resolution_button.size())
self.custom_resolution_button.setIcon(QIcon(self.create_resolution_button_image("Custom Resolution")))
self.custom_resolution_button.clicked.connect(self.show_custom_resolution_dialog)
def create_resolution_button_image(self, resolution_text):
template_path = os.path.join(self.btn_path, "resolution_template_button.png")
if os.path.exists(template_path):
base_image = QPixmap(template_path)
if 'Resolution' in resolution_text:
base_image = base_image.scaled(195, 50)
else:
base_image = base_image.scaled(187, 75)
else:
base_image = QPixmap(185, 75)
base_image.fill(QColor(44, 62, 80))
painter = QPainter(base_image)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
font = QFont()
font.setPointSize(10)
font.setBold(True)
painter.setFont(font)
painter.setPen(QColor(0, 255, 255))
text_rect = base_image.rect()
painter.drawText(text_rect, Qt.AlignmentFlag.AlignCenter | Qt.AlignmentFlag.AlignVCenter, resolution_text)
painter.end()
return base_image
def show_larger_resolutions(self):
if self.showing_larger_resolutions:
self.hide_larger_resolutions()
else:
self.hide_standard_resolutions()
self.showing_larger_resolutions = True
self.larger_resolutions_button.setIcon(QIcon(self.create_resolution_button_image("Standard Resolutions")))
larger_resolutions = [
("2560x1600", (595, 90, 180, 70)),
("2560x1440", (595, 170, 180, 70)),
("1920x1440", (595, 250, 180, 70)),
("1792x1344", (595, 330, 180, 70)),
("2048x1152", (595, 410, 180, 70))
]
for i, (resolution, geometry) in enumerate(larger_resolutions):
button = QPushButton(self)
button.setGeometry(*geometry)
button.setIconSize(button.size())
button.setCheckable(True)
button.setVisible(True)
button.setIcon(QIcon(self.create_resolution_button_image(resolution)))
button.clicked.connect(lambda _, res=resolution: self.on_larger_resolution_clicked(res))
self.larger_resolution_buttons.append(button)
self.buttonGroup.addButton(button, len(self.buttons) + i)
def hide_larger_resolutions(self):
for button in self.larger_resolution_buttons:
self.buttonGroup.removeButton(button)
button.deleteLater()
self.larger_resolution_buttons.clear()
self.showing_larger_resolutions = False
self.larger_resolutions_button.setIcon(QIcon(self.create_resolution_button_image("Larger Resolutions")))
self.show_standard_resolutions()
def hide_standard_resolutions(self):
for button in self.buttons:
button.setVisible(False)
def show_standard_resolutions(self):
for button in self.buttons:
button.setVisible(True)
def on_standard_resolution_clicked(self, dimentions):
self.custom_resolution_button.setChecked(False)
self.show_dimentions(dimentions)
def on_larger_resolution_clicked(self, dimentions):
self.custom_resolution_button.setChecked(False)
self.show_dimentions(dimentions)
def show_custom_resolution_dialog(self):
dialog = QDialog(self)
dialog.setWindowTitle("Custom Resolution")
dialog.setFixedSize(300, 150)
dialog.setModal(True)
dialog.setStyleSheet("""
QDialog {
background-color: #2c3e50;
border: 2px solid #00ffff;
border-radius: 10px;
}
QLabel {
color: white;
font-size: 12px;
}
QLineEdit {
background-color: #34495e;
color: white;
border: 1px solid #00ffff;
border-radius: 5px;
padding: 5px;
font-size: 12px;
}
QPushButton {
background-color: #2c3e50;
color: white;
border: 2px solid #00ffff;
border-radius: 5px;
padding: 8px;
font-size: 12px;
}
QPushButton:hover {
background-color: #34495e;
}
""")
layout = QVBoxLayout()
input_layout = QHBoxLayout()
width_label = QLabel("Width:")
width_input = QLineEdit()
width_input.setPlaceholderText("1920")
height_label = QLabel("Height:")
height_input = QLineEdit()
height_input.setPlaceholderText("1080")
input_layout.addWidget(width_label)
input_layout.addWidget(width_input)
input_layout.addWidget(height_label)
input_layout.addWidget(height_input)
button_layout = QHBoxLayout()
ok_button = QPushButton("OK")
cancel_button = QPushButton("Cancel")
button_layout.addWidget(ok_button)
button_layout.addWidget(cancel_button)
layout.addLayout(input_layout)
layout.addLayout(button_layout)
dialog.setLayout(layout)
def validate_and_accept():
try:
width = int(width_input.text())
height = int(height_input.text())
if width <= 0 or height <= 0:
QMessageBox.warning(dialog, "Invalid Resolution", "Width and height must be positive numbers.")
return
if width > 10000 or height > 10000:
QMessageBox.warning(dialog, "Invalid Resolution", "Resolution too large. Maximum 10000x10000.")
return
custom_resolution = f"{width}x{height}"
self.show_dimentions(custom_resolution)
dialog.accept()
except ValueError:
QMessageBox.warning(dialog, "Invalid Input", "Please enter valid numbers for width and height.")
ok_button.clicked.connect(validate_and_accept)
cancel_button.clicked.connect(dialog.reject)
dialog.exec()
def update_swarp_json(self):
inserted_data = {
@ -3385,13 +3573,46 @@ class ScreenPage(Page):
self.update_status.write_data(inserted_data)
def show_dimentions(self, dimentions):
self.display.setPixmap(QPixmap(os.path.join(self.btn_path, f"{dimentions}.png")).scaled(self.display.size(), Qt.AspectRatioMode.KeepAspectRatio))
try:
image_path = os.path.join(self.btn_path, f"{dimentions}.png")
if os.path.exists(image_path):
self.display.setPixmap(QPixmap(image_path).scaled(self.display.size(), Qt.AspectRatioMode.KeepAspectRatio))
else:
self.create_resolution_preview_image(dimentions)
except:
self.display.clear()
self.selected_dimentions_icon = dimentions
self.button_next.setVisible(True)
self.update_swarp_json()
self.update_swarp_json()
def create_resolution_preview_image(self, resolution_text):
template_path = os.path.join(self.btn_path, "resolution_template.png")
if os.path.exists(template_path):
base_image = QPixmap(template_path)
base_image = base_image.scaled(580, 435, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
else:
base_image = QPixmap(580, 435)
base_image.fill(QColor(44, 62, 80))
painter = QPainter(base_image)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
font = QFont()
font.setPointSize(24)
font.setBold(True)
painter.setFont(font)
painter.setPen(QColor(0, 255, 255))
text_rect = base_image.rect()
painter.drawText(text_rect, Qt.AlignmentFlag.AlignCenter, resolution_text)
painter.end()
self.display.setPixmap(base_image)
class ResumePage(Page):
def __init__(self, page_stack, main_window=None, parent=None):
@ -3506,6 +3727,14 @@ class ResumePage(Page):
parent_label.setPixmap(base_image)
parent_label.show()
self.labels_creados.append(parent_label)
elif item == 'dimentions':
base_image = ScreenPage.create_resolution_button_image(self, text)
geometry = (585, initial_y + i * label_height, 185, 75)
parent_label = QLabel(self)
parent_label.setGeometry(*geometry)
parent_label.setPixmap(base_image)
parent_label.show()
self.labels_creados.append(parent_label)
else:
icon_path = os.path.join(self.btn_path, f"{text}_button.png")
geometry = (585, initial_y + i * label_height, 185, 75)
@ -3811,9 +4040,13 @@ class EditorPage(Page):
self.profiles_data = menu_page.match_core_profiles(profiles_dict=new_profiles)
self.data_profile = self.profiles_data[selected_profiles_str].copy()
profile_id = int(selected_profiles_str.split('_')[1])
self.data_profile['id'] = profile_id
if selected_profiles_str in self.temp_changes:
for key, value in self.temp_changes[selected_profiles_str].items():
self.data_profile[key] = value
self.name.textChanged.connect(self.update_name_value)
self.verificate(self.data_profile, selected_profiles_str)
@ -3827,7 +4060,7 @@ class EditorPage(Page):
"connection": ['browser-only', 'system-wide'],
"location": self.connection_manager.get_location_list(),
"browser": self.connection_manager.get_browser_list(),
"dimentions": ['800x600', '1024x760', '1152x1080', '1280x1024', '1920x1080']
"dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
}, selected_profile_str)
elif protocol == "residential" or protocol == "hidetor":
@ -3836,7 +4069,7 @@ class EditorPage(Page):
"connection": ['tor', 'just proxy'],
"location": self.connection_manager.get_location_list(),
"browser": self.connection_manager.get_browser_list(),
"dimentions": ['800x600', '1024x760', '1152x1080', '1280x1024', '1920x1080']
"dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
}, selected_profile_str)
elif protocol == "lokinet":
@ -3917,9 +4150,13 @@ class EditorPage(Page):
image_path = os.path.join(self.btn_path, f"button_{current_value}.png")
base_image = QPixmap(image_path)
if base_image.isNull():
locations = self.connection_manager.get_location_info(current_value)
fallback_path = os.path.join(self.btn_path, "default_location_button.png")
base_image = LocationPage.create_location_button_image(locations.country_name, fallback_path)
base_image = LocationPage.create_location_button_image(current_value, fallback_path)
elif key == 'dimentions':
current_value = f"{data_profile.get(key, '')}"
if current_value != 'None':
base_image = ScreenPage.create_resolution_button_image(self, current_value)
else:
image_path = os.path.join(self.btn_path, f"{data_profile.get(key, '')}_button.png")
current_value = data_profile.get(key, '')
@ -6230,6 +6467,4 @@ if __name__ == "__main__":
app = QApplication(sys.argv)
window = CustomWindow()
window.show()
sys.exit(app.exec())
sys.exit(app.exec())

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1,012 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1,000 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 999 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB