/usr/share/pyspread/src/lib/clipboard.py is in pyspread 1.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright Martin Manns
# Distributed under the terms of the GNU General Public License
# --------------------------------------------------------------------
# pyspread is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyspread is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyspread. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------
"""
clipboard
=========
Provides
--------
* Clipboard: Clipboard interface class
"""
import wx
import src.lib.i18n as i18n
#use ugettext instead of getttext to avoid unicode errors
_ = i18n.language.ugettext
class Clipboard(object):
"""Clipboard access
Provides:
---------
get_clipboard: Get clipboard content
set_clipboard: Set clipboard content
grid_paste: Inserts data into grid target
"""
clipboard = wx.TheClipboard
def _convert_clipboard(self, datastring=None, sep='\t'):
"""Converts data string to iterable.
Parameters:
-----------
datastring: string, defaults to None
\tThe data string to be converted.
\tself.get_clipboard() is called if set to None
sep: string
\tSeparator for columns in datastring
"""
if datastring is None:
datastring = self.get_clipboard()
data_it = ((ele for ele in line.split(sep))
for line in datastring.splitlines())
return data_it
def get_clipboard(self):
"""Returns the clipboard content
If a bitmap is contained then it is returned.
Otherwise, the clipboard text is returned.
"""
bmpdata = wx.BitmapDataObject()
textdata = wx.TextDataObject()
if self.clipboard.Open():
is_bmp_present = self.clipboard.GetData(bmpdata)
self.clipboard.GetData(textdata)
self.clipboard.Close()
else:
wx.MessageBox(_("Can't open the clipboard"), _("Error"))
if is_bmp_present:
return bmpdata.GetBitmap()
else:
return textdata.GetText()
def set_clipboard(self, data, datatype="text"):
"""Writes data to the clipboard
Parameters
----------
data: Object
\tData object for clipboard
datatype: String in ["text", "bitmap"]
\tIdentifies datatype to be copied to teh clipboard
"""
error_log = []
if datatype == "text":
data = wx.TextDataObject(text=data)
elif datatype == "bitmap":
data = wx.BitmapDataObject(bitmap=data)
else:
msg = _("Datatype {type} unknown").format(type=datatype)
raise ValueError(msg)
if self.clipboard.Open():
self.clipboard.SetData(data)
self.clipboard.Close()
else:
wx.MessageBox(_("Can't open the clipboard"), _("Error"))
return error_log
# end of class Clipboard
|