|
24 | 24 |
|
25 | 25 | import wx |
26 | 26 | import re |
| 27 | +import base64 |
27 | 28 |
|
28 | 29 | from diffpy.pdfgui.gui.pdfguiglobals import iconpath |
29 | 30 | from diffpy.pdfgui.control.fitting import Fitting |
@@ -556,8 +557,10 @@ def CopyBranch(self, startnode): |
556 | 557 | if isinstance(cdata, Fitting): |
557 | 558 | cdata = cdata.stripped() |
558 | 559 | cdata.type = nodetype |
559 | | - cdatastring = safeCPickleDumps(cdata) |
560 | | - cdatastring = "pdfgui_cliboard=" + cdatastring |
| 560 | + cdatabytes = safeCPickleDumps(cdata) |
| 561 | + cdatabytes = "pdfgui_cliboard=" + cdatabytes |
| 562 | + #wxpython only accepts str, use base64 to convert bytes to str |
| 563 | + cdatastring = base64.b64encode(cdatabytes) |
561 | 564 | textdata = wx.TextDataObject(cdatastring) |
562 | 565 | if not wx.TheClipboard.IsOpened(): |
563 | 566 | opened = wx.TheClipboard.Open() |
@@ -586,12 +589,15 @@ def GetClipboard(self): |
586 | 589 | cdatastring = textdata.GetText() |
587 | 590 |
|
588 | 591 | cdata = None |
589 | | - if cdatastring[:16] == "pdfgui_cliboard=": |
590 | | - cdatastring = cdatastring[16:] |
591 | | - try: |
| 592 | + # use base64 to convert str back to bytes |
| 593 | + try: |
| 594 | + cdatabytes = base64.b64decode(cdatastring.encode()) |
| 595 | + |
| 596 | + if cdatabytes[:16] == b'pdfgui_cliboard=': |
| 597 | + cdatabytes = cdatabytes[16:] |
592 | 598 | cdata = pickle_loads(cdatastring) |
593 | | - except: |
594 | | - pass |
| 599 | + except: |
| 600 | + pass |
595 | 601 | return cdata |
596 | 602 |
|
597 | 603 | def PasteBranch(self, entrypoint = None): |
|
0 commit comments