我尝试在面板右侧添加一个“变量”按钮,该按钮位于面板的上部,但是当我添加它时,在另一个面板向下的位置中,我总是发现缩放显示错误,如何通过保持右上方的面板与右下方的子面板之间的绑定来添加按钮
我尝试在右上角有2个子面板,一个用于按钮,另一个用于绘图,但是当我选择缩放以在子面板右下角对其进行绘图时,会给我错误:
self.GrandParent.right.bottom.top.right.Update(self.zoom_axes)
AttributeError: 'RightPanel' object has no attribute 'right'
当我遇到错误(Python 3.6)时,这就是代码的一部分:
class RightPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent,name = "Right",style = wx.SUNKEN_BORDER)
self.top = RightPanelTop(self)
self.bottom = RightPanelBottom(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.top, 1, wx.EXPAND,5)
sizer.Add(self.bottom, 1, wx.EXPAND,5)
self.SetSizer(sizer)
class RightPanelTop(wx.Panel):
def __init__(self, parent):
super().__init__(parent , name="RightTop", style = wx.SUNKEN_BORDER,size = (300,300))
self.SetBackgroundColour('black')
self.top = RightPanelTopTop(self)
self.bottom = RightPanelTopBottom(self)
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(self.top, 0.5, wx.EXPAND)
sizer1.Add(self.bottom, 8, wx.EXPAND)
self.SetSizer(sizer1)
class RightPanelBottom(wx.Panel):
def __init__(self, parent):
super().__init__(parent, name="RightBottom", style = wx.SUNKEN_BORDER,size = (300,200))
self.SetBackgroundColour('snow2')
self.top = PanelTop(self)
self.bottom = PanelBottom(self)
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(self.top, 1, wx.EXPAND)
sizer1.Add(self.bottom, 1, wx.EXPAND)
self.SetSizer(sizer1)
class RightPanelTopTop(wx.Panel):
def __init__(self,parent):
super().__init__(parent,name = "RightTopTop",size = (30,30))
self.SetBackgroundColour('black')
dynamique=wx.Button(self,-1,"Dynamique",size=(140,30),pos=(120,0))
dynamique.SetBackgroundColour('white')
variable =wx.Button(self,-1,"Variable",size=(140,30),pos=(0,0))
variable.SetBackgroundColour('white')
variable.Bind(wx.EVT_BUTTON, self.ShowPopup)
def ShowPopup(self, event):
popmenu = wx.Menu()
visible = wx.Menu()
visible.Append( -1, "VIS006")
visible.Append( -1, "VIS008")
popmenu.Append( -1, "Visible", visible)
infrared = wx.Menu()
infrared.Append( -1, "IR039")
infrared.Append( -1, "WV073")
infrared.Append( -1, "IR108")
infrared.Append( -1, "IR120")
infrared.Append( -1, "IR134")
popmenu.Append( -1, "Infrarouge", infrared)
self.Bind(wx.EVT_MENU, self.OnChoice)
self.PopupMenu(popmenu)
popmenu.Destroy()
def OnChoice(self, event):
id = event.GetId()
obj = event.GetEventObject()
print("Option chosen",obj.GetLabelText(id))
class RightPanelTopBottom(wx.Panel):
def __init__(self,parent):
super().__init__(parent,name="RightTopBottom",style = wx.SUNKEN_BORDER,size = (300,200))
self.SetBackgroundColour('black')
def Update(self,zoom_axes):
#Load axis values of the selected rectangle
#zoom_axes=parent.zoom_axes
#duplicate the plot from the main panel
self.figure = Figure(figsize =(5,5))
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_subplot(111)
self.figure.subplots_adjust(left=0.009,right=0.95,bottom=0.1,top=0.98)
#Apply axis of drawn rectangle to the plot
self.axes.axis(zoom_axes)
path=file_names
nc = netCDF4.Dataset(file_names)
keys = nc.variables.keys()
list_var = [nc.variables['VIS006'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073']]
data_list = ['VIS006','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073']
list_var = [nc.variables[f] for f in data_list]
self.axes.imshow(list_var[5],origin='lower')
self.axes.get_xaxis().set_visible(False)
self.axes.get_yaxis().set_visible(False)
self.canvas.draw()
self.Refresh()
try:
self.RS.set_visible(False)
except:
pass
self.RS = RectangleSelector(self.axes,self.line_select_callback,
drawtype='box', useblit=False,
button=[1, 3],minspanx=5, minspany=5,
spancoords='pixels',
interactive=True, rectprops = dict(facecolor='None',edgecolor='red',alpha=5,fill=False))
self.RS.to_draw.set_visible(True)
self.RS.extents = (1000,1500,1000,1600)
def line_select_callback(self, eclick, erelease):
'eclick and erelease are the press and release events'
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
self.zoom_axes=[x1,x2,y1,y2]
self.GrandParent.right.bottom.top.right.Update(self.zoom_axes)
class RightPanelBottomTopLeft(wx.Panel):
def __init__(self, parent):
super().__init__(parent,name = "RightBottomTopLeft" ,style = wx.SUNKEN_BORDER)
self.SetBackgroundColour('black')
def Update(self,zoom_axes):
#Load axis values of the selected rectangle
#zoom_axes=parent.zoom_axes
#duplicate the plot from the main panel
self.figure = Figure(figsize =(2.5,2.5))
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_subplot(111)
self.figure.subplots_adjust(left=0.009,right=1,bottom=0.1,top=0.98)
#Apply axis of drawn rectangle to the plot
self.axes.axis(zoom_axes)
path=file_names
nc = netCDF4.Dataset(file_names)
keys = nc.variables.keys()
list_var = [nc.variables['VIS006'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073']]
data_list = ['VIS006','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073']
list_var = [nc.variables[f] for f in data_list]
self.axes.imshow(list_var[5],origin='lower')
self.axes.get_xaxis().set_visible(False)
self.axes.get_yaxis().set_visible(False)
self.canvas.draw()
self.Refresh()
class RightPanelBottomTopMiddle(wx.Panel):
def __init__(self, parent):
super().__init__(parent,name = "RightBottomTopMiddle",style = wx.SUNKEN_BORDER)
self.SetBackgroundColour('black')
def Update(self,zoom_axes):
#Load axis values of the selected rectangle
#zoom_axes=parent.zoom_axes
#duplicate the plot from the main panel
self.figure = Figure(figsize =(2.5,2.5))
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_subplot(111)
self.figure.subplots_adjust(left=0.009,right=0.95,bottom=0.1,top=0.98)
#Apply axis of drawn rectangle to the plot
self.axes.axis(zoom_axes)
path=file_names
nc = netCDF4.Dataset(file_names)
keys = nc.variables.keys()
list_var = [nc.variables['VIS006'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073']]
data_list = ['VIS006','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073']
list_var = [nc.variables[f] for f in data_list]
self.axes.imshow(list_var[5],origin='lower')
self.axes.get_xaxis().set_visible(False)
self.axes.get_yaxis().set_visible(False)
self.canvas.draw()
self.Refresh()
class RightPanelBottomTopRight(wx.Panel):
def __init__(self, parent):
super().__init__(parent,name = "RightBottomTopRight",style = wx.SUNKEN_BORDER,size = (50,50))
self.SetBackgroundColour('black')
def Update(self,zoom_axes):
#Load axis values of the selected rectangle
#zoom_axes=parent.zoom_axes
#duplicate the plot from the main panel
self.figure = Figure(figsize =(2.5,2.5))
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_subplot(111)
self.figure.subplots_adjust(left=0.009,right=1,bottom=0.1,top=0.98)
#Apply axis of drawn rectangle to the plot
self.axes.axis(zoom_axes)
path=file_names
nc = netCDF4.Dataset(file_names)
keys = nc.variables.keys()
list_var = [nc.variables['VIS006'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],nc.variables['IR_134'],nc.variables['IR_039'],nc.variables['WV_073']]
data_list = ['VIS006','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073']
list_var = [nc.variables[f] for f in data_list]
self.axes.imshow(list_var[5],origin='lower')
self.axes.get_xaxis().set_visible(False)
self.axes.get_yaxis().set_visible(False)
self.canvas.draw()
self.Refresh()
class PanelBottom(wx.Panel):
def __init__(self,parent):
super().__init__(parent)
self.SetBackgroundColour('grey77')
class PanelTop(wx.Panel):
def __init__(self,parent):
super().__init__(parent)
self.left = RightPanelBottomTopLeft(self)
self.middle = RightPanelBottomTopMiddle(self)
self.right = RightPanelBottomTopRight(self)
sizer1 = wx.BoxSizer(wx.HORIZONTAL)
sizer1.Add(self.left, 1, wx.EXPAND)
sizer1.Add(self.middle, 1, wx.EXPAND)
sizer1.Add(self.right, 1, wx.EXPAND)
self.SetSizer(sizer1)
app = wx.App()
frame = MainFrame(None).Show()
app.MainLoop()