won’t compile on wxPython 4.1.0 use wxPython 4.0.7 instead
这里使用是这个版本的wxPython 4.0.7.post2,最新版本会存在更多的不兼容。
对于有些unhashable types不能作为dict key,我创建一个类class,他可以作为dict.key
#################view.py下的修改
class lc:
#for (lengend_color) to be hashable
#so can be dict.key using wx.Colour
def __init__(self,name):
self.name=name
################lyf
self.legend_color = dict([
(lc(wx.Colour(64,128,128,trans)),1),(lc(wx.Colour(255,0,255,trans)),0),
(lc(wx.Colour(64,0,0,trans)),0), (lc(wx.Colour(255,255,0,trans)),0),
(lc(wx.Colour(0,128,255,trans)),0),(lc(wx.Colour(128,0,255,trans)),0),
(lc(wx.Colour(128,128,64,trans)),0),])
################################
def get_color(self):
for color, used in self.legend_color.items():
if not used:
self.legend_color[color] = 1
#lpj
return color.name
###########原始版本python2
self.legend_color = dict([
(wx.Colour(64,128,128,trans),1),(wx.Colour(255,0,255,trans),0),
(wx.Colour(64,0,0,trans),0), (wx.Colour(255,255,0,trans),0),
(wx.Colour(0,128,255,trans),0),(wx.Colour(128,0,255,trans),0),
(wx.Colour(128,128,64,trans),0),])
# Format: [color, 0 or 1] 0 stands for not being used
# 1 for being used
def get_color(self):
for color, used in self.legend_color.iteritems():
if not used:
self.legend_color[color] = 1
return color
#######gui.py下的修改
grid_panel.legend_color =dict([
(lc(wx.Colour(64,128,128,trans)),1),(lc(wx.Colour(255,0,255,trans)),0),
(lc(wx.Colour(64,0,0,trans)),0), (lc(wx.Colour(255,255,0,trans)),0),
(lc(wx.Colour(0,128,255,trans)),0),(lc(wx.Colour(128,0,255,trans)),0),
(lc(wx.Colour(128,128,64,trans)),0),])
# Format: [color, 0 or 1] 0 stands for not being used
# 1 for being used
#################################
color = view_material.zone_color.pop()
#lyf
for color_index, used in grid_panel.legend_color.items():
if color_index.name==color:
grid_panel.legend_color[color_index]=0
#lpj comment one line
#grid_panel.legend_color[color] = 0
# Delete the last zone
########################原始版本
grid_panel.legend_color =dict([
(wx.Colour(64,128,128,trans),1),(wx.Colour(255,0,255,trans),0),
(wx.Colour(64,0,0,trans),0), (wx.Colour(255,255,0,trans),0),
(wx.Colour(0,128,255,trans),0),(wx.Colour(128,0,255,trans),0),
(wx.Colour(128,128,64,trans),0),])
####################################
color = view_material.zone_color.pop()
grid_panel.legend_color[color] = 0
此外,对于画图包wxpython,在view.py中有一些语句在python3中已经被弃用,因此将其comment
#lyf comment
#dc.BeginDrawing()
##################################
#lyf comment
#dc.EndDrawing()