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

[pygame] Scrap module not working with external applications



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

And, this is the output from pasting something from pygame:

UTF8_STRING Test string
TEXT Test string
STRING Test string
text/plain Test string


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

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.
	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.

Attachment: signature.asc
Description: This is a digitally signed message part