File: wx.DataObject.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (313 lines) | stat: -rw-r--r-- 11,389 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.DataObject:

==========================================================================================================================================
|phoenix_title|  **wx.DataObject**
==========================================================================================================================================

A :ref:`wx.DataObject`  represents data that can be copied to or from the clipboard, or dragged and dropped.          

The important thing about :ref:`wx.DataObject`  is that this is a 'smart' piece of data unlike 'dumb' data containers such as memory buffers or files. Being 'smart' here means that the data object itself should know what data formats it supports and how to render itself in each of its supported formats. 

A supported format, incidentally, is exactly the format in which the data can be requested from a data object or from which the data object may be set. In the general case, an object may support different formats on 'input' and 'output', i.e. it may be able to render itself in a given format but not be created from data on this format or vice versa. :ref:`wx.DataObject`  defines the :meth:`wx.DataObject.Direction`   enumeration type which distinguishes between them. 

See :ref:`wx.DataFormat`  documentation for more about formats. 

Not surprisingly, being 'smart' comes at a price of added complexity. This is reasonable for the situations when you really need to support multiple formats, but may be annoying if you only want to do something simple like cut and paste text. 

To provide a solution for both cases, wxWidgets has two predefined classes which derive from :ref:`wx.DataObject`: :ref:`wx.DataObjectSimple`  and :ref:`wx.DataObjectComposite`. :ref:`wx.DataObjectSimple`  is the simplest :ref:`wx.DataObject`  possible and only holds data in a single format (such as HTML or text) and :ref:`wx.DataObjectComposite`  is the simplest way to implement a :ref:`wx.DataObject`  that does support multiple formats because it achieves this by simply holding several :ref:`wx.DataObjectSimple`  objects. 

So, you have several solutions when you need a :ref:`wx.DataObject`  class (and you need one as soon as you want to transfer data via the clipboard or drag and drop): 



- Use one of the built-in classes.

  - You may use :ref:`wx.TextDataObject`, :ref:`wx.BitmapDataObject`  :ref:`wx.FileDataObject`, :ref:`wx.URLDataObject`  in the simplest cases when you only need to support one format and your data is either text, bitmap or list of files. 



- Use :ref:`wx.DataObjectSimple`

  - Deriving from :ref:`wx.DataObjectSimple`  is the simplest solution for custom data - you will only support one format and so probably won't be able to communicate with other programs, but data transfer will work in your program (or between different instances of it). 



- Use :ref:`wx.DataObjectComposite`

  - This is a simple but powerful solution which allows you to support any number of formats (either standard or custom if you combine it with the previous solution). 



- Use :ref:`wx.DataObject`  directly

  - This is the solution for maximum flexibility and efficiency, but it is also the most difficult to implement. 







Please note that the easiest way to use drag and drop and the clipboard with multiple formats is by using :ref:`wx.DataObjectComposite`, but it is not the most efficient one as each :ref:`wx.DataObjectSimple`  would contain the whole data in its respective formats. Now imagine that you want to paste 200 pages of text in your proprietary format, as well as Word, ``RTF``, HTML, Unicode and plain text to the clipboard and even today's computers are in trouble. For this case, you will have to derive from :ref:`wx.DataObject`  directly and make it enumerate its formats and provide the data in the requested format on demand. 

Note that neither the GTK+ data transfer mechanisms for clipboard and drag and drop, nor ``OLE`` data transfer, `copies`  any data until another application actually requests the data. This is in contrast to the 'feel' offered to the user of a program who would normally think that the data resides in the clipboard after having pressed 'Copy' - in reality it is only declared to be `available`. 

You may also derive your own data object classes from :ref:`wx.CustomDataObject`  for user-defined types. The format of user-defined data is given as a mime-type string literal, such as "application/word" or "image/png". These strings are used as they are under Unix (so far only GTK+) to identify a format and are translated into their Windows equivalent under Win32 (using the ``OLE`` IDataObject for data exchange to and from the clipboard and for drag and drop). Note that the format string translation under Windows is not yet finished. 

Each class derived directly from :ref:`wx.DataObject`  must override and implement all of its functions which are pure virtual in the base class. The data objects which only render their data or only set it (i.e. work in only one direction), should return 0 from :meth:`~wx.DataObject.GetFormatCount`. 





|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>DataObject</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.DataObject_inheritance.png" alt="Inheritance diagram of DataObject" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.DataObject.html" title="wx.DataObject" alt="" coords="5,5,120,35"/> </map> 
   </p>

|


|sub_classes| Known Subclasses
==============================

:ref:`wx.DataObjectComposite`, :ref:`wx.DataObjectSimple`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.DataObject.__init__`                                                  Constructor.
:meth:`~wx.DataObject.GetAllFormats`                                             Returns a list of wx.DataFormat objects which this data object
:meth:`~wx.DataObject.GetDataHere`                                               Copies this data object's data in the requested format to the buffer provided.
:meth:`~wx.DataObject.GetDataSize`                                               Returns the data size of the given format `format`.
:meth:`~wx.DataObject.GetFormatCount`                                            Returns the number of available formats for rendering or setting the data.
:meth:`~wx.DataObject.GetPreferredFormat`                                        Returns the preferred format for either rendering the data (if `dir`  is  ``Get`` , its default value) or for setting it.
:meth:`~wx.DataObject.IsSupported`                                               Returns ``True`` if this format is supported.
:meth:`~wx.DataObject.SetData`                                                   Copies data from the provided buffer to this data object for the specified format.
:meth:`~wx.DataObject._testGetAllFormats`                                        
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.DataObject.AllFormats`                                                See :meth:`~wx.DataObject.GetAllFormats`
:attr:`~wx.DataObject.DataHere`                                                  See :meth:`~wx.DataObject.GetDataHere`
:attr:`~wx.DataObject.FormatCount`                                               See :meth:`~wx.DataObject.GetFormatCount`
:attr:`~wx.DataObject.PreferredFormat`                                           See :meth:`~wx.DataObject.GetPreferredFormat`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.DataObject(object)

   **Possible constructors**::

       DataObject()
       
   
   A DataObject represents data that can be copied to or from the
   clipboard, or dragged and dropped.



   .. method:: __init__(self)

      Constructor.                   





   .. method:: GetAllFormats(self, dir=Get)

                              Returns a list of wx.DataFormat objects which this data object
                              supports transferring in the given direction.  





   .. method:: GetDataHere(self, format, buf)

      Copies this data object's data in the requested format to the buffer provided. 

      :rtype: `bool`








   .. method:: GetDataSize(self, format)

      Returns the data size of the given format `format`.                  


      :param `format`: 
      :type `format`: wx.DataFormat




      :rtype: `int`








   .. method:: GetFormatCount(self, dir=Get)

      Returns the number of available formats for rendering or setting the data.                  


      :param `dir`: 
      :type `dir`: wx.DataObject.Direction




      :rtype: `int`








   .. method:: GetPreferredFormat(self, dir=Get)

      Returns the preferred format for either rendering the data (if `dir`  is  ``Get`` , its default value) or for setting it.                   

      Usually this will be the native format of the :ref:`wx.DataObject`.                  


      :param `dir`: 
      :type `dir`: wx.DataObject.Direction




      :rtype: :ref:`wx.DataFormat`








   .. method:: IsSupported(self, format, dir=Get)

      Returns ``True`` if this format is supported.                  


      :param `format`: 
      :type `format`: wx.DataFormat
      :param `dir`: 
      :type `dir`: wx.DataObject.Direction




      :rtype: `bool`








   .. method:: SetData(self, format, buf)

      Copies data from the provided buffer to this data object for the specified format. 

      :rtype: `bool`








   .. method:: _testGetAllFormats(self)






   .. attribute:: AllFormats

      See :meth:`~wx.DataObject.GetAllFormats`


   .. attribute:: DataHere

      See :meth:`~wx.DataObject.GetDataHere`


   .. attribute:: FormatCount

      See :meth:`~wx.DataObject.GetFormatCount`


   .. attribute:: PreferredFormat

      See :meth:`~wx.DataObject.GetPreferredFormat`


.. toctree::
   :maxdepth: 1
   :hidden:

   wx.DataObject.Direction.enumeration