From 2ad5dd1e0be6febe0c0bc69f031c8ec08fd5066e Mon Sep 17 00:00:00 2001 From: Axel Rafn Date: Fri, 12 Jul 2024 19:44:46 +0200 Subject: [PATCH] chore: Update search input layout in URLManager and add more icons for actions --- app.py | 110 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/app.py b/app.py index 6eed652..1a9893b 100644 --- a/app.py +++ b/app.py @@ -3,11 +3,12 @@ import json import os from PyQt5.QtWidgets import ( QApplication, QWidget, QVBoxLayout, QHBoxLayout, - QLineEdit, QPushButton, QListWidget, QTextEdit, QComboBox, - QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem + QLineEdit, QPushButton, QTextEdit, QComboBox, + QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem, + QHeaderView # Import QHeaderView from PyQt5.QtWidgets ) 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.QtGui import QDesktopServices @@ -16,7 +17,7 @@ class URLManager(QWidget): super().__init__() 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 self.setWindowIcon(QIcon('assets/logo.png')) @@ -31,15 +32,13 @@ class URLManager(QWidget): # Settings button self.settings_button = QPushButton() - self.settings_button.setFixedHeight(self.url_input.sizeHint().height()) - self.settings_button.setFixedWidth(self.url_input.sizeHint().height()) + self.settings_button.setFixedSize(24, 24) # Set fixed size for icon button self.settings_button.clicked.connect(self.show_settings_dialog) self.url_layout.addWidget(self.settings_button) # Info button self.info_button = QPushButton() - self.info_button.setFixedHeight(self.url_input.sizeHint().height()) - self.info_button.setFixedWidth(self.url_input.sizeHint().height()) + self.info_button.setFixedSize(24, 24) # Set fixed size for icon button self.info_button.clicked.connect(self.show_info_dialog) 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.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 self.add_button = QPushButton("Save") self.add_button.clicked.connect(self.add_url) @@ -74,10 +78,12 @@ class URLManager(QWidget): self.search_input.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) # 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.setColumnWidth(0, 200) - self.url_list.setColumnWidth(1, 100) + self.url_list.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) # Stretch first column + 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.setLayout(self.layout) @@ -108,9 +114,19 @@ class URLManager(QWidget): if palette.color(palette.Window).value() < 128: settings_icon_path = 'assets/cogwheel_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: settings_icon_path = 'assets/cogwheel_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.info_button.setIcon(QIcon(info_icon_path)) @@ -118,7 +134,7 @@ class URLManager(QWidget): def add_url(self): url = self.url_input.text() 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: date_added = QDateTime.currentDateTime().toString(Qt.ISODate) self.urls.append({'url': url, 'description': description, 'date': date_added, 'group': group}) @@ -130,7 +146,7 @@ class URLManager(QWidget): def update_url(self): selected_item = self.url_list.currentItem() if selected_item: - row = self.url_list.row(selected_item) + row = selected_item.row() new_url = self.url_input.text() new_description = self.description_input.toPlainText() self.urls[row]['url'] = new_url @@ -149,7 +165,11 @@ class URLManager(QWidget): self.update_url_list() 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()] self.update_url_list(filtered_urls) @@ -157,33 +177,41 @@ class URLManager(QWidget): if urls is None: urls = self.urls - self.url_list.setRowCount(0) - for url in urls: - row_position = self.url_list.rowCount() - self.url_list.insertRow(row_position) - self.url_list.setItem(row_position, 0, QTableWidgetItem(url['url'])) - self.url_list.setItem(row_position, 1, QTableWidgetItem(url['date'])) + self.url_list.setRowCount(len(urls)) + for row, url in enumerate(urls): + self.url_list.setItem(row, 0, QTableWidgetItem(url['url'])) + self.url_list.setItem(row, 1, QTableWidgetItem(url['date'])) # Action buttons actions_layout = QHBoxLayout() edit_button = QPushButton() - edit_button.setFixedSize(30, 30) # Set fixed size for icon button - edit_icon_path = 'assets/edit_dark.svg' if self.is_dark_mode() else 'assets/edit_light.svg' - edit_button.setIcon(QIcon(edit_icon_path)) - edit_button.clicked.connect(lambda ch, row=row_position: self.edit_url(row)) + edit_button.setIcon(QIcon(self.action_icons["edit"])) + edit_button.setFixedSize(18, 18) # Set smaller size for icon button + edit_button.setStyleSheet("border: none; padding: 0px;") + edit_button.clicked.connect(lambda _, row=row: self.edit_url(row)) delete_button = QPushButton() - delete_button.setFixedSize(30, 30) # Set fixed size for icon button - delete_icon_path = 'assets/delete_dark.svg' if self.is_dark_mode() else 'assets/delete_light.svg' - delete_button.setIcon(QIcon(delete_icon_path)) - delete_button.clicked.connect(lambda ch, row=row_position: self.delete_url(row)) + delete_button.setIcon(QIcon(self.action_icons["delete"])) + delete_button.setFixedSize(18, 18) # Set smaller size for icon button + delete_button.setStyleSheet("border: none; padding: 0px;") + 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(search_button) actions_layout.addWidget(delete_button) actions_widget = QWidget() 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): url = self.urls[row] @@ -191,24 +219,21 @@ class URLManager(QWidget): self.description_input.setPlainText(url['description']) self.urls.pop(row) - def is_dark_mode(self): - # Heuristic to check if the application is in dark mode - palette = self.palette() - return palette.color(palette.Window).value() < 128 + def search_url(self, row): + url = self.urls[row]['url'] + search_engine = self.search_engines[self.search_engine_combobox.currentText()] + search_url = search_engine + QUrl(url).toString(QUrl.FullyEncoded) + QDesktopServices.openUrl(QUrl(search_url)) def load_settings(self): settings_path = 'data/settings.json' if os.path.exists(settings_path): - if os.path.getsize(settings_path) > 0: - with open(settings_path, 'r') as file: - settings = json.load(file) - self.data_directory = settings.get('data_directory', 'data/') - self.search_engine = settings.get('search_engine', 'Google') - else: - self.data_directory = 'data/' - self.search_engine = 'Google' - self.save_settings() + with open(settings_path, 'r') as file: + settings = json.load(file) + self.data_directory = settings['data_directory'] + self.search_engine = settings['search_engine'] else: + # Default settings self.data_directory = 'data/' self.search_engine = 'Google' self.save_settings() @@ -321,7 +346,6 @@ class SettingsDialog(QDialog): if __name__ == '__main__': app = QApplication(sys.argv) - app.setWindowIcon(QIcon('assets/logo.png')) # Set the application icon using PNG for compatibility window = URLManager() window.show() sys.exit(app.exec_())