diff --git a/Apps/apps.ini b/Apps/apps.ini index 9c6feea..fe99be8 100644 --- a/Apps/apps.ini +++ b/Apps/apps.ini @@ -60,7 +60,6 @@ # * Default: yes #auto_terminal = yes - # Custom Commands # # As a slightly more flexible port of Launchy's Runner plugin to Keypirinha, the @@ -105,6 +104,20 @@ # elevated privileges? (default is "no") # * item_label: # See the 'item_label' setting from the [custom_commands] section above. +# *icon_name: +# A icon name that is used to set the icon of the custom command, These icons +# need to be added to tha packaged zip file, by default this is under +# "default\Packages\Apps.keypirinha-package" +# Icon Package structure should follow the bellow, please try to add all 4 icons +# for best visuals +# Apps.keypirinha-package +# ->apps.py +# ->icons +# ->{iconName} +# ->{iconName-16.ico} +# ->{iconName-32.ico} +# ->{iconName-48.ico} +# ->{iconName-256.ico} # * Placeholders: # * Format: "{{x}}" # * Where "x" can be: diff --git a/Apps/apps.py b/Apps/apps.py index 6828bfd..faedaab 100644 --- a/Apps/apps.py +++ b/Apps/apps.py @@ -525,6 +525,14 @@ def _read_config(self): cmd_elevated = settings.get_bool( "elevated", section=section, fallback=False) + icon_name = settings.get( + "icon_name", section=section, fallback=False) + + if icon_name: + icon = self._config_icon(icon_name) + else: + icon = self._customcmd_icon(cmd_lines) + cmd_has_placeholders = any(map( lambda s: self.REGEX_PLACEHOLDER.search(s) is not None, cmd_lines)) @@ -539,10 +547,29 @@ def _read_config(self): 'item_label': cmd_item_label, 'args_hint': cmd_args_hint, 'hit_hint': cmd_hit_hint, - 'icon_handle': self._customcmd_icon(cmd_lines), + 'icon_handle': icon, 'auto_terminal': cmd_auto_terminal, 'elevated': cmd_elevated} + def _config_icon(self, icon_name): + initFilePath = f"res://{self.package_full_name()}/" + resources = self.find_resources("*") + try: + location = [] + sizes = [16, 32, 48, 256] + for size in sizes: + file_part_path = f"icons/{icon_name}/{icon_name}-{size}.ico" + if file_part_path in resources: + location.append(f"{initFilePath}{file_part_path}") + else: + self.info(f"Icon for file size {size} does not exist in path {file_part_path}") + return self.load_icon(location) + + except ValueError: + self.info(f"No Icon files found for icon {icon_name}") + self.info(f"Please Read configuration which explains how to load icons") + return None + def _customcmd_icon(self, cmd_lines): #for cmdline in cmd_lines: # try: