2424)
2525
2626# Local imports
27- from spyder .api .config .mixins import (
28- SpyderConfigurationAccessor ,
29- SpyderConfigurationObserver
30- )
27+ from spyder .api .config .mixins import SpyderConfigurationAccessor
3128from spyder .api .exceptions import SpyderAPIError
3229from spyder .api .shortcuts import SpyderShortcutsMixin
3330from spyder .api .widgets .menus import SpyderMenu
3936from spyder .utils .registries import (
4037 ACTION_REGISTRY , MENU_REGISTRY , TOOLBAR_REGISTRY , TOOLBUTTON_REGISTRY )
4138from spyder .utils .stylesheet import PANES_TOOLBAR_STYLESHEET
39+ from spyder .utils .svg_colorizer import SVGColorize
4240
4341
4442class SpyderToolButtonMixin :
@@ -757,7 +755,7 @@ class SvgToScaledPixmap(SpyderConfigurationAccessor):
757755 def svg_to_scaled_pixmap (self , svg_file , rescale = None , in_package = True ):
758756 """
759757 Transform svg to a QPixmap that is scaled according to the factor set
760- by users in Preferences.
758+ by users in Preferences. Uses the icon manager for proper colorization.
761759
762760 Parameters
763761 ----------
@@ -771,6 +769,7 @@ def svg_to_scaled_pixmap(self, svg_file, rescale=None, in_package=True):
771769 if in_package :
772770 image_path = get_image_path (svg_file )
773771
772+ # Get user's DPI scale factor
774773 if self .get_conf ('high_dpi_custom_scale_factor' , section = 'main' ):
775774 scale_factors = self .get_conf (
776775 'high_dpi_custom_scale_factors' ,
@@ -780,6 +779,52 @@ def svg_to_scaled_pixmap(self, svg_file, rescale=None, in_package=True):
780779 else :
781780 scale_factor = 1
782781
782+ # Check if the SVG has colorization classes before colorization
783+ should_colorize = False
784+ try :
785+ svg_paths_data = SVGColorize .get_colored_paths (
786+ image_path , ima .ICON_COLORS
787+ )
788+ if svg_paths_data and svg_paths_data .get ('paths' ):
789+ # Check if any of the paths have colorization classes
790+ # (not just default colors)
791+ paths = svg_paths_data .get ('paths' , [])
792+ for path in paths :
793+ # If a path has a color that's not the default color,
794+ # it means it has a colorization class
795+ default_color = ima .ICON_COLORS .get (
796+ 'ICON_1' , '#FF0000' # Get default color from palette
797+ )
798+ if path .get ('color' ) != default_color :
799+ should_colorize = True
800+ break
801+ except Exception :
802+ should_colorize = False
803+
804+ # Try to use the icon manager for colorization only if SVG supports it
805+ if should_colorize :
806+ icon = ima .get_icon (svg_file )
807+ if icon and not icon .isNull ():
808+ # Get the original SVG dimensions
809+ pm = QPixmap (image_path )
810+ width = pm .width ()
811+ height = pm .height ()
812+
813+ # Apply rescale factor
814+ if rescale is not None :
815+ aspect_ratio = width / height
816+ width = int (width * rescale )
817+ height = int (width / aspect_ratio )
818+
819+ # Get a properly scaled pixmap from the icon
820+ # Use the maximum dimension to maintain aspect ratio
821+ max_dimension = max (
822+ int (width * scale_factor ),
823+ int (height * scale_factor )
824+ )
825+ return icon .pixmap (max_dimension , max_dimension )
826+
827+ # Fallback to original method for icons without colorization classes.
783828 # Get width and height
784829 pm = QPixmap (image_path )
785830 width = pm .width ()
0 commit comments