Skip to content

Commit fab0b5e

Browse files
committed
cisstInteractive: more updates for Python 3
1 parent f65524f commit fab0b5e

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

cisstInteractive/code/irepy/ireLogCtrl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ def __init__(self, parent, id, title='',
9696
self.ChannelMask.Enable(False)
9797

9898
self.HeaderSizer = wx.BoxSizer(wx.HORIZONTAL)
99-
self.HeaderSizer.Add(self.Text, 0, wx.ALIGN_LEFT)
99+
self.HeaderSizer.Add(self.Text, 0, wx.ALIGN_TOP)
100100
self.HeaderSizer.Add((0,0),3) # Add a stretchable space
101-
self.HeaderSizer.Add(self.EnableBox, 0, wx.ALIGN_LEFT)
101+
self.HeaderSizer.Add(self.EnableBox, 0, wx.ALIGN_TOP)
102102
self.HeaderSizer.Add((0,0),3) # Add a stretchable space
103-
self.HeaderSizer.Add(self.ChannelMaskText, 0, wx.ALIGN_RIGHT)
104-
self.HeaderSizer.Add(self.ChannelMask, 0, wx.ALIGN_LEFT)
103+
self.HeaderSizer.Add(self.ChannelMaskText, 0, wx.ALIGN_TOP)
104+
self.HeaderSizer.Add(self.ChannelMask, 0, wx.ALIGN_TOP)
105105
self.HeaderSizer.Add((0,0),1) # Add a smaller stretchable space
106106

107107
self.logText = wx.TextCtrl(self, -1, style=style)

cisstInteractive/code/irepy/ireMain.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@
3636
#------------------------------------------------------
3737
import os, sys, time, types, warnings
3838
if sys.version_info.major == 2:
39-
import imp, cPickle, exceptions
39+
import cPickle as pickle
40+
import imp
41+
else:
42+
import pickle
43+
import importlib.util
4044
import string as String
4145

4246
#-----------------------------------------------------
4347
# Ignore Python future warnings (nuissances)
4448
#-----------------------------------------------------
45-
if sys.version_info.major == 2:
46-
warnings.simplefilter('ignore', exceptions.FutureWarning)
49+
warnings.simplefilter('ignore', FutureWarning)
4750

4851
#------------------------------------------------------
4952
# Import what we need from the wx toolkit
@@ -597,14 +600,14 @@ def GetTypeString(self, _Str):
597600
def SaveHistoryToFile(self):
598601
cmdlist = self.CommandHistoryListCtrl.GetAllItems()
599602
f = open(self.HISTORY_FILENAME, 'w')
600-
cPickle.dump(cmdlist, f)
603+
pickle.dump(cmdlist, f)
601604

602605
def LoadHistoryFromFile(self, fn=HISTORY_FILENAME):
603606
Data = []
604607
if os.path.isfile(fn):
605608
try:
606-
Data = cPickle.load(open(fn))
607-
except exceptions.Exception as error:
609+
Data = pickle.load(open(fn))
610+
except Exception as error:
608611
msgdlg = wx.MessageDialog(self, str(error), "Load History", wx.OK | wx.ICON_ERROR)
609612
msgdlg.ShowModal()
610613
msgdlg.Destroy()
@@ -687,13 +690,13 @@ def TruncateHistoryFile(self):
687690
# write the command file up to the selected line into the named file
688691
# fetch any existing list first and append to it
689692
try:
690-
archlist = cPickle.load(open(fn))
693+
archlist = pickle.load(open(fn))
691694
except IOError:
692695
archlist = []
693696
n=0
694697
for n in range(choice):
695698
archlist.append( cmdlist[n] )
696-
cPickle.dump( archlist, open(fn, 'w'))
699+
pickle.dump( archlist, open(fn, 'w'))
697700
text = "Your command history was archived to " + fn
698701
msgdlg = wx.MessageDialog(self, text, title, wx.OK | wx.ICON_INFORMATION)
699702
msgdlg.ShowModal()
@@ -987,10 +990,15 @@ def OnUpdateMenu(self, event):
987990

988991
# ModuleAvailable: returns true if the module 'name' is present on the path.
989992
def ModuleAvailable(name):
990-
try:
991-
imp.find_module(name)
992-
except ImportError:
993-
return False
993+
if sys.version_info.major == 2:
994+
try:
995+
imp.find_module(name)
996+
except ImportError:
997+
return False
998+
else:
999+
spec = importlib.util.find_spec(name)
1000+
if not spec:
1001+
return False
9941002
return True
9951003

9961004
def launchIrePython():

cisstInteractive/code/irepy/ireWorkspace.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525

2626
import sys
2727
if sys.version_info.major == 2:
28-
import exceptions
29-
import cPickle
28+
import cPickle as pickle
29+
else:
30+
import pickle
3031

3132
class NoOutput:
3233
def write(self, String):
3334
pass
3435

3536
def IsPicklable(Object):
3637
try:
37-
cPickle.dump(Object, NoOutput())
38-
except exceptions.Exception as error: #cPickle.PicklingError, error:
38+
pickle.dump(Object, NoOutput())
39+
except Exception as error: #pickle.PicklingError, error:
3940
return False
4041
return True
4142

@@ -49,15 +50,15 @@ def SaveWorkspaceToFile(ObjectDictionary, File):
4950
for ObjectName in ObjectDictionary:
5051
if IsPicklable(ObjectDictionary[ObjectName]):
5152
Workspace.update({ObjectName:ObjectDictionary[ObjectName]})
52-
cPickle.dump(Workspace,File)
53+
pickle.dump(Workspace,File)
5354

5455
#------------------------------------------------------
5556
# LoadWorkspaceFile
5657
#
5758
# Load workspace variables and statements from a file
5859
#------------------------------------------------------
5960
def LoadWorkspaceFile(ObjectDictionary, File):
60-
Workspace = cPickle.load(File)
61+
Workspace = pickle.load(File)
6162
for Variable in Workspace:
6263
ObjectDictionary[Variable] = Workspace[Variable]
6364

@@ -75,7 +76,7 @@ def main():
7576
v1 = v2 = None
7677
print('v1 = ', v1, '\nv2 = ', v2)
7778
LoadFile(open('workspace'))
78-
Workspace = cPickle.load(open('workspace'))
79+
Workspace = pickle.load(open('workspace'))
7980
for Variable in Workspace:
8081
exec(Variable + " = Workspace['" + Variable + "']")
8182
print('v1 = ', v1, '\nv2 = ', v2)

0 commit comments

Comments
 (0)