Menu

#2661 Copy & paste images in Unix

obsolete: 8.5.7
closed-fixed
5
2009-07-15
2009-07-15
Ramon Ribó
No

Hello,

I have been playing today with copy and paste images in TCL-TK and
Unix. The origin of the image is Firefox, where I open the contextual
menu over one image and select "copy image"

The TCL code for pasting the image is:

package require img::png
set data [binary format c* [selection get -selection CLIPBOARD -type
image/png]]
set img [image create photo -data $data]

This code does not work in a standard wish as there is a bug in file
tkUnixSelect.c

After a small modification in file "tkUnixSelect.c", it works
correctly!!

The modification is the following:

in function TkSelEventProc

...
if (format != 32 && format != 8) {
char buf[64 + TCL_INTEGER_SPACE];

sprintf(buf,
"bad format for selection: wanted \"32\" or \"8\", got \"%d\"",
format);
Tcl_SetResult(retrPtr->interp, buf, TCL_VOLATILE);
retrPtr->result = TCL_ERROR;
return;
}
Tcl_DStringInit(&ds);
if (format == 32) {
SelCvtFromX((long *) propInfo, (int) numItems, type,
(Tk_Window) winPtr, &ds);
} else {
SelCvtFromX8((char *) propInfo, (int) numItems, type,
(Tk_Window) winPtr, &ds);
}
....

in function SelRcvIncrProc (a similar change)

new function "SelCvtFromX8":

static void
SelCvtFromX8(
register char *propPtr, /* Property value from X. */
int numValues, /* Number of 8-bit values in property. */
Atom type, /* Type of property Should not be XA_STRING
* (if so, don't bother calling this function
* at all). */
Tk_Window tkwin, /* Window to use for atom conversion. */
Tcl_DString *dsPtr) /* Where to store the converted string. */
{
/*
* Convert each long in the property to a string value, which is
either
* the name of an atom (if type is XA_ATOM) or a hexadecimal
string. We
* build the list in a Tcl_DString because this is easier than
trying to
* get the quoting correct ourselves; this is tricky because atoms
can
* contain spaces in their names (encountered when the atoms are
really
* MIME types). [Bug 1353414]
*/

for ( ; numValues > 0; propPtr++, numValues--) {
if (type == XA_ATOM) {
Tcl_DStringAppendElement(dsPtr,
Tk_GetAtomName(tkwin, (Atom) *propPtr));
} else {
char buf[12];

sprintf(buf, "0x%x", (unsigned char) *propPtr);
Tcl_DStringAppendElement(dsPtr, buf);
}
}

Discussion

  • Ramon Ribó

    Ramon Ribó - 2009-07-15
     
  • Donal K. Fellows

    • labels: 318670 --> 52. [clipboard]
    • milestone: --> obsolete: 8.5.7
    • assigned_to: jenglish --> dkf
    • status: open --> open-accepted
     
  • Donal K. Fellows

    Applied to 8.6

     
  • Donal K. Fellows

    • status: open-accepted --> closed-fixed
     
  • Donal K. Fellows

    And to 8.5

     
  • Donal K. Fellows

    Note that we still can't do the reverse operation: dispatching a sequence of bytes. Not at all sure how to either right now.