Skip to content

Commit

Permalink
load_icon() helper function was removed.
Browse files Browse the repository at this point in the history
JalIcon class was extended with aux_icon() method to load icons by name.
  • Loading branch information
titov-vv committed Feb 3, 2024
1 parent 2f1f976 commit 901dd4d
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 7 deletions.
5 changes: 0 additions & 5 deletions jal/db/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ def db_row2dict(model, row) -> dict:
record = model.record(row)
return {record.field(x).name(): record.value(x) for x in range(record.count())}

# -------------------------------------------------------------------------------------------------------------------
# returns QIcon loaded from the file with icon_name located in folder Setup.ICONS_PATH
def load_icon(icon_name) -> QIcon:
return QIcon(get_app_path() + Setup.ICONS_PATH + os.sep + icon_name)

# -------------------------------------------------------------------------------------------------------------------
# Returns timestamp of the first second of the year of given timestamp
def year_begin(timestamp: int) -> int:
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
13 changes: 13 additions & 0 deletions jal/widgets/icons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import re
from enum import auto
from collections import UserDict
from PySide6.QtGui import QIcon
Expand All @@ -9,6 +10,7 @@

ICON_PREFIX = "ui_"
FLAG_PREFIX = "flag_"
AUX_PREFIX = "aux_"

class JalIcon(UserDict):
NONE = auto()
Expand Down Expand Up @@ -108,6 +110,10 @@ def __init__(self):
self._icons[icon_id] = self.load_icon(img_path + ICON_PREFIX + filename)
for icon_id, filename in self._flag_files.items():
self._icons[icon_id] = self.load_icon(img_path + FLAG_PREFIX + filename)
for filename in os.listdir(img_path):
match = re.match(f"^{AUX_PREFIX}.*", filename)
if match:
self._icons[filename] = self.load_icon(img_path + filename)

@staticmethod
def load_icon(path) -> QIcon:
Expand All @@ -127,3 +133,10 @@ def country_flag(cls, country_code) -> QIcon:
if country_code not in cls._flags:
return QIcon()
return cls._icons[cls._flags[country_code]]

@classmethod
def aux_icon(cls, icon_name) -> QIcon:
filename = AUX_PREFIX + icon_name
if filename not in cls._icons:
return QIcon()
return cls._icons[filename]
4 changes: 2 additions & 2 deletions jal/widgets/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
CategoryListDialog, QuotesListDialog, PeerListDialog, BaseCurrencyDialog
from jal.constants import Setup
from jal.db.backup_restore import JalBackup
from jal.db.helpers import get_app_path, get_dbfilename, load_icon
from jal.db.helpers import get_app_path, get_dbfilename
from jal.db.account import JalAccount
from jal.db.asset import JalAsset
from jal.db.settings import JalSettings
Expand Down Expand Up @@ -186,7 +186,7 @@ def createStatementsImportMenu(self):
for i, statement in enumerate(self.statements.items):
statement_name = statement['name'].replace('&', '&&') # & -> && to prevent shortcut creation
if statement['icon']:
statement_icon = load_icon(statement['icon'])
statement_icon = JalIcon.aux_icon(statement['icon'])
action = QAction(statement_icon, statement_name, self)
else:
action = QAction(statement_name, self)
Expand Down

0 comments on commit 901dd4d

Please sign in to comment.