Как показать диалоговое сообщение wx в плагине KiCAD pcbnew

При использовании Python API KiCAD для pcbnew вы можете показать диалог, используя следующий фрагмент

show_wx_dialog_example.py
# Show info dialog
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, показывающий wx MessageDialog с иконкой ошибки о том, что футпринты не выбраны

Полный пример плагина:

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

class DialogExamplePlugin(pcbnew.ActionPlugin):
    def defaults(self):
        self.name = "Show dialog example"
        self.category = "A descriptive category name"
        self.description = "A description of the plugin and what it does"
        self.show_toolbar_button = False # Optional, defaults to 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() # Instantiate and register to Pcbnew

Вы можете разместить этот плагин, например, в

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

Не забудьте обновить плагины из меню pcbnew.


Check out similar posts by category: KiCad Python