Skip to content

Commit

Permalink
rewrote get_colored_icon, removed get_colored_pixmap
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtedde committed Oct 21, 2023
1 parent 2c72dd5 commit 98af58b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/vorta/views/about_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from vorta._version import __version__
from vorta.store.models import BackupProfileMixin
from vorta.utils import get_asset
from vorta.views.utils import get_colored_pixmap
from vorta.views.utils import get_colored_icon

uifile = get_asset('UI/abouttab.ui')
AboutTabUI, AboutTabBase = uic.loadUiType(uifile)
Expand All @@ -26,8 +26,8 @@ def __init__(self, parent=None):
f'<a href="file://{config.LOG_DIR}"><span style="text-decoration:'
'underline; color:#0984e3;">Click here</span></a> to view the logs.'
)
self.gpl_logo.setPixmap(get_colored_pixmap('gpl_logo', 40))
self.python_logo.setPixmap(get_colored_pixmap('python_logo', 40))
self.gpl_logo.setPixmap(get_colored_icon('gpl_logo', scaled_height=40, return_qpixmap=True))
self.python_logo.setPixmap(get_colored_icon('python_logo', scaled_height=40, return_qpixmap=True))

def set_borg_details(self, version, path):
self.borgVersion.setText(version)
Expand Down
21 changes: 5 additions & 16 deletions src/vorta/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from vorta.utils import get_asset, uses_dark_mode


def get_colored_icon(icon_name):
def get_colored_icon(icon_name, scaled_height=120, return_qpixmap=False):
"""
Return SVG icon in the correct color.
"""
Expand All @@ -12,20 +12,9 @@ def get_colored_icon(icon_name):
if uses_dark_mode():
svg_str = svg_str.replace(b'#000000', b'#ffffff')
# Reduce image size to 128 height
svg_img = QImage.fromData(svg_str).scaledToHeight(128)

return QIcon(QPixmap(svg_img))


def get_colored_pixmap(icon_name, scaled_height):
"""
Return SVG icon in the correct color.
"""
with open(get_asset(f"icons/{icon_name}.svg"), 'rb') as svg_file:
svg_str = svg_file.read()
if uses_dark_mode():
svg_str = svg_str.replace(b'#000000', b'#ffffff')
# Reduce image size to specified scaled height
svg_img = QImage.fromData(svg_str).scaledToHeight(scaled_height)

return QPixmap(svg_img)
if return_qpixmap:
return QPixmap(svg_img)
else:
return QIcon(QPixmap(svg_img))

0 comments on commit 98af58b

Please sign in to comment.