So are you declaring your synchObjectInstance global?

-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Nate Lowrie
Sent: Thursday, July 08, 2010 12:35 PM
To: Dabo Users list
Subject: Re: [dabo-users] dabo.ui.yieldUI

On Thu, Jul 8, 2010 at 11:31, Douglas Buchanan <[email protected]> wrote:
> Nate, that sounds promising. What I have now is using events that are posted 
> by the worker thread and subscribed to by the progress dialog that is part of 
> the main UI thread. I have two lingering issues:
>
> 1) I indicate what document (x of X) that I am processing. Although an 
> event is posted for each one, the UI does not update smoothly enough 
> to reflect each one. It jumps numbers, although I know the dialog is 
> actually receiving and processing each event
> 2) There is a Cancel button on the dialog that responds correctly the 
> first time. It asks "Are you sure", and if you hit No the processing 
> continues (it is actually still happening in the background worker 
> thread while waiting). The issue with this is that once No is clicked, 
> then Cancel button will not respond to any future clicks
>
> I had originally looked at the callAfterInterval, but discarded it for some 
> reason I cannot remember. What are you using for a synchronization object 
> between threads? A Queue?

It's just an object.

class SynchObject(object):
    def __init__(self):
        self.TotalDocuments = 0
        self.CurrentDocument = 0
        self.CancelProcess = False

Worker thread's run method:

def run(self):
    for document in DocumentsList:
        if synchObjectInstance.CancelProcess:
            break
        # process document
        synchObjectInstance.CurrentDocument += 1

UI's methods:

def updateUI(self):
    self.currentDocumentLabel.Text = synchObjectInstance.CurrentDocument
    if synchObjectInstance.CurrentDocument < synchObjectInstance.TotalDocuments 
and not
synchObjectInstance.CancelProcess:
        dabo.ui.callAfterInterval(100, self.updateUI)
    else:
        self.closeDialog()


Hope this gives you an idea.  Clicking the cancel button should call an event 
that just sets CancelProcess to True.  The reason I call the close dialog 
method from the updateUI method is that I want to be sure that the UI update 
has stopped.  In the close dialog method, you also want to make sure that the 
worker thread has been released before you close the dialog.

One more thing.  Python's threading libraries can't take advantage of running 
simultaneously on multiple processors, so you don't need to worry about 
concurrency issues.  This is why you can use a simple object.  If you want/need 
to encapsulate each value in a property you can, I just used attributes for 
space and time's sake.

Regards,

Nate
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/d4face13c6ced24b91be6f0ee804a8a54b679d5...@vmbx124.ihostexchange.net

Reply via email to