From 4f512225a95b27f69127e1afb4d2751e9c29457b Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 1 Nov 2021 16:58:16 +0100 Subject: [PATCH] add icons to actions --- README.md | 4 +++- bigtext.py | 20 +++++++++++++++----- colorbutton.py | 4 ++-- highlightingdialog.py | 24 +++++++++++++++++------- main.py | 12 +++++++----- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1787bac..e3e2130 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ RavenLog is a viewer for text files of arbitrary length. * UTF-8 support * Filter files with regular expressions. * Case insensitive filtering enabled by default. -* Filter matches are highlighted. +* Filter matches are highlighted (can be disabled). * Filter results don't disappear when changing tabs. * Colored highlighting of lines or matches based on regular expression. * Pleasing color palette. * Highlighters are automatically saved and restored. * Select arbitrary strings (not just fill lines). +* Double click selects word. +* Triple click selects line. * Copy protection: Users is warned before creating a clipboard more than 5 MB in size. They can choose to copy the selection into a new file instead. diff --git a/bigtext.py b/bigtext.py index cec0c44..6d8b50f 100644 --- a/bigtext.py +++ b/bigtext.py @@ -136,9 +136,7 @@ class InnerBigText(QWidget): elif e.modifiers() == Qt.KeyboardModifier.ControlModifier and e.key() == 67: # ctrl + c self.copy_selection() elif e.modifiers() == Qt.KeyboardModifier.ControlModifier and e.key() == 65: # ctrl + a - self.selection_highlight.start_byte = 0 - self.selection_highlight.end_byte = self.model.byte_count() - self.update() + self._select_all() def wheelEvent(self, event: QWheelEvent): direction = 1 if event.angleDelta().y() < 0 else -1 @@ -156,15 +154,22 @@ class InnerBigText(QWidget): def _open_menu(self, position): menu = QMenu(self) - copy_clipboard = QAction(self.tr("&Copy to Clipboard"), self, triggered=self.copy_selection) + copy_clipboard = QAction(QIcon.fromTheme("edit-copy"), self.tr("&Copy to Clipboard"), self, + triggered=self.copy_selection) copy_clipboard.setShortcut("CTRL+C") copy_clipboard.setDisabled(not self._has_selection()) menu.addAction(copy_clipboard) - copy_to_file = QAction(self.tr("Copy to &File"), self, triggered=self._copy_selection_to_file) + copy_to_file = QAction(QIcon.fromTheme("document-save-as"), self.tr("Copy to &File"), self, + triggered=self._copy_selection_to_file) copy_to_file.setDisabled(not self._has_selection()) menu.addAction(copy_to_file) + select_all = QAction(QIcon.fromTheme("edit-select-all"), self.tr("Select &All"), self, + triggered=self._select_all) + select_all.setShortcut("CTRL+A") + menu.addAction(select_all) + manage_highlighting = QAction( self.tr("&Highlighter"), self, @@ -328,6 +333,11 @@ class InnerBigText(QWidget): if selected_file: self.model.write_range(start, end, selected_file) + def _select_all(self): + self.selection_highlight.start_byte = 0 + self.selection_highlight.end_byte = self.model.byte_count() + self.update() + def paintEvent(self, event: QPaintEvent) -> None: # print("paintEvent") painter = QPainter(self) diff --git a/colorbutton.py b/colorbutton.py index 4d00321..491b5ae 100644 --- a/colorbutton.py +++ b/colorbutton.py @@ -65,14 +65,14 @@ class ColorButton(QWidget): self.color_drop_down = QComboBox() self.layout.addWidget(self.color_drop_down) - self.color_drop_down.addItem("transparent", "None") + self.color_drop_down.addItem(QIcon(self._color_pixmap("ffffffff")), self.tr("transparent"), "None") for color_name in colors.keys(): color_value = colors[color_name] self.color_drop_down.addItem(QIcon(self._color_pixmap(color_value)), color_name, color_value) self.color_drop_down.currentIndexChanged.connect(self._color_selected) - self.btn_color_picker = QPushButton(self.tr("custom")) + self.btn_color_picker = QPushButton(QIcon.fromTheme("color-picker"), self.tr("custom")) self.layout.addWidget(self.btn_color_picker) self.btn_color_picker.pressed.connect(self._update_color) self.btn_color_picker.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) diff --git a/highlightingdialog.py b/highlightingdialog.py index 39f8fcb..a3d185f 100644 --- a/highlightingdialog.py +++ b/highlightingdialog.py @@ -1,7 +1,8 @@ import re +from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QDialog, QLineEdit, QLabel, QGridLayout, QCheckBox, QListWidget, QListWidgetItem, \ - QPushButton, QDialogButtonBox, QMessageBox + QPushButton, QDialogButtonBox, QMessageBox, QSizePolicy from colorbutton import ColorButton from hbox import HBox @@ -31,18 +32,27 @@ class HighlightingDialog(QDialog): form_grid.addWidget(self.list, row, 0, 1, 2) row = row + 1 - self.btn_add = QPushButton(self.tr("Add")) + self.btn_add = QPushButton(QIcon.fromTheme("list-add"), self.tr("Add")) + self.btn_add.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_add.pressed.connect(self._add) + self.btn_update = QPushButton(self.tr("Update")) + self.btn_update.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_update.pressed.connect(self._update) - self.btn_delete = QPushButton(self.tr("Delete")) + + self.btn_delete = QPushButton(QIcon.fromTheme("list-remove"), self.tr("Remove")) + self.btn_delete.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_delete.pressed.connect(self._delete) - self.btn_move_up = QPushButton(self.tr("Move Up")) + + self.btn_move_up = QPushButton(QIcon.fromTheme("go-up"), self.tr("Up")) + self.btn_move_up.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_move_up.pressed.connect(self._move_up) - self.btn_move_down = QPushButton(self.tr("Move Down")) + + self.btn_move_down = QPushButton(QIcon.fromTheme("go-down"), self.tr("Down")) + self.btn_move_down.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_move_down.pressed.connect(self._move_down) - form_grid.addWidget(HBox(self.btn_add, self.btn_update, self.btn_delete, self.btn_move_up, self.btn_move_down), - row, 0, 1, 2) + button_box = HBox(self.btn_update, self.btn_add, self.btn_delete, self.btn_move_up, self.btn_move_down) + form_grid.addWidget(button_box, row, 0, 1, 2) row = row + 1 self.query = QLineEdit(self) diff --git a/main.py b/main.py index a478181..432e06b 100644 --- a/main.py +++ b/main.py @@ -22,6 +22,8 @@ MAX_LINE_LENGTH = 4096 logging.basicConfig(level=logging.INFO) log = logging.getLogger("main") +raven_icon = "icon7.png" + class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): @@ -55,11 +57,11 @@ class MainWindow(QMainWindow): def file_menu(self) -> QMenu: file_menu = QMenu(self.tr("&File", "name of the file menu"), self) - open_file = QAction(self.tr("&Open..."), self) + open_file = QAction(QIcon.fromTheme("document-open"), self.tr("&Open..."), self) open_file.setShortcut('Ctrl+O') open_file.triggered.connect(self._open_file_dialog) - close_action = QAction(self.tr("E&xit", "menu item to close the application"), self) + close_action = QAction(QIcon.fromTheme("exit"), self.tr("E&xit", "menu item to close the application"), self) close_action.setShortcut('Ctrl+X') close_action.triggered.connect(self.destruct) @@ -77,7 +79,7 @@ class MainWindow(QMainWindow): manage.triggered.connect(lambda: HighlightingDialog(self.settings).exec()) result.addAction(manage) - highlight_search_terms = QAction(self.tr("Highlight &Search Terms"), self) + highlight_search_terms = QAction(self.tr("Highlight &Searches"), self) highlight_search_terms.setCheckable(True) highlight_search_terms.setChecked(self.settings.session.getboolean("general", "highlight_search_term")) highlight_search_terms.triggered.connect( @@ -90,7 +92,7 @@ class MainWindow(QMainWindow): def help_menu(self) -> QMenu: help_menu = QMenu(self.tr("&Help", "name of the help menu"), self) - about_action = QAction(self.tr("&About"), self) + about_action = QAction(QIcon(raven_icon), self.tr("&About"), self) about_action.triggered.connect(lambda: AboutDialog().exec()) help_menu.addAction(about_action) @@ -179,7 +181,7 @@ def stop_signal(signum, _stackframe): if __name__ == "__main__": app = QApplication(sys.argv) - app.setWindowIcon(QIcon("icon7.png")) + app.setWindowIcon(QIcon(raven_icon)) # translator = QTranslator() # if translator.load(QLocale("de"), "messages_de.ts"):