I’ve been working on some code that includes a “switch” statement for calling into functions (as a result of GUI button presses). When pressing a button, I keep getting:
“Function is Traceback (most recent call last):
File “D:_Technical_Tech_Projects\Freq_Cntr_LC_and_ESR_Meter_Software_System Software\FreqCntr_Sys.pyw”, line 437, in FrontPanelBtns_Proc
self.fpfunc_slct(buttonslct) # Go do function
File “D:_Technical_Tech_Projects\Freq_Cntr_LC_and_ESR_Meter_Software_System Software\FreqCntr_Sys.pyw”, line 467, in fpfunc_slct
return func()
TypeError: ‘NoneType’ object is not callable” error and it’s unclear why that is. Here’s that piece of my code:
(lots of snipping)...
self.fpfunc_slct(buttonslct) (Line 437) # Go do function
#
def fpfunc_slct(self, buttonslct):
global pwrbtn_id, cplbtn_id, attnbtn_id, impbtn_id, lpfbtn_id, slpstartbtn_id, slpstopbtn_id
global enterbtn_id, uparrbtn_id, dwnarrbtn_id, lftarrbtn_id, rtarrbtn_id, PWR_ON
if PWR_ON == False: # If power is off, allow only ON/STANDBY button. Else allow all
buttonslct = self.pwr_btn
# buttonslct.Id = self.pwr_btn.id
#
btnslct_id = buttonslct.Id
switcher={
pwrbtn_id:self.pwrbtn_func(buttonslct), # ON/OFF function
cplbtn_id:self.cplngbtn_func(buttonslct), # Set AC/DC input
attnbtn_id:self.atten_func(buttonslct), # x1/X10 input select
impbtn_id:self.impedance_func(buttonslct), # Set 50/1M ohms input
lpfbtn_id:self.lpf_func(buttonslct), # En/dis-able LPF
slpstartbtn_id:self.slopestart_func(buttonslct), # Set start slope
slpstopbtn_id:self.slopestop_func(buttonslct), # Set end slope
enterbtn_id:self.mainmenu_func(buttonslct), # Enter menu select
uparrbtn_id:self.uparrow_func(buttonslct), # Up/incr
dwnarrbtn_id:self.downarrow_func(buttonslct), # Down/decr
lftarrbtn_id:self.leftarrow_func(buttonslct), # Left/prev select
rtarrbtn_id:self.rightarrow_func(buttonslct) # Right/next select
}
func=switcher.get(btnslct_id, lambda :"Invalid")
return func() (line 467)
I did a print of “func” and it certainly shows nothing has been registered. I have also dumped buttonslct (name, Id, etc.) and it appears the calling routine is passing correct info.
The self.fpfunc_slct(buttonslct), line 437, is at the end of a routine that captures the button event and passes the button object in buttonslct (D’oh!
Also, the “if PWR_ON == False:” statement is used to disable all other GUI buttons (except for the ON/STANDBY button) if power is off.
One of the things I’m unsure abt is if I can pass “buttonslct” again, or at all, thru my switch/dictionary to the function that actually processes the specific button.
Thanks in advance for any insight and help on this…cheers…