accessing a grid

I have a wxPython app that I have inherited. It has a modal form that
has many fields that are usually filled by the user. Now I have been
asked to make a mod where the form is brought up with all the fields
pre filled in based on a selection from a previous form. I have this
working for everything but one field that's a grid.

This grid that gets populated when the user enters values in 3 other
fields and then they can select items from the grid. When I populate
the 3 fields programmatically and then call the callback associated
with the fields and then display the form the grid is filled in. But I
need to select one row from the grid before displaying the form. But
in my code the grid does not have any data in it until I call
ShowModal (when I step through it at some point it gets populated),
This is different behavior from every other type of widget - there are
many combo boxes that when selected determine the content of the rest
of the form. For those when I set the combo value and call the
callback the just instantiated fields are immediately available to me.
I even tried populating the grid myself but that seemed to have no
effect.

Is there some way I can get at the grid data and select a row before I
call ShowModal?

TIA!
-larry

Larry Martell wrote:

I have a wxPython app that I have inherited. It has a modal form that
has many fields that are usually filled by the user. Now I have been
asked to make a mod where the form is brought up with all the fields
pre filled in based on a selection from a previous form. I have this
working for everything but one field that's a grid.

This grid that gets populated when the user enters values in 3 other
fields and then they can select items from the grid. When I populate
the 3 fields programmatically and then call the callback associated
with the fields and then display the form the grid is filled in. But I
need to select one row from the grid before displaying the form. But
in my code the grid does not have any data in it until I call
ShowModal (when I step through it at some point it gets populated),
This is different behavior from every other type of widget - there are
many combo boxes that when selected determine the content of the rest
of the form. For those when I set the combo value and call the
callback the just instantiated fields are immediately available to me.
I even tried populating the grid myself but that seemed to have no
effect.

Is there some way I can get at the grid data and select a row before I
call ShowModal?

I'm not sure I follow your description above, can you make a small sample that demonstrates the problem?

http://wiki.wxpython.org/MakingSampleApps

···

--
Robin Dunn
Software Craftsman

I tried to come up with a small demo, but it just wasn't possible. This app
is the most obfuscated thing I have ever see. It has a ton of derived
classes with all this message passing going back and forth, with many
threads and events.

I think I figured out why the grid was not being populated until I returned
to the main loop - the grid is one of these derived classes and it has a
method that gets data from a database in a thread and posts an event that
the data is ready to be consumed. So the event isn't processed until I
return to the main loop.

So then I googled for how to process events without returning to the
mainloop. I found this and tried to implement it:

https://groups.google.com/forum/#!topic/wxpython-users/989tHIkLXtI

But I get module has no attribute GUIEventLoop. A dir(wx) confirms that. I
think we're running 2.8.9.1.

Thanks!
-larry

···

On Wed, Sep 25, 2013 at 1:26 PM, Robin Dunn <robin@alldunn.com> wrote:

Larry Martell wrote:

I have a wxPython app that I have inherited. It has a modal form that
has many fields that are usually filled by the user. Now I have been
asked to make a mod where the form is brought up with all the fields
pre filled in based on a selection from a previous form. I have this
working for everything but one field that's a grid.

This grid that gets populated when the user enters values in 3 other
fields and then they can select items from the grid. When I populate
the 3 fields programmatically and then call the callback associated
with the fields and then display the form the grid is filled in. But I
need to select one row from the grid before displaying the form. But
in my code the grid does not have any data in it until I call
ShowModal (when I step through it at some point it gets populated),
This is different behavior from every other type of widget - there are
many combo boxes that when selected determine the content of the rest
of the form. For those when I set the combo value and call the
callback the just instantiated fields are immediately available to me.
I even tried populating the grid myself but that seemed to have no
effect.

Is there some way I can get at the grid data and select a row before I
call ShowModal?

I'm not sure I follow your description above, can you make a small sample
that demonstrates the problem?

http://wiki.wxpython.org/**MakingSampleApps&lt;http://wiki.wxpython.org/MakingSampleApps&gt;

Larry Martell wrote:

    Larry Martell wrote:

        I have a wxPython app that I have inherited. It has a modal form
        that
        has many fields that are usually filled by the user. Now I have been
        asked to make a mod where the form is brought up with all the fields
        pre filled in based on a selection from a previous form. I have
        this
        working for everything but one field that's a grid.

        This grid that gets populated when the user enters values in 3 other
        fields and then they can select items from the grid. When I populate
        the 3 fields programmatically and then call the callback associated
        with the fields and then display the form the grid is filled in.
        But I
        need to select one row from the grid before displaying the form. But
        in my code the grid does not have any data in it until I call
        ShowModal (when I step through it at some point it gets populated),
        This is different behavior from every other type of widget -
        there are
        many combo boxes that when selected determine the content of the
        rest
        of the form. For those when I set the combo value and call the
        callback the just instantiated fields are immediately available
        to me.
        I even tried populating the grid myself but that seemed to have no
        effect.

        Is there some way I can get at the grid data and select a row
        before I
        call ShowModal?

    I'm not sure I follow your description above, can you make a small
    sample that demonstrates the problem?

    http://wiki.wxpython.org/__MakingSampleApps
    <http://wiki.wxpython.org/MakingSampleApps&gt;

I tried to come up with a small demo, but it just wasn't possible. This
app is the most obfuscated thing I have ever see. It has a ton of
derived classes with all this message passing going back and forth, with
many threads and events.

I think I figured out why the grid was not being populated until I
returned to the main loop - the grid is one of these derived classes and
it has a method that gets data from a database in a thread and posts an
event that the data is ready to be consumed. So the event isn't
processed until I return to the main loop.

So then I googled for how to process events without returning to the
mainloop. I found this and tried to implement it:

Redirecting to Google Groups

But I get module has no attribute GUIEventLoop. A dir(wx) confirms that.
I think we're running 2.8.9.1.

Using wx.GetApp().Yield() or one of the related functions is the normal way to allow events to be received and processed at some point before returning to the MainLoop or entering a nested event loop like ShowModal, but it is usually better to avoid using it if you can because there can be recursion issues. Plus in this case you probably can't be guaranteed that the worker thread is finished loading from the database at the time of the yield without a lot of additional hassle. So instead of trying to force population of the grid, why not just defer the setting of the row until later and just jump into ShowModal as soon as possible?

For example depending on how the notification from the worker thread is being done you may be able to set it up so your code is also notified when that happens (binding the same event, listening for the same pubsub message, sending a new message from the code that is populating the grid, etc.) Or if all else fails and if you can safely make an assumption that the database query and grid population will be done in a tenth of a second (or whatever) then you can simply use a timer to call the code that selects the row after that amount of time:

  wx.CallLater(100, self.functionThatSelectsRow)
  result = dlg.ShowModal()
  ...

···

On Wed, Sep 25, 2013 at 1:26 PM, Robin Dunn <robin@alldunn.com > <mailto:robin@alldunn.com>> wrote:

--
Robin Dunn
Software Craftsman

Larry Martell wrote:

    Larry Martell wrote:

        I have a wxPython app that I have inherited. It has a modal form
        that
        has many fields that are usually filled by the user. Now I have
been
        asked to make a mod where the form is brought up with all the
fields
        pre filled in based on a selection from a previous form. I have
        this
        working for everything but one field that's a grid.

        This grid that gets populated when the user enters values in 3
other
        fields and then they can select items from the grid. When I
populate
        the 3 fields programmatically and then call the callback
associated
        with the fields and then display the form the grid is filled in.
        But I
        need to select one row from the grid before displaying the form.
But
        in my code the grid does not have any data in it until I call
        ShowModal (when I step through it at some point it gets
populated),
        This is different behavior from every other type of widget -
        there are
        many combo boxes that when selected determine the content of the
        rest
        of the form. For those when I set the combo value and call the
        callback the just instantiated fields are immediately available
        to me.
        I even tried populating the grid myself but that seemed to have no
        effect.

        Is there some way I can get at the grid data and select a row
        before I
        call ShowModal?

    I'm not sure I follow your description above, can you make a small
    sample that demonstrates the problem?

    http://wiki.wxpython.org/__**MakingSampleApps&lt;http://wiki.wxpython.org/__MakingSampleApps&gt;

    <http://wiki.wxpython.org/**MakingSampleApps&lt;http://wiki.wxpython.org/MakingSampleApps&gt;
>

I tried to come up with a small demo, but it just wasn't possible. This
app is the most obfuscated thing I have ever see. It has a ton of
derived classes with all this message passing going back and forth, with
many threads and events.

I think I figured out why the grid was not being populated until I
returned to the main loop - the grid is one of these derived classes and
it has a method that gets data from a database in a thread and posts an
event that the data is ready to be consumed. So the event isn't
processed until I return to the main loop.

So then I googled for how to process events without returning to the
mainloop. I found this and tried to implement it:

https://groups.google.com/**forum/#!topic/wxpython-users/**989tHIkLXtI&lt;https://groups.google.com/forum/#!topic/wxpython-users/989tHIkLXtI&gt;

But I get module has no attribute GUIEventLoop. A dir(wx) confirms that.
I think we're running 2.8.9.1.

Why do I not have GUIEventLoop? Is it only in a later version?

Using wx.GetApp().Yield() or one of the related functions is the normal
way to allow events to be received and processed at some point before
returning to the MainLoop or entering a nested event loop like ShowModal,
but it is usually better to avoid using it if you can because there can be
recursion issues. Plus in this case you probably can't be guaranteed that
the worker thread is finished loading from the database at the time of the
yield without a lot of additional hassle. So instead of trying to force
population of the grid, why not just defer the setting of the row until
later and just jump into ShowModal as soon as possible?

I need to show the dialog with one of the rows in the grid selected. I
can't do that until the grid is populated.

For example depending on how the notification from the worker thread is
being done you may be able to set it up so your code is also notified when
that happens (binding the same event, listening for the same pubsub
message, sending a new message from the code that is populating the grid,
etc.) Or if all else fails and if you can safely make an assumption that
the database query and grid population will be done in a tenth of a second
(or whatever) then you can simply use a timer to call the code that selects
the row after that amount of time:

        wx.CallLater(100, self.functionThatSelectsRow)
        result = dlg.ShowModal()
        ...

I've spend 3 days digging through the code and I can't find the code that
populates the grid or generates or receives the event. I just know it gets
populated after I call ShowModal(). This is probably the most overly
complicated, obfuscated program I have seen in my 35 years of programming.
And what I've been asked to make it do is really putting a square pen in a
round hole. I try Yield and see if that works for me.

Thanks.

···

On Fri, Oct 4, 2013 at 11:56 AM, Robin Dunn <robin@alldunn.com> wrote:

On Wed, Sep 25, 2013 at 1:26 PM, Robin Dunn <robin@alldunn.com >> <mailto:robin@alldunn.com>> wrote:

Yield() is working for me. Thanks!

···

On Fri, Oct 4, 2013 at 12:08 PM, Larry Martell <larry.martell@gmail.com>wrote:

On Fri, Oct 4, 2013 at 11:56 AM, Robin Dunn <robin@alldunn.com> wrote:

Larry Martell wrote:

On Wed, Sep 25, 2013 at 1:26 PM, Robin Dunn <robin@alldunn.com >>> <mailto:robin@alldunn.com>> wrote:

    Larry Martell wrote:

        I have a wxPython app that I have inherited. It has a modal form
        that
        has many fields that are usually filled by the user. Now I have
been
        asked to make a mod where the form is brought up with all the
fields
        pre filled in based on a selection from a previous form. I have
        this
        working for everything but one field that's a grid.

        This grid that gets populated when the user enters values in 3
other
        fields and then they can select items from the grid. When I
populate
        the 3 fields programmatically and then call the callback
associated
        with the fields and then display the form the grid is filled in.
        But I
        need to select one row from the grid before displaying the form.
But
        in my code the grid does not have any data in it until I call
        ShowModal (when I step through it at some point it gets
populated),
        This is different behavior from every other type of widget -
        there are
        many combo boxes that when selected determine the content of the
        rest
        of the form. For those when I set the combo value and call the
        callback the just instantiated fields are immediately available
        to me.
        I even tried populating the grid myself but that seemed to have
no
        effect.

        Is there some way I can get at the grid data and select a row
        before I
        call ShowModal?

    I'm not sure I follow your description above, can you make a small
    sample that demonstrates the problem?

    http://wiki.wxpython.org/__**MakingSampleApps&lt;http://wiki.wxpython.org/__MakingSampleApps&gt;

    <http://wiki.wxpython.org/**MakingSampleApps&lt;http://wiki.wxpython.org/MakingSampleApps&gt;
>

I tried to come up with a small demo, but it just wasn't possible. This
app is the most obfuscated thing I have ever see. It has a ton of
derived classes with all this message passing going back and forth, with
many threads and events.

I think I figured out why the grid was not being populated until I
returned to the main loop - the grid is one of these derived classes and
it has a method that gets data from a database in a thread and posts an
event that the data is ready to be consumed. So the event isn't
processed until I return to the main loop.

So then I googled for how to process events without returning to the
mainloop. I found this and tried to implement it:

https://groups.google.com/**forum/#!topic/wxpython-users/**989tHIkLXtI&lt;https://groups.google.com/forum/#!topic/wxpython-users/989tHIkLXtI&gt;

But I get module has no attribute GUIEventLoop. A dir(wx) confirms that.
I think we're running 2.8.9.1.

Why do I not have GUIEventLoop? Is it only in a later version?

Using wx.GetApp().Yield() or one of the related functions is the normal
way to allow events to be received and processed at some point before
returning to the MainLoop or entering a nested event loop like ShowModal,
but it is usually better to avoid using it if you can because there can be
recursion issues. Plus in this case you probably can't be guaranteed that
the worker thread is finished loading from the database at the time of the
yield without a lot of additional hassle. So instead of trying to force
population of the grid, why not just defer the setting of the row until
later and just jump into ShowModal as soon as possible?

I need to show the dialog with one of the rows in the grid selected. I
can't do that until the grid is populated.

For example depending on how the notification from the worker thread is
being done you may be able to set it up so your code is also notified when
that happens (binding the same event, listening for the same pubsub
message, sending a new message from the code that is populating the grid,
etc.) Or if all else fails and if you can safely make an assumption that
the database query and grid population will be done in a tenth of a second
(or whatever) then you can simply use a timer to call the code that selects
the row after that amount of time:

        wx.CallLater(100, self.functionThatSelectsRow)
        result = dlg.ShowModal()
        ...

I've spend 3 days digging through the code and I can't find the code that
populates the grid or generates or receives the event. I just know it gets
populated after I call ShowModal(). This is probably the most overly
complicated, obfuscated program I have seen in my 35 years of
programming. And what I've been asked to make it do is really putting a
square peg in a round hole. I'll try Yield and see if that works for me.

Larry Martell wrote:

        I think we're running 2.8.9.1.

Why do I not have GUIEventLoop? Is it only in a later version?

Yep. 2.8.9.1 is over 5 years old.

···

--
Robin Dunn
Software Craftsman

I asked our admins here about upgrading and here is the reply I got back:

I actually tried to upgrade us to 2.8.12.1 in April 2012, and was stymied
by the impossible matrix of dependencies (wxPython has dependencies both on
the version of Python - ours is very very old - and on wx, and wx has
dependencies on gtk/gnome, which has dependencies on practically every hack
package every written by some scruffy punk programmer). So finding the
combination of everything that works, and getting it all built and
interoperating successfully, is typically a 2-3 week exercise in banging
your head against a cement block.

So I guess I'm struck with 2.8.9.1 <Sigh>

···

On Tue, Oct 8, 2013 at 7:19 PM, Robin Dunn <robin@alldunn.com> wrote:

Larry Martell wrote:

        I think we're running 2.8.9.1.

Why do I not have GUIEventLoop? Is it only in a later version?

Yep. 2.8.9.1 is over 5 years old.

Larry,

We all feel your pain.

···

On Thu, Oct 10, 2013 at 8:32 AM, Larry Martell larry.martell@gmail.com wrote:

Maybe you need some better admins. Folks have to realize that you can’t run new software, or develop with up to date libraries if you insist on running really old systems (and 5 years is prety old by these standards!)

wxPython does have a difficult dependency chain, yes.

why are you running a “very, very, old” Python? 2.7 was released in 2010 – there is very little reason to use an older that 2.7.* python for any new development work.

(and you can have more than one version on a system)

This is ridiculous – GTK is a very widely used and well maintained system – it’s not based on “every hack package”. And everything it depends on should be a simple apt-get or yum (or ??) install away.

These are clearly people that want “enterprise” style, everything built and supported for you – which is fine, but go buy a supported system from someone that’s not 5 years old! Recent Ubuntu, Suse, or what have you will have more recent versions of things. Or run frickin Windows or OS-X if you want it all delivered to you in a sealed package.

Even if you do need to build everything on an older system, and admin worth their salt should be able to do it in a couple days…

Oh well. Good luck. Though it will be a little harder to get questions answered, 2.8 was a fine system that we all built good software with.

-Chris


Christopher Barker, PhD

Python Language Consulting

  • Teaching
  • Scientific Software Development
  • Desktop GUI and Web Development
  • wxPython, numpy, scipy, Cython

I asked our admins

here about upgrading and here is the reply I got back:

I actually tried to upgrade us to 2.8.12.1 in April 2012, and was stymied by the impossible matrix of dependencies

(wxPython has dependencies both on the version of Python - ours is very very old

  • and on wx, and wx has dependencies on gtk/gnome, which has dependencies on practically every hack package every written by some scruffy punk programmer).

So finding the combination of everything that works, and getting it all built and interoperating successfully, is typically a 2-3 week exercise in banging your head against a cement block.

So I guess I’m struck with 2.8.9.1

Larry,

We all feel your pain.

Thanks. Misery loves company.

I asked our admins

Maybe you need some better admins.

Yeah, I've been saying that but it doesn't make me too popular.

Folks have to realize that you can't run new software, or develop with up
to date libraries if you insist on running really old systems (and 5 years
is prety old by these standards!)

You should have seen what I went through to get PHP upgraded a few months
back.

here about upgrading and here is the reply I got back:

I actually tried to upgrade us to 2.8.12.1 in April 2012, and was stymied
by the impossible matrix of dependencies

wxPython does have a difficult dependency chain, yes.

(wxPython has dependencies both on the version of Python - ours is very
very old

why are you running a "very, very, old" Python? 2.7 was released in 2010
-- there is very little reason to use an older that 2.7.* python for any
new development work.

Beats me. We're running 2.5.1.

(and you can have more than one version on a system)

- and on wx, and wx has dependencies on gtk/gnome, which has
dependencies on practically every hack package every written by some
scruffy punk programmer).

This is ridiculous -- GTK is a very widely used and well maintained system
-- it's not based on "every hack package". And everything it depends on
should be a simple apt-get or yum (or ??) install away.

These are clearly people that want "enterprise" style, everything built
and supported for you -- which is fine, but go buy a supported system from
someone that's not 5 years old! Recent Ubuntu, Suse, or what have you will
have more recent versions of things. Or run frickin Windows or OS-X if you
want it all delivered to you in a sealed package.

We run Centos here, but it seems things are not installed in a standard
way.

So finding the combination of everything that works, and getting it all

built and interoperating successfully, is typically a 2-3 week exercise in
banging your head against a cement block.

Even if you do need to build everything on an older system, and admin
worth their salt should be able to do it in a couple days...

So I guess I'm struck with 2.8.9.1 <Sigh>

Oh well. Good luck. Though it will be a little harder to get questions
answered, 2.8 was a fine system that we all built good software with.

Thanks.
-larry

···

On Thu, Oct 10, 2013 at 9:51 AM, Christopher Barker <pythonchb@gmail.com>wrote:

On Thu, Oct 10, 2013 at 8:32 AM, Larry Martell <larry.martell@gmail.com>wrote:

    why are you running a "very, very, old" Python? 2.7 was released in
    2010 -- there is very little reason to use an older that 2.7.*
    python for any new development work.

Beats me. We're running 2.5.1.

wxPython-2.9 works with python 2.5. Just a small patch

HTH
Niki

2.9? I thought the latest stable release was 2.8.12.1.

···

On Fri, Oct 11, 2013 at 4:49 AM, niki <niki@vintech.bg> wrote:

    why are you running a "very, very, old" Python? 2.7 was released in

    2010 -- there is very little reason to use an older that 2.7.*
    python for any new development work.

Beats me. We're running 2.5.1.

wxPython-2.9 works with python 2.5. Just a small patch

The short answer is yes, but.
Following explains it very well and it has recently been updated by
Robin.
I use 2.9.x for about a year now and know of others who are using it
too for maybe even longer then myself.
I distribute my stuff only as py2exe’d version, so I have control
what the user gets. I wanted to take advantage of some of the new
stuff in 2.9 and therefore use it and find it as ‘stable’ as 2.8 if
not better as it contains latest bug fixes.
Werner

···

On 11/10/2013 16:23, Larry Martell
wrote:

On Fri, Oct 11, 2013 at 4:49 AM, niki niki@vintech.bg
wrote:

              why are you running a "very, very, old" Python? 2.7

was released in

                  2010 -- there is very little reason to use an

older that 2.7.*

                  python for any new development work.





              Beats me. We're running 2.5.1.

wxPython-2.9 works with python 2.5. Just a small patch

2.9? I thought the latest stable release was 2.8.12.1.

:slight_smile:

http://wiki.wxpython.org/ReleaseSeries