On 10/11/2011 1:44 PM, Paul McNett wrote:
> On 10/11/11 10:28 AM, Adam wrote:
>> Also, a little off topic, but the intended purpose of the Run/Pause
>> button is to start or stop an ongoing process (the blocks in the bitmap
>> should move around and interact according to some rules, etc.). I am
>> wondering now how to achieve this, since if I put it in its own loop I
>> think this will arrest the main loop and render the controls inactive
>> until the inner loop stops (which should only be when the button is
>> pushed). Do I need to look into threading, or is there a way to merge
>> this into the main loop so the controls will still work?
> Interaction with the UI needs to happen in the main thread. The general
> approach to
> your problem goes sort of like:
>
> progress = setUpProgressVisualizer():
> for step in veryLongProcess():
> progress.iterate()
> dabo.ui.yieldUI()
> # ... do a step of the very long process here ...
>
> This keeps everything in the main thread, but lets your progress display
> update at
> regular intervals.
>
> Paul
I switched my button to a toggle button and replaced the for loop above
with:
while toggle.Value = True:
...
So far it works perfectly. Thanks!
On 10/11/2011 1:59 PM, Ed Leafe wrote:
> On Oct 11, 2011, at 12:28 PM, Adam wrote:
>
>> Maybe I should be using dImage instead of dBitmap. I am creating the
>> bitmap as a numpy array and then converting to a wxBitmap object:
>>
>> def arrayToBitmap(self, array):
>> width = len(array[0])
>> height = len(array)
>> image = wx.EmptyImage(width,height)
>> image.SetData(array.tostring())
>> image.Rescale(width*10,height*10)
>> wxBitmap = image.ConvertToBitmap()
>> return wxBitmap
>>
>> Then using dBitmap.drawBitmap(wxBitmap) to set the control. Maybe you
>> can suggest a better way than having to do this every time I want to
>> update the image.
> dImage supports streams, but the only ones we've dealt with had already
> been converted to wx.Image objects, akin to the point after the SetData()
> call in your routine.
>
> One of the goals of dImage is to eliminate the need to mess with the
> internals of wxPython image manipulation, so I would certainly like to add
> direct support for something like this, so that you could simply do:
>
> img = dabo.ui.dImage(self, Picture=array, ScaleMode="stretch")
>
> I don't use numpy, so let me ask this: how would the dImage Picture
> setter be able to recognize that it is being passed such an array?
>
>
>
> -- Ed Leafe
Direct support of arrays as image source would be great, but even
without this, I find that simply replacing my dBitmap control with a
dImage control solves my original problem with the image disappearing
when I hit the button. I'll stick with dImage from now on.
Thanks,
Adam
_______________________________________________
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]