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 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 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))
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_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" name_all = config_ark.ChapterCTE(parent[1])+ '|' + parent[2] + "|" + 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