find icons if cwd is not in the program root
This commit is contained in:
5
main.py
5
main.py
@@ -4,7 +4,6 @@ import signal
|
||||
from PySide6 import QtCore
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtGui import QIcon
|
||||
import sys
|
||||
|
||||
import constants
|
||||
@@ -12,6 +11,8 @@ from src.pluginregistry import PluginRegistry
|
||||
|
||||
import gettext
|
||||
|
||||
from src.ui.icon import Icon
|
||||
|
||||
gettext.install('krowlog', 'locale')
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
@@ -31,7 +32,7 @@ def stop_signal(signum, _stackframe):
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
app.setWindowIcon(QIcon(constants.krow_icon)) # works only for Linux
|
||||
app.setWindowIcon(Icon(constants.krow_icon)) # works only for Linux
|
||||
|
||||
# make icon appear in Windows
|
||||
# see https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105
|
||||
|
||||
@@ -3,6 +3,8 @@ from typing import Callable
|
||||
from PySide6.QtGui import QAction, QIcon
|
||||
from PySide6.QtWidgets import QMenu, QPushButton, QWidget
|
||||
|
||||
from src.ui.icon import Icon
|
||||
|
||||
|
||||
class RAction():
|
||||
|
||||
@@ -65,9 +67,9 @@ class RAction():
|
||||
def _update_check_state(self):
|
||||
if self._action:
|
||||
if self.checked:
|
||||
self._action.setIcon(QIcon("icons/ionicons/checkbox-outline.svg"))
|
||||
self._action.setIcon(Icon("icons/ionicons/checkbox-outline.svg"))
|
||||
else:
|
||||
self._action.setIcon(QIcon("icons/ionicons/square-outline.svg"))
|
||||
self._action.setIcon(Icon("icons/ionicons/square-outline.svg"))
|
||||
|
||||
def set_label(self, label: str):
|
||||
if self._action:
|
||||
@@ -77,9 +79,9 @@ class RAction():
|
||||
action = QAction(self.label, qmenu)
|
||||
self._action = action
|
||||
if self.icon_from_theme:
|
||||
action.setIcon(QIcon.fromTheme(self.icon_from_theme))
|
||||
action.setIcon(Icon.fromTheme(self.icon_from_theme))
|
||||
if self.icon_file:
|
||||
action.setIcon(QIcon(self.icon_file))
|
||||
action.setIcon(Icon(self.icon_file))
|
||||
if self.shortcut:
|
||||
action.setShortcut(self.shortcut)
|
||||
if self.action:
|
||||
@@ -95,9 +97,9 @@ class RAction():
|
||||
if self.label:
|
||||
button.setText(self.label)
|
||||
if self.icon_from_theme:
|
||||
button.setIcon(QIcon.fromTheme(self.icon_from_theme))
|
||||
button.setIcon(Icon.fromTheme(self.icon_from_theme))
|
||||
if self.icon_file:
|
||||
button.setIcon(QIcon(self.icon_file))
|
||||
button.setIcon(Icon(self.icon_file))
|
||||
if self.shortcut:
|
||||
button.setShortcut(self.shortcut)
|
||||
if self.action:
|
||||
|
||||
@@ -7,7 +7,9 @@ from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QFont, QPixmap
|
||||
from PySide6.QtWidgets import *
|
||||
|
||||
from pathlib import Path
|
||||
import constants
|
||||
from src.ui.icon import Icon
|
||||
from src.ui.label import Label
|
||||
from src.ui.vbox import VBox
|
||||
from src.i18n import _
|
||||
@@ -32,7 +34,7 @@ class AboutDialog(QDialog):
|
||||
version.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||
|
||||
app_icon = QLabel()
|
||||
app_icon.setPixmap(QPixmap(constants.krow_icon))
|
||||
app_icon.setPixmap(Icon(constants.krow_icon).pixmap(64, 64))
|
||||
heading = QWidget(self)
|
||||
hbox = QHBoxLayout(heading)
|
||||
hbox.addWidget(app_icon)
|
||||
@@ -85,8 +87,4 @@ class AboutDialog(QDialog):
|
||||
return result
|
||||
|
||||
def _version(self):
|
||||
with open('VERSION.info', "rt") as f:
|
||||
line = f.readline()
|
||||
version = line.strip()
|
||||
return version
|
||||
|
||||
return Path(__file__).parent.parent.parent.parent.joinpath('VERSION.info').read_text("utf8").strip()
|
||||
|
||||
@@ -18,6 +18,7 @@ from src.ui.bigtext.logFileModel import LogFileModel
|
||||
from src.i18n import _
|
||||
from src.pluginregistry import PluginRegistry
|
||||
from src.ui.hbox import HBox
|
||||
from src.ui.icon import Icon
|
||||
from src.ui.label import Label
|
||||
from src.zonedpluginregistry import ZonedPluginRegistry
|
||||
|
||||
@@ -151,7 +152,7 @@ class FilterWidget(QWidget):
|
||||
self.btn_cancel_search.pressed.connect(self._cancel_search)
|
||||
self.search_is_running.connect(self.search_running_status_changed)
|
||||
|
||||
self.btn_bookmark = QPushButton(QIcon("icons/ionicons/star.svg"), "")
|
||||
self.btn_bookmark = QPushButton(Icon("icons/ionicons/star.svg"), "")
|
||||
self.btn_bookmark.setToolTip(_("save query"))
|
||||
self.btn_bookmark.pressed.connect(self._save_query)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import QDialog, QLineEdit, QLabel, QGridLayout, QCheckBox, QListWidget, QListWidgetItem, \
|
||||
QPushButton, QDialogButtonBox, QMessageBox, QSizePolicy
|
||||
|
||||
@@ -9,6 +8,7 @@ from src.ui.hbox import HBox
|
||||
from src.settings.settings import Settings
|
||||
|
||||
from src.i18n import _
|
||||
from src.ui.icon import Icon
|
||||
|
||||
|
||||
class PayloadItem(QListWidgetItem):
|
||||
@@ -32,23 +32,23 @@ class HighlightingDialog(QDialog):
|
||||
form_grid.addWidget(self.list, row, 0, 1, 2)
|
||||
|
||||
row = row + 1
|
||||
self.btn_add = QPushButton(QIcon.fromTheme("list-add"), _("Add"))
|
||||
self.btn_add = QPushButton(Icon.fromTheme("list-add"), _("Add"))
|
||||
self.btn_add.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed))
|
||||
self.btn_add.pressed.connect(self._add)
|
||||
|
||||
self.btn_update = QPushButton(QIcon.fromTheme("stock_edit"), _("Update"))
|
||||
self.btn_update = QPushButton(Icon.fromTheme("stock_edit"), _("Update"))
|
||||
self.btn_update.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed))
|
||||
self.btn_update.pressed.connect(self._update)
|
||||
|
||||
self.btn_delete = QPushButton(QIcon.fromTheme("list-remove"), _("Remove"))
|
||||
self.btn_delete = QPushButton(Icon.fromTheme("list-remove"), _("Remove"))
|
||||
self.btn_delete.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed))
|
||||
self.btn_delete.pressed.connect(self._delete)
|
||||
|
||||
self.btn_move_up = QPushButton(QIcon.fromTheme("go-up"), _("Up"))
|
||||
self.btn_move_up = QPushButton(Icon.fromTheme("go-up"), _("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(QIcon.fromTheme("go-down"), _("Down"))
|
||||
self.btn_move_down = QPushButton(Icon.fromTheme("go-down"), _("Down"))
|
||||
self.btn_move_down.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed))
|
||||
self.btn_move_down.pressed.connect(self._move_down)
|
||||
button_box = HBox(self.btn_update, self.btn_add, self.btn_delete, self.btn_move_up, self.btn_move_down)
|
||||
|
||||
11
src/ui/icon.py
Normal file
11
src/ui/icon.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from PySide6.QtGui import QIcon
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Icon(QIcon):
|
||||
def __init__(self, file_name: str):
|
||||
super(Icon, self).__init__("%s" % Path(__file__).parent.parent.parent.joinpath(file_name).absolute())
|
||||
print("%s -> %s" % (file_name, Path(__file__).parent.parent.parent.joinpath(file_name).absolute()))
|
||||
|
||||
def fromTheme(icon_from_theme: str) -> QIcon:
|
||||
return QIcon.fromTheme(icon_from_theme)
|
||||
Reference in New Issue
Block a user