Skip to content

Commit

Permalink
Merge pull request #21641 from ccordoba12/improve-about-dialog
Browse files Browse the repository at this point in the history
PR: Additional UI improvements to the `About Spyder` dialog
  • Loading branch information
ccordoba12 authored Dec 23, 2023
2 parents 3cf7dc5 + c151f59 commit c5f032b
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 196 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/modules_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ for f in spyder/*/*/*/*.py; do
if [[ $f == spyder/plugins/findinfiles/widgets/main_widget.py ]]; then
continue
fi
if [[ $f == spyder/plugins/application/widgets/__init__.py ]]; then
continue
fi
python "$f"
if [ $? -ne 0 ]; then
exit 1
Expand Down
77 changes: 75 additions & 2 deletions spyder/api/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@

# Third party imports
from qtpy.QtCore import QPoint, Qt
from qtpy.QtGui import QIcon
from qtpy.QtGui import QIcon, QImage, QPainter, QPixmap
from qtpy.QtSvg import QSvgRenderer
from qtpy.QtWidgets import (
QApplication, QMainWindow, QSizePolicy, QToolBar, QWidget, QToolButton
)

# Local imports
from spyder.api.config.mixins import SpyderConfigurationObserver
from spyder.api.config.mixins import (
SpyderConfigurationAccessor,
SpyderConfigurationObserver
)
from spyder.api.exceptions import SpyderAPIError
from spyder.api.widgets.menus import SpyderMenu
from spyder.config.manager import CONF
from spyder.utils.icon_manager import ima
from spyder.utils.image_path_manager import get_image_path
from spyder.utils.qthelpers import create_action, create_toolbutton
from spyder.utils.registries import (
ACTION_REGISTRY, MENU_REGISTRY, TOOLBAR_REGISTRY, TOOLBUTTON_REGISTRY)
Expand Down Expand Up @@ -703,3 +708,71 @@ def move_to_primary_screen(self: QMainWindow):
# plugin ones, which usually are not maximized.
if not hasattr(self, 'is_window_widget'):
self.showMaximized()


class SvgToScaledPixmap(SpyderConfigurationAccessor):
"""
Mixin to transform an SVG to a QPixmap that is scaled according to the
factor set by users in Preferences.
"""

def svg_to_scaled_pixmap(self, svg_file, rescale=None, in_package=True):
"""
Transform svg to a QPixmap that is scaled according to the factor set
by users in Preferences.
Parameters
----------
svg_file: str
Name of or path to the svg file.
rescale: float, optional
Rescale pixmap according to a factor between 0 and 1.
in_package: bool, optional
Get svg from the `images` folder in the Spyder package.
"""
if in_package:
image_path = get_image_path(svg_file)

if self.get_conf('high_dpi_custom_scale_factor', section='main'):
scale_factors = self.get_conf(
'high_dpi_custom_scale_factors',
section='main'
)
scale_factor = float(scale_factors.split(":")[0])
else:
scale_factor = 1

# Get width and height
pm = QPixmap(image_path)
width = pm.width()
height = pm.height()

# Rescale but preserving aspect ratio
if rescale is not None:
aspect_ratio = width / height
width = int(width * rescale)
height = int(width / aspect_ratio)

# Paint image using svg renderer
image = QImage(
int(width * scale_factor), int(height * scale_factor),
QImage.Format_ARGB32_Premultiplied
)
image.fill(0)
painter = QPainter(image)
renderer = QSvgRenderer(image_path)
renderer.render(painter)
painter.end()

# This is also necessary to make the image look good for different
# scale factors
if scale_factor > 1.0:
image.setDevicePixelRatio(scale_factor)

# Create pixmap out of image
final_pm = QPixmap.fromImage(image)
final_pm = final_pm.copy(
0, 0, int(width * scale_factor), int(height * scale_factor)
)

return final_pm
5 changes: 2 additions & 3 deletions spyder/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,8 @@ def create_splash_screen(use_previous_factor=False):
# qt-snippet-render-svg-to-qpixmap-for.html for details.
if CONF.get('main', 'high_dpi_custom_scale_factor'):
if not use_previous_factor:
factor = float(
CONF.get('main', 'high_dpi_custom_scale_factors')
)
factors = CONF.get('main', 'high_dpi_custom_scale_factors')
factor = float(factors.split(":")[0])
else:
factor = previous_factor
else:
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/application/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from spyder.api.widgets.main_container import PluginMainContainer
from spyder.utils.installers import InstallerMissingDependencies
from spyder.config.base import get_conf_path, get_debug_level
from spyder.plugins.application.widgets import AboutDialog
from spyder.plugins.console.api import ConsoleActions
from spyder.utils.environ import UserEnvDialog
from spyder.utils.qthelpers import start_file, DialogManager
from spyder.widgets.about import AboutDialog
from spyder.widgets.dependencies import DependenciesDialog
from spyder.widgets.helperwidgets import MessageCheckBox

Expand Down
10 changes: 10 additions & 0 deletions spyder/plugins/application/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
#
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""Widgets for the Application plugin."""

from .about import AboutDialog # noqa
Loading

0 comments on commit c5f032b

Please sign in to comment.