Explorar el Código

windows python3 fixes

Oz N Tiram hace 8 años
padre
commit
d1f2f5a899
Se han modificado 1 ficheros con 4 adiciones y 15 borrados
  1. 4 15
      pwman/ui/win.py

+ 4 - 15
pwman/ui/win.py

@@ -67,26 +67,15 @@ def winGetClipboard():
 
 
 def winSetClipboard(text):
-    text = str(text)
     GMEM_DDESHARE = 0x2000
     ctypes.windll.user32.OpenClipboard(0)
     ctypes.windll.user32.EmptyClipboard()
-    try:
-        # works on Python 2 (bytes() only takes one argument)
-        hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE,
-                                                 len(bytes(text))+1)
-    except TypeError:
-        # works on Python 3 (bytes() requires an encoding)
-        hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE,
+    hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE,
                                                  len(bytes(text, 'ascii'))+1)
     pchData = ctypes.windll.kernel32.GlobalLock(hCd)
-    try:
-        # works on Python 2 (bytes() only takes one argument)
-        ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData), bytes(text))
-    except TypeError:
-        # works on Python 3 (bytes() requires an encoding)
-        ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData),
-                                  bytes(text, 'ascii'))
+    
+    ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData),
+                              text.decode())
     ctypes.windll.kernel32.GlobalUnlock(hCd)
     ctypes.windll.user32.SetClipboardData(1, hCd)
     ctypes.windll.user32.CloseClipboard()