sherif
sherif

Reputation: 71

Copy Text From Texit_Input

I need to copy the text to later use At pressing (ctrl + c), There will be error So I used bubble, but the same error appears

*****Python********

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder

class Progress(Popup):
    pass
class ScreenManagement(ScreenManager):
    pass

class Func(Screen):
    pass

presentation = Builder.load_file("try_.kv")

class MainApp(App):
    Progress = Progress()
    def build(self):
        return presentation
if __name__ == "__main__":
    MainApp().run()

*****KV File*******

#:import Factory kivy.factory.Factory
# #:import Clipboard kivy.core.clipboard.Clipboard
<Progress>:
    text: ""
    separator_color: 0, 0, 0, 0

    BoxLayout:
        TextInput:
            id: textinput
            text: "Your Key is samphone"
            copydata: 'text'
            readonly: True
            use_bubble: True
            allow_copy: True

        Button:
            text: "Click"
            on_release:
                root.dismiss()

ScreenManagement:
    Func:

<Func>:
    BoxLayout:
        Button:
            text: "Click"
            on_release:
                Factory.Progress().open()

****Error*****

File "C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\textinput.py", line 378, in do textinput.copy() File "C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\textinput.py", line 1712, in copy return Clipboard.copy(self.selection_text) File "C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\clipboard__init__.py", line 73, in copy self._copy(data) File "C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\clipboard__init__.py", line 87, in _copy self.put(data, self._clip_mime_type)

File "C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\clipboard\clipboard_winctypes.py", line 55, in put msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))

ValueError: embedded null character

Upvotes: 1

Views: 882

Answers (2)

Peter Badida
Peter Badida

Reputation: 12199

Actually, the whole ValueError here is "only" about quite a recent(3.5.4+ and 3.6.3+) change in the CPython internals in this pull request which basically for our ctypes clipboard meant calling a changed API _PyUnicode_AsUnicode instead of the original PyUnicode_AsUnicode and as described in the commit message:

_PyUnicode_AsUnicode() which is similar to PyUnicode_AsUnicode(), but checks for null characters..

it raised an error. It took a while to figure this one out because I didn't find it in the release notes, however it's fixed in kivy#5579 and will be soon in master branch.

Upvotes: 0

ikolim
ikolim

Reputation: 16041

Please refer to the following example for details:

Example

main.py

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen


class Progress(Popup):
    pass


class Func(Screen):
    pass


class ScreenManagement(ScreenManager):
    pass


class MainApp(App):

    def build(self):
        return ScreenManagement()


if __name__ == "__main__":
    MainApp().run()

main.kv

#:import Factory kivy.factory.Factory

<Progress>:
    text: ""
    separator_color: 0, 0, 0, 0

    BoxLayout:
        TextInput:
            id: textinput
            text: "Your Key is samphone"
            readonly: True
            allow_copy: True
            copydata: self.text

        Button:
            text: "Click"
            on_release:
                root.dismiss()

<Func>:
    BoxLayout:
        Button:
            text: "Click"
            on_release:
                Factory.Progress().open()

<ScreenManagement>:
    Func:

Output - Paste Later

enter image description here

Upvotes: 0

Related Questions