Skip to content

Commit 3f7706d

Browse files
committed
change add_action method slightly
1 parent 98a8e8b commit 3f7706d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

arho_feature_template/plugin.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def __init__(self) -> None:
4747

4848
def add_action(
4949
self,
50-
icon_path: str,
5150
text: str,
51+
icon: QIcon | None = None,
5252
triggered_callback: Callable | None = None,
5353
*,
5454
toggled_callback: Callable | None = None,
@@ -63,8 +63,7 @@ def add_action(
6363
) -> QAction:
6464
"""Add a toolbar icon to the toolbar.
6565
66-
:param icon_path: Path to the icon for this action. Can be a resource
67-
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
66+
:param icon: Icon for this action.
6867
6968
:param text: Text that should be shown in menu items for this action.
7069
@@ -91,8 +90,8 @@ def add_action(
9190
added to self.actions list.
9291
:rtype: QAction
9392
"""
94-
95-
icon = QIcon(icon_path)
93+
if not icon:
94+
icon = QIcon("")
9695
action = QAction(icon, text, parent)
9796
# noinspection PyUnresolvedReferences
9897
if triggered_callback:
@@ -138,16 +137,14 @@ def initGui(self) -> None: # noqa N802
138137

139138
# Add main plugin action to the toolbar
140139
self.new_land_use_plan_action = self.add_action(
141-
"",
142-
"Luo uusi kaava",
143-
self.add_new_plan,
140+
text="Luo uusi kaava",
141+
triggered_callback=self.add_new_plan,
144142
add_to_menu=True,
145143
add_to_toolbar=True,
146144
status_tip="Luo uusi kaava",
147145
)
148146

149147
self.load_land_use_plan_action = self.add_action(
150-
"",
151148
text="Lataa/avaa kaavaa",
152149
triggered_callback=self.load_existing_land_use_plan,
153150
parent=iface.mainWindow(),
@@ -157,25 +154,21 @@ def initGui(self) -> None: # noqa N802
157154
)
158155

159156
self.template_dock_action = self.add_action(
160-
"",
161-
"Kaavakohdetemplaatit",
162-
None,
157+
text="Kaavakohdetemplaatit",
163158
toggled_callback=self.toggle_template_dock,
164159
checkable=True,
165160
add_to_menu=True,
166161
add_to_toolbar=True,
167162
)
168163

169164
self.new_plan_regulation_group = self.add_action(
170-
"",
171165
text="Luo kaavamääräysryhmä",
172166
triggered_callback=self.open_plan_regulation_group_form,
173167
add_to_menu=True,
174168
add_to_toolbar=True,
175169
)
176170

177171
self.serialize_plan_action = self.add_action(
178-
"",
179172
text="Tallenna kaava JSON",
180173
triggered_callback=self.serialize_plan,
181174
add_to_menu=True,
@@ -184,7 +177,6 @@ def initGui(self) -> None: # noqa N802
184177
)
185178

186179
self.plugin_settings_action = self.add_action(
187-
"",
188180
text="Asetukset",
189181
triggered_callback=self.open_settings,
190182
add_to_menu=True,

0 commit comments

Comments
 (0)