chore: Update search input layout in URLManager and add more icons for actions

This commit is contained in:
2024-07-12 19:44:46 +02:00
parent 91258bc3e1
commit 2ad5dd1e0b

110
app.py
View File

@ -3,11 +3,12 @@ import json
import os import os
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QLineEdit, QPushButton, QListWidget, QTextEdit, QComboBox, QLineEdit, QPushButton, QTextEdit, QComboBox,
QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem,
QHeaderView # Import QHeaderView from PyQt5.QtWidgets
) )
from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, QUrl, QDateTime from PyQt5.QtCore import Qt, QDateTime, QUrl
from PyQt5.QtSvg import QSvgWidget from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtGui import QDesktopServices from PyQt5.QtGui import QDesktopServices
@ -16,7 +17,7 @@ class URLManager(QWidget):
super().__init__() super().__init__()
self.setWindowTitle('tabRemember - URL Manager') self.setWindowTitle('tabRemember - URL Manager')
self.setGeometry(100, 100, 400, 600) self.setGeometry(100, 100, 800, 600) # Set a larger initial size
# Set the application icon # Set the application icon
self.setWindowIcon(QIcon('assets/logo.png')) self.setWindowIcon(QIcon('assets/logo.png'))
@ -31,15 +32,13 @@ class URLManager(QWidget):
# Settings button # Settings button
self.settings_button = QPushButton() self.settings_button = QPushButton()
self.settings_button.setFixedHeight(self.url_input.sizeHint().height()) self.settings_button.setFixedSize(24, 24) # Set fixed size for icon button
self.settings_button.setFixedWidth(self.url_input.sizeHint().height())
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)
# Info button # Info button
self.info_button = QPushButton() self.info_button = QPushButton()
self.info_button.setFixedHeight(self.url_input.sizeHint().height()) self.info_button.setFixedSize(24, 24) # Set fixed size for icon button
self.info_button.setFixedWidth(self.url_input.sizeHint().height())
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)
@ -54,6 +53,11 @@ class URLManager(QWidget):
self.description_input.setMaximumHeight(100) # Limit height to approximately 5 lines self.description_input.setMaximumHeight(100) # Limit height to approximately 5 lines
self.layout.addWidget(self.description_input) self.layout.addWidget(self.description_input)
# Group selection combobox
self.group_combobox = QComboBox()
self.group_combobox.addItem("Default Group") # Add default group option
self.layout.addWidget(self.group_combobox)
# Add URL button # Add URL button
self.add_button = QPushButton("Save") self.add_button = QPushButton("Save")
self.add_button.clicked.connect(self.add_url) self.add_button.clicked.connect(self.add_url)
@ -74,10 +78,12 @@ class URLManager(QWidget):
self.search_input.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) self.search_input.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
# URL list # URL list
self.url_list = QTableWidget(0, 3) self.url_list = QTableWidget()
self.url_list.setColumnCount(3)
self.url_list.setHorizontalHeaderLabels(['URL', 'Date', 'Actions']) self.url_list.setHorizontalHeaderLabels(['URL', 'Date', 'Actions'])
self.url_list.setColumnWidth(0, 200) self.url_list.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) # Stretch first column
self.url_list.setColumnWidth(1, 100) self.url_list.setColumnWidth(1, 150) # Set fixed width for Date column
self.url_list.setColumnWidth(2, 150) # Set fixed width for Actions column
self.layout.addWidget(self.url_list) self.layout.addWidget(self.url_list)
self.setLayout(self.layout) self.setLayout(self.layout)
@ -108,9 +114,19 @@ class URLManager(QWidget):
if palette.color(palette.Window).value() < 128: if palette.color(palette.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 = {
"edit": 'assets/edit_dark.svg',
"delete": 'assets/delete_dark.svg',
"search": 'assets/search_dark.svg'
}
else: else:
settings_icon_path = 'assets/cogwheel_light.svg' settings_icon_path = 'assets/cogwheel_light.svg'
info_icon_path = 'assets/info_light.svg' info_icon_path = 'assets/info_light.svg'
self.action_icons = {
"edit": 'assets/edit_light.svg',
"delete": 'assets/delete_light.svg',
"search": 'assets/search_light.svg'
}
self.settings_button.setIcon(QIcon(settings_icon_path)) self.settings_button.setIcon(QIcon(settings_icon_path))
self.info_button.setIcon(QIcon(info_icon_path)) self.info_button.setIcon(QIcon(info_icon_path))
@ -118,7 +134,7 @@ class URLManager(QWidget):
def add_url(self): def add_url(self):
url = self.url_input.text() url = self.url_input.text()
description = self.description_input.toPlainText() description = self.description_input.toPlainText()
group = self.group_combobox.currentText() # Assuming you have a group_combobox group = self.group_combobox.currentText() # Retrieve selected group
if url: if url:
date_added = QDateTime.currentDateTime().toString(Qt.ISODate) date_added = QDateTime.currentDateTime().toString(Qt.ISODate)
self.urls.append({'url': url, 'description': description, 'date': date_added, 'group': group}) self.urls.append({'url': url, 'description': description, 'date': date_added, 'group': group})
@ -130,7 +146,7 @@ class URLManager(QWidget):
def update_url(self): def update_url(self):
selected_item = self.url_list.currentItem() selected_item = self.url_list.currentItem()
if selected_item: if selected_item:
row = self.url_list.row(selected_item) row = selected_item.row()
new_url = self.url_input.text() new_url = self.url_input.text()
new_description = self.description_input.toPlainText() new_description = self.description_input.toPlainText()
self.urls[row]['url'] = new_url self.urls[row]['url'] = new_url
@ -149,7 +165,11 @@ class URLManager(QWidget):
self.update_url_list() self.update_url_list()
def filter_urls(self): def filter_urls(self):
search_term = self.search_input.text().lower() search_term = self.search_input.text().strip().lower()
if not search_term:
self.update_url_list() # Reset to show all URLs
return
filtered_urls = [url for url in self.urls if search_term in url['url'].lower() or search_term in url['description'].lower()] filtered_urls = [url for url in self.urls if search_term in url['url'].lower() or search_term in url['description'].lower()]
self.update_url_list(filtered_urls) self.update_url_list(filtered_urls)
@ -157,33 +177,41 @@ class URLManager(QWidget):
if urls is None: if urls is None:
urls = self.urls urls = self.urls
self.url_list.setRowCount(0) self.url_list.setRowCount(len(urls))
for url in urls: for row, url in enumerate(urls):
row_position = self.url_list.rowCount() self.url_list.setItem(row, 0, QTableWidgetItem(url['url']))
self.url_list.insertRow(row_position) self.url_list.setItem(row, 1, QTableWidgetItem(url['date']))
self.url_list.setItem(row_position, 0, QTableWidgetItem(url['url']))
self.url_list.setItem(row_position, 1, QTableWidgetItem(url['date']))
# Action buttons # Action buttons
actions_layout = QHBoxLayout() actions_layout = QHBoxLayout()
edit_button = QPushButton() edit_button = QPushButton()
edit_button.setFixedSize(30, 30) # Set fixed size for icon button edit_button.setIcon(QIcon(self.action_icons["edit"]))
edit_icon_path = 'assets/edit_dark.svg' if self.is_dark_mode() else 'assets/edit_light.svg' edit_button.setFixedSize(18, 18) # Set smaller size for icon button
edit_button.setIcon(QIcon(edit_icon_path)) edit_button.setStyleSheet("border: none; padding: 0px;")
edit_button.clicked.connect(lambda ch, row=row_position: self.edit_url(row)) edit_button.clicked.connect(lambda _, row=row: self.edit_url(row))
delete_button = QPushButton() delete_button = QPushButton()
delete_button.setFixedSize(30, 30) # Set fixed size for icon button delete_button.setIcon(QIcon(self.action_icons["delete"]))
delete_icon_path = 'assets/delete_dark.svg' if self.is_dark_mode() else 'assets/delete_light.svg' delete_button.setFixedSize(18, 18) # Set smaller size for icon button
delete_button.setIcon(QIcon(delete_icon_path)) delete_button.setStyleSheet("border: none; padding: 0px;")
delete_button.clicked.connect(lambda ch, row=row_position: self.delete_url(row)) delete_button.clicked.connect(lambda _, row=row: self.delete_url(row))
search_button = QPushButton()
search_button.setIcon(QIcon(self.action_icons["search"]))
search_button.setFixedSize(18, 18) # Set smaller size for icon button
search_button.setStyleSheet("border: none; padding: 0px;")
search_button.clicked.connect(lambda _, row=row: self.search_url(row))
actions_layout.addWidget(edit_button) actions_layout.addWidget(edit_button)
actions_layout.addWidget(search_button)
actions_layout.addWidget(delete_button) actions_layout.addWidget(delete_button)
actions_widget = QWidget() actions_widget = QWidget()
actions_widget.setLayout(actions_layout) actions_widget.setLayout(actions_layout)
self.url_list.setCellWidget(row_position, 2, actions_widget) self.url_list.setCellWidget(row, 2, actions_widget)
# Hide row numbers in the first column
self.url_list.verticalHeader().setVisible(False)
def edit_url(self, row): def edit_url(self, row):
url = self.urls[row] url = self.urls[row]
@ -191,24 +219,21 @@ class URLManager(QWidget):
self.description_input.setPlainText(url['description']) self.description_input.setPlainText(url['description'])
self.urls.pop(row) self.urls.pop(row)
def is_dark_mode(self): def search_url(self, row):
# Heuristic to check if the application is in dark mode url = self.urls[row]['url']
palette = self.palette() search_engine = self.search_engines[self.search_engine_combobox.currentText()]
return palette.color(palette.Window).value() < 128 search_url = search_engine + QUrl(url).toString(QUrl.FullyEncoded)
QDesktopServices.openUrl(QUrl(search_url))
def load_settings(self): def load_settings(self):
settings_path = 'data/settings.json' settings_path = 'data/settings.json'
if os.path.exists(settings_path): if os.path.exists(settings_path):
if os.path.getsize(settings_path) > 0: with open(settings_path, 'r') as file:
with open(settings_path, 'r') as file: settings = json.load(file)
settings = json.load(file) self.data_directory = settings['data_directory']
self.data_directory = settings.get('data_directory', 'data/') self.search_engine = settings['search_engine']
self.search_engine = settings.get('search_engine', 'Google')
else:
self.data_directory = 'data/'
self.search_engine = 'Google'
self.save_settings()
else: else:
# Default settings
self.data_directory = 'data/' self.data_directory = 'data/'
self.search_engine = 'Google' self.search_engine = 'Google'
self.save_settings() self.save_settings()
@ -321,7 +346,6 @@ class SettingsDialog(QDialog):
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
app.setWindowIcon(QIcon('assets/logo.png')) # Set the application icon using PNG for compatibility
window = URLManager() window = URLManager()
window.show() window.show()
sys.exit(app.exec_()) sys.exit(app.exec_())