From 672a0d98a8923ed61940af4fc7c8ed4878e0d8d7 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Thu, 5 Dec 2024 13:58:24 +0200 Subject: [PATCH 1/2] change add_action method slightly --- arho_feature_template/plugin.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/arho_feature_template/plugin.py b/arho_feature_template/plugin.py index eee14f0..0ca0b94 100644 --- a/arho_feature_template/plugin.py +++ b/arho_feature_template/plugin.py @@ -47,8 +47,8 @@ def __init__(self) -> None: def add_action( self, - icon_path: str, text: str, + icon: QIcon | None = None, triggered_callback: Callable | None = None, *, toggled_callback: Callable | None = None, @@ -63,8 +63,7 @@ def add_action( ) -> QAction: """Add a toolbar icon to the toolbar. - :param icon_path: Path to the icon for this action. Can be a resource - path (e.g. ':/plugins/foo/bar.png') or a normal file system path. + :param icon: Icon for this action. :param text: Text that should be shown in menu items for this action. @@ -91,8 +90,8 @@ def add_action( added to self.actions list. :rtype: QAction """ - - icon = QIcon(icon_path) + if not icon: + icon = QIcon("") action = QAction(icon, text, parent) # noinspection PyUnresolvedReferences if triggered_callback: @@ -138,16 +137,14 @@ def initGui(self) -> None: # noqa N802 # Add main plugin action to the toolbar self.new_land_use_plan_action = self.add_action( - "", - "Luo uusi kaava", - self.add_new_plan, + text="Luo uusi kaava", + triggered_callback=self.add_new_plan, add_to_menu=True, add_to_toolbar=True, status_tip="Luo uusi kaava", ) self.load_land_use_plan_action = self.add_action( - "", text="Lataa/avaa kaavaa", triggered_callback=self.load_existing_land_use_plan, parent=iface.mainWindow(), @@ -157,9 +154,7 @@ def initGui(self) -> None: # noqa N802 ) self.template_dock_action = self.add_action( - "", - "Kaavakohdetemplaatit", - None, + text="Kaavakohdetemplaatit", toggled_callback=self.toggle_template_dock, checkable=True, add_to_menu=True, @@ -167,7 +162,6 @@ def initGui(self) -> None: # noqa N802 ) self.new_plan_regulation_group = self.add_action( - "", text="Luo kaavamääräysryhmä", triggered_callback=self.open_plan_regulation_group_form, add_to_menu=True, @@ -175,7 +169,6 @@ def initGui(self) -> None: # noqa N802 ) self.serialize_plan_action = self.add_action( - "", text="Tallenna kaava JSON", triggered_callback=self.serialize_plan, add_to_menu=True, @@ -184,7 +177,6 @@ def initGui(self) -> None: # noqa N802 ) self.plugin_settings_action = self.add_action( - "", text="Asetukset", triggered_callback=self.open_settings, add_to_menu=True, From f4b4e8894463210b66d9cfde0a1b2b5801c98aa2 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Thu, 5 Dec 2024 15:51:51 +0200 Subject: [PATCH 2/2] add QGIS icons for each toolbar action --- arho_feature_template/plugin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arho_feature_template/plugin.py b/arho_feature_template/plugin.py index 0ca0b94..ff486ea 100644 --- a/arho_feature_template/plugin.py +++ b/arho_feature_template/plugin.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Callable, cast +from qgis.core import QgsApplication from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtWidgets import QAction, QWidget @@ -44,6 +45,7 @@ def __init__(self) -> None: self.menu = Plugin.name self.toolbar = iface.addToolBar("ARHO Toolbar") + self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) def add_action( self, @@ -135,9 +137,15 @@ def initGui(self) -> None: # noqa N802 iface.mapCanvas().mapToolSet.connect(self.templater.digitize_map_tool.deactivate) + # icons to consider: + # icon=QgsApplication.getThemeIcon("mActionStreamingDigitize.svg"), + # icon=QgsApplication.getThemeIcon("mIconGeometryCollectionLayer.svg"), + # icon=QgsApplication.getThemeIcon("mActionSharingExport.svg"), + # Add main plugin action to the toolbar self.new_land_use_plan_action = self.add_action( text="Luo uusi kaava", + icon=QgsApplication.getThemeIcon("mActionNewMap.svg"), triggered_callback=self.add_new_plan, add_to_menu=True, add_to_toolbar=True, @@ -146,6 +154,7 @@ def initGui(self) -> None: # noqa N802 self.load_land_use_plan_action = self.add_action( text="Lataa/avaa kaavaa", + icon=QgsApplication.getThemeIcon("mActionFileOpen.svg"), triggered_callback=self.load_existing_land_use_plan, parent=iface.mainWindow(), add_to_menu=True, @@ -155,6 +164,7 @@ def initGui(self) -> None: # noqa N802 self.template_dock_action = self.add_action( text="Kaavakohdetemplaatit", + icon=QgsApplication.getThemeIcon("mIconFieldGeometry.svg"), toggled_callback=self.toggle_template_dock, checkable=True, add_to_menu=True, @@ -163,6 +173,7 @@ def initGui(self) -> None: # noqa N802 self.new_plan_regulation_group = self.add_action( text="Luo kaavamääräysryhmä", + icon=QgsApplication.getThemeIcon("mActionAddManualTable.svg"), triggered_callback=self.open_plan_regulation_group_form, add_to_menu=True, add_to_toolbar=True, @@ -170,6 +181,7 @@ def initGui(self) -> None: # noqa N802 self.serialize_plan_action = self.add_action( text="Tallenna kaava JSON", + icon=QgsApplication.getThemeIcon("mActionFileSaveAs.svg"), triggered_callback=self.serialize_plan, add_to_menu=True, add_to_toolbar=True,