模块中的 IronPython 单击事件触发过程
IronPython Click Event fire procedure in module
我在尝试将模块内的过程附加到 TextChanged 事件时遇到错误。
附加事件代码:
import NewMortgage
txtNewMortgageValue = LogicalTreeHelper.FindLogicalNode(_tikitSender,'txtLoanAmount')
txtNewMortgageValue.TextChanged += NewMortgage.evtMortgage_RecalcNet
模块NewMortgage.py:
def evtMortgage_RecalcNet(sender, e):
MessageBox.Show('test')
我将 LogicalTreeHelper 功能移动到模块中,然后可以访问事件代码。
我还创建了一个全局模块来保存经常使用的变量。
我首先包含模块
import leanGlobal
import leanNewMortgage
下面是 leanNewMortgage 模块,在文件底部创建的 class 的实例。
注意这个模块也有 'import leanGlobal' 所以我可以访问全局变量和函数。
###### NEW MORTGAGE FUNCTIONS & VARS ######
from System.Windows import MessageBox
from System.Windows import LogicalTreeHelper
import leanGlobal
class NewMortgage(object):
def Init(self):
self.txtLoanAmount = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtLoanAmount')
self.txtLenderChaps = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtLenderChaps')
self.txtCashBack = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtCashBack')
self.txtRetention = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtRetention')
self.txtNETAdvance = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtNETAdvance')
self.AddEvents()
def AddEvents(self):
self.RemoveEvents()
self.txtLoanAmount.TextChanged += self.evtMortgage_RecalcNet
self.txtLenderChaps.TextChanged += self.evtMortgage_RecalcNet
self.txtCashBack.TextChanged += self.evtMortgage_RecalcNet
self.txtRetention.TextChanged += self.evtMortgage_RecalcNet
def RemoveEvents(self):
self.txtLoanAmount.TextChanged -= self.evtMortgage_RecalcNet
self.txtLenderChaps.TextChanged -= self.evtMortgage_RecalcNet
self.txtCashBack.TextChanged -= self.evtMortgage_RecalcNet
self.txtRetention.TextChanged -= self.evtMortgage_RecalcNet
def evtMortgage_RecalcNet(self,sender, e):
self.RemoveEvents()
if (self.txtLoanAmount.Text==""):
self.txtLoanAmount.Text="0"
if (self.txtLenderChaps.Text==""):
self.txtLenderChaps.Text="0"
if (self.txtCashBack.Text==""):
self.txtCashBack.Text="0"
if (self.txtRetention.Text==""):
self.txtRetention.Text="0"
self.txtNETAdvance.Text=(float(self.txtLoanAmount.Text.replace(',', ''))
-float(self.txtLenderChaps.Text.replace(',', ''))
+float(self.txtCashBack.Text.replace(',', ''))
-float(self.txtRetention.Text.replace(',', ''))).ToString()
self.AddEvents()
NewMortgage.txtLoanAmount=object
NewMortgage.txtLenderChaps=object
NewMortgage.txtCashBack=object
NewMortgage.txtRetention=object
NewMortgage.txtNETAdvance=object
oNewMortgage=NewMortgage()
我首先创建全局class:
leanGlobal.oGlobal.Init(_tikitEntity,_tikitMatter.ToString(),_tikitDbAccess,_tikitSender)
然后我调用计算模块(leanNewMortgage.py),一切正常
leanNewMortgage.oNewMortgage.Init()
请注意,我还添加了事件,并在触发时暂时删除了它们。
这是因为我想要一个中心事件而不是为每个文本框创建一个事件。当事件修改文本框时,需要暂时禁用事件,否则将发生无限循环!
对我来说,与这个问题相关的主要课程是如何创建一个整洁的程序结构。
虽然我是 IronPython 的新手,但我对结构很满意,但很想听听任何评论。
我在尝试将模块内的过程附加到 TextChanged 事件时遇到错误。
附加事件代码:
import NewMortgage
txtNewMortgageValue = LogicalTreeHelper.FindLogicalNode(_tikitSender,'txtLoanAmount')
txtNewMortgageValue.TextChanged += NewMortgage.evtMortgage_RecalcNet
模块NewMortgage.py:
def evtMortgage_RecalcNet(sender, e):
MessageBox.Show('test')
我将 LogicalTreeHelper 功能移动到模块中,然后可以访问事件代码。
我还创建了一个全局模块来保存经常使用的变量。
我首先包含模块
import leanGlobal
import leanNewMortgage
下面是 leanNewMortgage 模块,在文件底部创建的 class 的实例。
注意这个模块也有 'import leanGlobal' 所以我可以访问全局变量和函数。
###### NEW MORTGAGE FUNCTIONS & VARS ######
from System.Windows import MessageBox
from System.Windows import LogicalTreeHelper
import leanGlobal
class NewMortgage(object):
def Init(self):
self.txtLoanAmount = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtLoanAmount')
self.txtLenderChaps = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtLenderChaps')
self.txtCashBack = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtCashBack')
self.txtRetention = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtRetention')
self.txtNETAdvance = LogicalTreeHelper.FindLogicalNode(leanGlobal.oGlobal.Sender, 'txtNETAdvance')
self.AddEvents()
def AddEvents(self):
self.RemoveEvents()
self.txtLoanAmount.TextChanged += self.evtMortgage_RecalcNet
self.txtLenderChaps.TextChanged += self.evtMortgage_RecalcNet
self.txtCashBack.TextChanged += self.evtMortgage_RecalcNet
self.txtRetention.TextChanged += self.evtMortgage_RecalcNet
def RemoveEvents(self):
self.txtLoanAmount.TextChanged -= self.evtMortgage_RecalcNet
self.txtLenderChaps.TextChanged -= self.evtMortgage_RecalcNet
self.txtCashBack.TextChanged -= self.evtMortgage_RecalcNet
self.txtRetention.TextChanged -= self.evtMortgage_RecalcNet
def evtMortgage_RecalcNet(self,sender, e):
self.RemoveEvents()
if (self.txtLoanAmount.Text==""):
self.txtLoanAmount.Text="0"
if (self.txtLenderChaps.Text==""):
self.txtLenderChaps.Text="0"
if (self.txtCashBack.Text==""):
self.txtCashBack.Text="0"
if (self.txtRetention.Text==""):
self.txtRetention.Text="0"
self.txtNETAdvance.Text=(float(self.txtLoanAmount.Text.replace(',', ''))
-float(self.txtLenderChaps.Text.replace(',', ''))
+float(self.txtCashBack.Text.replace(',', ''))
-float(self.txtRetention.Text.replace(',', ''))).ToString()
self.AddEvents()
NewMortgage.txtLoanAmount=object
NewMortgage.txtLenderChaps=object
NewMortgage.txtCashBack=object
NewMortgage.txtRetention=object
NewMortgage.txtNETAdvance=object
oNewMortgage=NewMortgage()
我首先创建全局class:
leanGlobal.oGlobal.Init(_tikitEntity,_tikitMatter.ToString(),_tikitDbAccess,_tikitSender)
然后我调用计算模块(leanNewMortgage.py),一切正常
leanNewMortgage.oNewMortgage.Init()
请注意,我还添加了事件,并在触发时暂时删除了它们。 这是因为我想要一个中心事件而不是为每个文本框创建一个事件。当事件修改文本框时,需要暂时禁用事件,否则将发生无限循环!
对我来说,与这个问题相关的主要课程是如何创建一个整洁的程序结构。
虽然我是 IronPython 的新手,但我对结构很满意,但很想听听任何评论。