Clipboard handling

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Clipboard handling

Dietmar Schwertberger-2
Hi!

If I'm right then with wxPython the only way to place something on the
clipboard is to calculate the data and create a DataObject.
The disadvantage is that the calculation may be time and/or
memory intensive, especially when I want to offer multiple
different formats.

Is there a way to calculate the data only on demand?
The standard way under win32 is to claim the clipboard
using this way:

win32clipboard.OpenClipboard(self.hwnd)
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, 0)
win32clipboard.CloseClipboard()

Once another application wants to get the data,
we receive a win32con.WM_RENDERFORMAT event and then use
win32clipboard.SetClipboardData(win32con.CF_TEXT, "Text")
to actually place the text on the clipboard.

Is there a cross-platform or win32 way under wxPython to achieve
the same?

Plan B:
It's probably OK to use win32clipboard from within a wx
application, but how can I register a handler for a
WM_RENDERFORMAT event without messing things up?

Regards,

Dietmar

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Clipboard handling

Tim Roberts
Dietmar Schwertberger wrote:
> Once another application wants to get the data,
> we receive a win32con.WM_RENDERFORMAT event and then use
> win32clipboard.SetClipboardData(win32con.CF_TEXT, "Text")
> to actually place the text on the clipboard.
>
> Is there a cross-platform or win32 way under wxPython to achieve
> the same?

Perhaps surprisingly, the behavior of the clipboard is one thing that
varies wildly among the various GUI systems.  This is not just a Python
thing, it's something all application authors have to battle.  X, for
example, dictates no clipboard policy at all.  It was left to window
managers and desktop environments to decide that.


> Plan B:
> It's probably OK to use win32clipboard from within a wx
> application, but how can I register a handler for a
> WM_RENDERFORMAT event without messing things up?

You don't  have to mess things up.  You just need to subclass the
window.  That's common in the C++ world; not as common, but still
possible in the Python world:
    http://wiki.wxpython.org/HookingTheWndProc

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Clipboard handling

Robin Dunn
Tim Roberts wrote:

> Dietmar Schwertberger wrote:
>> Once another application wants to get the data,
>> we receive a win32con.WM_RENDERFORMAT event and then use
>> win32clipboard.SetClipboardData(win32con.CF_TEXT, "Text")
>> to actually place the text on the clipboard.
>>
>> Is there a cross-platform or win32 way under wxPython to achieve
>> the same?
>
> Perhaps surprisingly, the behavior of the clipboard is one thing that
> varies wildly among the various GUI systems.  This is not just a Python
> thing, it's something all application authors have to battle.  X, for
> example, dictates no clipboard policy at all.  It was left to window
> managers and desktop environments to decide that.
>
>
>> Plan B:
>> It's probably OK to use win32clipboard from within a wx
>> application, but how can I register a handler for a
>> WM_RENDERFORMAT event without messing things up?
>
> You don't  have to mess things up.  You just need to subclass the
> window.  That's common in the C++ world; not as common, but still
> possible in the Python world:
>      http://wiki.wxpython.org/HookingTheWndProc
>

wxWidgets does support dealing with the clipboard at a lower level and
not having to provide the data until it is asked for in a supported
format.  Unfortunately that was a little too complex and messy for the
wxPython wrappers and I never got around to making it possible to do
that from Python.  Until Phoenix.  The Phoenix wrappers of the data
object classes allow fully overriding all the pertinent virtual methods
and also doing data transfers to/from the clipboard (or the other end of
the clipboard transaction actually) using Python memoryview or other
buffer objects.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Clipboard handling

Dietmar Schwertberger-2
In reply to this post by Tim Roberts
Am 21.02.2013 18:52, schrieb Tim Roberts:

> Dietmar Schwertberger wrote:
>> It's probably OK to use win32clipboard from within a wx
>> application, but how can I register a handler for a
>> WM_RENDERFORMAT event without messing things up?
>
> You don't  have to mess things up.  You just need to subclass the
> window.  That's common in the C++ world; not as common, but still
> possible in the Python world:
>      http://wiki.wxpython.org/HookingTheWndProc
>
Thanks a lot. That's cool and I will probably take this route.

Regards,

Dietmar


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.