wx._core.PyAssertionError: C++ assertion "IsValid(n)" failed at ..\..\src\common \ctrlsub.cpp(193) in wxItemContainer::GetClientObject(): Invalid index passed to GetClientObject() >>>

Hello.
I’m Toufik and I’m new in programming. First I’m not a native English speaker and I’m sorry for the mistakes in writing
I’ve a project in python 2.7 and wx , and the idea is to have
three choices :

  • the student choice to select the student name.
  • and the stage choice to select the stage .
  • and the course choice to select the course
    But it didn’t work and I got the following error .
    Please help me.

Traceback (most recent call last):
File “E:\quran\progect\toufik\test.py”, line 63, in
myFrame(None,-1,‘frame’, (0, 4), (400, 600))
File “E:\quran\progect\toufik\test.py”, line 43, in init
course = os.listdir(self.stageChoice.GetClientData(self.stageChoice.GetSelec
tion()))
File “C:\Python27\lib\site-packages\wx-3.0-msw\wx_core.py”, line 12923, in Ge
tClientData
return core.ItemContainer_GetClientData(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion “IsValid(n)” failed at …..\src\common
\ctrlsub.cpp(193) in wxItemContainer::GetClientObject(): Invalid index passed to
GetClientObject()

test.py (2.39 KB)

···

pythonist12@gmail.com wrote:

I'm Toufik and I'm new in programming. First I'm not a native English
speaker and I'm sorry for the mistakes in writing

Let me compliment you for your message, which included (a) the code, (b)
what you expected, and (c) what you actually saw. That's a good way to
get help.

The root of your problem is a simple typo. When you populate the
"stageChoice" box, you have
    self.studentChoice.SetSelection(0)
instead of
    self.stageChoice.SetSelection(0)
Because of that, self.stageChoice has nothing selected, so
self.stageChoice.GetSelection() returns None, and it's not valid to pass
None to GetClientData.

However, there is a bigger problem here. You need to think about the
order that things happen. Remember that your myFrame.__init__ function
is called and completed before the user ever sees anything, and is not
called again. You populate the "studentChoice" list from the
directories in files\content. Then, you populate the "stage" list from
the directories in whatever the first studentChoice was, and you
populate the "course" list from the first directory in that. But when
the user make a choice, you don't rebuild the lists. They will always
be stuck on the first entries.

Here's what I think you want. You should populate the "studentChoice"
list during __init__, just as you are doing, but leave the other two
lists empty. (You can set them disabled to prevent accidents.) Then,
in onStudent, you fetch their selection, and use that to populate the
"stage" box (and enable it). Similarly, in the onStageChoice handler,
you fetch their choice and populate the "course" handler.

That should lead to better success, I think.

···

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

Hello Tim Roberts thank you for your reply.
You are right about what I want, I tryed to understand you and change my code but it didn’t work
the course choice does not show any thing

  • I populate the studentChoice from the directories in files\content.
    than I want to populate the stage list from the directories in whatever the selected studentChoice was, .
    in the stageChoice every thing is ok it works find . But when I try to populate
    the course list from the directories in whatever the selected stageChoice was, .
    Nothing appears in the courseChoice.
    Any help with that
    And I got the following error :
    wx._core.PyAssertionError: C++ assertion “HasClientObjectData()” failed at …..
    \src\common\ctrlsub.cpp(190) in wxItemContainer::GetClientObject(): this window
    doesn’t have object client data

بتاريخ الجمعة، 28 أبريل، 2017 7:19:47 م UTC+1، كتب Tim Roberts:

test.py (2.75 KB)

···

pytho...@gmail.com wrote:

I’m Toufik and I’m new in programming. First I’m not a native English

speaker and I’m sorry for the mistakes in writing

Let me compliment you for your message, which included (a) the code, (b)

what you expected, and (c) what you actually saw. That’s a good way to

get help.

The root of your problem is a simple typo. When you populate the

“stageChoice” box, you have

self.studentChoice.SetSelection(0)

instead of

self.stageChoice.SetSelection(0)

Because of that, self.stageChoice has nothing selected, so

self.stageChoice.GetSelection() returns None, and it’s not valid to pass

None to GetClientData.

However, there is a bigger problem here. You need to think about the

order that things happen. Remember that your myFrame.init function

is called and completed before the user ever sees anything, and is not

called again. You populate the “studentChoice” list from the

directories in files\content. Then, you populate the “stage” list from

the directories in whatever the first studentChoice was, and you

populate the “course” list from the first directory in that. But when

the user make a choice, you don’t rebuild the lists. They will always

be stuck on the first entries.

Here’s what I think you want. You should populate the “studentChoice”

list during init, just as you are doing, but leave the other two

lists empty. (You can set them disabled to prevent accidents.) Then,

in onStudent, you fetch their selection, and use that to populate the

“stage” box (and enable it). Similarly, in the onStageChoice handler,

you fetch their choice and populate the “course” handler.

That should lead to better success, I think.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Right. The error message tells the story: you populate the stageChoice list (all at once), but you did not set the client data, as you did when you populated studentChoice.

Note, however, that you don't actually need to set the client data. You know that everything in studentChoice is a subdirectory of files/content, and you know that everything in stageChoice is a subdirectory of that, and everything in courseChoice is a subdirectory of that. So, rather than use the client data to store the paths, you COULD just build them when you need to. So:

    def onStudent( self, event ):
        base = os.path.join( "files", "content/"
            self.studentChoice.GetStringSelection())
        self.stageChoice.Set( os.listdir( base ) )
    def onStage( self, event ):
        base = os.path.join( "files", "content/"
            self.studentChoice.GetStringSelection(),
            self.stageChoice.GetStringSelection())
        self.courseChoice.Set( os.listdir( base ) )

Do you see? Each of the boxes has one piece of the path, so you can rebuild the whole path at any time, without using client data.

···

On Apr 28, 2017, at 10:11 PM, pythonist12@gmail.com wrote:

Hello Tim Roberts thank you for your reply.
You are right about what I want, I tryed to understand you and change my code but it didn't work
the course choice does not show any thing
- I populate the studentChoice from the directories in files\content.
than I want to populate the stage list from the directories in whatever the selected studentChoice was, .
in the stageChoice every thing is ok it works find . But when I try to populate
the course list from the directories in whatever the selected stageChoice was, .
Nothing appears in the courseChoice.


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

Hello Tim Roberts thank you for your reply.
Thank you very much . Now the script is good and I have another question .
Because I’m blind person and I use a screen reader and I want to use a button with wx.BitmapButton in my script , but when I move the focus to the bitmapButton the screen reader it says Unknown
it didn’t recognize the button . So my question can I use text label with wx.BitmapButton as in wx.Button, so my screen reader can recognize the button and say the text label.

بتاريخ الأحد، 30 أبريل، 2017 8:29:30 ص UTC+1، كتب Tim Roberts:

···

On Apr 28, 2017, at 10:11 PM, pytho...@gmail.com wrote:

Hello Tim Roberts thank you for your reply.

You are right about what I want, I tryed to understand you and change my code but it didn’t work
the course choice does not show any thing

  • I populate the studentChoice from the directories in files\content.

than I want to populate the stage list from the directories in whatever the selected studentChoice was, .

in the stageChoice every thing is ok it works find . But when I try to populate
the course list from the directories in whatever the selected stageChoice was, .

Nothing appears in the courseChoice.

Right. The error message tells the story: you populate the stageChoice list (all at once), but you did not set the client data, as you did when you populated studentChoice.

Note, however, that you don’t actually need to set the client data. You know that everything in studentChoice is a subdirectory of files/content, and you know that everything in stageChoice is a subdirectory of that, and everything in courseChoice is a subdirectory of that. So, rather than use the client data to store the paths, you COULD just build them when you need to. So:

def onStudent( self, event ):

    base = os.path.join( "files", "content/"

        self.studentChoice.GetStringSelection())

    self.stageChoice.Set( os.listdir( base ) )

def onStage( self, event ):

    base = os.path.join( "files", "content/"

        self.studentChoice.GetStringSelection(),

        self.stageChoice.GetStringSelection())

    self.courseChoice.Set( os.listdir( base ) )

Do you see? Each of the boxes has one piece of the path, so you can rebuild the whole path at any time, without using client data.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

No, wx.BitmapButton does not support any text at all. You'll either need to use a regular button, or create your own custom button control with both text and bitmap.

···

On Apr 30, 2017, at 10:53 PM, pythonist12@gmail.com wrote:

Because I'm blind person and I use a screen reader and I want to use a button with wx.BitmapButton in my script , but when I move the focus to the bitmapButton the screen reader it says Unknown
it didn't recognize the button . So my question can I use text label with wx.BitmapButton as in wx.Button, so my screen reader can recognize the button and say the text label.


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

Hi,

Hello Tim Roberts thank you for your reply.

Thank you very much . Now the script is good and I have another question .
Because I’m blind person and I use a screen reader and I want to use a button with wx.BitmapButton in my script , but when I move the focus to the bitmapButton the screen reader it says Unknown
it didn’t recognize the button . So my question can I use text label with wx.BitmapButton as in wx.Button, so my screen reader can recognize the button and say the text label.

Assuming you are using wxPython Phoenix or Classic at least from version 2.9.1, then wx.Button supports both text and image:

https://wxpython.org/Phoenix/docs/html/wx.Button.html

Andrea.

···

On Mon, 1 May 2017 at 07:53, pythonist12@gmail.com wrote:

بتاريخ الأحد، 30 أبريل، 2017 8:29:30 ص UTC+1، كتب Tim Roberts:

On Apr 28, 2017, at 10:11 PM, pytho...@gmail.com wrote:

Hello Tim Roberts thank you for your reply.

You are right about what I want, I tryed to understand you and change my code but it didn’t work
the course choice does not show any thing

  • I populate the studentChoice from the directories in files\content.

than I want to populate the stage list from the directories in whatever the selected studentChoice was, .

in the stageChoice every thing is ok it works find . But when I try to populate
the course list from the directories in whatever the selected stageChoice was, .

Nothing appears in the courseChoice.

Right. The error message tells the story: you populate the stageChoice list (all at once), but you did not set the client data, as you did when you populated studentChoice.

Note, however, that you don’t actually need to set the client data. You know that everything in studentChoice is a subdirectory of files/content, and you know that everything in stageChoice is a subdirectory of that, and everything in courseChoice is a subdirectory of that. So, rather than use the client data to store the paths, you COULD just build them when you need to. So:

def onStudent( self, event ):

    base = os.path.join( "files", "content/"

        self.studentChoice.GetStringSelection())

    self.stageChoice.Set( os.listdir( base ) )

def onStage( self, event ):

    base = os.path.join( "files", "content/"

        self.studentChoice.GetStringSelection(),

        self.stageChoice.GetStringSelection())

    self.courseChoice.Set( os.listdir( base ) )

Do you see? Each of the boxes has one piece of the path, so you can rebuild the whole path at any time, without using client data.

Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andrea Gavana has put together and maintains a set of Advanced Generic
Widgets, (AGW in the demo), that includes:

  - a buttonpanel with buttons that have both images, (from PNG files),
and text,
  - aquabutton with images and text and
  - shapedbutton which includes SBitmapTextToggleButton and shaped
coloured buttons with rotatable text.

I may well be worth giving the demo programs a go to check how they work
with screen readers.

I hope that the above may resolve your issues.

···

On 01/05/2017 07:16, Tim Roberts wrote:

On Apr 30, 2017, at 10:53 PM, pythonist12@gmail.com wrote:

Because I'm blind person and I use a screen reader and I want to use a button with wx.BitmapButton in my script , but when I move the focus to the bitmapButton the screen reader it says Unknown
it didn't recognize the button . So my question can I use text label with wx.BitmapButton as in wx.Button, so my screen reader can recognize the button and say the text label.

No, wx.BitmapButton does not support any text at all. You'll either need to use a regular button, or create your own custom button control with both text and bitmap.

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

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

Thank you for your help Gadget Steve
Can I get a demo for SBitmapTextToggleButton
.

بتاريخ الاثنين، 1 مايو، 2017 7:47:23 ص UTC+1، كتب Gadget Steve:

···

On 01/05/2017 07:16, Tim Roberts wrote:

On Apr 30, 2017, at 10:53 PM, pytho...@gmail.com wrote:

Because I’m blind person and I use a screen reader and I want to use a button with wx.BitmapButton in my script , but when I move the focus to the bitmapButton the screen reader it says Unknown

it didn’t recognize the button . So my question can I use text label with wx.BitmapButton as in wx.Button, so my screen reader can recognize the button and say the text label.

No, wx.BitmapButton does not support any text at all. You’ll either need to use a regular button, or create your own custom button control with both text and bitmap.

Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Andrea Gavana has put together and maintains a set of Advanced Generic
Widgets, (AGW in the demo), that includes:

  • a buttonpanel with buttons that have both images, (from PNG files),
    and text,

  • aquabutton with images and text and

  • shapedbutton which includes SBitmapTextToggleButton and shaped
    coloured buttons with rotatable text.

I may well be worth giving the demo programs a go to check how they work
with screen readers.

I hope that the above may resolve your issues.


Steve (Gadget) Barnes

Any opinions in this message are my personal opinions and do not reflect
those of my employer.

The Docs & Demo package includes a demo of it under demo.py->Advanced
Generic Widgets->Buttons.

···

On 01/05/2017 17:43, pythonist12@gmail.com wrote:

Thank you for your help Gadget Steve
Can I get a demo for SBitmapTextToggleButton
.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

Thank you for your help.