KiCAD pcbnew プラグインで wx ダイアログメッセージを表示する方法

pcbnew 用の KiCAD Python API を使用する場合、次のスニペットを使用してダイアログを表示できます:

show_wx_dialog_example.py
# 情報ダイアログを表示
dlg = wx.MessageDialog(None, "Please select one or multiple footprints!\n...or use Ctrl+A to select everything.", "No footprints selected", wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()

次を行う必要があることに注意してください:

import_wx.py
import wx

プラグインの先頭で行う必要があります。

このコードは次のダイアログを表示します:

KiCAD pcbnew plugin showing wx MessageDialog with error icon about no footprints selected

完全なプラグイン例:

DialogExamplePlugin.py
#!/usr/bin/env python
import pcbnew
import wx

class DialogExamplePlugin(pcbnew.ActionPlugin):
    def defaults(self):
        self.name = "ダイアログ例を表示"
        self.category = "説明的なカテゴリ名"
        self.description = "プラグインとその機能の説明"
        self.show_toolbar_button = False # オプション、デフォルトは False

    def Run(self):
        dlg = wx.MessageDialog(None, "Please select one or multiple footprints!\n...or use Ctrl+A to select everything.", "No footprints selected", wx.OK | wx.ICON_ERROR)
        dlg.ShowModal()
        dlg.Destroy()

DialogExamplePlugin().register() # インスタンス化して Pcbnew に登録

このプラグインを、例えば次の場所に配置できます:

kicad_plugin_path.txt
~/.local/share/kicad/7.0/scripting/plugins/DialogExamplePlugin.py

pcbnew メニューからプラグインを更新するのを忘れないでください。


同じカテゴリの類似記事をチェック: KiCad Python