Update translations for English and Icelandic languages, add URL description field, and update button labels. Added a huge clause into the README.md, calling this version 1.0 beta.

This commit is contained in:
2024-07-13 19:05:18 +02:00
parent b1d72dde93
commit 57024c48a1
5 changed files with 357 additions and 112 deletions

View File

@ -6,12 +6,11 @@ from PyQt6.QtWidgets import (
QLineEdit, QPushButton, QTextEdit, QMessageBox,
QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog,
QFormLayout, QTableWidget, QTableWidgetItem, QHeaderView,
QComboBox
QComboBox, QAbstractItemView
)
from PyQt6.QtGui import QIcon
from PyQt6.QtGui import QIcon, QDesktopServices
from PyQt6.QtCore import Qt, QDateTime, QUrl
from PyQt6.QtSvgWidgets import QSvgWidget
from PyQt6.QtGui import QDesktopServices
class URLSearch:
def __init__(self, url, search_engine_url):
@ -59,7 +58,7 @@ class URLSearch:
search_url = f"{self.search_engine_url}{search_query}"
QDesktopServices.openUrl(QUrl(search_url))
else:
print("No valid search term extracted, search disabled.")
QDesktopServices.openUrl(QUrl(self.url)) # Open the URL directly if no valid search term is extracted
class URLManager(QWidget):
def __init__(self):
@ -68,7 +67,7 @@ class URLManager(QWidget):
self.settings = self.load_settings()
self.translations = {}
self.load_translations(f'lang/translations_{self.settings["language"].lower()[:2]}.json')
self.setWindowTitle(self.translations['title'])
self.setWindowTitle(self.get_translation('title', 'URL Manager'))
self.setGeometry(100, 100, 600, 600)
self.setWindowIcon(QIcon('assets/logo.png'))
@ -77,16 +76,18 @@ class URLManager(QWidget):
# URL input and settings button layout
self.url_layout = QHBoxLayout()
self.url_input = QLineEdit()
self.url_input.setPlaceholderText(self.translations['url_placeholder'])
self.url_input.setPlaceholderText(self.get_translation('url_placeholder', 'Enter URL'))
self.url_layout.addWidget(self.url_input)
self.settings_button = QPushButton()
self.settings_button.setFixedSize(16, 16)
self.settings_button.setFixedSize(28, 28)
self.settings_button.setStyleSheet("padding: 5px;")
self.settings_button.clicked.connect(self.show_settings_dialog)
self.url_layout.addWidget(self.settings_button)
self.info_button = QPushButton()
self.info_button.setFixedSize(16, 16)
self.info_button.setFixedSize(28, 28)
self.info_button.setStyleSheet("padding: 5px;")
self.info_button.clicked.connect(self.show_info_dialog)
self.url_layout.addWidget(self.info_button)
@ -95,11 +96,11 @@ class URLManager(QWidget):
self.update_icon_color()
self.description_input = QTextEdit()
self.description_input.setPlaceholderText(self.translations['description_placeholder'])
self.description_input.setPlaceholderText(self.get_translation('description_placeholder', 'Enter Description or Thoughts'))
self.description_input.setMaximumHeight(100)
self.layout.addWidget(self.description_input)
self.add_button = QPushButton(self.translations['save_url_button'])
self.add_button = QPushButton(self.get_translation('save_url_button', 'Save URL'))
self.add_button.clicked.connect(self.add_url)
self.layout.addWidget(self.add_button)
@ -107,7 +108,7 @@ class URLManager(QWidget):
self.search_layout = QHBoxLayout()
self.search_input = QLineEdit()
self.search_input.setPlaceholderText(self.translations['search_placeholder'])
self.search_input.setPlaceholderText(self.get_translation('search_placeholder', 'Search...'))
self.search_input.textChanged.connect(self.filter_urls)
self.search_layout.addWidget(self.search_input)
self.layout.addLayout(self.search_layout)
@ -116,10 +117,15 @@ class URLManager(QWidget):
self.url_list = QTableWidget()
self.url_list.setColumnCount(3)
self.url_list.setHorizontalHeaderLabels(['URL', self.translations['column_date'], self.translations['column_actions']])
self.url_list.setHorizontalHeaderLabels([
self.get_translation('column_url', 'URL'),
self.get_translation('column_date', 'Date'),
self.get_translation('column_actions', 'Actions')
])
self.url_list.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
self.url_list.setColumnWidth(1, 150)
self.url_list.setColumnWidth(2, 100)
self.url_list.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
self.layout.addWidget(self.url_list)
self.setLayout(self.layout)
@ -144,12 +150,17 @@ class URLManager(QWidget):
data = json.load(file)
self.translations = data['translations']
def get_translation(self, key, default):
return self.translations.get(key, default)
def update_icon_color(self):
palette = self.palette()
if palette.color(palette.ColorRole.Window).value() < 128:
settings_icon_path = 'assets/cogwheel_dark.svg'
info_icon_path = 'assets/info_dark.svg'
self.action_icons = {
"visit": 'assets/visit_dark.svg',
"info": 'assets/info_dark.svg',
"search": 'assets/search_dark.svg',
"delete": 'assets/delete_dark.svg'
}
@ -157,6 +168,8 @@ class URLManager(QWidget):
settings_icon_path = 'assets/cogwheel_light.svg'
info_icon_path = 'assets/info_light.svg'
self.action_icons = {
"visit": 'assets/visit_light.svg',
"info": 'assets/info_light.svg',
"search": 'assets/search_light.svg',
"delete": 'assets/delete_light.svg'
}
@ -187,21 +200,14 @@ class URLManager(QWidget):
with open(url_path, 'w') as file:
json.dump(url_list, file)
def update_url(self):
selected_item = self.url_list.currentItem()
if selected_item:
row = selected_item.row()
new_url = self.url_input.text()
new_description = self.description_input.toPlainText()
self.urls[row]['url'] = new_url
self.urls[row]['description'] = new_description
self.save_urls()
self.update_url_list()
self.url_input.clear()
self.description_input.clear()
def update_url(self, row, new_url, new_description):
self.urls[row]['url'] = new_url
self.urls[row]['description'] = new_description
self.save_urls()
self.update_url_list()
def delete_url(self, row):
reply = QMessageBox.question(self, self.translations['delete_confirmation_title'], self.translations['delete_confirmation'],
reply = QMessageBox.question(self, self.get_translation('delete_confirmation_title', 'Delete URL'), self.get_translation('delete_confirmation', 'Are you sure you want to delete this URL?'),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No)
if reply == QMessageBox.StandardButton.Yes:
del self.urls[row]
@ -224,21 +230,39 @@ class URLManager(QWidget):
self.url_list.insertRow(row)
self.url_list.setItem(row, 0, QTableWidgetItem(url['url']))
formatted_date = self.format_date(url['date'])
self.url_list.setItem(row, 1, QTableWidgetItem(formatted_date))
date_item = QTableWidgetItem(formatted_date)
date_item.setTextAlignment(Qt.AlignmentFlag.AlignVCenter)
self.url_list.setItem(row, 1, date_item)
actions_layout = QHBoxLayout()
actions_layout.setContentsMargins(0, 0, 0, 0)
actions_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
visit_button = QPushButton()
visit_button.setIcon(QIcon(self.action_icons["visit"]))
visit_button.setFixedSize(22, 22)
visit_button.setStyleSheet("border: none; padding: 3px;")
visit_button.clicked.connect(lambda _, url=url['url']: self.visit_url(url))
actions_layout.addWidget(visit_button)
info_button = QPushButton()
info_button.setIcon(QIcon(self.action_icons["info"]))
info_button.setFixedSize(22, 22)
info_button.setStyleSheet("border: none; padding: 3px;")
info_button.clicked.connect(lambda _, row=row: self.view_description(row))
actions_layout.addWidget(info_button)
search_button = QPushButton()
search_button.setIcon(QIcon(self.action_icons["search"]))
search_button.setFixedSize(18, 18)
search_button.setStyleSheet("border: none; padding: 0px;")
search_button.setFixedSize(22, 22)
search_button.setStyleSheet("border: none; padding: 3px;")
search_button.clicked.connect(lambda _, url=url['url']: self.search_url(url))
actions_layout.addWidget(search_button)
delete_button = QPushButton()
delete_button.setIcon(QIcon(self.action_icons["delete"]))
delete_button.setFixedSize(18, 18)
delete_button.setStyleSheet("border: none; padding: 0px;")
delete_button.setFixedSize(22, 22)
delete_button.setStyleSheet("border: none; padding: 3px;")
delete_button.clicked.connect(lambda _, row=row: self.delete_url(row))
actions_layout.addWidget(delete_button)
@ -261,6 +285,13 @@ class URLManager(QWidget):
else:
return date_str
def visit_url(self, url):
QDesktopServices.openUrl(QUrl(url))
def view_description(self, row):
dialog = DescriptionDialog(self, row)
dialog.exec()
def search_url(self, url):
search_engine_url = self.search_engines[self.settings['search_engine']]
url_search = URLSearch(url, search_engine_url)
@ -313,7 +344,7 @@ class URLManager(QWidget):
def show_info_dialog(self):
dialog = QDialog(self)
dialog.setWindowTitle(self.translations['about_title'])
dialog.setWindowTitle(self.get_translation('about_title', 'About URL Manager'))
layout = QVBoxLayout()
@ -321,11 +352,11 @@ class URLManager(QWidget):
svg_widget.setFixedSize(256, 256)
layout.addWidget(svg_widget, alignment=Qt.AlignmentFlag.AlignCenter)
written_by_label = QLabel(self.translations['developed_by'])
written_by_label = QLabel(self.get_translation('developed_by', 'Developed by Axel Rafn'))
layout.addWidget(written_by_label, alignment=Qt.AlignmentFlag.AlignCenter)
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.get_translation("repository_link", "#")}">{self.get_translation("repository_link_name", "Project Home")}</a>')
link_label.setOpenExternalLinks(True)
layout.addWidget(link_label, alignment=Qt.AlignmentFlag.AlignCenter)
@ -338,22 +369,54 @@ class URLManager(QWidget):
self.settings = self.load_settings()
self.update_url_list()
class DescriptionDialog(QDialog):
def __init__(self, parent, row):
super().__init__(parent)
self.parent = parent
self.row = row
self.setWindowTitle(self.parent.get_translation('description_title', 'URL Description'))
layout = QVBoxLayout()
self.url_input = QLineEdit(self.parent.urls[row]['url'])
layout.addWidget(self.url_input)
self.description_input = QTextEdit(self.parent.urls[row]['description'])
layout.addWidget(self.description_input)
button_layout = QHBoxLayout()
self.update_button = QPushButton(self.parent.get_translation('update_button', 'Update'))
self.update_button.clicked.connect(self.update_url)
self.close_button = QPushButton(self.parent.get_translation('close_button', 'Close'))
self.close_button.clicked.connect(self.close)
button_layout.addWidget(self.update_button)
button_layout.addWidget(self.close_button)
layout.addLayout(button_layout)
self.setLayout(layout)
def update_url(self):
new_url = self.url_input.text()
new_description = self.description_input.toPlainText()
self.parent.update_url(self.row, new_url, new_description)
self.accept()
class SettingsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle(parent.translations['settings_title'])
self.setWindowTitle(parent.get_translation('settings_title', 'Settings'))
self.setFixedWidth(360)
self.parent = parent
layout = QVBoxLayout()
directory_label = QLabel(parent.translations['data_directory_label'])
directory_label = QLabel(parent.get_translation('data_directory_label', 'Data Directory:'))
layout.addWidget(directory_label)
directory_layout = QHBoxLayout()
self.directory_input = QLineEdit(self.parent.settings['data_directory'])
self.browse_button = QPushButton(self.parent.translations['browse_button'])
self.browse_button = QPushButton(self.parent.get_translation('browse_button', 'Browse...'))
self.browse_button.clicked.connect(self.browse_directory)
directory_layout.addWidget(self.directory_input)
directory_layout.addWidget(self.browse_button)
@ -368,24 +431,24 @@ class SettingsDialog(QDialog):
search_engines = sorted(self.parent.search_engines.keys())
self.search_engine_combobox.addItems(search_engines)
self.search_engine_combobox.setCurrentText(self.parent.settings['search_engine'])
form_layout.addRow(self.parent.translations['search_engine_label'], self.search_engine_combobox)
form_layout.addRow(self.parent.get_translation('search_engine_label', 'Search Engine:'), self.search_engine_combobox)
# Populate Date Format Combobox
self.date_format_combobox = QComboBox()
self.date_format_combobox.addItems(["Nerdy", "Normal", "Murica!"])
self.date_format_combobox.setCurrentText(self.parent.settings['date_format'])
form_layout.addRow(self.parent.translations['date_format_label'], self.date_format_combobox)
form_layout.addRow(self.parent.get_translation('date_format_label', 'Date Format:'), self.date_format_combobox)
# Populate Language Combobox
self.language_combobox = QComboBox()
self.populate_language_combobox()
current_language_code = self.parent.settings['language']
self.set_current_language(current_language_code)
form_layout.addRow(self.parent.translations['language_label'], self.language_combobox)
form_layout.addRow(self.parent.get_translation('language_label', 'Language:'), self.language_combobox)
layout.addLayout(form_layout)
self.save_button = QPushButton(self.parent.translations['save_button'])
self.save_button = QPushButton(self.parent.get_translation('save_button', 'Save'))
self.save_button.clicked.connect(self.save_settings)
layout.addWidget(self.save_button)
@ -429,7 +492,7 @@ class SettingsDialog(QDialog):
self.parent.save_settings(self.parent.settings)
if old_language != language_code:
QMessageBox.information(self, self.parent.translations['restart_required_title'], self.parent.translations['restart_required_message'])
QMessageBox.information(self, self.parent.get_translation('restart_required_title', 'Restart Required'), self.parent.get_translation('restart_required_message', 'You need to restart the application for the language changes to take effect.'))
self.accept()