String or Unicode required in Dialog ??

I get an error saying “String or Unicode required”. I do not know where is it required. Please Help

Thanks in advance

--------------------------------- Code -------------------------------------

#Boa:Dialog:Dialog1

import wx

def create(parent):

return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1BTCANCEL, wxID_DIALOG1BTSAVE, wxID_DIALOG1NAME,

wxID_DIALOG1NUMBER, wxID_DIALOG1STNAME, wxID_DIALOG1STNUMBER,

] = [wx.NewId() for _init_ctrls in range(7)]

class Dialog1(wx.Dialog):

def _init_coll_flexGridSizer1_Items(self, parent):

generated method, don’t edit

parent.AddWindow(self.btSave, 0, border=5, flag=wx.ALL)

parent.AddWindow(self.btCancel, 0, border=5, flag=wx.ALL)

def _init_coll_boxSizer1_Items(self, parent):

generated method, don’t edit

parent.AddWindow(self.stName, 0, border=5, flag=wx.ALL)

parent.AddWindow(self.Name, 0, border=5, flag=wx.ALL)

parent.AddWindow(self.stNumber, 0, border=5, flag=wx.ALL)

parent.AddWindow(self.Number, 0, border=5, flag=wx.ALL)

parent.AddSizer(self.flexGridSizer1, 0, border=0, flag=0)

def _init_sizers(self):

generated method, don’t edit

self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

self.flexGridSizer1 = wx.FlexGridSizer(cols=0, hgap=0, rows=1, vgap=0)

self._init_coll_boxSizer1_Items(self.boxSizer1)

self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)

self.SetSizer(self.boxSizer1)

def _init_ctrls(self, prnt):

generated method, don’t edit

wx.Dialog.init(self, id=wxID_DIALOG1, name=’’, parent=prnt,

pos=wx.Point(470, 298), size=wx.Size(224, 180),

style=wx.DEFAULT_DIALOG_STYLE, title=‘Add Contact’)

self.SetClientSize(wx.Size(216, 146))

self.stName = wx.StaticText(id=wxID_DIALOG1STNAME, label=u’Name’,

name=u’stName’, parent=self, pos=wx.Point(5, 5), size=wx.Size(27,

13), style=0)

self.Name = wx.TextCtrl(id=wxID_DIALOG1NAME, name=u’Name’, parent=self,

pos=wx.Point(5, 28), size=wx.Size(115, 21), style=0, value=u’’)

self.stNumber = wx.StaticText(id=wxID_DIALOG1STNUMBER, label=u’Number’,

name=u’stNumber’, parent=self, pos=wx.Point(5, 59),

size=wx.Size(37, 13), style=0)

self.Number = wx.TextCtrl(id=wxID_DIALOG1NUMBER, name=u’Number’,

parent=self, pos=wx.Point(5, 82), size=wx.Size(203, 21), style=0,

value=u’’)

self.btSave = wx.Button(id=wxID_DIALOG1BTSAVE, label=u’Save’,

name=u’btSave’, parent=self, pos=wx.Point(5, 113),

size=wx.Size(75, 23), style=0)

self.btCancel = wx.Button(id=wxID_DIALOG1BTCANCEL, label=u’Cancel’,

name=u’btCancel’, parent=self, pos=wx.Point(90, 113),

size=wx.Size(75, 23), style=0)

self._init_sizers()

def init(self, parent):

self._init_ctrls(parent)

if name == ‘main’:

app = wx.PySimpleApp()

dlg = create(None)

try:

dlg.ShowModal()

finally:

dlg.Destroy()

app.MainLoop()

···

Regards
Tanay Shah

Name is an EXISTING, if IMHO utterly useless, property of wx.Dialog, and is a string, not a wx.Window.

···

2009/4/2 Tanay Shah tanay.shah@gmail.com

Hmm… I guess it might be some kind of a bug.

Anyways, thanks Werner. You’re always a great help !

On Thu, Apr 2, 2009 at 4:02 PM, Werner F. Bruhin werner.bruhin@free.fr wrote:

Hi Tanay,

Tanay Shah wrote:

I get an error saying “String or Unicode required”. I do not know where is it required. Please Help

When you run your code you get an exception in the Boa Traceback window (at the bottom of the screen) and the text version is this:

Traceback (most recent call last):

File “module1.py”, line 78, in

dlg = create(None)

File “module1.py”, line 7, in create

return Dialog1(parent)

File “module1.py”, line 73, in init

self._init_ctrls(parent)

File “module1.py”, line 52, in _init_ctrls

pos=wx.Point(5, 28), size=wx.Size(115, 21), style=0, value=u’')

File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line 8479, in SetName

return core.Window_SetName(*args, **kwargs)

TypeError: String or Unicode type required

Read this from the bottom up, i.e. the first line points to code in _core.py which is part of wxPython. To start with just assume that this is not the issue and go up one line, this then points to line 52 in module1.py (which what I named your file on my system).

Now you know where the error comes from within your code and you can start to debug.

Looking at that code I could not see what is wrong and creating another new wx.TextCtrl in Boa showed that the syntax is correct.

So, I started to play around with it, i.e. commented that control and the add to the sizer for it. Then the program run, so I then re-instated the control and changed the text from blank to something, got the same error again. I then renamed it from Name to Name2 and it runs without error.

Frankly, I can not explain why using “Name” for the wx.TextCtrl attribute name is a problem. Hopefully someone else here can explain this to us.

Werner


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Regards
Tanay Shah


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Shah wrote:

I get an error saying "String or Unicode required". I do not know
where is it required. Please Help
...
class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        ...
        self.Name = wx.TextCtrl(id=wxID_DIALOG1NAME, name=u'Name',
parent=self,
              pos=wx.Point(5, 28), size=wx.Size(115, 21), style=0,
value=u'')

You can't call this field "self.Name". Your class is derived from
wx.Dialog, which is derived from wx.Window, and all window objects have
a Name property. So, when you say this:
    self.Name = xxx
you are not creating a new attribute called Name. Instead, you are
assigning a value to the Name property of the window class, and the Name
property can only be a string.

To avoid this problem, do not use names that start with a capital letter
in wx classes.

Werner wrote:

Frankly, I can not explain why using "Name" for the wx.TextCtrl
attribute name is a problem. Hopefully someone else here can explain
this to us.

It's not about the wx.TextCtrl attribute name. It's that the name he
was assigning to was also the name of a property of the class.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

dir(wx.Dialog)

···

2009/4/2 Tim Roberts timr@probo.com

Shah wrote:

I get an error saying “String or Unicode required”. I do not know

where is it required. Please Help

class Dialog1(wx.Dialog):
def _init_ctrls(self, prnt):

    # generated method, don't edit
    ...
    self.Name = wx.TextCtrl(id=wxID_DIALOG1NAME, name=u'Name',

parent=self,

          pos=wx.Point(5, 28), size=wx.Size(115, 21), style=0,

value=u’')

You can’t call this field “self.Name”. Your class is derived from

wx.Dialog, which is derived from wx.Window, and all window objects have

a Name property. So, when you say this:

self.Name = xxx

you are not creating a new attribute called Name. Instead, you are

assigning a value to the Name property of the window class, and the Name

property can only be a string.

To avoid this problem, do not use names that start with a capital letter

in wx classes.

Werner wrote:

Frankly, I can not explain why using “Name” for the wx.TextCtrl

attribute name is a problem. Hopefully someone else here can explain

this to us.

It’s not about the wx.TextCtrl attribute name. It’s that the name he

was assigning to was also the name of a property of the class.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Half true: every object has an ID; not (quite) every object has a name. Try adding the Widget Inspector to one of your projects and check it out! In my experience, the name is usually much more useful, since you can set/change it yourself; referring to objects by ID is much more fraught.

To use the Inspector, add this line:
import wx.lib.inspection
at the top of your project,
and this line:
wx.lib.inspection.InspectionTool().Show()
just before your MainLoop().
When you’re done inspecting, just comment out the Show() line.

···

2009/4/2 raffaello barbarossa.platz@gmail.com

What is the use of a name? wx,Python calls objects by IDs, not names.


www.fsrtechnologies.com