Skip to content

Commit a00ff15

Browse files
MAINT: use base64 to convert bytes to str for wxpython
1 parent a9de126 commit a00ff15

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/diffpy/pdfgui/gui/fittree.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import wx
2626
import re
27+
import base64
2728

2829
from diffpy.pdfgui.gui.pdfguiglobals import iconpath
2930
from diffpy.pdfgui.control.fitting import Fitting
@@ -556,8 +557,10 @@ def CopyBranch(self, startnode):
556557
if isinstance(cdata, Fitting):
557558
cdata = cdata.stripped()
558559
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)
561564
textdata = wx.TextDataObject(cdatastring)
562565
if not wx.TheClipboard.IsOpened():
563566
opened = wx.TheClipboard.Open()
@@ -586,12 +589,15 @@ def GetClipboard(self):
586589
cdatastring = textdata.GetText()
587590

588591
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:]
592598
cdata = pickle_loads(cdatastring)
593-
except:
594-
pass
599+
except:
600+
pass
595601
return cdata
596602

597603
def PasteBranch(self, entrypoint = None):

0 commit comments

Comments
 (0)