[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Scrap module not working with external applications

On, Fri Jul 13, 2012, Sam Bull wrote:

> There is a problem with the scrap module not pasting text from external
> applications (testing on Ubuntu). This is due to the SCRAP_TEXT
> constant. If I run this program:
> import pygame
> from pygame.locals import *
> pygame.display.init()
> screen = pygame.display.set_mode((600,480))
> pygame.scrap.init()
> while True:
>     e = pygame.event.wait()
>     if e.type == KEYDOWN:
>         if e.key == K_c:
>             pygame.scrap.put(SCRAP_TEXT, "Test string")
>         elif e.key == K_p:
>             types = pygame.scrap.get_types()
>             for t in types:
>                 print t, pygame.scrap.get(t)
>         elif e.key == K_ESCAPE:
>             break
> This is the output when pasting from an external application:
> UTF8_STRING string from external application
> COMPOUND_TEXT string from external application
> TEXT string from external application
> STRING string from external application
> text/plain;charset=utf-8 string from external application
> text/plain None

What external application? What underlying UI toolkit does it use? How
do you put text into the clipboard with it? Where do you paste the
content to? How do you paste the content (middle mouse button, special
other operation, application-builtin command)?

> And, this is the output from pasting something from pygame:
> UTF8_STRING Test string
> TEXT Test string
> STRING Test string
> text/plain Test string

Am I right that you refer to the test program above? Where do you paste
the content to and how do you do it?

> The problem, is that the SCAP_TEXT constant is "text/plain". As can be
> seen, this is None from an external application.

If the external application does not set the mime-type text/plain, then
it is None, correct.

> There is however, a "text/plain;charset=utf-8". So, the more complex
> solution would be to split the type on the ';' and compare only the
> first part of the type.

No, that's hideous and likely to mess up mime-type stuff in the

> 	The easier solution would be to just change the constant to be "TEXT",
> as this is present in both versions. This should be checked that it
> works on other platforms first though.

TEXT is quite strict in its definition within the X11 libraries,
especially when it comes to the encoding (woohay, multibyte...). It
might be better to change the SCRAP_TEXT definition to
"text/plain;charset=utf-8" as default - if most other applications
support it already.

Otherwise I'd recommend to query the available types first and then pick
the content for the type that suits the application-specific needs best.


Attachment: pgplnIFYFMzC3.pgp
Description: PGP signature