wxPython is used. Not just the text format. Many formats are supported.
Topics
About: the Python programming language
The table of contents of this article
- Starting Context
- Target Context
- Orientation
- Main Body
- 1: Aim: to Implement Multiple Copy Buffers for a Word Processor
- 2: The Text Format Is Not Enough
- 3: I Will Use wxPython
- 4: Some Basics of Clipboard Datum Formats
- 5: The Specifications of 'wx.DataObject'
- 6: How to Know the Possible Datum Formats a Priori
- 7: My Code
- 8: The Limitation
- 9: Testing
Starting Context
- The reader has a basic knowledge on the Python programming language.
Target Context
- The reader will know how to get and set a composite of format-specific data from and to the operating system clipboard, in Python, with wxPython.
Orientation
Many, but not all the, formats are supported by this technique.
More , but still not all the, formats are supported by a technique in C# for Microsoft Windows, as will be introduced in a future article of another series.
All the formats are supported by a technique in C++ for Linux or Microsoft Windows, as will be introduced in a future article of another series.
The reason why any Python variable is a pointer (a prerequisite knowledge) has been explained in a previous article.
Main Body
1: Aim: to Implement Multiple Copy Buffers for a Word Processor
Hypothesizer 7
As I use Vim as a text editor, one of the benefits is that it has multiple copy buffers: I can copy a piece of text to the buffer 'a', another piece of text to the buffer 'b', etc.. That is huge help.
As I use LibreOffice Writer as a word processor, I want that functionality in it.
In fact, having been accustomed to the functionality, the lack of it is a considerable frustration.
A Python macro will implement the functionality, if it can get and set clipboard data.
2: The Text Format Is Not Enough
Hypothesizer 7
Getting and setting a text format clipboard datum is easy; for example, 'pyperclip' can do the work.
But, obviously, that is not enough for word processor: I need the fonts information to be copied, at least. And some image data and objects like tables may want to be copied to multiple buffers, too.
Ideally, the whole clipboard data should be copied as they are.
3: I Will Use wxPython
Hypothesizer 7
As I searched the internet, I could not find any tutorial for getting and setting the whole clipboard data in Python (ones that handle text data abound, though).
As I use wxPython, hoping that it may have the functionality, I searched the official wxPython document and found some information.
'wx.CustomDataObjec' sounded promising, but turned out to be for a datum of a single format, not for any composite of format-specific data.
'wx.DataObjectComposite' is for composites, but seems rather cumbersome unless I have a predetermined set of supported datum formats.
Well, 'wx.DataObject' (which is described as "for maximum flexibility and efficiency, but it is also the most difficult to implement" in the document) seems to be the one I should use, but even it seems to be supposing that I have a predetermined set of supported datum formats, which I do not.
After all, the concept of wxPython clipboard handling does not match my interest of getting and setting the whole clipboard data of whatever multiple datum formats, but I will see what I can do.
4: Some Basics of Clipboard Datum Formats
Hypothesizer 7
Although the clipboard mechanism of X Window system and that of Microsoft Windows are very different, at least wxPython-wise, each clipboard datum format always has a number as the identification of the format.
However, the number may be ephemeral, which means that a format may have '49161' at a time and '49162' at another; so, generally speaking, I cannot permanently identify a format with the number (although some usual formats like 'Text' have fixed numbers).
On the other hand, some formats do not have names (or at least the names cannot be retrieved API-wise).
However, such formats should have fixed numbers.
So, each of the formats that have names can be identified by the name, while each of the formats that have no name can be identified by the number.
5: The Specifications of 'wx.DataObject'
Hypothesizer 7
As the official document is not so clear on the specifications of the class (especially on when each method is called), I had to experiment to know necessary information.
An important point I have found is that any instance of 'wx.DataObject' becomes invalid after it has been passed into the 'SetData' method of 'wx.Clipboard', where 'invalid'.means that it cannot be passed into the 'SetData' method again
Well, that means that 'wx.DataObject' cannot be used as a clipboard data container for my purpose (as my clipboard data have to be able to be set into the clipboard repeatedly). So, 'wx.DataObject' is a clipboard events handler, for me.
These are what I have found out about the timings at which the methods are called.
| Method | Called When |
|---|---|
| GetFormatCount | When 'wx.Clipboard.GetData' has been called 1st for the composite 1st per format When 'wx.Clipboard.SetData' has been called after 'GetPreferredFormat' for the composite 1st per format |
| GetAllFormats | When 'wx.Clipboard.GetData' has been called after 'GetFormatCount' for the composite after 'GetFormatCount' per format When 'wx.Clipboard.SetData' has been called after 'GetFormatCount' for the composite after 'GetFormatCount' per format |
| GetDataHere | When 'wx.Clipboard.SetData' has been called after 'GetDataSize' per format |
| GetDataSize | When 'wx.Clipboard.SetData' has been called twice after 'GetAllFormats' per format |
| GetPreferredFormat | When 'wx.Clipboard.SetData' has been called 1st for the composite |
| IsSupported | Never |
| SetData | When 'wx.Clipboard.GetData' has been called after 'GetAllFormats' per format |
For 'wx.Clipboard.GetData', 'GetFormatCount' and 'GetAllFormats' have to respond with all the possible datum formats known a priori, because the existing datum formats in the clipboard are unknown to my program. But I can be assured that the methods that are called per format are called for only datum formats that exist in the clipboard (not all the datum formats returned by 'GetAllFormats').
Anyway, I find some things enigmatic. 1st, why 'GetFormatCount' and 'GetAllFormats' are called per format? 2nd, why is 'GetDataSize' called twice per format? 3rd, 'GetPreferredFormat' is called only for 'wx.Clipboard.SetData' in spite of the official document, and I do not see any effect whatever it returns.
The 'buf' arguments of 'GetDataHere' and 'SetData' are 'memoryview' instances.
6: How to Know the Possible Datum Formats a Priori
Hypothesizer 7
How can I know possible datum formats a priori?
In Linux, this command shows the datum formats that exist in the clipboard.
@bash Source Code
xclip -t TARGETS -o
In Microsoft Windows, well, I have created a C++ Win32 API program, as will be seen in a future article of another series.
For example, when a text piece in LibreOffice Writer is copied in Linux, the available formats are these.
@Output
application/x-openoffice-embed-source-xml;windows_formatname="Star Embed Source (XML)"text/rtftext/richtexttext/htmltext/plain;charset=utf-16application/x-openoffice-objectdescriptor-xml;windows_formatname="Star Object Descriptor (XML)";classname="8BC6B165-B1B2-4EDD-aa47-dae2ee689dd6";typename="LibreOffice 6.4 Text Document";viewaspect="1";width="16999";height="2995";posx="0";posy="0"text/plain;charset=utf-8text/plainUTF8_STRINGSTRINGTEXTTARGETSMULTIPLETIMESTAMPSAVE_TARGETS
For Microsoft Windows, the available formats are these.
@Output
DataObjectStar Embed Source (XML)Rich Text FormatRichtext FormatHTML (HyperText Markup Language)HTML FormatUnicodeTextTextLinkStar Object Descriptor (XML)Ole Private DataLocaleOEMText
7: My Code
Hypothesizer 7
As I noticed earlier, 'wx.DataObject' cannot be used as a data container for my purpose. So, I have created a data container class, 'theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataComposite' (and 'theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDatum' as its component) and a data history class, 'theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataCompositesHistory', which is the multi buffers container.
theBiasPlanet/coreUtilities/clipboardHandling/ClipboardFormatSpecificDatum.py
@Python Source Code
class ClipboardFormatSpecificDatum:def __init__ (a_this: "ClipboardFormatSpecificDatum", a_formatName: str, a_formatNumber: int, a_datum: bytearray) -> None:a_this.i_formatName: str = a_formatNamea_this.i_formatNumber: int = a_formatNumbera_this.i_datum: bytearray = a_datumdef __del__ (a_this: "ClipboardFormatSpecificDatum") -> None:Nonedef getFormatName (a_this: "ClipboardFormatSpecificDatum") -> str:return a_this.i_formatNamedef getFormatNumber (a_this: "ClipboardFormatSpecificDatum") -> int:return a_this.i_formatNumberdef getDatumSize (a_this: "ClipboardFormatSpecificDatum") -> int:return len (a_this.i_datum)def getDatum (a_this: "ClipboardFormatSpecificDatum") -> bytearray:return a_this.i_datum
theBiasPlanet/coreUtilities/clipboardHandling/ClipboardFormatSpecificDataComposite.py
@Python Source Code
from typing import Listfrom collections import OrderedDictfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDatum import ClipboardFormatSpecificDatumclass ClipboardFormatSpecificDataComposite:def __init__ (a_this: "ClipboardFormatSpecificDataComposite") -> None:a_this.i_formatNameToDatumMap: "OrderedDict [str, ClipboardFormatSpecificDatum]" = OrderedDict ()def __del__ (a_this: "ClipboardFormatSpecificDataComposite") -> None:Nonedef addFormatSpecificDatum (a_this: "ClipboardFormatSpecificDataComposite", a_formatSpecificDatum: "ClipboardFormatSpecificDatum") -> bool:a_this.i_formatNameToDatumMap [a_formatSpecificDatum.getFormatName ()] = a_formatSpecificDatumreturn Truedef getFormatNames (a_this: "ClipboardFormatSpecificDataComposite") -> List [str]:l_formatNames: List [str] = []l_formatName: str = Nonefor l_formatName in a_this.i_formatNameToDatumMap:l_formatNames.append (l_formatName)return l_formatNamesdef getFormatSpecificDatum (a_this: "ClipboardFormatSpecificDataComposite", a_formatName: str) -> "ClipboardFormatSpecificDatum":l_formatSpecificDatum: "ClipboardFormatSpecificDatum" = Nonetry:l_formatSpecificDatum = a_this.i_formatNameToDatumMap [a_formatName]except (KeyError) as l_exception:Nonereturn l_formatSpecificDatum
theBiasPlanet/coreUtilities/clipboardHandling/ClipboardFormatSpecificDataCompositesHistory.py
@Python Source Code
from collections import OrderedDictfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataComposite import ClipboardFormatSpecificDataCompositeclass ClipboardFormatSpecificDataCompositesHistory:def __init__ (a_this: "ClipboardFormatSpecificDataCompositesHistory") -> None:a_this.i_dataCompositeKeyToDataCompositeMap: "OrderedDict [str, ClipboardFormatSpecificDataComposite]" = OrderedDict ()def __del__ (a_this: "ClipboardFormatSpecificDataCompositesHistory") -> None:Nonedef addDataComposite (a_this: "ClipboardFormatSpecificDataCompositesHistory", a_dataCompositeKey: str, a_dataComposite: "ClipboardFormatSpecificDataComposite") -> bool:a_this.i_dataCompositeKeyToDataCompositeMap [a_dataCompositeKey] = a_dataCompositereturn Truedef removeDataComposite (a_this: "ClipboardFormatSpecificDataCompositesHistory", a_dataCompositeKey: str) -> bool:try:a_this.i_dataCompositeKeyToDataCompositeMap.pop (a_dataCompositeKey)return Trueexcept (KeyError) as l_exception:return Falsedef getDataComposite (a_this: "ClipboardFormatSpecificDataCompositesHistory", a_dataCompositeKey: str) -> "ClipboardFormatSpecificDataComposite":l_dataComposite: "ClipboardFormatSpecificDataComposite" = Nonetry:l_dataComposite = a_this.i_dataCompositeKeyToDataCompositeMap [a_dataCompositeKey]except (KeyError) as l_exception:Nonereturn l_dataComposite
The 'wx.DataObject' extension class is this.
theBiasPlanet/coreUtilities/clipboardHandling/WxPythonClipboardEventsHandler.py
@Python Source Code
from typing import Listfrom typing import castfrom collections import OrderedDictimport sysfrom wx import DataFormat as wx_DataFormatfrom wx import DataObject as wx_DataObjectimport wxfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataComposite import ClipboardFormatSpecificDataCompositefrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDatum import ClipboardFormatSpecificDatumclass WxPythonClipboardEventsHandler (wx_DataObject):s_possibleDatumFormatNameToFormatMap: "OrderedDict [str, wx_DataFormat]" = Nones_preferedDatumFormatName: str = Nones_possibleDatumFormats: List [wx_DataFormat] = None@staticmethoddef getDatumFormatName (a_datumFormat: wx_DataFormat) -> str:l_datumFormatNumber: int = a_datumFormat.GetType ()l_datumFormatName: str = Noneif l_datumFormatNumber == wx.DF_TEXT:l_datumFormatName = "Text"elif l_datumFormatNumber == wx.DF_BITMAP:l_datumFormatName = "Bitmap"elif l_datumFormatNumber == wx.DF_METAFILE:l_datumFormatName = "Metafile"elif l_datumFormatNumber == wx.DF_FILENAME:l_datumFormatName = "Filename"elif l_datumFormatNumber == wx.DF_HTML:l_datumFormatName = "HTML Format"else:l_datumFormatName = a_datumFormat.GetId ()return l_datumFormatNamedef __init__ (a_this: "WxPythonClipboardEventsHandler", a_formatSpecificDataComposite: "ClipboardFormatSpecificDataComposite") -> None:a_this.i_formatSpecificDataComposite: "ClipboardFormatSpecificDataComposite" = a_formatSpecificDataCompositea_this.i_supportedDatumFormats: List [wx_DataFormat] = Nonesuper ().__init__ ()l_availableDatumFormatNames: List [str] = a_this.i_formatSpecificDataComposite.getFormatNames ()if len (l_availableDatumFormatNames) > 0:a_this.i_supportedDatumFormats = []l_datumFormatName: str = Nonefor l_datumFormatName in l_availableDatumFormatNames:a_this.i_supportedDatumFormats.append (WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap [l_datumFormatName])else:a_this.i_supportedDatumFormats = WxPythonClipboardEventsHandler.s_possibleDatumFormatsdef getFormatSpecificDataComposite (a_this: "WxPythonClipboardEventsHandler") -> "ClipboardFormatSpecificDataComposite":return a_this.i_formatSpecificDataCompositedef GetFormatCount (a_this: "WxPythonClipboardEventsHandler", a_datumTransferDirection: wx_DataObject.Direction = wx_DataObject.Direction.Get) -> int:sys.stdout.write ("### GetFormatCount: {0:d}\n".format (len (a_this.i_supportedDatumFormats)))return len (a_this.i_supportedDatumFormats)def GetAllFormats (a_this: "WxPythonClipboardEventsHandler", a_datumTransferDirection: wx_DataObject.Direction = wx_DataObject.Direction.Get) -> List [wx_DataFormat]:sys.stdout.write ("### GetAllFormats:\n")return a_this.i_supportedDatumFormats# 'a_formatSpecificDatum' is not really 'bytearray', but 'memoryview', but the stub of 'memoryview' seems to be mistaken, which makes me use 'bytearray' instead.def GetDataHere (a_this: "WxPythonClipboardEventsHandler", a_datumFormat: wx_DataFormat, a_formatSpecificDatum: bytearray) -> bool:sys.stdout.write ("### GetDataHere: {0:s}\n".format (WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat)))l_formatSpecificDatumIsFound: bool = Falseif a_formatSpecificDatum is not None:l_formatSpecificDatum: "ClipboardFormatSpecificDatum" = a_this.i_formatSpecificDataComposite.getFormatSpecificDatum (WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat))if l_formatSpecificDatum is not None:l_copiedFormatSpecificDatum: bytearray = l_formatSpecificDatum.getDatum ()l_byteIndex: int = 0for l_byteIndex in range (0, len (a_formatSpecificDatum), 1):#a_formatSpecificDatum [l_byteIndex:l_byteIndex + 1] = cast (Sequence [bytes], bytes ([l_copiedFormatSpecificDatum [l_byteIndex]])) # This is if I rather use 'memoryview'.a_formatSpecificDatum [l_byteIndex] = l_copiedFormatSpecificDatum [l_byteIndex]l_formatSpecificDatumIsFound = Truereturn l_formatSpecificDatumIsFounddef GetDataSize (a_this: "WxPythonClipboardEventsHandler", a_datumFormat: wx_DataFormat) -> int:sys.stdout.write ("### GetDataSize:\n")l_size: int = 0l_formatSpecificDatum: "ClipboardFormatSpecificDatum" = a_this.i_formatSpecificDataComposite.getFormatSpecificDatum (WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat))if l_formatSpecificDatum is not None:l_size = len (l_formatSpecificDatum.getDatum ())return l_sizedef GetPreferredFormat (a_this: "WxPythonClipboardEventsHandler", a_datumTransferDirection: wx_DataObject.Direction = wx_DataObject.Direction.Get) -> wx_DataFormat:sys.stdout.write ("### GetPreferredFormat:\n")return WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap [WxPythonClipboardEventsHandler.s_preferedDatumFormatName]def IsSupported (a_this: "WxPythonClipboardEventsHandler", a_datumFormat: wx_DataFormat, a_datumTransferDirection: wx_DataObject.Direction = wx_DataObject.Direction.Get) -> bool:sys.stdout.write ("### IsSupported:\n")try:WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap [WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat)]return Trueexcept (KeyError) as l_exception:return Falsedef SetData (a_this: "WxPythonClipboardEventsHandler", a_datumFormat: wx_DataFormat, a_formatSpecificDatum: memoryview) -> bool:sys.stdout.write ("### SetData: {0:s}\n".format (WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat)))l_datumFormatName: str = WxPythonClipboardEventsHandler.getDatumFormatName (a_datumFormat)if a_formatSpecificDatum is not None:l_datumSize = len (a_formatSpecificDatum)l_copiedFormatSpecificDatum: bytearray = Noneif l_datumFormatName == "Text" or l_datumFormatName == "HTML Format":l_copiedFormatSpecificDatum = bytearray (l_datumSize + 1)l_copiedFormatSpecificDatum [l_datumSize] = 0else:l_copiedFormatSpecificDatum = bytearray (l_datumSize)l_byteIndex: int = 0for l_byteIndex in range (0, len (a_formatSpecificDatum), 1):l_copiedFormatSpecificDatum [l_byteIndex] = a_formatSpecificDatum [l_byteIndex]a_this.i_formatSpecificDataComposite.addFormatSpecificDatum (ClipboardFormatSpecificDatum (l_datumFormatName, a_datumFormat.GetType (), l_copiedFormatSpecificDatum))return False
Of course, you cannot do like 'a_formatSpecificDatum = l_formatSpecificDatum.getDatum ()' for 'GetDataHere' (if you think you can, you do not understand that any Python variable is a pointer).
The clipboard handling class is this.
theBiasPlanet/coreUtilities/clipboardHandling/WxPythonClipboard.py
@Python Source Code
from typing import Listfrom collections import OrderedDictfrom wx import DataFormat as wx_DataFormatimport wxfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataComposite import ClipboardFormatSpecificDataCompositefrom theBiasPlanet.coreUtilities.clipboardHandling.WxPythonClipboardEventsHandler import WxPythonClipboardEventsHandlerclass WxPythonClipboard:@staticmethoddef setUp (a_datumFormatNameToFormatMap: "OrderedDict [str, wx_DataFormat]", a_preferedDatumFormatName: str) -> bool:WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap = a_datumFormatNameToFormatMapWxPythonClipboardEventsHandler.s_preferedDatumFormatName = a_preferedDatumFormatNameWxPythonClipboardEventsHandler.s_possibleDatumFormats = []l_datumFormatName: str = Nonefor l_datumFormatName in WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap:WxPythonClipboardEventsHandler.s_possibleDatumFormats.append (WxPythonClipboardEventsHandler.s_possibleDatumFormatNameToFormatMap [l_datumFormatName])return True@staticmethoddef openClipboard () -> bool:wx.TheClipboard.Open ()return True@staticmethoddef closeClipboard () -> bool:wx.TheClipboard.Close ()return True@staticmethoddef clearClipboard () -> bool:wx.TheClipboard.Clear ()return True@staticmethoddef getFormatSpecificDataComposite () -> "ClipboardFormatSpecificDataComposite":l_wxPythonClipboardEventsHandler: "WxPythonClipboardEventsHandler" = WxPythonClipboardEventsHandler (ClipboardFormatSpecificDataComposite ())wx.TheClipboard.GetData (l_wxPythonClipboardEventsHandler)return l_wxPythonClipboardEventsHandler.getFormatSpecificDataComposite ()@staticmethoddef setFormatSpecificDataComposite (a_formatSpecificDataComposite: "ClipboardFormatSpecificDataComposite") -> bool:l_wxPythonClipboardEventsHandler: "WxPythonClipboardEventsHandler" = WxPythonClipboardEventsHandler (a_formatSpecificDataComposite)wx.TheClipboard.SetData (l_wxPythonClipboardEventsHandler)wx.TheClipboard.Flush ()return True
8: The Limitation
Hypothesizer 7
In fact, not the data of all the formats can be gotten or set in this technique.
For example, in Microsoft Windows, for a LibreOffice Writer clipboard data, the 'UnicodeText', 'Locale', and 'OEMText' data cannot be gotten.
Why? Well, in Microsoft Windows, it is not that the datum of any format can be just gotten in a uniform way as a bytes array; the data of a format have to be gotten in a certain way, but wxPython has not made the effort of supporting all the possible formats.
If the supported formats are not satisfactory, I will have to go to another technique (there will be an article for C# and an article for C++)
9: Testing
Hypothesizer 7
My test code is this for Microsoft Windows.
@Python Source Code
from typing import Listrom typing import TextIOimport sysimport wxfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataComposite import ClipboardFormatSpecificDataCompositefrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDataCompositesHistory import ClipboardFormatSpecificDataCompositesHistoryfrom theBiasPlanet.coreUtilities.clipboardHandling.ClipboardFormatSpecificDatum import ClipboardFormatSpecificDatumfrom theBiasPlanet.coreUtilities.clipboardHandling.WxPythonClipboard import WxPythonClipboardfrom theBiasPlanet.coreUtilities.clipboardHandling.WxPythonClipboardEventsHandler import WxPythonClipboardEventsHandlerfrom theBiasPlanet.coreUtilities.constantsGroups.ClipboardDatumFormatNameToFormatMapsConstantsGroup import ClipboardDatumFormatNameToFormatMapsConstantsGroupclass Test1Test:@staticmethoddef main (a_arguments: List [str]) -> None:Test1Test.test ()@staticmethoddef test () -> None:l_clipbardFormatSpecificDataCompositesHistory: "ClipboardFormatSpecificDataCompositesHistory" = ClipboardFormatSpecificDataCompositesHistory ()l_standardInputReader: TextIO = sys.stdinWxPythonClipboard.setUp (ClipboardDatumFormatNameToFormatMapsConstantsGroup.c_windowsDatumFormatNameToFormatMap, "Text")while True:sys.stdout.write ("### Input 'S' (Set), 'G' (Get), 'D (Display)', or 'Q' (Quit):\n")sys.stdout.flush ()l_userInput: str = l_standardInputReader.read (2)l_clipboardFormatSpecificDataCompositeKey: strif l_userInput.startswith ("S") or l_userInput.startswith ("G") or l_userInput.startswith ("D"):sys.stdout.write ("### Input the key:\n")sys.stdout.flush ()l_clipboardFormatSpecificDataCompositeKey = l_standardInputReader.read (2) [0]if l_userInput.startswith ("S"):WxPythonClipboard.openClipboard ()WxPythonClipboard.clearClipboard ()WxPythonClipboard.setFormatSpecificDataComposite (l_clipbardFormatSpecificDataCompositesHistory.getDataComposite (l_clipboardFormatSpecificDataCompositeKey))WxPythonClipboard.closeClipboard ()elif l_userInput.startswith ("G"):WxPythonClipboard.openClipboard ()l_clipbardFormatSpecificDataCompositesHistory.addDataComposite (l_clipboardFormatSpecificDataCompositeKey, WxPythonClipboard.getFormatSpecificDataComposite ())WxPythonClipboard.closeClipboard ()elif l_userInput.startswith ("D"):l_clipboardFormatSpecificDataComposite: "ClipboardFormatSpecificDataComposite " = l_clipbardFormatSpecificDataCompositesHistory.getDataComposite (l_clipboardFormatSpecificDataCompositeKey)l_clipboardDatumFormatNames: List [str] = l_clipboardFormatSpecificDataComposite.getFormatNames ()l_clipboardDatumFormatName: str = Nonefor l_clipboardDatumFormatName in l_clipboardDatumFormatNames:l_clipboardFormatSpecificDatum: "ClipboardFormatSpecificDatum " = l_clipboardFormatSpecificDataComposite.getFormatSpecificDatum (l_clipboardDatumFormatName)sys.stdout.write ("### clipboard datum format number, format name, size: {0:d}, {1:s}, {2:d}\n".format (l_clipboardFormatSpecificDatum.getFormatNumber (), l_clipboardDatumFormatName, l_clipboardFormatSpecificDatum.getDatumSize ()))sys.stdout.flush ()else:breakif __name__ == "__main__":l_application = wx.App ()Test1Test.main (sys.argv)
theBiasPlanet/coreUtilities/constantsGroups/ClipboardDatumFormatNameToFormatMapsConstantsGroup.py
@Python Source Code
from collections import OrderedDictfrom wx import DataFormat as wx_DataFormatimport wxclass ClipboardDatumFormatNameToFormatMapsConstantsGroup:c_linuxDatumFormatNameToFormatMap: "OrderedDict [str, wx_DataFormat]" = OrderedDict ({"Text": wx_DataFormat (wx.DF_TEXT), "Bitmap": wx_DataFormat (wx.DF_BITMAP), "Metafile": wx_DataFormat (wx.DF_METAFILE), "Filename": wx_DataFormat (wx.DF_FILENAME), "HTML Format": wx_DataFormat (wx.DF_HTML), "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"": wx_DataFormat ("application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\""), "text/rtf": wx_DataFormat ("text/rtf"), "text/richtext": wx_DataFormat ("text/richtext"), "text/html": wx_DataFormat ("text/html"), "text/plain;charset=utf-16": wx_DataFormat ("text/plain;charset=utf-16"), "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\";classname=\"8BC6B165-B1B2-4EDD-aa47-dae2ee689dd6\";typename=\"LibreOffice 6.4 Text Document\";viewaspect=\"1\";width=\"16999\";height=\"2995\";posx=\"0\";posy=\"0\"": wx_DataFormat ("application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\";classname=\"8BC6B165-B1B2-4EDD-aa47-dae2ee689dd6\";typename=\"LibreOffice 6.4 Text Document\";viewaspect=\"1\";width=\"16999\";height=\"2995\";posx=\"0\";posy=\"0\""), "text/plain;charset=utf-8": wx_DataFormat ("text/plain;charset=utf-8"), "text/plain": wx_DataFormat ("text/plain"), "UTF8_STRING": wx_DataFormat ("UTF8_STRING"), "STRING": wx_DataFormat ("STRING"), "TEXT": wx_DataFormat ("TEXT"), "MULTIPLE": wx_DataFormat ("MULTIPLE"), "TIMESTAMP": wx_DataFormat ("TIMESTAMP")})c_windowsDatumFormatNameToFormatMap: "OrderedDict [str, wx_DataFormat]" = OrderedDict ({"Text": wx_DataFormat (wx.DF_TEXT), "Metafile": wx_DataFormat (wx.DF_METAFILE), "Filename": wx_DataFormat (wx.DF_FILENAME), "UnicodeText": wx_DataFormat ("UnicodeText"), "Locale": wx_DataFormat ("Locale"), "OEMText": wx_DataFormat ("OEMText"), "DataObject": wx_DataFormat ("DataObject"), "Preferred DropEffect": wx_DataFormat ("Preferred DropEffect"), "Ole Private Data": wx_DataFormat ("Ole Private Data"), "HTML Format": wx_DataFormat (wx.DF_HTML), "HTML (HyperText Markup Language)": wx_DataFormat ("HTML (HyperText Markup Language)"), "Star Embed Source (XML)": wx_DataFormat ("Star Embed Source (XML)"), "Rich Text Format": wx_DataFormat ("Rich Text Format"), "Richtext Format": wx_DataFormat ("Richtext Format"), "Link": wx_DataFormat ("Link"), "Star Object Descriptor (XML)": wx_DataFormat ("Star Object Descriptor (XML)"), "GDIMetaFile": wx_DataFormat ("GDIMetaFile"), "EnhancedMetafile": wx_DataFormat ("EnhancedMetafile"), "MetaFilePict": wx_DataFormat ("MetaFilePict"), "PNG": wx_DataFormat ("PNG"), "DeviceIndependentBitmap": wx_DataFormat ("DeviceIndependentBitmap"), "Windows Bitmap": wx_DataFormat ("Windows Bitmap"), "SymbolicLink": wx_DataFormat ("SymbolicLink"), "DataInterchangeFormat": wx_DataFormat ("DataInterchangeFormat"), "EditEngine ODF": wx_DataFormat ("EditEngine ODF")})
After I have copied a text piece on a 'cmd' terminal, I get an output like this for the 'G' -> 'A' -> 'D' -> 'A' inputs.
@Output
### clipboard datum format number, format name, size: 1, Text, 8
After I have copied a text piece on a LibreOffice Writer instance, I get an output like this for the 'G' -> 'A' -> 'D' -> 'A' inputs.
@Output
### clipboard datum format number, format name, size: 1, Text, 37### clipboard datum format number, format name, size: 49161, DataObject, 8### clipboard datum format number, format name, size: 49171, Ole Private Data, 552### clipboard datum format number, format name, size: 30, HTML Format, 772### clipboard datum format number, format name, size: 49819, HTML (HyperText Markup Language), 667### clipboard datum format number, format name, size: 49817, Star Embed Source (XML), 6279### clipboard datum format number, format name, size: 49285, Rich Text Format, 2675### clipboard datum format number, format name, size: 49790, Richtext Format, 2675### clipboard datum format number, format name, size: 49852, Link, 111### clipboard datum format number, format name, size: 49853, Star Object Descriptor (XML), 164
For Linux, I have to change the expected clipboard datum formats.