Hello everyone! I haven't programmed in quite a while and now that I'm getting back into the programming environment for my robotics project again, I'm a little stumped on something:

I'm getting this error message for an exception raised in my VAST python script for my robot. It goes like this:

Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 12, in <module>
from wxPython.wx import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\__init__.py", line 15, in <module>
import _wx
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_wx.py", line 8, in <module>
from _misc import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_misc.py", line 456, in <module>
wxDateTime_GetNumberOfDaysinYear = wx._misc.DateTime_GetNumberOfDaysinYear
AttributeError: 'module' object has no attribute 'DateTime_GetNumberOfDaysinYear'

What stumps me is when I go to line 456, I only see this:

"I'll get over it" : "speaker.Speak(random.choice(Health2))",

I went back to Health2, but didn't see anything on DateTime_GetNumberOfDaysinYear, there. I even did a find for the phrase in my scripts, but it says it can't find it. I brushed up on my python books, but can't isolate the problem.

If someone could give me any help with this, I'd be obliged. Thanks in advance.

My money's on a bug in speaker.Speak() OR on an improperly installed wxPython module. Here's why:

Your line chooses a random item from Health2, which is presumed to be a list.

If Health2 is not a list, then random.choice throws a TypeError, which is not your issue.

Further, random.choice() is a well-tested function that couldn't possibly throw the error you're getting. So ... that leaves speaker.Speak() as the source of the error.

Next task: identify the class of "speaker", and check out the code for its Speak() method.

It looks like from the first line of your Traceback that speaker.Speak() tries to import wxPython and do something fancy from there.

Here's how to test for a problem with your wxPython install:

From the command line of IDLE:

>>> import wx
>>> e = wx.DateTime()
>>> e.GetNumberOfDaysInYear(2008)
366

If you get the right result, then the bug's in Speak(). If not, then you should (re?)install wx.

Jeff

Hello again, Jeff!

I test the wxPython install like you said and got the result as you indicated, so its no wxPython.

I think I've isolated the problem to somewhere much earlier in my program:

from wxPython.wx import *

I tried typing this in the command prompt and it gave back this result:

from wxPython.wx import *
__main__:1: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible.
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\__init__.py", line 15, in <module>
import _wx
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_wx.py", line 8, in <module>
from _misc import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_misc.py", line 456, in <module>
wxDateTime_GetNumberOfDaysinYear = wx._misc.DateTime_GetNumberOfDaysinYear
AttributeError: 'module' object has no attribute 'DateTime_GetNumberOfDaysinYear'

If I understand correctly, the package I just installed isn't good anymore, so I need to switch to the "wx" package? Where can I find that?

Okay, I think I found the answer to that. All I had to do was change, say wxbitmap to wx.bitmap, in my script.

But now I'm getting something else. When I try running the script, I get this error message:

Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 75, in <module>
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
TypeError: Error when calling the metaclass bases
cannot create 'NoneType' instances

I first thought this had something to do with the SAPI SDK 5.1 not being install on my New computer (my old laptop suffered a spill, so that's why I'm having trouble getting this script to work again on my new one). But apparently, after reinstalling it, I get the same message. Could it be that the python win32 extention isn't installed on my laptop? Because I thought I installed it...

I believe the bug is indeed, in speaker.Speak(). I tried retyping the script in the comman line to see step by step what was working and what was going through. The moment I finished typing in

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
newResult = win32com.client.Dispatch(Result)

I got that

TypeError: Error when calling the metaclass bases

I only have a rough idea of whats happening in the computer as far as coding is concerned, so I'm not sure how to fix this problem...

And I have no knowledge at all of the Voice Recognition module... :lol:

This error is saying something interesting:

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
TypeError: Error when calling the metaclass bases
cannot create 'NoneType' instances

Apparently, it is defining a class that inherits from the result of the call to

win32com.client.getevents("SAPI.SpSharedRecoContext")

I've not heard of dynamic inheritance before, but it makes sense that Python could do it!

I was able to reproduce the bug like this:

class MyClass(eval(raw_input("Enter a Class: "))):
    pass
>>> Enter a Class: object
>>> m = MyClass()
>>> print m
<__main__.MyClass object at 0x00BFB250>

---

>>> 
Enter a Class: str
>>> m = MyClass()
>>> print m

>>> m
''
>>> 

---

>>> Enter a Class: None
>>> m = MyClass()
Traceback (most recent call last):
  File "C:/Python25/dyninherit.py", line 1, in <module>
    class MyClass(eval(raw_input("Enter a Class"))):
TypeError: Error when calling the metaclass bases
    cannot create 'NoneType' instances

So apparently, win32com.client.getevents("SAPI.SpSharedRecoContext") is returning None when it ought to return some class name.

Can you find anything out about that?

Jeff

Hi Jeff. I think my problem was I hadn't used the MakePy Windows speech Object Library on it, because it got rid of that error. Now I'm getting something else, much farther down the script:

Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 551, in OnInit
self.InitSpeech()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 527, in InitSpeech
self.turnedOn = true
NameError: global name 'true' is not defined

From what I understand, 'true' is a type of switch or property. It should work in any python script without importing or fancy defining or anything like that.

Here's the chunk of code that seems to be affected:

def InitSpeech(self):
listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
self.context = listener.CreateRecoContext()
self.grammar = self.context.CreateGrammar()
self.grammar.DictationSetState(0)
self.ListItemsRule = self.grammar.Rules.Add("ListItemsRule", constants.SRATopLevel + constants.SRADynamic, 0)
events = ContextEvents(self.context)
self.turnedOn = true
self.SetWords()

Its part of a class called "MyApp(wx.App):" which is extremely vast with the lists of phrases my robot responds to.

Any ideas? I think we're both sort of exploring this speech recognition python territory. I'll keep investigating on my own as well.

'True', not 'true'.

It should turn purple when spelled correctly.

Oh, right. Thanks, Jeff! That solved that problem.

Now when I run the script, the windows speed recognition activates! Theres another exception that comes up though, but since the windows speech recognition comes up just before the exception, I know we're getting close.

Here's whats coming up now:

Setting words - turned on
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 553, in OnInit
self.frame = wx.Frame(NULL, -1, "Speech tester", wx.Point(10,10), wx.Size(770,300))
NameError: global name 'NULL' is not defined

Here's the chunk of code that seems to be affected.

def OnInit(self):
self.setItems()
self.InitSpeech()

self.frame = wx.Frame(NULL, -1, "Speech tester", wx.Point(10,10), wx.Size(770,300))
self.listBox = wx.ListBox(self.frame, self.LISTBOX_ID, wx.Point(10, 10), wx.Size(120, 200),
self.items.keys(), wx.LB_SINGLE)
self.addButton = wx.Button(self.frame, self.ADD_BUTTON_ID, "Add", wx.Point(10,230), wx.Size(50, 30))
self.deleteButton = wx.Button(self.frame, self.DELETE_BUTTON_ID, "Delete", wx.Point(80, 230), wx.Size(50, 30))
self.editor = wx.TextCtrl(self.frame, self.EDITOR_ID, "", wx.Point(140,10), wx.Size(600,200),
style=wx.SUNKEN_BORDER+wx.TE_MULTILINE+wx.TE_PROCESS_TAB)
self.testButton = wx.Button(self.frame, self.TEST_BUTTON_ID, "Test", wx.Point(140, 230), wx.Size(50, 30))

self.turnonButton = wx.Button(self.frame, self.TURNON_BUTTON_ID, "On", wx.Point(210, 230), wx.Size(50, 30))
self.turnoffButton = wx.Button(self.frame, self.TURNOFF_BUTTON_ID, "Off", wx.Point(280, 230), wx.Size(50, 30))

self.SetUpTaskbar()

EVT_LISTBOX(self, self.LISTBOX_ID, self.OnListBoxSelect)
EVT_BUTTON(self, self.ADD_BUTTON_ID, self.OnAddClick)
EVT_BUTTON(self, self.DELETE_BUTTON_ID, self.OnDeleteClick)
EVT_BUTTON(self, self.TEST_BUTTON_ID, self.OnTestClick)
EVT_BUTTON(self, self.TURNON_BUTTON_ID, self.OnTurnOnClick)
EVT_BUTTON(self, self.TURNOFF_BUTTON_ID, self.OnTurnOffClick)
EVT_TEXT(self, self.EDITOR_ID, self.OnTextEntered)

EVT_ICONIZE(self.frame, self.OnIconize)
EVT_CLOSE(self.frame, self.OnExitFrame)

self.listBox.SetSelection(0)
self.displayTextBox()

self.frame.Show(True)
self.SetTopWindow(self.frame)
return True

Once again, I'm not sure how that works. Isn't NULL an expression you can use without defining it? I think that might be typed incorrectly, like with 'true,' but I'm not sure how to fix it. You know what's going on? I'll hit the books in the meantime.

Loren

Yes, it's a bug that was clearly written by a C++ coder who has migrated to Python.

The first argument to wx.Frame() is its parent, which should be None in a typical case. In C++, the corresponding value would be NULL.

So if you change NULL to None, it oughta work (up to the next exception :) )

Jeff

Thanks Jeff!

I think we just have a little more ways to go. It's now giving me a NameError that goes like this:

Setting words - turned on
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 565, in OnInit
self.SetUpTaskbar()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 545, in SetUpTaskbar
EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate)
NameError: global name 'EVT_TASKBAR_LEFT_DCLICK' is not defined

On this I'm clueless...but I'll see what I can find out about it.

should be wx.EVT_TASKBAR_LEFT_DCLICK

Oh, I think I get it now. That's defined in

self.tbicon = wx.TaskBarIcon()
icon = wx.IconFromXPMData(getMondrianData())

I should've seen that coming.

I've added the wx to the other parts in that chunck of code, and thats seems to account for several more exceptions. Except for one of them (man, these exceptions are going on forever:confused:

Anyway, I'm now getting the wx-gui part of the script to appear, so we're getting pretty close.

What's troubling me this time is

wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)

This error message comes up with it:

Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 565, in OnInit
self.SetUpTaskbar()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 546, in SetUpTaskbar
wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)
AttributeError: 'module' object has no attribute 'ACCEL_ALTEVT_TASKBAR_RIGHT_UP'

Isn't the "(self.tbicon, self.OnTaskBarMenu)" the attribute of "wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP"?

Here's how to debug it from the command prompt:

>>> import wx
>>> evts = [x for x in dir(wx) if "EVT" in x]
>>> print evts

(You could just print dir(wx), but it's sooo long that finding stuff is a challenge).

I suspect a mis-spelling somewhere.

Jeff

Well, I couldn't figure out what was wrong. I checked for speeling errors and anything else that might have been wrong but couldn't get anything. Since I'm building a robot and I mainly won't be using the script with a graphical user interface, I decided to use a simple solution:

Get rid of the code that involves a taskbar!

Hurray! I can talk to my robot again!

Thank you so much, Jeff! I couldn't do this without you. I'll continue to hit the books and brush up on my python.

Loren

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.