Como mostrar mensagem de diálogo wx no plugin pcbnew do KiCAD

Ao usar a API Python do KiCAD para pcbnew, você pode mostrar um diálogo usando o seguinte trecho

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()

Note que você precisa

import_wx.py
import wx

no topo do seu plugin.

Este código mostrará o seguinte diálogo:

Plugin pcbnew do KiCAD mostrando wx MessageDialog com ícone de erro sobre nenhum footprint selecionado

Exemplo completo de plugin:

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

Você pode colocar este plugin, por exemplo, em

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

Não se esqueça de atualizar os plugins a partir do menu do pcbnew.


Check out similar posts by category: KiCad Python