I'm trying (quite unsucessfully, of course) to copy a plot generated
by wx.plot to the clipboard.
In my attempt at doing this, I'v put together the following (very
dirty, very ugly) method:
def EditCopyItemClick(self, event):
self.client.SaveFile("Temp.bmp")
if wx.TheClipboard.Open():
bitmap = wx.Bitmap("Temp.bmp")
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
wx.TheClipboard.Clear()
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
wx.MessageBox("Plot copied to the Clipboard", "Information")
where self.client is an instance of wx.lib.plot.PlotCanvas.
The plot is correctly generated, and the temporary bitmap file is also
correctly saved. However, nothing is copied to the clipboard. I'm sure
I'm missing a crucial point (besides, there may be a more elegant way
to do this, without saving a temporary file to disk).
Thanks in advance for any assistance you can provide.
With warmest regards,
···
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."
I'm trying (quite unsucessfully, of course) to copy a plot generated
by wx.plot to the clipboard.
In my attempt at doing this, I'v put together the following (very
dirty, very ugly) method:
def EditCopyItemClick(self, event):
self.client.SaveFile("Temp.bmp")
if wx.TheClipboard.Open():
bitmap = wx.Bitmap("Temp.bmp")
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
wx.TheClipboard.Clear()
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
wx.MessageBox("Plot copied to the Clipboard", "Information")
where self.client is an instance of wx.lib.plot.PlotCanvas.
The plot is correctly generated, and the temporary bitmap file is also
correctly saved. However, nothing is copied to the clipboard. I'm sure
I'm missing a crucial point (besides, there may be a more elegant way
to do this, without saving a temporary file to disk).
Thanks in advance for any assistance you can provide.
With warmest regards,
···
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."
I'm trying (quite unsucessfully, of course) to copy a plot generated
by wx.plot to the clipboard.
In my attempt at doing this, I'v put together the following (very
dirty, very ugly) method:
def EditCopyItemClick(self, event):
self.client.SaveFile("Temp.bmp")
if wx.TheClipboard.Open():
bitmap = wx.Bitmap("Temp.bmp")
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
wx.TheClipboard.Clear()
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
wx.MessageBox("Plot copied to the Clipboard", "Information")
where self.client is an instance of wx.lib.plot.PlotCanvas.
The plot is correctly generated, and the temporary bitmap file is also
correctly saved. However, nothing is copied to the clipboard. I'm sure
I'm missing a crucial point (besides, there may be a more elegant way
to do this, without saving a temporary file to disk).
The PlotCanvas is using double buffered drawing to display the plot, and that buffer bitmap is accessible as self.client._Buffer, so you should be able to use that bitmap for putting the drawing on the clipboard without a temporary file.
However I'm not sure why your copy to the clipboard is not working. It shouldn't make any difference, but you could try it without doing the Clear() since the SetData is already doing a Clear.
As a quickie test I just did this in the demo using the WIT where the PlotCanvas is selected in the WIT tree (so it is the 'obj' object in the code below,) and then pasted the image into a paint program:
>>> obj._Buffer
<wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x1dd6eb8> >
>>> dobj = wx.BitmapDataObject(obj._Buffer)
>>> wx.TheClipboard.Open()
True
>>> wx.TheClipboard.SetData(dobj)
True
···
wx.TheClipboard.Close()
>>>
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Thank you very much for your help. In fact, it worked by using
self.client_Buffer as you suggested, and so I got rid of the temporary
file.
The working version is as follows:
def EditCopyItemClick(self, event):
if wx.TheClipboard.Open():
data = wx.BitmapDataObject(self.client_Buffer)
wx.TheClipboard.Clear()
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
wx.MessageBox("Plot copied to the Clipboard", "Information")
Notice that keeping the call to Clear() did not make any difference.
Again, thank you very much, for you kind help and for the superb wxPython!
With warmest regards,
···
2009/5/4 Robin Dunn <robin@alldunn.com>:
Mauro Cavalcanti wrote:
Dear ALL,
I'm trying (quite unsucessfully, of course) to copy a plot generated
by wx.plot to the clipboard.
In my attempt at doing this, I'v put together the following (very
dirty, very ugly) method:
def EditCopyItemClick(self, event):
self.client.SaveFile("Temp.bmp")
if wx.TheClipboard.Open():
bitmap = wx.Bitmap("Temp.bmp")
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
wx.TheClipboard.Clear()
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
wx.MessageBox("Plot copied to the Clipboard",
"Information")
where self.client is an instance of wx.lib.plot.PlotCanvas.
The plot is correctly generated, and the temporary bitmap file is also
correctly saved. However, nothing is copied to the clipboard. I'm sure
I'm missing a crucial point (besides, there may be a more elegant way
to do this, without saving a temporary file to disk).
The PlotCanvas is using double buffered drawing to display the plot, and
that buffer bitmap is accessible as self.client._Buffer, so you should be
able to use that bitmap for putting the drawing on the clipboard without a
temporary file.
However I'm not sure why your copy to the clipboard is not working. It
shouldn't make any difference, but you could try it without doing the
Clear() since the SetData is already doing a Clear.
As a quickie test I just did this in the demo using the WIT where the
PlotCanvas is selected in the WIT tree (so it is the 'obj' object in the
code below,) and then pasted the image into a paint program:
>>> obj._Buffer
<wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x1dd6eb8> >
>>> dobj = wx.BitmapDataObject(obj._Buffer)
>>> wx.TheClipboard.Open()
True
>>> wx.TheClipboard.SetData(dobj)
True
>>> wx.TheClipboard.Close()
>>>
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."
Notice that keeping the call to Clear() did not make any difference.
so what did? was:
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
rather than
data = wx.BitmapDataObject(self.client_Buffer)
the problem?
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Yes, the problem was solved by making use of the wxPlot buffer bitmap
(stored in _Buffer), as suggested by Robin.
Best regards,
···
2009/5/5 Christopher Barker <Chris.Barker@noaa.gov>:
Mauro Cavalcanti wrote:
Notice that keeping the call to Clear() did not make any difference.
so what did? was:
data = wx\.BitmapDataObject\(\)
data\.SetBitmap\(bitmap\)
rather than
data = wx\.BitmapDataObject\(self\.client\_Buffer\)
the problem?
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@gmail.com
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."
Yes, the problem was solved by making use of the wxPlot buffer bitmap
(stored in _Buffer), as suggested by Robin.
I'm confused then -- when you were reading it from a file, it was a waste of time, but it should have worked -- you had a valid bitmap.
However, I suspect that:
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
rather than
data = wx.BitmapDataObject(self.client_Buffer)
is the issue -- the create an empty BitmapDataObject, then set the Bitmap, may not work, where creating it by passing int he bitmap did. Maybe I'll test this myself...
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception