Events between frames

Hi
I'm trying to make an simple image viewer with wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit.
http://pastebin.com/m7bfa2889
The class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 43) creates the menu, where the function "def
onRotate" (l. 46) is called. The slider appear in at 2nd window "class
rotationSlider(wx.Frame)" (l. 11). After selecting the value with the
slider "def doRotate" (l. 53) should rotate the image.
I've tried binding the function doRotate and when the rotationSlider
frame is closed. But I couldn't make it work, and it didn't make it
possible to get the slider value. So it's properly the rotationSlider
frame that should call the doRotate function. But despited goggling
and looking at the wxPython wiki I'm a bit stuck.

I'll put up the complete code, if needed...

/Lars

If you want two frames to communicate with each other, one of the
easiest ways is pubsub. Check out the wiki:

http://wiki.wxpython.org/PubSub

I've used this method successfully several times.

···

On Sep 10, 10:02 am, Lars <noge...@gmail.com> wrote:

Hi
I'm trying to make an simple image viewer with wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit.http://pastebin.com/m7bfa2889
The class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 43) creates the menu, where the function "def
onRotate" (l. 46) is called. The slider appear in at 2nd window "class
rotationSlider(wx.Frame)" (l. 11). After selecting the value with the
slider "def doRotate" (l. 53) should rotate the image.
I've tried binding the function doRotate and when the rotationSlider
frame is closed. But I couldn't make it work, and it didn't make it
possible to get the slider value. So it's properly the rotationSlider
frame that should call the doRotate function. But despited goggling
and looking at the wxPython wiki I'm a bit stuck.

I'll put up the complete code, if needed...

/Lars

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

I'd suggest, that you think in terms of two things:

1) An aside: Change the names of your functions and classes to better
represent what they are. Your rotationSlider class is not a
slider, but a frame with a slider within it. Changing it rotationSliderFrame
might be better. Same with your method, self.frameRotate, which
is in the form of a verb that suggests it does the work of rotating the
image, but it actually represents actually an instance of the
rotationSlider frame.

2) Think in terms of passing names effectively. If you call an
instance of your rotationSlider from within the main Frame, you
really only need it to return an angle to the Frame when the
button is pushed, which you can then pass to a RotateImage()
method that will do the actual rotation. Inter-frame communication
is a frequent topic on this list. As Mike said, pubsub is a good
way to go. A quick-fix for you now though might be:

self.frameRotate = rotationSlider(parent=self, id=-1)
#Now it is a child of the main frame, and therefore can directly
#communicate with it.

Then the button in the rotationSlider frame can bind to an
event handler that calls this function:

#Within the rotationSlider class:
ReturnRotationAngle():
    angle = self.slider.GetValue()
    self.parent.DoRotate(angle)

and then DoRotate, a method of Frame, would make use
of that angle in the rotation. The point is you have a
reference to the Frame within the rotationSlider class,
so you can communicate to it. Pubsub is a better method,
though, because it doesn't introduce coupling, and so you
could later reuse/rearrange things without breaking it.

Che

···

On Thu, Sep 10, 2009 at 11:02 AM, Lars <nogetfx@gmail.com> wrote:

Hi
I'm trying to make an simple image viewer with wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit.
http://pastebin.com/m7bfa2889
The class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 43) creates the menu, where the function "def
onRotate" (l. 46) is called. The slider appear in at 2nd window "class
rotationSlider(wx.Frame)" (l. 11). After selecting the value with the
slider "def doRotate" (l. 53) should rotate the image.
I've tried binding the function doRotate and when the rotationSlider
frame is closed. But I couldn't make it work, and it didn't make it
possible to get the slider value. So it's properly the rotationSlider
frame that should call the doRotate function. But despited goggling
and looking at the wxPython wiki I'm a bit stuck.

I'll put up the complete code, if needed...'

Thank you for the comments. Pubsub works perfect.
Regarding my names, you're right. The project has been used to get an
understanding of wxpython, so I been naming things what first come to
mind.

/Lars

Hello,

I have a wxgrid that I am using and I have a problem because the mouse motion seems to cause the grid to update/refresh. my gridtablebase has the standard methods such as GetNumberRows GetNumberCols GetLabelName GetValue and these seem to be called just when I move the mouse over the grid window. The problem is that I am changing the dataset and before a ResetView method is called which updates the grid columns and rows if they are appended/deleted the mouse motion may result in a call to one of the above methods and of course if the dataset has changed and teh grid not yet updated then the rows or cols the grid is trying to update do not exists in the dataset and I get a error.

The dataset is maintained in a separate thread so I tell the wxgrid to update via a queue. even in this small amount of time, if there is any mouse motion this problem happens. if there is no mouse motion, then no problem. I would prefer to call UpdateValues and ResetView etc manually so this doesn’t occur. is there a way to disable this functionality in the wxGrid?

thanks,

Jeff

Hello,

I have a wxgrid that I am using and I have a problem because the mouse
motion seems to cause the grid to update/refresh. my gridtablebase has
the standard methods such as GetNumberRows GetNumberCols GetLabelName
GetValue and these seem to be called just when I move the mouse over the
grid window. The problem is that I am changing the dataset and before a
ResetView method is called which updates the grid columns and rows if
they are appended/deleted the mouse motion may result in a call to one
of the above methods and of course if the dataset has changed and teh
grid not yet updated then the rows or cols the grid is trying to update
do not exists in the dataset and I get a error.

What platform are you on? Unless you are doing something to cause it to do so, the grid should not be redrawing the cells (or fetching the data for them) just for a mouse-over. It should only be doing it when a cell or something else in the window needs to be redrawn.

The dataset is maintained in a separate thread so I tell the wxgrid to
update via a queue. even in this small amount of time, if there is any
mouse motion this problem happens. if there is no mouse motion, then no
problem. I would prefer to call UpdateValues and ResetView etc manually
so this doesn't occur. is there a way to disable this functionality in
the wxGrid?

It's pretty much driven from the need to repaint all or a portion of the window (including any Refresh calls within the grid code itself.) The grid has BeginBatch and EndBatch methods that can be used to suspend the refresh of the cells, but perhaps a better approach for you would be to cache the values you get from the data source and just redraw the cached values when the grid wants to refresh. Then you just need to synchronize the cache and the data source.

···

On 9/11/09 7:51 AM, Jeff Peery wrote:

--
Robin Dunn
Software Craftsman