我正在编写一个使用wx.Dialog
的KiCAD插件。创建对话框(viastitching_gui
)的代码是由wxFormDesigner自动创建的,我认为它应该可以正常工作。
如果需要完整的代码,可以通过https://github.com/weirdgyn/viastitching获得以下代码(部分代码),对话框和插件是managed
:
viastitching_dialog.py
:
import wx
import pcbnew
import gettext
import math
from viastitching_gui import viastitching_gui
from math import sqrt
_ = gettext.gettext
__version__ = "0.1"
class ViaStitchingDialog(viastitching_gui):
def __init__(self, board):
super(ViaStitchingDialog, self).__init__(None)
self.SetTitle(_(u"ViaStitching v{0}").format(__version__))
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
self.m_btnCancel.Bind(wx.EVT_BUTTON, self.onCloseWindow)
if not self.GetAreaConfig():
wx.MessageBox(_(u"Please select a valid area"))
self.Destroy()
else:
#self.CollectOverlappingItems()
self.PopulateNets()
def onCloseWindow(self, event):
self.Destroy()
def InitViaStitchingDialog(board):
"""Launch the dialog"""
dlg = ViaStitchingDialog(board)
dlg.Show(True)
return dlg
viastitching_plugin.py
:
import wx
import os
import pcbnew
import gettext
from pcbnew import ActionPlugin, GetBoard
from viastitching_dialog import InitViaStitchingDialog
class ViaStitchingPlugin(ActionPlugin):
"""Class that gathers the actionplugin stuff"""
def defaults(self):
self.name = _(u"ViaStitching")
self.category = _(u"Modify PCB")
self.description = _(u"Create a vias stitching pattern")
self.show_toolbar_button = True
self.icon_file_name = os.path.join(os.path.dirname(__file__), 'viastitching.png')
def Run(self):
InitViaStitchingDialog(pcbnew.GetBoard())
__init__.py
:
from viastitching_plugin import ViaStitchingPlugin
ViaStitchingPlugin().register()
方法GetAreaConfig
检查要选择的区域,并相应地返回False
/True
如果用户选择了一个有效的区域,一切正常,但如果用户没有选择区域,GetAreaConfig
返回False
,因此在显示警告消息后,插件对话框关闭,但只有在显示自己一段时间后…我更希望在启动时显示其中一个对话框,在显示警报消息之前,然后关闭或根本不显示。
如果有错误,错误在哪里?
如何修改代码以防止对话框在打算关闭时显示?
我既不是Python方面的专家,也不是wxPython方面的专家
当然,您需要KiCAD来运行插件AFAIK
目前没有回答
相关问题 更多 >
编程相关推荐