wxProgressDialog question

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
jdubchak
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Sep 01, 2004 11:45 am
Location: Minneapolis, MN

wxProgressDialog question

Post by jdubchak »

I implmented a database intensive method where I want to update the user on progress, obviously using a wxProgressDialog dialog. However, the database layer is separate frpm the user interface that initiated that process and being able to update from one to the other has been problematic.

Has anyone else encountered this problem and been able to create a workable solution?

Thanks,
John
Ryan Wilcox
I live to help wx-kind
I live to help wx-kind
Posts: 194
Joined: Mon Aug 30, 2004 1:26 pm
Location: PA, USA

Re: wxProgressDialog question

Post by Ryan Wilcox »

jdubchak wrote:I implmented a database intensive method where I want to update the user on progress, obviously using a wxProgressDialog dialog. However, the database layer is separate frpm the user interface that initiated that process and being able to update from one to the other has been problematic.
Sounds like you're trying (or have) some sort of MVC design in your application. At least, you have an obvious model (the database app), and an obvious view (wxProgressDialog)

What I would do is probably something like this

Code: Select all

void myControllerObject::DoThatLongThing()
{

     for (int i = 0; i > countRecordsToChange; i++)
    {
        updateRecord(i);
        //update my wxProgressBar
    }
}
Or perhaps your database provides a callback function -- you have it call the function at some point during the operation, and it lets you update the progress?
Ryan Wilcox
Wilcox Development Solutions
http://www.wilcoxd.com
jdubchak
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Sep 01, 2004 11:45 am
Location: Minneapolis, MN

Re: wxProgressDialog question

Post by jdubchak »

Ryan Wilcox wrote:Sounds like you're trying (or have) some sort of MVC design in your application.
Yes, absolutely. Doesn't everyone? :D
Ryan Wilcox wrote:At least, you have an obvious model (the database app), and an obvious view (wxProgressDialog)
The problem is that the wxProgressDialog expects to be created on the stack as a local variable and you must update it using that locally scoped variable. Which you can't.

I've tried both the callback mechanism and custom events - neither of which have proven useful. I think I may have to implement another class which wraps (not extends) the wxProgressDialog in order to get the functionality I want...
Ryan Wilcox wrote:What I would do is probably something like this

Code: Select all

void myControllerObject::DoThatLongThing()
{

     for (int i = 0; i > countRecordsToChange; i++)
    {
        updateRecord(i);
        //update my wxProgressBar
    }
}
Yep, except what you've done here is broken the MVC separation because the model now contains a visual component.

Thanks very much.

John
Ryan Wilcox
I live to help wx-kind
I live to help wx-kind
Posts: 194
Joined: Mon Aug 30, 2004 1:26 pm
Location: PA, USA

Re: wxProgressDialog question

Post by Ryan Wilcox »

Ryan Wilcox wrote:What I would do is probably something like this

Code: Select all

void myControllerObject::DoThatLongThing()
{

     for (int i = 0; i > countRecordsToChange; i++)
    {
        updateRecord(i);
        //update my wxProgressBar
    }
}
John wrote: Yep, except what you've done here is broken the MVC separation because the model now contains a visual component.
I typoed. I mean

Code: Select all

  myModelObject->UpdateRecord(i);
As having to create it on the stack.. Why do you think it requires this? What errors do you get if you go the new/delete way?
Ryan Wilcox
Wilcox Development Solutions
http://www.wilcoxd.com
jdubchak
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Sep 01, 2004 11:45 am
Location: Minneapolis, MN

Post by jdubchak »

As having to create it on the stack.. Why do you think it requires this?
Sorry, a more accurate statement would be: I would prefer two-step construction with wxProgressDialog, similar to many (if not all) of the other wxWidgets Windows.

The disadvantage to the current wxProgressDialog is that the constructor is responsible for showing the dialog, so you can't construct it and show it some point later in the code.

Maybe I'm looking at the problem incorrectly, but I don't see how the current wxProgressDialog can be used effectively with a callback without some code monkeying...

Thanks,
John