Copying multiple images to Clipboard

  1. I have worked out that wx.DataObjectComposite is about different versions of the same object (e.g. a text version, an image version etc) - not about multiple items of the same type.

From a Robin Dunn answer in 2008:

"You can only have one data object of each type on the clipboard at the same time. DataObjectComposite helps you have more than one object, but you are still limited by the platform to a single text object, a single bitmap object, etc.

Another way to look at it is that the clipboard can only allow a single object to be available at a time, but does allow for multiple representations of that same single object to be provided. For example, you could have the string “foobar”, a bitmap drawing of “foobar” and a custom data format that is pickle of the foobar object. On the other hand you are trying to have multiple objects present, each with a single representation (i.e. you were storing each cell independently.)

So the thing to do would be to figure out the various ways that you want to be able to provide the all data in the listctrl as a single data object, such as a string in tab-separated-values format, or similar. If you want to provide multiple representations then you can use the DataObjectComposite to do that."

  1. I have also worked out that adding multiple objects to the clipboards using wx.TheClipboard.AddData() only retains the last. You still can’t add multiple items of the same sort to the clipboard. When you paste you just get the last of a certain type.

  2. So what if I want to have multiple images? It is possible to copy multiple images to the clipboard in office suites, file managers, when copying and pasting selections from HTML etc. So the OS allows it. Is this a wxPython limit? Or is there some way of making an object which is a set of images? Note - I don’t want to stitch the images together into one larger image.

You could try using a pickled list of Images - this would be
assuming that you are pasting into one of your own applications. I
believe that the other applications that you mention tend to use a
list of file names, (possibly temporary files if the items don’t
exist as files), or in the case of a browser a single string of
HTML, which of course includes the URLs of any pictures, (these
would be fetched from the cache).
Gadget/Steve

···

On 15/08/2012 11:45 AM, Grant
Paton-Simpson wrote:

  1) I have worked out that wx.DataObjectComposite is

about different versions of the same object (e.g. a text version,
an image version etc) - not about multiple items of the same type.

  From a Robin Dunn answer in 2008:


    "You can only have one data object

of each type on the clipboard at the same time.
DataObjectComposite helps you have more than one object, but
you are still limited by the platform to a single text object, a
single bitmap object, etc.

    Another way to look at it is that the clipboard can only allow a

single object to be available at a time, but does allow for
multiple representations of that same single object to be
provided. For example, you could have the string “foobar”, a
bitmap drawing of “foobar” and a custom data format that is
pickle of the foobar object. On the other hand you are trying
to have multiple objects present, each with a single
representation (i.e. you were storing each cell independently.)

    So the thing to do would be to figure out the various ways that

you want to be able to provide the all data in the listctrl as a
single data object, such as a string in tab-separated-values
format, or similar. If you want to provide multiple
representations then you can use the DataObjectComposite to do
that."

  2) I have also worked out that adding multiple objects to the

clipboards using wx.TheClipboard.AddData() only retains the last.
You still can’t add multiple items of the same sort to the
clipboard. When you paste you just get the last of a certain type.

  3) So what if I want to have multiple images? It is possible to

copy multiple images to the clipboard in office suites, file
managers, when copying and pasting selections from HTML etc. So
the OS allows it. Is this a wxPython limit? Or is there some way
of making an object which is a set of images? Note - I don’t want
to stitch the images together into one larger image.

  --

  To unsubscribe, send email to

or visit

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

Hi Gadget/Steve,

Thanks for the quick reply. The pickling is out because I am wanting

to be able to paste into Word Processors and Image editors (like the
GIMP). So your suggestion about lists of file names looks relevant.
My initial experiments are failing - do you have any pointers?

All the best, Grant
···

On 15/08/12 23:02, Gadget/Steve wrote:

  You could try using a pickled list of Images - this would be

assuming that you are pasting into one of your own applications.
I believe that the other applications that you mention tend to use
a list of file names, (possibly temporary files if the items don’t
exist as files), or in the case of a browser a single string of
HTML, which of course includes the URLs of any pictures, (these
would be fetched from the cache).
Gadget/Steve
– To unsubscribe, send email to
or visit

    On 15/08/2012 11:45 AM, Grant

Paton-Simpson wrote:

    1) I have worked out that wx.DataObjectComposite is

about different versions of the same object (e.g. a text
version, an image version etc) - not about multiple items of the
same type.

    From a Robin Dunn answer in 2008:


      "You can only have one data

object of each type on the clipboard at the same time.
DataObjectComposite helps you have more than one object, but
you are still limited by the platform to a single text object,
a single bitmap object, etc.

      Another way to look at it is that the clipboard can only allow

a single object to be available at a time, but does allow for
multiple representations of that same single object to be
provided. For example, you could have the string “foobar”, a
bitmap drawing of “foobar” and a custom data format that is
pickle of the foobar object. On the other hand you are trying
to have multiple objects present, each with a single
representation (i.e. you were storing each cell
independently.)

      So the thing to do would be to figure out the various ways

that you want to be able to provide the all data in the
listctrl as a single data object, such as a string in
tab-separated-values format, or similar. If you want to
provide multiple representations then you can use the
DataObjectComposite to do that."

    2) I have also worked out that adding multiple objects to the

clipboards using wx.TheClipboard.AddData() only retains the
last. You still can’t add multiple items of the same sort to the
clipboard. When you paste you just get the last of a certain
type.

    3) So what if I want to have multiple images? It is possible to

copy multiple images to the clipboard in office suites, file
managers, when copying and pasting selections from HTML etc. So
the OS allows it. Is this a wxPython limit? Or is there some way
of making an object which is a set of images? Note - I don’t
want to stitch the images together into one larger image.

    --

    To unsubscribe, send email to or visit

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

How about knocking up a quick script, or using the demo, setting it
to accept the pastes and using some debug output, or the debugger to
see what pasting multiple images from your word processor supplies
to the script/demo in the OnPaste event handler?
That should let you know what the WP is supplying and, (hopefully),
what it will accept.
Gadget/Steve

···

On 15/08/2012 12:26 PM, Grant
Paton-Simpson wrote:

Hi Gadget/Steve,

  Thanks for the quick reply. The pickling is out because I am

wanting to be able to paste into Word Processors and Image editors
(like the GIMP). So your suggestion about lists of file names
looks relevant. My initial experiments are failing - do you have
any pointers?

  All the best, Grant

Very interesting. Thanks for that. I’ll have to give that a go
tomorrow NZ time. I have set something up that can grab and print
any text added to the clipboard but I need to add a little more to
that foundation.

···

On 15/08/12 23:39, Gadget/Steve wrote:

  How about knocking up a quick script, or using the demo, setting

it to accept the pastes and using some debug output, or the
debugger to see what pasting multiple images from your word
processor supplies to the script/demo in the OnPaste event
handler?
That should let you know what the WP is supplying and,
(hopefully), what it will accept.
Gadget/Steve
– To unsubscribe, send email to
or visit

    On 15/08/2012 12:26 PM, Grant

Paton-Simpson wrote:

Hi Gadget/Steve,

    Thanks for the quick reply. The pickling is out because I am

wanting to be able to paste into Word Processors and Image
editors (like the GIMP). So your suggestion about lists of file
names looks relevant. My initial experiments are failing - do
you have any pointers?

    All the best, Grant

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

Depending on your platform there are already some tools available to help you inspect the native Clipboard or DnD data objects. For example on Windows look for ClipSpy and on OSX look for Pasteboard Inspector.

BTW, for multiple files you can add more than one path name to wx.FileDataObject.

···

On 8/15/12 5:22 AM, Grant Paton-Simpson wrote:

Very interesting. Thanks for that. I'll have to give that a go tomorrow
NZ time. I have set something up that can grab and print any text added
to the clipboard but I need to add a little more to that foundation.

--
Robin Dunn
Software Craftsman

Hi Robin,

Great tip about wx.FileDataObject. It works brilliantly on Windows - successfully pasting a series of charts into the file manager or into Word etc. And they aren't just links either - I was able to open the document in Ubuntu and see all the charts.

I don't have to worry about Mac at this stage (other problems to solve first) but I'll have a closer look at Ubuntu to see if I can get this to work there. Initial signs are not promising but I have a fall-back of sorts if I can't get it going on Linux.

Here is the very simple code I used. Given it is just a snippet I have included it in the email rather than as an attachment:

if not wx.TheClipboard.IsOpened():
     do = wx.FileDataObject()
     myroot = u"C:/Documents and Settings/grant/sofastats/reports/output_test_images"
     for filename in os.listdir(myroot):
         if os.path.splitext(filename)[1] == u".png":
             do.AddFile(os.path.join(myroot, filename))
     wx.TheClipboard.Open()
     wx.TheClipboard.AddData(do)
     wx.TheClipboard.Close()
     wx.MessageBox(u"Finished")

All the best,
Grant

···

On 16/08/12 03:55, Robin Dunn wrote:

BTW, for multiple files you can add more than one path name to wx.FileDataObject.

Hi Robin,

It looks like the ability to add multiple images to the clipboard so

the user can paste them into file managers, word processors etc, is
a Windows-only option. I hope I’m wrong and there is a robust
workaround - perhaps creating multi-item objects.

Anyway, one fall-back approach I am considering for Linux is a loop

where for each image (often just one, usually just a handful) the
user sees a messagebox telling them to paste the first item and then
click OK to receive the next one etc. I can easily use the
BitmapDataObject for that.

wx.TheClipboard.Open()

      img_demo = wx.Image(imgname, wx.BITMAP_TYPE_PNG)

      bmp_demo = wx.BitmapFromImage(img_demo)

      do = wx.DataObjectComposite() # multiple formats not items

      do.Add(wx.BitmapDataObject(bmp_demo), True)

      alt_txt = (u"If you see this text instead of the "

             u"image \"%s\", try pasting the output into a "

             u"graphics program first and edit/copy/save "

             u"from there etc." % imgname)

      do.Add(wx.TextDataObject(alt_txt), False)

  wx.TheClipboard.AddData(do)

  wx.TheClipboard.Close()
I should add the following to the record for future people who bump

into this thread:

  FileDataObject is a specialization of

DataObject for file names.

  The program works with it just as if it were a list of absolute

file names, but internally it uses the same format as Explorer and
other compatible programs under Windows or GNOME/KDE filemanager
under Unix which makes it possible to receive files from them
using this class.

  Warning - Under all **        non-Windows platforms this class is

currently “input-only”** , i.e. you can receive the files from
another application, but copying (or dragging) file(s) from a
wxWidgets application is not currently supported. PS: GTK2 should
work as well.
and
AddFile Adds a file to the file list
represented by this data object (Windows only).
All the best, Grant

···

http://wxpython.org/Phoenix/docs/html/FileDataObject.html

On 16/08/12 03:55, Robin Dunn wrote:

  On

8/15/12 5:22 AM, Grant Paton-Simpson wrote:

    Very interesting. Thanks for that. I'll

have to give that a go tomorrow

    NZ time. I have set something up that can grab and print any

text added

    to the clipboard but I need to add a little more to that

foundation.

  Depending on your platform there are already some tools available

to help you inspect the native Clipboard or DnD data objects. For
example on Windows look for ClipSpy and on OSX look for Pasteboard
Inspector.

  BTW, for multiple files you can add more than one path name to

wx.FileDataObject.

These statements are no longer true. Adding multiple path names to the data object and dragging files from wx applications works fine on MSW, OSX and GTK.

···

On 8/15/12 6:35 PM, Grant Paton-Simpson wrote:

Hi Robin,

It looks like the ability to add multiple images to the clipboard so the
user can paste them into file managers, word processors etc, is a
Windows-only option. I hope I'm wrong and there is a robust workaround -
perhaps creating multi-item objects.

Anyway, one fall-back approach I am considering for Linux is a loop
where for each image (often just one, usually just a handful) the user
sees a messagebox telling them to paste the first item and then click OK
to receive the next one etc. I can easily use the BitmapDataObject for that.

wx.TheClipboard.Open()
    img_demo = wx.Image(imgname, wx.BITMAP_TYPE_PNG)
    bmp_demo = wx.BitmapFromImage(img_demo)
    do = wx.DataObjectComposite() # multiple formats not items
    do.Add(wx.BitmapDataObject(bmp_demo), True)
    alt_txt = (u"If you see this text instead of the "
           u"image \"%s\", try pasting the output into a "
           u"graphics program first and edit/copy/save "
           u"from there etc." % imgname)
    do.Add(wx.TextDataObject(alt_txt), False)
wx.TheClipboard.AddData(do)
wx.TheClipboard.Close()

I should add the following to the record for future people who bump into
this thread:

FileDataObject is a specialization of DataObject for file names.

The program works with it just as if it were a list of absolute file
names, but internally it uses the same format as Explorer and other
compatible programs under Windows or GNOME/KDE filemanager under Unix
which makes it possible to receive files from them using this class.

Warning - Under all *non-Windows platforms this class is currently
�input-only�*, i.e. you can receive the files from another
application, but copying (or dragging) file(s) from a wxWidgets
application is not currently supported. PS: GTK2 should work as well.

and

AddFile Adds a file to the file list represented by this data
object (*Windows only*).

http://wxpython.org/Phoenix/docs/html/FileDataObject.html

--
Robin Dunn
Software Craftsman

That's fantastic news. Since which version of wxPython? I am using 2.8.12.1 on Ubuntu.

···

On 17/08/12 14:28, Robin Dunn wrote:

On 8/15/12 6:35 PM, Grant Paton-Simpson wrote:

Hi Robin,

It looks like the ability to add multiple images to the clipboard so the
user can paste them into file managers, word processors etc, is a
Windows-only option. I hope I'm wrong and there is a robust workaround -
perhaps creating multi-item objects.

Anyway, one fall-back approach I am considering for Linux is a loop
where for each image (often just one, usually just a handful) the user
sees a messagebox telling them to paste the first item and then click OK
to receive the next one etc. I can easily use the BitmapDataObject for that.

wx.TheClipboard.Open()
    img_demo = wx.Image(imgname, wx.BITMAP_TYPE_PNG)
    bmp_demo = wx.BitmapFromImage(img_demo)
    do = wx.DataObjectComposite() # multiple formats not items
    do.Add(wx.BitmapDataObject(bmp_demo), True)
    alt_txt = (u"If you see this text instead of the "
           u"image \"%s\", try pasting the output into a "
           u"graphics program first and edit/copy/save "
           u"from there etc." % imgname)
    do.Add(wx.TextDataObject(alt_txt), False)
wx.TheClipboard.AddData(do)
wx.TheClipboard.Close()

I should add the following to the record for future people who bump into
this thread:

FileDataObject is a specialization of DataObject for file names.

The program works with it just as if it were a list of absolute file
names, but internally it uses the same format as Explorer and other
compatible programs under Windows or GNOME/KDE filemanager under Unix
which makes it possible to receive files from them using this class.

Warning - Under all *non-Windows platforms this class is currently
�input-only�*, i.e. you can receive the files from another
application, but copying (or dragging) file(s) from a wxWidgets
application is not currently supported. PS: GTK2 should work as well.

and

AddFile Adds a file to the file list represented by this data
object (*Windows only*).

http://wxpython.org/Phoenix/docs/html/FileDataObject.html

These statements are no longer true. Adding multiple path names to the data object and dragging files from wx applications works fine on MSW, OSX and GTK.

I think it has been at least that long.

···

On 8/16/12 7:42 PM, Grant Paton-Simpson wrote:

That's fantastic news. Since which version of wxPython? I am using
2.8.12.1 on Ubuntu.

--
Robin Dunn
Software Craftsman