Skip to content

Commit

Permalink
load_icon() calls were replaced by JalIcon class for UI-icons
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Feb 3, 2024
1 parent 48315a8 commit f4e274e
Show file tree
Hide file tree
Showing 40 changed files with 72 additions and 46 deletions.
Binary file removed jal/img/accept.png
Binary file not shown.
Binary file removed jal/img/add.png
Binary file not shown.
Binary file removed jal/img/add_child.png
Binary file not shown.
Binary file removed jal/img/broom.png
Binary file not shown.
Binary file removed jal/img/cancel.png
Binary file not shown.
Binary file removed jal/img/chart.png
Binary file not shown.
Binary file removed jal/img/copy.png
Binary file not shown.
Binary file removed jal/img/delete.png
Binary file not shown.
Binary file removed jal/img/list.png
Binary file not shown.
Binary file removed jal/img/meatballs.png
Binary file not shown.
Binary file removed jal/img/new.png
Binary file not shown.
Binary file removed jal/img/quik.ico
Binary file not shown.
Binary file removed jal/img/remove.png
Binary file not shown.
Binary file removed jal/img/tag.png
Binary file not shown.
Binary file removed jal/img/tax.png
Binary file not shown.
Binary file added jal/img/ui_add.ico
Binary file not shown.
Binary file added jal/img/ui_add_child.ico
Binary file not shown.
Binary file added jal/img/ui_cancel.ico
Binary file not shown.
Binary file added jal/img/ui_chart.ico
Binary file not shown.
Binary file added jal/img/ui_clean.ico
Binary file not shown.
Binary file added jal/img/ui_copy.ico
Binary file not shown.
Binary file added jal/img/ui_details.ico
Binary file not shown.
Binary file added jal/img/ui_list.ico
Binary file not shown.
Binary file added jal/img/ui_ok.ico
Binary file not shown.
Binary file added jal/img/ui_remove.ico
Binary file not shown.
Binary file added jal/img/ui_tag.ico
Binary file not shown.
Binary file modified jal/img/ui_tax.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions jal/reports/income_spending.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from jal.db.asset import JalAsset
from jal.ui.reports.ui_income_spending_report import Ui_IncomeSpendingReportWidget
from jal.constants import CustomColor
from jal.db.helpers import load_icon
from jal.db.category import JalCategory
from jal.widgets.helpers import is_signal_connected, month_list, month_start_ts, month_end_ts, \
week_list, week_start_ts, week_end_ts, str2int
from jal.widgets.icons import JalIcon
from jal.widgets.delegates import GridLinesDelegate, FloatDelegate
from jal.widgets.mdi import MdiWidget

Expand Down Expand Up @@ -394,7 +394,7 @@ def __init__(self, parent: Reports, settings: dict = None):

# Operations view context menu
self.contextMenu = QMenu(self.ui.ReportTreeView)
self.actionDetails = QAction(load_icon("list.png"), self.tr("Show operations"), self)
self.actionDetails = QAction(JalIcon[JalIcon.LIST], self.tr("Show operations"), self)
self.contextMenu.addAction(self.actionDetails)

self.connect_signals_and_slots()
Expand Down
7 changes: 4 additions & 3 deletions jal/reports/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from jal.db.holdings_model import HoldingsModel
from jal.widgets.mdi import MdiWidget
from jal.db.tax_estimator import TaxEstimator
from jal.widgets.icons import JalIcon
from jal.widgets.price_chart import ChartWindow
from jal.widgets.selection_dialog import SelectTagDialog

Expand Down Expand Up @@ -72,18 +73,18 @@ def updateReport(self):
def onHoldingsContextMenu(self, pos):
index = self.ui.PortfolioTreeView.indexAt(pos)
contextMenu = QMenu(self.ui.PortfolioTreeView)
actionShowChart = QAction(icon=load_icon("chart.png"), text=self.tr("Show Price Chart"), parent=self.ui.PortfolioTreeView)
actionShowChart = QAction(icon=JalIcon[JalIcon.CHART], text=self.tr("Show Price Chart"), parent=self.ui.PortfolioTreeView)
actionShowChart.triggered.connect(partial(self.showPriceChart, index))
contextMenu.addAction(actionShowChart)
tax_submenu = contextMenu.addMenu(load_icon("tax.png"), self.tr("Estimate tax"))
tax_submenu = contextMenu.addMenu(JalIcon[JalIcon.TAX], self.tr("Estimate tax"))
actionEstimateTaxPt = QAction(icon=load_icon("pt.png"), text=self.tr("Portugal"), parent=self.ui.PortfolioTreeView)
actionEstimateTaxPt.triggered.connect(partial(self.estimateRussianTax, index, 'pt'))
tax_submenu.addAction(actionEstimateTaxPt)
actionEstimateTaxRu = QAction(icon=load_icon("ru.png"), text=self.tr("Russia"), parent=self.ui.PortfolioTreeView)
actionEstimateTaxRu.triggered.connect(partial(self.estimateRussianTax, index, 'ru'))
tax_submenu.addAction(actionEstimateTaxRu)
contextMenu.addSeparator()
actionSetTag = QAction(icon=load_icon("tag.png"), text=self.tr("Set asset tag"), parent=self.ui.PortfolioTreeView)
actionSetTag = QAction(icon=JalIcon[JalIcon.TAG], text=self.tr("Set asset tag"), parent=self.ui.PortfolioTreeView)
actionSetTag.triggered.connect(partial(self.setTag, index))
contextMenu.addAction(actionSetTag)
contextMenu.addSeparator()
Expand Down
6 changes: 3 additions & 3 deletions jal/widgets/abstract_operation_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from PySide6.QtGui import QFont
from PySide6.QtWidgets import QWidget, QDataWidgetMapper
from PySide6.QtSql import QSqlTableModel
from jal.db.helpers import load_icon
from jal.db.db import JalModel
from jal.widgets.icons import JalIcon


class AbstractOperationDetails(QWidget):
Expand All @@ -28,8 +28,8 @@ def __init__(self, parent=None, ui_class=None):
self.bold_font = QFont()
self.bold_font.setBold(True)

self.ui.commit_button.setIcon(load_icon("accept.png"))
self.ui.revert_button.setIcon(load_icon("cancel.png"))
self.ui.commit_button.setIcon(JalIcon[JalIcon.OK])
self.ui.revert_button.setIcon(JalIcon[JalIcon.CANCEL])

def _init_db(self, table_name):
self.table_name = table_name
Expand Down
15 changes: 8 additions & 7 deletions jal/widgets/asset_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from PySide6.QtWidgets import QDialog, QDataWidgetMapper, QStyledItemDelegate, QComboBox, QLineEdit
from jal.ui.ui_asset_dlg import Ui_AssetDialog
from jal.constants import PredefinedAsset, AssetData, MarketDataFeed
from jal.db.helpers import load_icon, localize_decimal
from jal.db.helpers import localize_decimal
from jal.widgets.delegates import DateTimeEditWithReset, BoolDelegate, ConstantLookupDelegate
from jal.db.reference_models import AbstractReferenceListModel
from jal.db.tag import JalTag
from jal.widgets.icons import JalIcon
from jal.widgets.reference_selector import TagSelector


Expand Down Expand Up @@ -55,12 +56,12 @@ def __init__(self, parent):
self._data_model.select()
self._data_model.configureView()

self.ui.AddSymbolButton.setIcon(load_icon("add.png"))
self.ui.RemoveSymbolButton.setIcon(load_icon("delete.png"))
self.ui.AddDataButton.setIcon(load_icon("add.png"))
self.ui.RemoveDataButton.setIcon(load_icon("delete.png"))
self.ui.OkButton.setIcon(load_icon("accept.png"))
self.ui.CancelButton.setIcon(load_icon("cancel.png"))
self.ui.AddSymbolButton.setIcon(JalIcon[JalIcon.ADD])
self.ui.RemoveSymbolButton.setIcon(JalIcon[JalIcon.REMOVE])
self.ui.AddDataButton.setIcon(JalIcon[JalIcon.ADD])
self.ui.RemoveDataButton.setIcon(JalIcon[JalIcon.REMOVE])
self.ui.OkButton.setIcon(JalIcon[JalIcon.OK])
self.ui.CancelButton.setIcon(JalIcon[JalIcon.CANCEL])

self.ui.TypeCombo.currentIndexChanged.connect(self.onTypeUpdate)
self.ui.AddSymbolButton.clicked.connect(self.onAddSymbol)
Expand Down
7 changes: 4 additions & 3 deletions jal/widgets/corporate_action_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from PySide6.QtGui import QFont
from jal.ui.widgets.ui_corporate_action_operation import Ui_CorporateActionOperation
from jal.widgets.abstract_operation_details import AbstractOperationDetails
from jal.widgets.icons import JalIcon
from jal.widgets.delegates import WidgetMapperDelegateBase, AssetSelectorDelegate, FloatDelegate
from jal.db.view_model import JalViewModel
from jal.db.helpers import load_icon, localize_decimal, now_ts
from jal.db.helpers import localize_decimal, now_ts
from jal.db.operations import LedgerTransaction


Expand All @@ -34,8 +35,8 @@ def __init__(self, parent=None):
self.percent_delegate = FloatDelegate(2, percent=True)

self.ui.timestamp_editor.setFixedWidth(self.ui.timestamp_editor.fontMetrics().horizontalAdvance("00/00/0000 00:00:00") * 1.25)
self.ui.add_button.setIcon(load_icon("add.png"))
self.ui.del_button.setIcon(load_icon("remove.png"))
self.ui.add_button.setIcon(JalIcon[JalIcon.ADD])
self.ui.del_button.setIcon(JalIcon[JalIcon.REMOVE])
self.ui.results_table.horizontalHeader().setFont(self.bold_font)
self.ui.arrow.setText(" 🡆 ") # it crashes if added via Qt-Designer

Expand Down
6 changes: 3 additions & 3 deletions jal/widgets/custom/log_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from datetime import datetime
from jal.constants import CustomColor
from jal.db.helpers import load_icon
from jal.widgets.icons import JalIcon
from PySide6.QtCore import Qt, Slot, qInstallMessageHandler, QtMsgType
from PySide6.QtWidgets import QApplication, QPlainTextEdit, QLabel, QPushButton
from PySide6.QtGui import QBrush
Expand Down Expand Up @@ -47,9 +47,9 @@ def __init__(self, parent=None):
self.expanded_text = self.tr("▲ logs")

self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.addAction(load_icon("copy.png"), self.tr('Copy'), self._copy2clipboard)
self.addAction(JalIcon[JalIcon.COPY], self.tr('Copy'), self._copy2clipboard)
self.addAction(self.tr('Select all'), self.selectAll)
self.addAction(load_icon("delete.png"), self.tr('Clear'), self.clear)
self.addAction(JalIcon[JalIcon.CLEAN], self.tr('Clear'), self.clear)

def _copy2clipboard(self):
cursor = self.textCursor()
Expand Down
22 changes: 22 additions & 0 deletions jal/widgets/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,69 @@
ICON_PREFIX = "ui_"
class JalIcon(UserDict):
NONE = auto()
ADD = auto()
ADD_CHILD = auto()
BOND_AMORTIZATION = auto()
BOND_INTEREST = auto()
BUY = auto()
CANCEL = auto()
CHART = auto()
CLEAN = auto()
COPY = auto()
DELISTING = auto()
DEPOSIT_OPEN = auto()
DEPOSIT_CLOSE = auto()
DETAILS = auto()
DIVIDEND = auto()
FEE = auto()
INTEREST = auto()
LIST = auto()
MERGER = auto()
MINUS = auto()
OK = auto()
PLUS = auto()
REMOVE = auto()
SELL = auto()
SPINOFF = auto()
SPLIT = auto()
STOCK_DIVIDEND = auto()
STOCK_VESTING = auto()
SYMBOL_CHANGE = auto()
TAG = auto()
TAX = auto()
TRANSFER_IN = auto()
TRANSFER_OUT = auto()

_icon_files = {
ADD: "add.ico",
ADD_CHILD: "add_child.ico",
BOND_AMORTIZATION: "amortization.ico",
BOND_INTEREST: "coupon.ico",
BUY: "buy.ico",
CANCEL: "cancel.ico",
CHART: "chart.ico",
CLEAN: "clean.ico",
COPY: "copy.ico",
DELISTING: "delisting.ico",
DEPOSIT_OPEN: "deposit_open.ico",
DEPOSIT_CLOSE: "deposit_close.ico",
DETAILS: "details.ico",
DIVIDEND: "dividend.ico",
FEE: "fee.ico",
INTEREST: "interest.ico",
LIST: "list.ico",
MERGER: "merger.ico",
MINUS: "minus.ico",
OK: "ok.ico",
PLUS: "plus.ico",
REMOVE: "remove.ico",
SELL: "sell.ico",
SPINOFF: "spinoff.ico",
SPLIT: "split.ico",
STOCK_DIVIDEND: "dividend_stock.ico",
STOCK_VESTING: "vesting.ico",
SYMBOL_CHANGE: "renaming.ico",
TAG: "tag.ico",
TAX: "tax.ico",
TRANSFER_IN: "transfer_in.ico",
TRANSFER_OUT: "transfer_out.ico"
Expand Down
9 changes: 5 additions & 4 deletions jal/widgets/income_spending_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from PySide6.QtGui import QFont
from jal.ui.widgets.ui_income_spending_operation import Ui_IncomeSpendingOperation
from jal.widgets.abstract_operation_details import AbstractOperationDetails
from jal.widgets.icons import JalIcon
from jal.db.view_model import JalViewModel
from jal.db.helpers import load_icon, localize_decimal, db_row2dict, now_ts
from jal.db.helpers import localize_decimal, db_row2dict, now_ts
from jal.db.operations import LedgerTransaction
from jal.widgets.delegates import WidgetMapperDelegateBase, FloatDelegate, CategorySelectorDelegate, TagSelectorDelegate

Expand All @@ -34,9 +35,9 @@ def __init__(self, parent=None):
self.ui.timestamp_editor.setFixedWidth(self.ui.timestamp_editor.fontMetrics().horizontalAdvance("00/00/0000 00:00:00") * 1.25)
self.ui.a_currency.setText(self.tr("Paid in foreign currency:"))
self.ui.details_table.horizontalHeader().setFont(self.bold_font)
self.ui.add_button.setIcon(load_icon("add.png"))
self.ui.del_button.setIcon(load_icon("remove.png"))
self.ui.copy_button.setIcon(load_icon("copy.png"))
self.ui.add_button.setIcon(JalIcon[JalIcon.ADD])
self.ui.del_button.setIcon(JalIcon[JalIcon.REMOVE])
self.ui.copy_button.setIcon(JalIcon[JalIcon.COPY])

self.ui.add_button.clicked.connect(self.add_child)
self.ui.copy_button.clicked.connect(self.copy_child)
Expand Down
5 changes: 3 additions & 2 deletions jal/widgets/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
class MainWindow(QMainWindow):
def __init__(self, language):
super().__init__()
self.icons = JalIcon() # This variable is used to initialize JalIcons class and keep its cache in memory.
# It is not used directly but icons are accessed via @classmethod of JalIcons class
# Should be called before ui-initialization
self.running = False
self.ui = Ui_JAL_MainWindow()
self.ui.setupUi(self)
self.restoreGeometry(base64.decodebytes(JalSettings().getValue('WindowGeometry', '').encode('utf-8')))
self.restoreState(base64.decodebytes(JalSettings().getValue('WindowState', '').encode('utf-8')))

self.ledger = Ledger()
self.icons = JalIcon() # This variable is used to initialize JalIcons class and keep its cache in memory.
# It is not used directly but icons are accessed via @classmethod of JalIcons class

# Customize Status bar and logs
self.ProgressBar = QProgressBar(self)
Expand Down
8 changes: 4 additions & 4 deletions jal/widgets/operations_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from jal.widgets.mdi import MdiWidget
from jal.widgets.selection_dialog import SelectTagDialog
from jal.widgets.helpers import ManipulateDate
from jal.db.helpers import load_icon
from jal.widgets.icons import JalIcon
from jal.db.account import JalAccount
from jal.db.asset import JalAsset
from jal.db.balances_model import BalancesModel
Expand All @@ -28,9 +28,9 @@ def __init__(self, parent=None):
self.current_index = None # this is used in onOperationContextMenu() to track item for menu

# Set icons
self.ui.NewOperationBtn.setIcon(load_icon("new.png"))
self.ui.CopyOperationBtn.setIcon(load_icon("copy.png"))
self.ui.DeleteOperationBtn.setIcon(load_icon("delete.png"))
self.ui.NewOperationBtn.setIcon(JalIcon[JalIcon.ADD])
self.ui.CopyOperationBtn.setIcon(JalIcon[JalIcon.COPY])
self.ui.DeleteOperationBtn.setIcon(JalIcon[JalIcon.REMOVE])

# Customize UI configuration
self.balances_model = BalancesModel(self.ui.BalancesTableView)
Expand Down
12 changes: 6 additions & 6 deletions jal/widgets/reference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PySide6.QtWidgets import QDialog, QMessageBox, QMenu, QWidgetAction, QLabel

from jal.ui.ui_reference_data_dlg import Ui_ReferenceDataDialog
from jal.db.helpers import load_icon
from jal.widgets.icons import JalIcon


# --------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -42,11 +42,11 @@ def __init__(self, parent=None):
self.ui.GroupCombo.setVisible(False)
self.ui.SearchFrame.setVisible(False)

self.ui.AddBtn.setIcon(load_icon("add.png"))
self.ui.AddChildBtn.setIcon(load_icon("add_child.png"))
self.ui.RemoveBtn.setIcon(load_icon("delete.png"))
self.ui.CommitBtn.setIcon(load_icon("accept.png"))
self.ui.RevertBtn.setIcon(load_icon("cancel.png"))
self.ui.AddBtn.setIcon(JalIcon[JalIcon.ADD])
self.ui.AddChildBtn.setIcon(JalIcon[JalIcon.ADD_CHILD])
self.ui.RemoveBtn.setIcon(JalIcon[JalIcon.REMOVE])
self.ui.CommitBtn.setIcon(JalIcon[JalIcon.OK])
self.ui.RevertBtn.setIcon(JalIcon[JalIcon.CANCEL])

self.ui.SearchString.textChanged.connect(self.OnSearchChange)
self.ui.GroupCombo.currentIndexChanged.connect(self.OnGroupChange)
Expand Down
6 changes: 3 additions & 3 deletions jal/widgets/reference_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PySide6.QtWidgets import QWidget, QHBoxLayout, QLineEdit, QLabel, QToolButton, QCompleter
from PySide6.QtGui import QPalette
import jal.widgets.reference_dialogs as ui_dialogs
from jal.db.helpers import load_icon
from jal.widgets.icons import JalIcon
from jal.constants import CustomColor


Expand All @@ -28,10 +28,10 @@ def __init__(self, parent=None, validate=True):
self.details.setVisible(False)
self.layout.addWidget(self.details)
self.button = QToolButton()
self.button.setIcon(load_icon("meatballs.png"))
self.button.setIcon(JalIcon[JalIcon.DETAILS])
self.layout.addWidget(self.button)
self.clean_button = QToolButton()
self.clean_button.setIcon(load_icon("broom.png"))
self.clean_button.setIcon(JalIcon[JalIcon.CLEAN])
self.layout.addWidget(self.clean_button)
self.setLayout(self.layout)

Expand Down
11 changes: 5 additions & 6 deletions jal/widgets/term_deposit_widget.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import logging
from decimal import Decimal
from PySide6.QtCore import Qt, Slot
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QMessageBox, QHeaderView
from PySide6.QtSql import QSqlTableModel
from PySide6.QtGui import QFont
from jal.ui.widgets.ui_term_deposit_operation import Ui_TermDepositOperation
from jal.widgets.abstract_operation_details import AbstractOperationDetails
from jal.constants import DepositActions
from jal.db.view_model import JalViewModel
from jal.db.operations import LedgerTransaction
from jal.db.helpers import load_icon, now_ts, localize_decimal, db_row2dict
from jal.db.helpers import now_ts, db_row2dict
from jal.widgets.delegates import FloatDelegate, TimestampDelegate, ConstantLookupDelegate
from jal.widgets.icons import JalIcon


# ----------------------------------------------------------------------------------------------------------------------
Expand All @@ -25,8 +24,8 @@ def __init__(self, parent=None):
self.action_delegate = ConstantLookupDelegate(DepositActions, self)

self.ui.actions_table.horizontalHeader().setFont(self.bold_font)
self.ui.add_button.setIcon(load_icon("add.png"))
self.ui.del_button.setIcon(load_icon("remove.png"))
self.ui.add_button.setIcon(JalIcon[JalIcon.ADD])
self.ui.del_button.setIcon(JalIcon[JalIcon.REMOVE])

self.ui.add_button.clicked.connect(self.add_action)
self.ui.del_button.clicked.connect(self.remove_action)
Expand Down

0 comments on commit f4e274e

Please sign in to comment.