illume avatar illume committed 1d7a19d

Some mac scrap fixes from Marcus.
... cumulative adds however are not supported for now.

Comments (0)

Files changed (4)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+May 2, 2007
+    fromstring, and tostring work correctly for alpha.  Thanks Brian Fisher!
+
 Apr 26, 2007
     Some code cleanups from Marcus von Appen.  min->MIN, indentation, other.
     A rewritten scrap module.  Hasn't been tested on osx/windows.
 def get(scrap_type):
     board = NSPasteboard.generalPasteboard()
     if scrap_type == SCRAP_TEXT:
-        content = board.stringForType_(NSStringPboardType)
-        return content
+        return board.stringForType_(NSStringPboardType)
     elif scrap_type == SCRAP_BMP:
         # We could try loading directly but I don't trust pygame's TIFF
         # loading.  This is slow and stupid but it does happen to work.
         data = rep.representationUsingType_properties_(NSBMPFileType, None)
         bmp = StringIO(data)
         return pygame.image.load(bmp, "scrap.bmp")
-    else:
-        raise ValueError("Unsupported scrap_type: %r" % (scrap_type,))
-
+    elif scrap_type in board.types:
+        return board.stringForType_(scrap_type)
 
 def put(scrap_type, thing):
     board = NSPasteboard.generalPasteboard()
         board.setData_forType_(tiff, NSTIFFPboardType)
         board.setString_forType_(u'', ScrapPboardType)
     else:
-        raise ValueError("Unsupported scrap_type: %r" % (scrap_type,))
+        pass
 
-def lost():
-    board = NSPasteboard.generalPasteboard()
-    return not board.availableTypeFromArray_([ScrapPboardType])
+def set_mode (mode):
+    # No diversion between clipboard and selection modes on MacOS X.
+    pass
+
+def contains (scrap_type):
+    return scrap_type in NSPasteboard.generalPasteboard ().types ()
+
+def get_types ():
+    typelist = []
+    types = NSPasteboard.generalPasteboard ().types ()
+    for t in types:
+        typelist.append (t)
+    return typelist
+
+def lost ():
+    board = NSPasteboard.generalPasteboard ()
+    return not board.availableTypeFromArray_ ([ScrapPboardType])
     return _scrapinitialized;
 }
 
-#if !defined(MAC_SCRAP)
-
 /*DOC*/ static char doc_scrap_init[] = 
 /*DOC*/    "scrap.init () -> None\n"
 /*DOC*/    "Initializes the scrap module.\n"
 /*DOC*/    "Tries to initialize the scrap module and raises an exception, if\n"
 /*DOC*/    "it fails\n";
 
+#if !defined(MAC_SCRAP)
 /*
  * Initializes the pygame scrap module.
  */
 
     Py_RETURN_NONE;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_get_types[] = 
 /*DOC*/    "scrap.get_types () -> list\n"
 /*DOC*/    "method to get the clipboard content of the specific type.\n"
 /*DOC*/    "If there is no data in the clipboard, an empty list is returned.";
 
+#if !defined(MAC_SCRAP)
 /*
  * Gets the currently available types from the active clipboard.
  */
         return list;
     while (types[i] != NULL)
     {
+        printf ("Adding: %s\n", types[i]);
         PyList_Append (list, PyString_FromString (types[i]));
         i++;
     }
     return list;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_contains[] =
 /*DOC*/    "scrap.contains (type) -> bool\n"
 /*DOC*/    "Returns True, if data fpr the passed type is available in the\n"
 /*DOC*/    "clipboard, False otherwise.";
 
+#if !defined(MAC_SCRAP)
 /*
  * Checks whether the active clipboard contains a certain type.
  */
         Py_RETURN_TRUE;
     Py_RETURN_FALSE;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_get_scrap[] =
 /*DOC*/    "scrap.get (type) -> string\n"
 /*DOC*/    "The data is returned as string and might need further processing.\n"
 /*DOC*/    "If no data for the passed type is available, None is returned.";
 
+#if !defined(MAC_SCRAP)
 /*
  * Gets the content for a certain type from the active clipboard.
  */
     retval = PyString_FromStringAndSize (scrap, count);
     return retval;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_put_scrap[] =
 /*DOC*/    "scrap.put(type, data) -> None\n"
 /*DOC*/    "The method raises an exception, if the content could not be placed\n"
 /*DOC*/    "into the clipboard.\n";
 
+#if !defined(MAC_SCRAP)
 /*
  * This will put a python string into the clipboard.
  */
 
     Py_RETURN_NONE;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_lost_scrap[] =
 /*DOC*/    "scrap.lost() -> bool\n"
 /*DOC*/    "Returns true, if the clipboard is currently owned by the pygame\n"
 /*DOC*/    "application, false otherwise.\n";
 
+#if !defined(MAC_SCRAP)
 /*
  * Checks whether the pygame window has lost the clipboard.
  */
         Py_RETURN_TRUE;
     Py_RETURN_FALSE;
 }
+#endif
 
 /*DOC*/ static char doc_scrap_set_mode[] =
 /*DOC*/    "scrap.set_mode(mode) -> None\n"
 /*DOC*/    " available. The method does not have any influence on other\n"
 /*DOC*/    " environments.";
 
+#if !defined(MAC_SCRAP)
 /*
  * Sets the clipboard mode. This only works for the X11 environment, which
  * diverses between mouse selections and the clipboard.
 {
     return mac_scrap_call ("contains", args);
 }
+
+static PyObject*
+_scrap_set_mode (PyObject *self, PyObject *args)
+{
+    return mac_scrap_call ("set_mode", args);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.