chore: Update PyQT version to PyQT6 and adjust window geometry in URLManager
This commit is contained in:
54
app-new.py
54
app-new.py
@ -1,19 +1,17 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
from PyQt6.QtWidgets import (
|
||||||
from PyQt5.QtWidgets import (
|
|
||||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
|
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
|
||||||
QLineEdit, QPushButton, QTextEdit, QMessageBox,
|
QLineEdit, QPushButton, QTextEdit, QMessageBox,
|
||||||
QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog,
|
QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog,
|
||||||
QFormLayout, QTableWidget, QTableWidgetItem, QHeaderView,
|
QFormLayout, QTableWidget, QTableWidgetItem, QHeaderView,
|
||||||
QComboBox
|
QComboBox
|
||||||
)
|
)
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt6.QtGui import QIcon
|
||||||
from PyQt5.QtCore import Qt, QDateTime, QUrl
|
from PyQt6.QtCore import Qt, QDateTime, QUrl
|
||||||
from PyQt5.QtSvg import QSvgWidget
|
from PyQt6.QtSvgWidgets import QSvgWidget
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt6.QtGui import QDesktopServices
|
||||||
|
|
||||||
|
|
||||||
class URLSearch:
|
class URLSearch:
|
||||||
def __init__(self, url, search_engine_url):
|
def __init__(self, url, search_engine_url):
|
||||||
@ -28,14 +26,14 @@ class URLSearch:
|
|||||||
if file_name.endswith('.filter.py'):
|
if file_name.endswith('.filter.py'):
|
||||||
domain = '.'.join(file_name.split('.')[:-2]) # Extracting domain.tld from domain.tld.filter.py
|
domain = '.'.join(file_name.split('.')[:-2]) # Extracting domain.tld from domain.tld.filter.py
|
||||||
filters[domain] = os.path.join(self.filters_dir, file_name)
|
filters[domain] = os.path.join(self.filters_dir, file_name)
|
||||||
# print("Loaded filters:", filters) # Debug print
|
print("Loaded filters:", filters) # Debug print
|
||||||
return filters
|
return filters
|
||||||
|
|
||||||
def extract_terms(self):
|
def extract_terms(self):
|
||||||
parsed_url = QUrl(self.url)
|
parsed_url = QUrl(self.url)
|
||||||
host_parts = parsed_url.host().split('.')
|
host_parts = parsed_url.host().split('.')
|
||||||
domain = '.'.join(host_parts[-2:]) # Extract full domain including TLD
|
domain = '.'.join(host_parts[-2:]) # Extract full domain including TLD
|
||||||
# print("Extracted domain:", domain) # Debug print
|
print("Extracted domain:", domain) # Debug print
|
||||||
if domain in self.available_filters:
|
if domain in self.available_filters:
|
||||||
filter_file = self.available_filters[domain]
|
filter_file = self.available_filters[domain]
|
||||||
terms = self.apply_filter(filter_file)
|
terms = self.apply_filter(filter_file)
|
||||||
@ -71,7 +69,7 @@ class URLManager(QWidget):
|
|||||||
self.translations = {}
|
self.translations = {}
|
||||||
self.load_translations(f'lang/translations_{self.settings["language"].lower()[:2]}.json')
|
self.load_translations(f'lang/translations_{self.settings["language"].lower()[:2]}.json')
|
||||||
self.setWindowTitle(self.translations['title'])
|
self.setWindowTitle(self.translations['title'])
|
||||||
self.setGeometry(100, 100, 600, 800)
|
self.setGeometry(100, 100, 600, 600)
|
||||||
self.setWindowIcon(QIcon('assets/logo.png'))
|
self.setWindowIcon(QIcon('assets/logo.png'))
|
||||||
|
|
||||||
self.layout = QVBoxLayout()
|
self.layout = QVBoxLayout()
|
||||||
@ -83,12 +81,12 @@ class URLManager(QWidget):
|
|||||||
self.url_layout.addWidget(self.url_input)
|
self.url_layout.addWidget(self.url_input)
|
||||||
|
|
||||||
self.settings_button = QPushButton()
|
self.settings_button = QPushButton()
|
||||||
self.settings_button.setFixedSize(24, 24)
|
self.settings_button.setFixedSize(16, 16)
|
||||||
self.settings_button.clicked.connect(self.show_settings_dialog)
|
self.settings_button.clicked.connect(self.show_settings_dialog)
|
||||||
self.url_layout.addWidget(self.settings_button)
|
self.url_layout.addWidget(self.settings_button)
|
||||||
|
|
||||||
self.info_button = QPushButton()
|
self.info_button = QPushButton()
|
||||||
self.info_button.setFixedSize(24, 24)
|
self.info_button.setFixedSize(16, 16)
|
||||||
self.info_button.clicked.connect(self.show_info_dialog)
|
self.info_button.clicked.connect(self.show_info_dialog)
|
||||||
self.url_layout.addWidget(self.info_button)
|
self.url_layout.addWidget(self.info_button)
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ class URLManager(QWidget):
|
|||||||
self.add_button.clicked.connect(self.add_url)
|
self.add_button.clicked.connect(self.add_url)
|
||||||
self.layout.addWidget(self.add_button)
|
self.layout.addWidget(self.add_button)
|
||||||
|
|
||||||
self.layout.addSpacerItem(QSpacerItem(0, 10, QSizePolicy.Minimum, QSizePolicy.Fixed))
|
self.layout.addSpacerItem(QSpacerItem(0, 10, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed))
|
||||||
|
|
||||||
self.search_layout = QHBoxLayout()
|
self.search_layout = QHBoxLayout()
|
||||||
self.search_input = QLineEdit()
|
self.search_input = QLineEdit()
|
||||||
@ -114,12 +112,12 @@ class URLManager(QWidget):
|
|||||||
self.search_layout.addWidget(self.search_input)
|
self.search_layout.addWidget(self.search_input)
|
||||||
self.layout.addLayout(self.search_layout)
|
self.layout.addLayout(self.search_layout)
|
||||||
|
|
||||||
self.search_input.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
self.search_input.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
|
||||||
|
|
||||||
self.url_list = QTableWidget()
|
self.url_list = QTableWidget()
|
||||||
self.url_list.setColumnCount(3)
|
self.url_list.setColumnCount(3)
|
||||||
self.url_list.setHorizontalHeaderLabels([self.translations['url_placeholder'], self.translations['column_date'], self.translations['column_actions']])
|
self.url_list.setHorizontalHeaderLabels(['URL', self.translations['column_date'], self.translations['column_actions']])
|
||||||
self.url_list.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
self.url_list.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
|
||||||
self.url_list.setColumnWidth(1, 150)
|
self.url_list.setColumnWidth(1, 150)
|
||||||
self.url_list.setColumnWidth(2, 100)
|
self.url_list.setColumnWidth(2, 100)
|
||||||
self.layout.addWidget(self.url_list)
|
self.layout.addWidget(self.url_list)
|
||||||
@ -148,7 +146,7 @@ class URLManager(QWidget):
|
|||||||
|
|
||||||
def update_icon_color(self):
|
def update_icon_color(self):
|
||||||
palette = self.palette()
|
palette = self.palette()
|
||||||
if palette.color(palette.Window).value() < 128:
|
if palette.color(palette.ColorRole.Window).value() < 128:
|
||||||
settings_icon_path = 'assets/cogwheel_dark.svg'
|
settings_icon_path = 'assets/cogwheel_dark.svg'
|
||||||
info_icon_path = 'assets/info_dark.svg'
|
info_icon_path = 'assets/info_dark.svg'
|
||||||
self.action_icons = {
|
self.action_icons = {
|
||||||
@ -170,7 +168,7 @@ class URLManager(QWidget):
|
|||||||
url = self.url_input.text()
|
url = self.url_input.text()
|
||||||
description = self.description_input.toPlainText()
|
description = self.description_input.toPlainText()
|
||||||
if url:
|
if url:
|
||||||
date_added = QDateTime.currentDateTime().toString(Qt.ISODate)
|
date_added = QDateTime.currentDateTime().toString(Qt.DateFormat.ISODate)
|
||||||
url_data = {'url': url, 'description': description, 'date': date_added}
|
url_data = {'url': url, 'description': description, 'date': date_added}
|
||||||
self.urls.append(url_data)
|
self.urls.append(url_data)
|
||||||
self.save_url(url_data)
|
self.save_url(url_data)
|
||||||
@ -204,8 +202,8 @@ class URLManager(QWidget):
|
|||||||
|
|
||||||
def delete_url(self, row):
|
def delete_url(self, row):
|
||||||
reply = QMessageBox.question(self, self.translations['delete_confirmation_title'], self.translations['delete_confirmation'],
|
reply = QMessageBox.question(self, self.translations['delete_confirmation_title'], self.translations['delete_confirmation'],
|
||||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No)
|
||||||
if reply == QMessageBox.Yes:
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
del self.urls[row]
|
del self.urls[row]
|
||||||
self.save_urls()
|
self.save_urls()
|
||||||
self.update_url_list()
|
self.update_url_list()
|
||||||
@ -253,7 +251,7 @@ class URLManager(QWidget):
|
|||||||
vertical_header.setVisible(False)
|
vertical_header.setVisible(False)
|
||||||
|
|
||||||
def format_date(self, date_str):
|
def format_date(self, date_str):
|
||||||
date = QDateTime.fromString(date_str, Qt.ISODate)
|
date = QDateTime.fromString(date_str, Qt.DateFormat.ISODate)
|
||||||
if self.settings['date_format'] == 'Nerdy':
|
if self.settings['date_format'] == 'Nerdy':
|
||||||
return date.toString("yyyy-MM-ddTHH:mm:ss")
|
return date.toString("yyyy-MM-ddTHH:mm:ss")
|
||||||
elif self.settings['date_format'] == 'Normal':
|
elif self.settings['date_format'] == 'Normal':
|
||||||
@ -321,22 +319,22 @@ class URLManager(QWidget):
|
|||||||
|
|
||||||
svg_widget = QSvgWidget('assets/logo.svg')
|
svg_widget = QSvgWidget('assets/logo.svg')
|
||||||
svg_widget.setFixedSize(256, 256)
|
svg_widget.setFixedSize(256, 256)
|
||||||
layout.addWidget(svg_widget, alignment=Qt.AlignCenter)
|
layout.addWidget(svg_widget, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
written_by_label = QLabel(self.translations['developed_by'])
|
written_by_label = QLabel(self.translations['developed_by'])
|
||||||
layout.addWidget(written_by_label, alignment=Qt.AlignCenter)
|
layout.addWidget(written_by_label, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
link_label = QLabel()
|
link_label = QLabel()
|
||||||
link_label.setText(f'<a href="{self.translations["repository_link"]}">{self.translations["repository_link_name"]}</a>')
|
link_label.setText(f'<a href="{self.translations["repository_link"]}">{self.translations["repository_link_name"]}</a>')
|
||||||
link_label.setOpenExternalLinks(True)
|
link_label.setOpenExternalLinks(True)
|
||||||
layout.addWidget(link_label, alignment=Qt.AlignCenter)
|
layout.addWidget(link_label, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
dialog.setLayout(layout)
|
dialog.setLayout(layout)
|
||||||
dialog.exec_()
|
dialog.exec()
|
||||||
|
|
||||||
def show_settings_dialog(self):
|
def show_settings_dialog(self):
|
||||||
dialog = SettingsDialog(self)
|
dialog = SettingsDialog(self)
|
||||||
if dialog.exec_() == QDialog.Accepted:
|
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
self.settings = self.load_settings()
|
self.settings = self.load_settings()
|
||||||
self.update_url_list()
|
self.update_url_list()
|
||||||
|
|
||||||
@ -361,7 +359,7 @@ class SettingsDialog(QDialog):
|
|||||||
directory_layout.addWidget(self.browse_button)
|
directory_layout.addWidget(self.browse_button)
|
||||||
layout.addLayout(directory_layout)
|
layout.addLayout(directory_layout)
|
||||||
|
|
||||||
layout.addSpacerItem(QSpacerItem(0, 4, QSizePolicy.Minimum, QSizePolicy.Fixed))
|
layout.addSpacerItem(QSpacerItem(0, 4, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed))
|
||||||
|
|
||||||
form_layout = QFormLayout()
|
form_layout = QFormLayout()
|
||||||
|
|
||||||
@ -439,4 +437,4 @@ if __name__ == '__main__':
|
|||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = URLManager()
|
window = URLManager()
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec())
|
||||||
|
|||||||
2
app.py
2
app.py
@ -71,7 +71,7 @@ class URLManager(QWidget):
|
|||||||
self.translations = {}
|
self.translations = {}
|
||||||
self.load_translations(f'lang/translations_{self.settings["language"].lower()[:2]}.json')
|
self.load_translations(f'lang/translations_{self.settings["language"].lower()[:2]}.json')
|
||||||
self.setWindowTitle(self.translations['title'])
|
self.setWindowTitle(self.translations['title'])
|
||||||
self.setGeometry(100, 100, 600, 800)
|
self.setGeometry(100, 100, 600, 600)
|
||||||
self.setWindowIcon(QIcon('assets/logo.png'))
|
self.setWindowIcon(QIcon('assets/logo.png'))
|
||||||
|
|
||||||
self.layout = QVBoxLayout()
|
self.layout = QVBoxLayout()
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
PyQT5
|
PyQT6
|
||||||
|
|||||||
Reference in New Issue
Block a user