Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Executive ability is prominent in your make-up.


comp / comp.lang.python / Re: win32clipboard writing to clipboard on Windows 11

SubjectAuthor
o Re: win32clipboard writing to clipboard on Windows 11Thomas Passin

1
Subject: Re: win32clipboard writing to clipboard on Windows 11
From: Thomas Passin
Newsgroups: comp.lang.python
Date: Tue, 18 Jun 2024 02:23 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: win32clipboard writing to clipboard on Windows 11
Date: Mon, 17 Jun 2024 22:23:07 -0400
Lines: 61
Message-ID: <mailman.150.1718677400.2909.python-list@python.org>
References: <f6e408ad-89c1-42b0-a771-d3677692f610@btinternet.com>
<7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com>
<78d80380-639c-432e-921d-6f5b7a7027fd@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de os01zTZY5F7Yd7VhL1nKogvPQpzeLxbn02f9vCpcApNA==
Cancel-Lock: sha1:ZCDlEaoiOqTxRH06CtOqOIYWQSM= sha256:i7OwRSXkvrlSfAOJQZCkTDdLjBro7KBtIFXiAVemAa0=
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=Kz9FGQbL;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'this:':
0.03; 'pip': 0.04; 'traceback': 0.04; '(most': 0.05; 'last):':
0.05; 'linux,': 0.07; 'subject:Windows': 0.07; 'acquired': 0.09;
'output:': 0.09; 'subject:writing': 0.09; 'import': 0.15;
'memory': 0.15; 'approach.': 0.16; 'program:': 0.16;
'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'wrote:': 0.16; 'problem': 0.16;
'uses': 0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20; 'machine':
0.22; 'laptop': 0.23; 'anyone': 0.25; 'tried': 0.26; 'old': 0.27;
'>>>': 0.28; 'recently': 0.29; 'this?': 0.29; 'error': 0.29;
'header:User-Agent:1': 0.30; 'putting': 0.31; 'program': 0.31;
'"",': 0.32; 'do.': 0.32; 'encountered': 0.32; 'python-list':
0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'windows': 0.34; 'same':
0.34; 'header:In-Reply-To:1': 0.34; 'running': 0.34; 'change':
0.36; "skip:' 10": 0.37; 'using': 0.37; "it's": 0.37; 'file':
0.38; 'could': 0.38; 'text': 0.39; 'handle': 0.39; 'use': 0.39;
'wishes': 0.40; 'something': 0.40; 'best': 0.61; 'sample': 0.61;
'skip:o 10': 0.61; 'url-ip:104.18/16': 0.67; 'header:Received:6':
0.67; 'received:64': 0.67; 'shed': 0.69; 'care': 0.71; 'change,':
0.76; 'subject:skip:w 10': 0.76; '11;': 0.84; 'install.': 0.84;
'rob': 0.84; 'consists': 0.93
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1718677389; a=rsa-sha256;
cv=none;
b=RjZ3g/wuySWvYHP0kvS+Z1ShpernUNu6ZQ4M996ovUyh9msclG9oKVFdlLcqFEwBRuKLW2
1lFYDlVr2hagHLUTyfg9WKIxSIUG4hF/vBtcJP8WEGbS7hLlhEkdus2wDG6tzmt8j8v9OO
/7BbpE40XYuZYTXdw/aaPUOu8jCZo3BYRJNX7DOki1MXhF46uZez7jhP+At0gtna5UvCMb
wv9OwPLm2Q6xNu526hMcJcrW3ymWX+CQY8Ce8WaRv2FFrG8/nMyzed+kq4tTWzVf8PRKf7
u8cnhqb3XKUDwzm8T0RLvQgDXNR/1mlkiN4thSWwqVTWAHU0eoaBWHXbx65cJA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1718677389;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=MIHF9LyLYicffy1+S9OL59uPrP5deDEoVuvLV0W3OCU=;
b=tUPbzSEvAz6UNnwGhtPPYL2ssxt5ZCtQrc+0OVJokVvdC7KUlj+HDkTs5eGvLoNTX8Kywa
Hfe55Vd5dd6sWfWs6pMdRW72dq364bQN62emsw/xU1Zcty4wruNVdPhzKFXKdPcoX2BSk5
mZqN/qyTWaZ6CSb4WkOUUkXOEHMY1MzgY1fbdCQpVe3zQ4T0VLbpgNl6r8NgCJBiO8ruOh
CpiiyEcdv1oE2wifXHM6Jk66rLw5bz5QwkKUzSELkUQMF/iqI07sBPYrMqqusjamkFWUGL
SduJCJ0tuhKSK+7Br2DeDuvZsvN0E5E/0ZeGWSNycmDT5rgw4vDMIDLMrpjNDQ==
ARC-Authentication-Results: i=1; rspamd-79677bdb95-9kws4;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Supply-Abiding: 6aca061a1b5ca380_1718677389527_251174794
X-MC-Loop-Signature: 1718677389527:1708499372
X-MC-Ingress-Time: 1718677389527
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1718677389;
bh=MIHF9LyLYicffy1+S9OL59uPrP5deDEoVuvLV0W3OCU=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=Kz9FGQbLVWtEyGAu8jNA20R50+TFHfKJZg1lopxe/CEaBdp8dBP8Sq0iMY2f1P9AB
pTzBxNSHMew00F9vDKNrOjYODtV3oKgZZtEc5VLOtZkVoljtVQaghZpG3mwDtTb49P
iNOVOtDFaNlrMvbhbbAbwXoipCuOgJjmSu0tLLSQ9qlk6Jf0oJ9kWEQNLL0+B1W0kj
anN+PW19EJWPsHR2NKRDQLbbOJXlADRO05Ovstgxg8uMvaY+hsOjsLAFg6g19xapxE
e3hAVgbhz2EhloFlQZ15SibON0pBR/cX0pouXPBEMbrNGQb7EjrGNEYs8xv2kRcdh0
h8tlmXU7Jr/mw==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <78d80380-639c-432e-921d-6f5b7a7027fd@tompassin.net>
X-Mailman-Original-References: <f6e408ad-89c1-42b0-a771-d3677692f610@btinternet.com>
<7e8c9107-6f71-4c49-a78b-ac5094073499@mrabarnett.plus.com>
View all headers

On 6/17/2024 9:30 PM, MRAB via Python-list wrote:
> On 2024-06-17 20:27, Rob Cliffe via Python-list wrote:
>> Recently I acquired a new laptop running WIndows 11; my previous one
>> uses WIndows 10.  I encountered a strange problem:
>> I am using the win32clipboard backage (part of pywin32), and when I use
>> SetClipboardData() to write text which consists ***entirely of digits***
>> to the clipboard, I either get an error (not always the same error
>> message) or a program crash.  The problem does not appear if I use
>> SetClipboardText() instead.  The problem does not occur on my old
>> machine (where I used the feature extensively).
>>
>> Sample program:
>>
>> from win32clipboard import *
>> OpenClipboard()
>> SetClipboardData(CF_UNICODETEXT, "A")
>> SetClipboardData(CF_UNICODETEXT, "A0")
>> SetClipboardData(CF_UNICODETEXT, "0A")
>> SetClipboardText("0", CF_UNICODETEXT)
>> print("OK so far")
>> SetClipboardData(CF_UNICODETEXT, "0")
>> CloseClipboard()
>>
>> Sample output:
>>
>> OK so far
>> Traceback (most recent call last):
>>     File "C:\TEST*.PY", line 8, in <module>
>>       SetClipboardData(CF_UNICODETEXT, "0")
>> pywintypes.error: (0, 'SetClipboardData', 'No error message is
>> available')
>>
>> Can anyone shed light on this?
>> Best wishes
>> Rob Cliffe
>
> I tried it on Windows 10 and got this:
>
> >>> from win32clipboard import *
> >>> OpenClipboard()
> >>> SetClipboardData(CF_UNICODETEXT, "A")
> 1830508101640
> >>> CloseClipboard()
> >>> OpenClipboard()
> >>> SetClipboardData(CF_UNICODETEXT, "0")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.')
> >>> CloseClipboard()
>
> It looks like it's something to memory ownership:
>
> https://stackoverflow.com/questions/1264137/how-to-copy-string-to-clipboard-in-c
>
> If you're putting text on the clipboard, why not just use
> SetClipboardText()? That's what I do.

If you can make a change, and you only need to work with text on the
clipboard, you could change to use pyperclip. It also works on Linux,
if you might care about that in the future. It's available as a pip
install. It's easier to use than the win32 approach.

1

rocksolid light 0.9.8
clearnet tor