class dataGraph(wx.Panel):
    # Create plot area and axes
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        fig_width_cm = 25.0
        inches_per_cm = 1.0 / 2.54
        fig_width = fig_width_cm * inches_per_cm
        golden_mean = (np.sqrt(5) - 1.0) / 2.0
        fig_height = golden_mean * fig_width
        fig_size = (fig_width, fig_height)
        params = {
            'backend': 'ps',
            'axes.labelsize': 10,
            'text.fontsize': 10,
            'label.fontsize': 10,
            'label.rotation': 45,
            'legend.fontsize': 10,
            'xtick.labelsize': 10,
            'ytick.labelsize': 10,
            'text.usetex': False,
            'figure.subplot.left': 0.01,
            'figure.subplot.bottom': 0.01,
            'figure.subplot.right': 0.99,
            'figure.subplot.top': 0.99,
            'figure.subplot.wspace': 0.00,
            'figure.subplot.hspace': 0.00,
            'figure.figsize': fig_size
        }
        plt.rcParams.update(params)

        self.fig = plt.figure()
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.canvas.SetPosition((0, 0))
        self.canvas.SetSize((640, 320))
        self.ax = self.fig.add_axes([0.08, 0.17, 0.83,
                                     0.8])  # left, bottom, right, top
        self.rax = self.ax.twinx()
        self.useAuto = True
        self.setup_axes()

    def setup_axes(self):
        self.ax.autoscale(True)
        self.formatter = plt.ScalarFormatter(useOffset=False, useMathText=True)
        self.ax.yaxis.set_major_formatter(self.formatter)
        self.rax.yaxis.set_major_formatter(self.formatter)
        self.ax.minorticks_on()
        self.rax.minorticks_on()
        self.ax.set_xlabel("Time")
        self.ax.set_ylabel("Temperature ($^\circ$C)")
        self.rax.set_ylabel("Humidity (% RH)")
        labels = self.ax.get_xticklabels()
        for label in labels:
            label.set_rotation(30)
Esempio n. 2
0
class Window(wx.Frame):
    def __init__(self):
        """ Creo la ventana con los botones y todo. """
        wx.Frame.__init__(self, None, -1,
                          "Servicio Meteorologico Nacional - VAyGeo",
                          (100, 100), (940, 580))
        self.SetBackgroundColour('#ece9d8')
        self.ReadStationData()

        # Variables
        self.DirPath = 'C:\\'
        self.OutPath = 'C:\\'
        self.cal_factor = 1
        self.FileList = []
        self.converted_file_list = []

        # Create plot area and axes
        self.fig = Figure(facecolor='#ece9d8')
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.canvas.SetPosition((0, 0))
        self.canvas.SetSize((640, 320))
        self.ax = self.fig.add_axes([0.08, 0.1, 0.86, 0.8])
        self.ax.autoscale(True)

        self.SL_data = SL.SL()

        # Create text box for event logging
        self.dataPath_text = wx.TextCtrl(self,
                                         -1,
                                         pos=(140, 320),
                                         size=(465, 25))
        self.outPath_text = wx.TextCtrl(self,
                                        -1,
                                        pos=(140, 360),
                                        size=(465, 25))

        # Texto para tomar el factor de calibración.
        wx.StaticText(self, -1, "Factor de calibración:", pos=(200, 400))
        self.t_cal_factor = wx.TextCtrl(self,
                                        -1,
                                        '1',
                                        pos=(320, 400),
                                        size=(50, 25))
        self.t_cal_factor.Bind(wx.EVT_KEY_UP, self.onCalFactorEdit)

        # Cuadro para listar archivos.
        self.t2 = wx.ListBox(self,
                             -1,
                             pos=(640, 32),
                             size=(200, 300),
                             style=wx.TE_MULTILINE | wx.TE_READONLY)
        self.t2.Bind(wx.EVT_LISTBOX_DCLICK, self.plotFile, self.t2)

        # Boton de directorio de datos:
        self.datadir_button = wx.Button(self,
                                        label='Datos',
                                        pos=(25, 320),
                                        size=(100, 25))
        self.datadir_button.SetFont(
            wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.datadir_button.Bind(wx.EVT_BUTTON, self.onDatadirButton)

        # Boton de directorio de salida de datos:
        self.outdir_button = wx.Button(self,
                                       label='Convertidos',
                                       pos=(25, 360),
                                       size=(100, 25))
        self.outdir_button.SetFont(
            wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.outdir_button.Bind(wx.EVT_BUTTON, self.onOutdirButton)

        # Create start/stop button
        self.convert_button = wx.Button(self,
                                        label='Convertir',
                                        pos=(25, 400),
                                        size=(100, 25))
        self.convert_button.SetFont(
            wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.convert_button.Bind(wx.EVT_BUTTON, self.onConvertButton)

        # Create start/stop button
        self.edit_button = wx.Button(self,
                                     label='Editar',
                                     pos=(25, 440),
                                     size=(100, 25))
        self.edit_button.SetFont(
            wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.edit_button.Bind(wx.EVT_BUTTON, self.onEditButton)

        # Texto para tomar el factor de calibración.
        estaciones = self.stations_data.Estacion.values
        wx.StaticText(self, -1, "Estación:", pos=(380, 400))
        self.combo_est = wx.ComboBox(self,
                                     -1,
                                     '1',
                                     pos=(440, 400),
                                     size=(50, 25),
                                     choices=estaciones)
        self.combo_est.Bind(wx.EVT_TEXT, self.SetStationParameters)

        wx.StaticText(self, -1, "N° de sensor:", pos=(640, 360))
        wx.StaticText(self, -1, "N° de estación:", pos=(640, 390))
        wx.StaticText(self, -1, "GAW ID:", pos=(640, 420))
        wx.StaticText(self, -1, "Latitud:", pos=(640, 450))
        wx.StaticText(self, -1, "Longitud:", pos=(640, 480))
        wx.StaticText(self, -1, "Altura:", pos=(640, 510))

        self.t_sens_numb = wx.TextCtrl(self,
                                       -1,
                                       '-',
                                       pos=(740, 355),
                                       size=(70, 25))
        self.t_station_numb = wx.TextCtrl(self,
                                          -1,
                                          '-',
                                          pos=(740, 385),
                                          size=(70, 25))
        self.t_gawid = wx.TextCtrl(self,
                                   -1,
                                   '-',
                                   pos=(740, 415),
                                   size=(70, 25))
        self.t_lat = wx.TextCtrl(self, -1, '-', pos=(740, 445), size=(70, 25))
        self.t_long = wx.TextCtrl(self, -1, '-', pos=(740, 475), size=(70, 25))
        self.t_alt = wx.TextCtrl(self, -1, '-', pos=(740, 505), size=(70, 25))

    def onCalFactorEdit(self, event):
        self.cal_factor = float(self.t_cal_factor.GetValue())

    def ReadStationData(self):
        self.stations_data = pd.read_csv('Estaciones.txt')

    def SetStationParameters(self, event):
        with open('Estaciones.txt') as stations_file:
            for line in stations_file:
                if line.startswith(self.combo_est.GetValue()):
                    station_data = line[:-1].split(',')

        self.t_sens_numb.SetValue(station_data[1])
        self.t_station_numb.SetValue(station_data[2])
        self.t_gawid.SetValue(station_data[3])
        self.t_lat.SetValue(station_data[4])
        self.t_long.SetValue(station_data[5])
        self.t_alt.SetValue(station_data[6])
        self.cal_factor = station_data[7]
        self.t_cal_factor.SetValue(station_data[7])

    def plotFile(self, event):

        self.SL_data, self.SL_date = SL.SL.load_solar_light_file(
            self.DirPath + '\\' + self.FileList[self.t2.GetSelection()])
        self.ax.clear()

        self.SL_data['Sensor1'] = self.SL_data[
            'Sensor1'].values * 0.35 * float(self.cal_factor)

        #  self.SL_data = self.SL_data.tz_localize('UTC').tz_convert('America/Buenos_Aires')

        position_text = self.SL_data.index.date[-1].strftime(
            '%Y-%m-%d') + ' 01:00'

        # Hago el grafico, cambio los limites, ajusto los ejes y pongo los titulos.
        self.ax.plot_date(self.SL_data.tz_localize('UTC').tz_convert(
            'America/Buenos_Aires').index.time,
                          self.SL_data.tz_localize('UTC').tz_convert(
                              'America/Buenos_Aires')['Sensor1'].values * 40,
                          markersize=0.5,
                          color='#00008D')

        self.ax.set_ylim(ymin=0, ymax=14)

        self.ax.set_yticks([0, 3, 6, 8, 11, 14], minor=False)
        self.ax.set_yticks([1, 2, 4, 5, 7, 9, 10, 12, 13], minor=True)
        self.ax.tick_params(axis='y', which='major', length=10, width=1.5)
        self.ax.tick_params(axis='y', which='minor', length=5, width=1)
        self.ax.grid(axis='y', b=None)
        self.ax.grid(axis='x')

        # Agrego los textos.
        self.ax.text(position_text, 1.5, 'Leve', verticalalignment='center')
        self.ax.text(position_text,
                     4.5,
                     'Moderado',
                     verticalalignment='center')
        self.ax.text(position_text, 7, 'Alto', verticalalignment='center')
        self.ax.text(position_text,
                     9.5,
                     'Muy Alto',
                     verticalalignment='center')
        self.ax.text(position_text,
                     12.5,
                     'Extremo',
                     verticalalignment='center')

        # Pongo los colores del fondo
        self.ax.axhspan(0, 3, color='#329500')  # Low
        self.ax.axhspan(3, 6, color='#F7E400')  # Moderated
        self.ax.axhspan(6, 8, color='#F85900')  # High
        self.ax.axhspan(8, 11, color='#D8001D')  # Very High
        self.ax.axhspan(11, 14, color='#6B49c8')  # Extreme

        # Agrego el mediodia solar
        localtz = timezone('America/Buenos_Aires')
        sun = SolarTime()
        solar_noon = sun.solar_noon_utc(self.SL_date,
                                        float(self.t_long.GetValue()))
        self.ax.axvline(solar_noon.astimezone(localtz).time(),
                        ymin=0,
                        ymax=14,
                        color='r')

        # Dibujo todo
        self.fig.canvas.draw()

    def GetFilesList(self):
        """ Hago una lista con todos los archivos del Solar Light
        que hay en el directorio seleccionado. """
        self.FileList = []
        self.converted_file_list = []

        for file in os.listdir(self.DirPath):
            if file.endswith('uvb') or file.endswith('UVB'):
                self.FileList.append(file)

        return

    def getData(self):
        """ Abro un archivo de Solar Light """
        self.SL_data, self.SL_date = SL.load_solar_light_file('BA170101.uvb')

        return

    def onEditButton(self, event):
        os.startfile(self.DirPath + '\\' +
                     self.FileList[self.t2.GetSelection()])
        if not self.t2.GetStringSelection().endswith(' (Editado)'):
            self.t2.SetString(self.t2.GetSelection(),
                              self.t2.GetStringSelection() + ' (Editado)')

        return

    def onConvertButton(self, event):
        """Convierto los datos al formato de WOUDC con una plantilla que es foo.txt"""

        if self.combo_est.GetValue() == '1':
            print('la')

        fi = open('foo.txt')
        fo_name = self.SL_date.strftime('%Y%m%d') + \
                  '.UV-Biometer.501.' + \
                  str(self.t_sens_numb.GetValue()) +\
                  '.smna.csv'

        fo = open(self.OutPath + '\\' + fo_name, 'w')

        src = Template(fi.read())
        fi.close()

        d = {
            'sensor_number': self.t_sens_numb.GetValue(),
            'numero_estacion': self.t_station_numb.GetValue(),
            'nombre_estacion': self.combo_est.GetValue(),
            'gaw_id': self.t_gawid.GetValue(),
            'lat': self.t_lat.GetValue(),
            'long': self.t_long.GetValue(),
            'altura': self.t_alt.GetValue(),
            'date': self.SL_date.strftime('%Y-%m-%d')
        }

        result = src.substitute(d)

        fo.write(result)
        self.SL_data[['Sensor1']].to_csv(fo,
                                         na_rep='',
                                         date_format='%H:%M:%S',
                                         float_format='%.7f',
                                         header=None)

        if not self.t2.GetStringSelection().startswith('* '):
            self.t2.SetString(self.t2.GetSelection(),
                              '* ' + self.t2.GetStringSelection())

        self.t2.SetSelection(self.t2.GetSelection() + 1)
        self.plotFile(wx.EVT_LEFT_DOWN)

        fo.close()

    def onDatadirButton(self, event):
        """ Selecciono la carpeta donde estan los archivos a procesar """
        dialog = wx.DirDialog(None,
                              "Choose a directory:",
                              style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
        if dialog.ShowModal() == wx.ID_OK:
            self.DirPath = dialog.GetPath()
            self.dataPath_text.WriteText(self.DirPath)
        dialog.Destroy()

        # Actualizo la lista de archivos.
        self.GetFilesList()
        self.t2.Set(self.FileList)

    def onOutdirButton(self, event):
        """ Selecciono la carpeta donde estan los archivos a procesar """
        dialog = wx.DirDialog(None,
                              "Choose a directory:",
                              style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
        if dialog.ShowModal() == wx.ID_OK:
            self.OutPath = dialog.GetPath()
            self.outPath_text.WriteText(self.OutPath)
        dialog.Destroy()
Esempio n. 3
0
class DataLoggerWindow(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Radiometer", (100, 100), (640, 480))

        self.SetBackgroundColour('#ece9d8')

        # Flag variables
        self.isLogging = False

        # Create data buffers
        self.N = 100
        self.n = range(self.N)
        self.M = 3
        self.x = []
        for m in range(self.M):
            self.x.append(0 * numpy.ones(self.N, numpy.int))

        # Create plot area and axes
        self.fig = Figure(facecolor='#ece9d8')
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.canvas.SetPosition((0, 0))
        self.canvas.SetSize((640, 320))
        self.ax = self.fig.add_axes([0.08, 0.1, 0.86, 0.8])
        self.ax.autoscale(True)
        self.ax.set_xlim(0, 99)
        self.ax.set_ylim(-50, 1100)
        for m in range(self.M):
            self.ax.plot(self.n, self.x[m])

        # Create text box for event logging
        self.log_text = wx.TextCtrl(self,
                                    -1,
                                    pos=(140, 320),
                                    size=(465, 100),
                                    style=wx.TE_MULTILINE)
        self.log_text.SetFont(
            wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))

        # Create timer to read incoming data and scroll plot
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.GetSample, self.timer)

        # Create start/stop button
        self.start_stop_button = wx.Button(self,
                                           label="Start",
                                           pos=(25, 320),
                                           size=(100, 100))
        self.start_stop_button.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.start_stop_button.Bind(wx.EVT_BUTTON, self.onStartStopButton)

    def GetSample(self, event=None):
        # Get a line of text from the serial port
        sample_string = self.ser.readline()

        # Add the line to the log text box
        self.log_text.AppendText(sample_string)

        # If the line is the right length, parse it
        if len(sample_string) == 24:
            sample_string = sample_string[0:-1]
            sample_values = sample_string.split()

            for m in range(self.M):
                # get one value from sample
                value = int(sample_values[m])
                self.x[m][0:99] = self.x[m][1:]
                self.x[m][99] = value

            # Update plot
            self.ax.cla()
            self.ax.autoscale(True)
            self.ax.set_xlim(0, self.N - 1)
            self.ax.set_ylim(-50, 1100)
            for m in range(self.M):
                self.ax.plot(self.n, self.x[m])
            self.canvas.draw()

    def onStartStopButton(self, event):
        if not self.isLogging:
            self.isLogging = True
            try:
                self.ser = serial.Serial("/dev/ttyUSB0",
                                         19200,
                                         8,
                                         'N',
                                         1,
                                         timeout=5)
            except:
                print "Error opening COM port.  Quitting."
                sys.exit(0)
            #self.ser = serial.Serial()
            #self.ser.baudrate = 19200
            #self.ser.timeout=0.25
            # We are going to assume a USBSerial adapter
            # which should be ttyUSBx, with x being the port number
            #self.ser.port = serial
            #for m in range(29, 0, -1):
            #self.ser.port = m
            #try:
            # Try this port number
            #self.ser.open()
            # We only get to here if port opened
            #self.log_text.AppendText(
            #	'Opened COM' + str(m+1) + '...\n')
            #break
            #except:
            # We end up here if this port number
            # failed to open
            #pass
            if self.ser.isOpen():
                # We successfully opened a port, so start
                # a timer to read incoming data
                self.timer.Start(100)
                self.start_stop_button.SetLabel("Stop")
        else:
            self.timer.Stop()
            self.ser.close()
            self.isLogging = False
            self.start_stop_button.SetLabel("Start")
Esempio n. 4
0
class MyFrame1(wx.Frame):
    def __init__(self, parent, pathToImage=None):
        wx.Frame.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          title="明日方舟关卡管理",
                          pos=wx.DefaultPosition,
                          size=wx.Size(900, 630),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        # relative data
        self.cls_path = "./digits_ymjh3.pkl"
        self.clf, self.pp = joblib.load(self.cls_path)
        self.cut_img = None
        self.origin_img = None
        self.handle = None
        self.draws = []
        self.guanqia_save = {}
        self.TotalChapter = [
            u'chapter1', u'chapter2', u'chapter3', u'chapter4', u'chapter5',
            u'活动'
        ]  # 第一级菜单
        # Use English dialog
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)

        # Create the fisrt canvas Create an axes, turn off the labels and add them to the figure
        self.figure = Figure(facecolor='gray')
        self.axes = plt.Axes(self.figure, [0, 0, 1, 1])
        self.axes.set_axis_off()
        self.figure.add_axes(self.axes)

        # Add the figure to the wxFigureCanvas
        self.canvas = FigureCanvas(self, -1, self.figure)
        # self.canvas.SetSize((320,480))
        # result = self.canvas.GetScreenRect()

        # Create the second canvas for preshow the figure
        self.figure2 = Figure(facecolor='gray')
        self.axes2 = plt.Axes(self.figure2, [0, 0, 1, 1])
        self.axes2.set_axis_off()
        self.figure2.add_axes(self.axes2)
        self.canvas2 = FigureCanvas(self, -1, self.figure2)
        self.canvas2.SetSize((160, 120))
        self.canvas2.SetPosition((710, 360))
        # Add Button and Progress Bar
        self.openBtn = wx.Button(self,
                                 -1,
                                 "打开文件",
                                 pos=(650, 10),
                                 size=(70, 40))
        self.simBtn = wx.Button(self,
                                -1,
                                "模拟器图像载入",
                                pos=(740, 10),
                                size=(100, 40))
        self.srcBtn = wx.Button(self,
                                -1,
                                "查看截图",
                                pos=(180, 500),
                                size=(150, 50))
        self.saveBtn = wx.Button(self,
                                 -1,
                                 "保存截图",
                                 pos=(360, 500),
                                 size=(150, 50))
        self.matchBtn = wx.Button(self,
                                  -1,
                                  "开始图像匹配",
                                  pos=(650, 150),
                                  size=(80, 40))
        # self.check = wx.CheckBox(self, -1, "一级菜单", pos=(650, 340), size=(70, 20))
        # self.chapterChoice = wx.Choice(self, wx.ID_ANY, (650, 365), (80, 30), self.TotalChapter, 0)
        # self.chapterChoice.SetSelection(0)
        # self.inputIntroText = wx.StaticText(self, -1, u"关卡或章节(活动)名称", pos=(730, 340), size=(175, 25))
        # self.inputText = wx.TextCtrl(self, -1, "", pos=(740, 365), size=(120, 25))
        # self.saveBtn = wx.Button(self, -1, "保存截图", pos=(760, 430), size=(100, 50))
        # yuanshi_choiceChoices = [u"No!", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10"]
        # self.yuanshi_choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, yuanshi_choiceChoices, 0)
        # self.yuanshi_choice.SetSelection(0)
        #self.scoreText = wx.StaticText(self, wx.ID_ANY, u"识图分数:", (650, 120), (60, 40), 0)
        #self.scoreText2 = wx.StaticText(self, wx.ID_ANY, u"", (710, 120), (50, 40), 0)
        self.scoreText3 = wx.StaticText(self, wx.ID_ANY, u"截图来源分辨率:",
                                        (650, 110), (100, 40), 0)
        self.scoreText4 = wx.StaticText(self, wx.ID_ANY, u"", (750, 110),
                                        (80, 40), 0)
        self.scoreText5 = wx.StaticText(self, wx.ID_ANY, u"模拟器分辨率:", (650, 70),
                                        (100, 40), 0)
        self.scoreText6 = wx.StaticText(self, wx.ID_ANY, u"", (750, 70),
                                        (80, 40), 0)
        self.scoreText7 = wx.StaticText(self, wx.ID_ANY, u"图像预览", (650, 410),
                                        (50, 40), 0)
        self.scoreText8 = wx.StaticText(self, wx.ID_ANY, u"", (750, 150),
                                        (120, 60), 0)
        image = matplotlib.image.imread('789.jpg')
        self.axes2.imshow(image, aspect='equal')
        self.canvas2.draw()
        # image = wx.Image('789.jpg',wx.BITMAP_TYPE_JPEG)
        # tmp = image.ConvertToBitmap()
        # self.pic = wx.StaticBitmap(self,wx.ID_ANY,pos=(750,370),size=(120,120),bitmap=tmp)
        guanqia_pic, _ = config_ark.get_guanqia_pic()
        huodong_pic, _ = config_ark.get_huodong_pic()
        self.guanqia_dict = config_ark.get_guanqia(guanqia_pic, huodong_pic)
        self.tree = wx.TreeCtrl(self,
                                id=wx.ID_ANY,
                                pos=(650, 220),
                                size=(220, 130))

        # load the root infor
        root = self.tree.AddRoot('root')
        for i in self.guanqia_dict.keys():
            total_class = self.tree.AppendItem(root, i)
            for j in self.guanqia_dict[i].keys():
                chapter = self.tree.AppendItem(total_class, j)
                for k in self.guanqia_dict[i][j]:
                    self.tree.AppendItem(chapter, k)
        self.tree.Expand(root)

        # load the basic pic infor
        basic_pic = self.tree.AppendItem(root, 'basic')
        self.pic_confirm, self.pic_confirm_res = config_ark.get_confirm_pic()
        self.pic_where, self.pic_where_res = config_ark.get_where_pic()
        for i in list(self.pic_where.keys()):
            self.tree.AppendItem(basic_pic, i)
        for i in list(self.pic_confirm.keys()):
            self.tree.AppendItem(basic_pic, i)

        # for i in self.

        # bind the buttons
        self.Bind(wx.EVT_BUTTON, self.get_score, self.matchBtn)
        self.Bind(wx.EVT_BUTTON, self.show_cut_img, self.srcBtn)
        self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.tree_r_click, self.tree)
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.tree_d_click, self.tree)
        self.Bind(wx.EVT_BUTTON, self.save_pic, self.saveBtn)
        self.Bind(wx.EVT_BUTTON, self.getSimPic, self.simBtn)
        self.Bind(wx.EVT_BUTTON, self.load, self.openBtn)

        # Initialise the rectangle
        self.rect = Rectangle((0, 0), 0, 0, facecolor='None', edgecolor='red')
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.axes.add_patch(self.rect)

        # The list of the picture(absolute path)
        self.fileList = []

        # Picture name
        self.picNameList = []

        # Picture index in list
        self.count = 0

        # Cut from the picture of the rectangle
        self.cut_img = None

        # Connect the mouse events to their relevant callbacks
        self.canvas.mpl_connect('button_press_event', self._onPress)
        self.canvas.mpl_connect('button_release_event', self._onRelease)
        self.canvas.mpl_connect('motion_notify_event', self._onMotion)

        # Lock to stop the motion event from behaving badly when the mouse isn't pressed
        self.pressed = False

        # If there is an initial image, display it on the figure
        if pathToImage is not None:
            self.setImage(pathToImage)

    #图像匹配
    def get_score(self, event):
        # if self.handle==None:
        #     self.handle = get_handle()
        # im = prtsc(self.handle)
        if isinstance(self.origin_img, np.ndarray) and isinstance(
                self.cut_img, np.ndarray):
            pass
        else:
            wx.MessageBox("请先载入并裁剪相应图像")
            return
        im = self.origin_img
        #changed to BGR aligned to the cv2
        #im = im [:,:,::-1]
        window_resolution = globalvar.get_window_resolution()
        max_resolution = self.origin_res
        match_im = config_ark.pic_resize(self.cut_img, window_resolution,
                                         max_resolution)
        # str_results = pytesseract.image_to_string(match_im,lang='eng')
        # point1, point2, point3, point4 = config_ark.baitan_price
        # im_crop = im[point2 - config_ark.ymjh_pc_shift[1]:point4 - config_ark.ymjh_pc_shift[1], point1 - config_ark.ymjh_pc_shift[0]:point3 - config_ark.ymjh_pc_shift[0], :]
        # thresh = [[220,255], [220,255], [220,255]]  # RGB
        # im_gray = cv2.cvtColor(im_crop.copy(), cv2.COLOR_BGR2GRAY)
        # im_thresh = threshhold(im_crop, thresh)
        # im_thresh = cv2.cvtColor(im_thresh.copy(), cv2.COLOR_BGR2GRAY)
        # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
        # # im_dilated = cv2.dilate(im_thresh, (3, 3))
        # im_erode = cv2.erode(im_thresh, kernel)
        # # cv2.imshow("123", im_crop)
        # # cv2.waitKey()
        # results = cfs(im_erode)
        # value_result = 0
        # for rect in results:
        #     roi1 = im_gray[:, rect[0]:rect[1]]
        #     # roi = np.transpose(roi,(1,0))
        #     roi = fillout(roi1)
        #     if isinstance(roi, np.ndarray) == False:
        #         continue
        #     roi_hog_fd = hog(roi.copy(), orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1),
        #                      visualise=False)
        #     roi_hog_fd = self.pp.transform(np.array([roi_hog_fd], 'float64'))
        #     nbr = self.clf.predict(roi_hog_fd)
        #     value_result = value_result * 10
        #     value_result += int(nbr[0])
        #     save_digits(roi,int(nbr[0]))
        #     # cv2.imshow("123",roi1)
        #     # cv2.waitKey()
        # print(value_result)

        point1, point2, point3, point4 = config_ark.yinliang_pos
        im_crop = im[point2 - config_ark.ymjh_pc_shift[1]:point4 -
                     config_ark.ymjh_pc_shift[1],
                     point1 - config_ark.ymjh_pc_shift[0]:point3 -
                     config_ark.ymjh_pc_shift[0], :]
        thresh = [[120, 200], [120, 200], [120, 200]]  # RGB
        im_gray = cv2.cvtColor(im_crop.copy(), cv2.COLOR_BGR2GRAY)
        im_thresh = threshhold(im_crop.copy(), thresh)
        im_thresh = cv2.cvtColor(im_thresh.copy(), cv2.COLOR_BGR2GRAY)
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
        # im_dilated = cv2.dilate(im_thresh, (3, 3))
        im_erode = cv2.erode(im_thresh, kernel)
        cv2.imshow("123", im_thresh)
        cv2.waitKey()
        results = cfs(im_erode)
        value_result = 0
        for rect in results:
            roi1 = im_gray[rect[2]:rect[3], rect[0]:rect[1]]
            # roi = np.transpose(roi,(1,0))
            roi = fillout(roi1)
            if isinstance(roi, np.ndarray) == False:
                continue
            roi_hog_fd = hog(roi.copy(),
                             orientations=9,
                             pixels_per_cell=(14, 14),
                             cells_per_block=(1, 1),
                             visualise=False)
            roi_hog_fd = self.pp.transform(np.array([roi_hog_fd], 'float64'))
            nbr = self.clf.predict(roi_hog_fd)
            value_result = value_result * 10
            value_result += int(nbr[0])
            save_digits(roi, int(nbr[0]))
            # cv2.imshow("123",roi1)
            # cv2.waitKey()
        print("当前银两{}".format(value_result))

        self.scoreText8.SetLabel("{}".format(value_result))
        results = pic_locate(match_im, im, 0.8, True, True)
        if results:
            for i in results:
                pos = i['rectangle'][0]
                width = i['rectangle'][2][0] - i['rectangle'][0][0]
                height = i['rectangle'][1][1] - i['rectangle'][0][1]
                # Draw the bounding rectangle
                #self.rect = Rectangle((0, 0), 0, 0, facecolor='None', edgecolor='red')
                #self.axes.add_patch(self.rect)
                tmp_rect = Rectangle((0, 0),
                                     0,
                                     0,
                                     facecolor='None',
                                     edgecolor='red')
                tmp_rect.set_width(width)
                tmp_rect.set_height(height)
                tmp_rect.set_xy(pos)
                self.axes.add_patch(tmp_rect)
                #tmp_rect.remove()
                self.draws.append(tmp_rect)
                #self.text = plt.text(pos[0],pos[1],"{0:.4f}".format(i['confidence']))
                tmp_text = self.axes.text(pos[0],
                                          pos[1],
                                          "{0:.3f}".format(i['confidence']),
                                          fontdict={
                                              'color': 'red',
                                              'size': 12
                                          },
                                          bbox=dict(facecolor='white',
                                                    alpha=0.8))
                #tmp_text.remove()
                self.draws.append(tmp_text)
            self.canvas.draw()
            for j in self.draws:
                j.remove()
            self.draws = []
        else:
            wx.MessageBox("模拟器中没有包含所选图像")

    def getSimPic(self, event):
        # 获取模拟器当前图像信息
        self.handle = get_handle(order=0, sim="一梦江湖")
        im = prtsc(self.handle)
        im = im[:, :, ::-1]
        self.origin_img = im
        self.origin_res = [self.origin_img.shape[1], self.origin_img.shape[0]]
        self.scoreText6.SetLabel('{},{}'.format(self.origin_res[0],
                                                self.origin_res[1]))
        self.setImage(im)

    # GetFilesPath with the end with .jpg or .png
    def getFilesPath(self, path):
        filesname = []
        dirs = os.listdir(path)
        for i in dirs:
            if os.path.splitext(i)[1] == ".jpg" or os.path.splitext(
                    i)[1] == ".png":
                filesname += [path + "/" + i]
                self.picNameList += [i[:-4]]
        return filesname

    # Load Picture button function
    def load(self, event):
        filesFilter = "PNG file(*.png)|*.png|All files (*.*)|*.*"
        dlg = wx.FileDialog(self,
                            "choose pic",
                            defaultDir=get_dir('root'),
                            wildcard=filesFilter,
                            style=wx.DD_DEFAULT_STYLE)
        # dlg = wx.DirDialog(self,"Choose File",style=wx.DD_DEFAULT_STYLE)
        if dlg.ShowModal() == wx.ID_OK:
            filepath = dlg.GetPath()
            if filepath:
                self.origin_img = cv2.imdecode(
                    np.fromfile(filepath, dtype=np.uint8), cv2.IMREAD_COLOR)
                #self.origin_img = cv2.imread(filepath)
                self.setImage(filepath)
                #self.origin_res = [self.origin_img.shape[1],self.origin_img.shape[0]]
                self.scoreText4.SetLabel('{},{}'.format(
                    self.origin_res[0], self.origin_res[1]))
            else:
                print("list null")
        dlg.Destroy()

    # save the cut pic to disk
    def save_pic(self, event):
        if isinstance(self.cut_img, np.ndarray):
            dlg = wx.FileDialog(self,
                                message=u"保存文件",
                                defaultDir=get_dir('pic'),
                                defaultFile=".png",
                                wildcard='PNG file(*.png)|*.png',
                                style=wx.FD_SAVE)
            if dlg.ShowModal() == wx.ID_OK:
                file_name = dlg.GetFilename()
                dir_name = dlg.GetDirectory()
                save_file = os.path.join(dir_name, file_name)
                if os.path.isfile(save_file):
                    tmp = wx.MessageBox("文件已存在,是否覆盖?", "确认", wx.CANCEL | wx.OK)
                    if tmp == wx.OK:
                        cv2.imencode('.png', self.cut_img)[1].tofile(save_file)
                else:
                    cv2.imencode('.png', self.cut_img)[1].tofile(save_file)
        else:
            wx.MessageBox('请先截图')

    #双击tree时触发
    def tree_d_click(self, event):
        tmp_parent = self._get_tree_struct()
        num_parent = len(tmp_parent)
        if num_parent > 1:
            if 'basic' in tmp_parent:
                if num_parent > 2:
                    img_path = config_ark.get_basic_path(tmp_parent[-1])
                    img_res = config_ark.get_basic_res(tmp_parent[-1])
                    if os.path.exists(img_path):
                        image = cv2.imdecode(
                            np.fromfile(img_path, dtype=np.uint8),
                            cv2.IMREAD_COLOR)
                        #image = self.cut_img
                        image = image[:, :, ::-1]
                        self.axes2.imshow(image, aspect='equal')
                        self.canvas2.draw()
                        #载入图像分辨率信息
                        #self.scoreText4.SetLabel('{},{}'.format(img_res[0],img_res[1]))
                        #self.origin_res = img_res
                    else:
                        wx.MessageBox(
                            'img_file {} doesn\'t exsit'.format(img_path))
            else:
                if tmp_parent[1] == '活动':
                    huodong = True
                else:
                    huodong = False
                if num_parent == 4:
                    tmp = config_ark.ChapterCTE(
                        tmp_parent[1]
                    ) + '|' + tmp_parent[2] + "|" + tmp_parent[3]
                elif num_parent == 3:
                    tmp = config_ark.ChapterCTE(
                        tmp_parent[1]) + '|' + tmp_parent[2]
                elif num_parent == 2:
                    tmp = config_ark.ChapterCTE(tmp_parent[1])
                if num_parent == 4:
                    dialog = SubclassDialog()
                    result = dialog.ShowModal()
                    if result == wx.ID_CANCEL:
                        img_path = config_ark.get_img_path(
                            tmp + '_confirm', huodong)
                        tmp_res = config_ark.get_img_res(
                            tmp + '_confirm', huodong)
                    else:
                        img_path = config_ark.get_img_path(tmp, huodong)
                        tmp_res = config_ark.get_img_res(tmp, huodong)
                else:
                    img_path = config_ark.get_img_path(tmp, huodong)
                    tmp_res = config_ark.get_img_res(tmp, huodong)
                if os.path.exists(img_path):
                    image = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8),
                                         cv2.IMREAD_COLOR)
                    #image = self.cut_img
                    image = image[:, :, ::-1]
                    self.axes2.imshow(image, aspect='equal')
                    self.canvas2.draw()
                    #载入图像分辨率信息
                    #self.scoreText4.SetLabel('{},{}'.format(tmp_res[0],tmp_res[1]))
                    #self.origin_res = tmp_res
                else:
                    wx.MessageBox(
                        'img_file {} doesn\'t exsit'.format(img_path))

    #右键tree时触发
    def tree_r_click(self, event):
        pos = event.GetPoint()
        pos_ctrl = self.tree.GetPosition()
        pos = pos + pos_ctrl
        items = event.GetItem()
        tmp_parent = self._get_tree_struct()
        self.popmenu = wx.Menu()
        num_level = len(tmp_parent)
        if "basic" in tmp_parent:
            if num_level is 3:
                tmp = self.popmenu.Append(-1, '载入相关图库')
                self.Bind(wx.EVT_MENU, self.show_pic, tmp)
                tmp = self.popmenu.Append(-1, '修改相关图库')
                #need complete
                self.Bind(wx.EVT_MENU, self.save_pic, tmp)
        else:
            if ("剿灭作战" in tmp_parent) and num_level == 2:
                num_level = 3
            if num_level is 2:
                self.popmenu.Append(-1, '修改图库')
                tmp = self.popmenu.Append(-1, '载入图库')
                self.Bind(wx.EVT_MENU, self.show_pic, tmp)
                tmp = self.popmenu.Append(-1, '添加章节')
                self.Bind(wx.EVT_MENU, self.save_chapter, tmp)
            elif num_level is 3:
                self.popmenu.Append(-1, '重命名')
                tmp = self.popmenu.Append(-1, '载入章节图库')
                self.Bind(wx.EVT_MENU, self.show_pic, tmp)
                tmp = self.popmenu.Append(-1, '添加关卡图库')
                self.Bind(wx.EVT_MENU, self.save_guanqia, tmp)
                tmp = self.popmenu.Append(-1, '添加关卡确认图库')
                self.Bind(wx.EVT_MENU, self.save_guanqia_confirm, tmp)
                tmp = self.popmenu.Append(-1, '删除章节')
                self.Bind(wx.EVT_MENU, self.delete_item, tmp)
            elif num_level is 4:
                self.popmenu.Append(-1, '重命名')
                tmp = self.popmenu.Append(-1, '载入关卡图库')
                self.Bind(wx.EVT_MENU, self.show_pic, tmp)
                tmp = self.popmenu.Append(-1, '删除关卡')
                self.Bind(wx.EVT_MENU, self.delete_item, tmp)
        self.PopupMenu(self.popmenu, pos)
        #self.tree.Get

    #双击tree控件时显示对应库中的图库,并自动载入到可以供识图的变量中
    def show_pic(self, event):
        tmp_parent = self._get_tree_struct()
        num_parent = len(tmp_parent)
        if 'basic' in tmp_parent:
            img_path = config_ark.get_basic_path(tmp_parent[-1])
            img_res = config_ark.get_basic_res(tmp_parent[-1])
            if os.path.exists(img_path):
                self.cut_img = cv2.imdecode(
                    np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_COLOR)
                cv2.destroyAllWindows()
                cv2.imshow('cut_image', self.cut_img)
                #载入图像分辨率信息
                self.scoreText4.SetLabel('{},{}'.format(
                    img_res[0], img_res[1]))
                self.origin_res = img_res
            else:
                wx.MessageBox('img_file {} doesn\'t exsit'.format(img_path))
        else:
            if tmp_parent[1] == '活动':
                huodong = True
            else:
                huodong = False
            if num_parent == 4:
                tmp = config_ark.ChapterCTE(
                    tmp_parent[1]) + '|' + tmp_parent[2] + "|" + tmp_parent[3]
            elif num_parent == 3:
                tmp = config_ark.ChapterCTE(
                    tmp_parent[1]) + '|' + tmp_parent[2]
            elif num_parent == 2:
                tmp = config_ark.ChapterCTE(tmp_parent[1])
            if num_parent == 4:
                dialog = SubclassDialog()
                result = dialog.ShowModal()
                if result == wx.ID_CANCEL:
                    img_path = config_ark.get_img_path(tmp + '_confirm',
                                                       huodong)
                    tmp_res = config_ark.get_img_res(tmp + '_confirm', huodong)
                else:
                    img_path = config_ark.get_img_path(tmp, huodong)
                    tmp_res = config_ark.get_img_res(tmp, huodong)
            else:
                img_path = config_ark.get_img_path(tmp, huodong)
                tmp_res = config_ark.get_img_res(tmp, huodong)
            if os.path.exists(img_path):
                self.cut_img = cv2.imdecode(
                    np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_COLOR)
                #self.cut_img = cv2.imread(img_path.encode('gbk').decode())
                cv2.destroyAllWindows()
                cv2.imshow('cut_image', self.cut_img)
                #载入图像分辨率信息
                self.scoreText4.SetLabel('{},{}'.format(
                    tmp_res[0], tmp_res[1]))
                self.origin_res = tmp_res
            else:
                wx.MessageBox('img_file {} doesn\'t exsit'.format(img_path))

    def save_chapter(self, event):
        if isinstance(self.cut_img, np.ndarray):
            pass
        else:
            wx.MessageBox("请先截图!")
            return
        tmp_str = self.tree.GetItemText(self.tree.GetSelection())
        #parent = self._get_tree_struct()
        dialog = wx.TextEntryDialog(None,
                                    "请输入添加章节的名称",
                                    "图库添加",
                                    "",
                                    style=wx.OK | wx.CANCEL)
        # 检查名称是否重名
        while (1):
            if dialog.ShowModal() == wx.ID_OK:
                name = dialog.GetValue()

                children = TREE.get_children(self.tree,
                                             self.tree.GetSelection())
                parent = self._get_tree_struct()
                if name in children:
                    wx.MessageBox("输出章节名称与当前存在章节名称重复,请重新输入!")
                else:
                    if tmp_str == "活动":
                        file_name = os.path.join(config_ark.huodong_path, name)
                    else:
                        file_name = os.path.join(config_ark.guanqia_path, name)
                    name_all = config_ark.ChapterCTE(parent[1]) + '|' + name
                    tmp_file = file_name
                    cnt = 0
                    while (1):
                        # 检查保存文件是否重名
                        if os.path.isfile(tmp_file + '.png'):
                            tmp_file = file_name + "{}".format(cnt)
                            cnt += 1
                        else:
                            break
                    # 保存图片文件
                    cv2.imencode('.png',
                                 self.cut_img)[1].tofile(tmp_file + ".png")
                    if os.path.isfile(tmp_file + ".png"):
                        wx.MessageBox("图像保存成功,位置{}".format(tmp_file + ".png"))
                    #cv2.imwrite(tmp_file + '.png',self.cut_img)
                    # 更新配置文件及内存配置信息
                    if tmp_str == "活动":
                        config_path = os.path.join(config_ark.CONFIG_PATH,
                                                   'pic_huodong')
                        config_ark.huodong_pic[name_all] = tmp_file + ".png"
                        config_ark.huodong_pic_res[name_all] = self.origin_res
                    else:
                        config_path = os.path.join(config_ark.CONFIG_PATH,
                                                   "guanqia")
                        config_ark.guanqia_pic[name_all] = tmp_file + ".png"
                        config_ark.guanqia_pic_res[name_all] = self.origin_res
                    with open(config_path, 'a', encoding='utf-8') as file:
                        file.write("{} {} {} {}\n".format(
                            name_all, tmp_file + ".png", self.origin_res[0],
                            self.origin_res[1]))
                    file.close()
                    # 更新tree
                    new_item = self.tree.AppendItem(self.tree.GetSelection(),
                                                    name)
                    wx.MessageBox("图库添加成功")
                    break
            else:
                break

    def save_guanqia(self, event):
        if isinstance(self.cut_img, np.ndarray):
            pass
        else:
            wx.MessageBox("请先截图!")
            return
        tmp_str = self.tree.GetItemText(self.tree.GetSelection())
        parent = self._get_tree_struct()
        dialog = wx.TextEntryDialog(None,
                                    "请输入添加关卡的名称",
                                    "图库添加",
                                    "",
                                    style=wx.OK | wx.CANCEL)
        # 检查名称是否重名
        while (1):
            if dialog.ShowModal() == wx.ID_OK:
                name = dialog.GetValue()
                children = TREE.get_children(self.tree,
                                             self.tree.GetSelection())
                if name in children:
                    wx.MessageBox("输出关卡名称与当前存在关卡名称重复,请重新输入!")
                else:
                    save_dict = {}
                    if len(parent) == 3:
                        #若三级关卡
                        name_all = config_ark.ChapterCTE(
                            parent[1]) + '|' + parent[2] + "|" + name
                    elif len(parent) == 2:
                        #若为二级关卡
                        name_all = config_ark.ChapterCTE(
                            parent[1]) + '|' + name
                    if tmp_str == "活动":
                        file_name = os.path.join(config_ark.huodong_path, name)
                    else:
                        file_name = os.path.join(config_ark.guanqia_path, name)
                    tmp_file = file_name
                    cnt = 0
                    while (1):
                        # 检查保存文件是否重名
                        if os.path.isfile(tmp_file + '.png'):
                            tmp_file = file_name + "{}".format(cnt)
                            cnt += 1
                        else:
                            break

                    save_dict['image'] = self.cut_img
                    save_dict['image_save_path'] = tmp_file + ".png"
                    save_dict['name_all'] = name_all
                    save_dict['origin_res'] = self.origin_res
                    save_dict['tree_item'] = self.tree.GetSelection()
                    save_dict['tree_add_name'] = name
                    save_dict['tmp'] = tmp_str
                    self.guanqia_save[name] = save_dict
                    name_confirm = name + "_confirm"
                    if (name in self.guanqia_save) and (name_confirm
                                                        in self.guanqia_save):
                        self._save_guanqia(name)
                    else:
                        wx.MessageBox(
                            "{}关卡已保存至内存,请继续添加对应关卡的确认图库完整图库添加流程".format(name))
                    break
            else:
                break

    def save_guanqia_confirm(self, event):
        if isinstance(self.cut_img, np.ndarray):
            pass
        else:
            wx.MessageBox("请先截图!")
            return
        tmp_str = self.tree.GetItemText(self.tree.GetSelection())
        parent = self._get_tree_struct()
        dialog = wx.TextEntryDialog(None,
                                    "请输入添加关卡的名称",
                                    "图库添加",
                                    "",
                                    style=wx.OK | wx.CANCEL)
        # 检查名称是否重名
        while (1):
            if dialog.ShowModal() == wx.ID_OK:
                name_origin = dialog.GetValue()
                children = TREE.get_children(self.tree,
                                             self.tree.GetSelection())
                if name_origin in children:
                    wx.MessageBox("输出关卡名称与当前存在关卡名称重复,请重新输入!")
                else:
                    save_dict = {}
                    name = name_origin + "_confirm"
                    if len(parent) == 3:
                        name_all = config_ark.ChapterCTE(
                            parent[1]) + '|' + parent[2] + "|" + name
                    elif len(parent) == 2:
                        name_all = config_ark.ChapterCTE(
                            parent[1]) + '|' + name
                    if tmp_str == "活动":
                        file_name = os.path.join(config_ark.huodong_path, name)
                    else:
                        file_name = os.path.join(config_ark.guanqia_path, name)
                    tmp_file = file_name
                    cnt = 0
                    while (1):
                        # 检查保存文件是否重名
                        if os.path.isfile(tmp_file + '.png'):
                            tmp_file = file_name + "{}".format(cnt)
                            cnt += 1
                        else:
                            break
                    # 保存相关信息,若图及确认图都存在则添加
                    save_dict['image'] = self.cut_img
                    save_dict['image_save_path'] = tmp_file + ".png"
                    save_dict['name_all'] = name_all
                    save_dict['origin_res'] = self.origin_res
                    save_dict['tree_item'] = self.tree.GetSelection()
                    save_dict['tree_add_name'] = name_origin
                    save_dict['tmp'] = tmp_str
                    self.guanqia_save[name] = save_dict
                    if (name in self.guanqia_save) and (name_origin
                                                        in self.guanqia_save):
                        self._save_guanqia(name_origin)
                    else:
                        wx.MessageBox(
                            "{}关卡确认图库已保存至内存,请继续添加对应关卡的图库完整图库添加流程".format(
                                name_origin))
                    break
                    #wx.MessageBox("图库添加成功")
            else:
                break
        pass

    def delete_item(self, event):
        item_now = self.tree.GetSelection()
        #tmp_str = self.tree.GetItemText(item_now)
        parent = self._get_tree_struct()
        if len(parent) == 4:
            #删除关卡
            name = config_ark.ChapterCTE(
                parent[1]) + '|' + parent[2] + "|" + parent[3]
            name_confirm = config_ark.ChapterCTE(
                parent[1]) + '|' + parent[2] + "|" + parent[3] + "_confirm"
            if parent[1] == "活动":
                huodong = True
            else:
                huodong = False
            self._delete(name, huodong)
            self._delete(name_confirm, huodong)
            pass
        elif len(parent) == 3:
            #删除章节
            name = config_ark.ChapterCTE(parent[1]) + '|' + parent[2]
            if parent[1] == "活动":
                huodong = True
            else:
                huodong = False
            self._delete(name, huodong)
        else:
            #其余情况暂时不可能出现
            print("123")
            pass
        #删除tree控件
        self.tree.Delete(item_now)
        wx.MessageBox("{}删除成功".format(name))

    def _delete(self, name, huodong=False):
        if huodong:
            pic_path = config_ark.huodong_pic[name]
            config_ark.huodong_pic.pop(name)
            config_ark.huodong_pic_res.pop(name)
        else:
            pic_path = config_ark.guanqia_pic[name]
            config_ark.guanqia_pic.pop(name)
            config_ark.guanqia_pic_res.pop(name)
        os.remove(pic_path)
        print("删除成功{}".format(pic_path))
        config_path = os.path.join(config_ark.CONFIG_PATH, 'guanqia')
        with open(config_path, 'r', encoding='utf-8') as file:
            lines = file.readlines()
            for index, s in enumerate(lines):
                if s:
                    if s.split(" ")[0] == name:
                        lines.pop(index)
                        break
        file.close()
        with open(config_path, 'w', encoding='utf-8') as file:
            file.writelines(lines)
        file.close()
        print("配置文件信息删除成功{}".format(config_path))

    #若confirm及原图两个都被添加,则保存到本地
    def _save_guanqia(self, name):
        def _save(self, name):
            file_name = self.guanqia_save[name]['image_save_path']
            name_all = self.guanqia_save[name]['name_all']
            origin_res = self.guanqia_save[name]['origin_res']
            cut_img = self.guanqia_save[name]['image']
            cv2.imencode('.png', cut_img)[1].tofile(file_name)
            if os.path.isfile(file_name):
                wx.MessageBox("图像保存成功,位置{}".format(file_name))
            # cv2.imwrite(tmp_file + '.png',self.cut_img)
            # 更新配置文件及内存配置信息
            if self.guanqia_save[name]['tmp'] == "活动":
                config_path = os.path.join(config_ark.CONFIG_PATH,
                                           'pic_huodong')
                config_ark.huodong_pic[name_all] = file_name
                config_ark.huodong_pic_res[name_all] = origin_res
            else:
                config_path = os.path.join(config_ark.CONFIG_PATH, "guanqia")
                config_ark.guanqia_pic[name_all] = file_name
                config_ark.guanqia_pic_res[name_all] = origin_res
            with open(config_path, 'a', encoding='utf-8') as file:
                file.write("{} {} {} {}\n".format(name_all, file_name,
                                                  origin_res[0],
                                                  origin_res[1]))
            file.close()

        _save(self, name)
        _save(self, name + "_confirm")
        # 更新tree
        new_item = self.tree.AppendItem(self.guanqia_save[name]['tree_item'],
                                        name)
        wx.MessageBox("图库添加成功")

    #返回list,包含当前选中的节点及其父节点,父节点在前
    def _get_tree_struct(self):
        tmp_parent = []
        current_selection = self.tree.GetSelection()
        parent_text = self.tree.GetItemText(current_selection)
        tmp_parent.append(self.tree.GetItemText(current_selection))
        while (1):
            if parent_text == 'root':
                break
            current_selection = self.tree.GetItemParent(current_selection)
            parent_text = self.tree.GetItemText(current_selection)
            tmp_parent.insert(0, parent_text)
        return tmp_parent

    def _onPress(self, event):
        ''' Callback to handle the mouse being clicked and held over the canvas'''
        # Check the mouse press was actually on the canvas
        if event.xdata is not None and event.ydata is not None:
            # Upon initial press of the mouse record the origin and record the mouse as pressed
            self.pressed = True
            self.rect.set_linestyle('dashed')
            self.x0 = event.xdata
            self.y0 = event.ydata

    def _onRelease(self, event):
        '''Callback to handle the mouse being released over the canvas'''
        # Check that the mouse was actually pressed on the canvas to begin with and this isn't a rouge mouse
        # release event that started somewhere else
        if self.pressed:

            # Upon release draw the rectangle as a solid rectangle
            self.pressed = False
            self.rect.set_linestyle('solid')

            # Check the mouse was released on the canvas, and if it wasn't then just leave the width and
            # height as the last values set by the motion event
            if event.xdata is not None and event.ydata is not None:
                self.x1 = event.xdata
                self.y1 = event.ydata

            # Set the width and height and origin of the bounding rectangle
            self.boundingRectWidth = abs(self.x1 - self.x0)
            self.boundingRectHeight = abs(self.y1 - self.y0)
            self.boundingRectOrigin = (min(self.x0,
                                           self.x1), min(self.y0, self.y1))

            # Draw the bounding rectangle
            self.rect.set_width(self.boundingRectWidth)
            self.rect.set_height(self.boundingRectHeight)
            self.rect.set_xy(self.boundingRectOrigin)
            #self.text = plt.text(self.boundingRectOrigin[0],self.boundingRectOrigin[1],"0.9865")
            self.canvas.draw()

            # OpenCV cut picture(all number shoudle be integer)
            x = int(self.boundingRectOrigin[0])
            y = int(self.boundingRectOrigin[1])
            width = int(self.boundingRectWidth)
            height = int(self.boundingRectHeight)
            if isinstance(self.origin_img, np.ndarray) and width:
                self.cut_img = self.origin_img[y:y + height, x:x + width, :]
                self.origin_res = [
                    self.origin_img.shape[1], self.origin_img.shape[0]
                ]
                self.scoreText4.SetLabel("{},{}".format(
                    self.origin_res[0], self.origin_res[1]))
                #cv2.imshow('1231',self.origin_img)
                cv2.destroyAllWindows()
                cv2.imshow('cut_image', self.cut_img)
            else:
                print("Draw Null Rectangle")
                return

    def _onMotion(self, event):
        '''Callback to handle the motion event created by the mouse moving over the canvas'''
        # If the mouse has been pressed draw an updated rectangle when the mouse is moved so
        # the user can see what the current selection is
        if self.pressed:
            # Check the mouse was released on the canvas, and if it wasn't then just leave the width and
            # height as the last values set by the motion event
            if event.xdata is not None and event.ydata is not None:
                self.x1 = event.xdata
                self.y1 = event.ydata

            # Set the width and height and draw the rectangle
            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
            self.canvas.draw()

        # Show Picture
    def show_cut_img(self, event):
        if isinstance(self.cut_img, np.ndarray):
            cv2.destroyAllWindows()
            cv2.imshow('cut_image', self.cut_img)
        else:
            wx.MessageBox('cut_img doesn\'t exsit')

    def setImage(self, image):
        #image BGR need transpose first
        '''Sets the background image of the canvas'''
        # Clear the rectangle in front picture
        self.axes.text(100, 100, '', None)
        self.rect.set_width(0)
        self.rect.set_height(0)
        self.rect.set_xy((0, 0))
        self.canvas.draw()
        # plt.cla()
        # self.initCanvas()

        # Load pic by OpenCV
        # image=cv2.imread(pathToImage,1)

        # Load the image into matplotlib and PIL
        if isinstance(image, np.ndarray):
            image = image[:, :, ::-1]
        else:
            image = matplotlib.image.imread(image)

        self.axes.imshow(image, aspect='equal')

        self.canvas.draw()