def switch_mode(self) -> str: """Switch tagging mode""" if self.mode == 'single': #Single to Sets self.set_index.reset() self.picture_index.reset() if self.folders_names: self.pictures_names = model.build_file_list( model.SETS_DIR + self.folders_names[self.set_index]) self.picture_index.set_max(len(self.pictures_names) - 1) self.mode = 'sets' self.aux_tag_box.grid(row=1, sticky=tk.N + tk.S) self.main_tag_box.grid(row=0, sticky=tk.N + tk.S) self.menu.entryconfig(5, label="Sets") self.menu.insert_radiobutton( 1, label="Next set", command=lambda index_mod=+1: self.change_set(index_mod)) self.menu.insert_radiobutton( 1, label="Prev set", command=lambda index_mod=-1: self.change_set(index_mod)) self.display_wrapper(0) return "Sets" else: #Sets to Single self.picture_index.reset() self.aux_tag_box.grid_remove() self.main_tag_box.grid(row=0, rowspan=2, sticky=tk.N + tk.S) self.pictures_names = model.build_file_list(model.SOURCE_DIR) self.picture_index.set_max(len(self.pictures_names) - 1) self.mode = 'single' self.menu.delete(1, 2) self.menu.entryconfig(5, label="Single") self.display_wrapper(0) return "Single"
def reload_list(self): """Re-creates the file list depending on the mode, updates the display, and notifies the user""" self.picture_index.reset() if self.mode == 'single': self.pictures_names = model.build_file_list(model.SOURCE_DIR) self.picture_index.set_max(len(self.pictures_names) - 1) elif self.mode == 'set': self.set_index.reset() self.pictures_names = model.build_file_list( model.SETS_DIR + self.folders_names[self.set_index]) self.picture_index.set_max(len(self.pictures_names) - 1) self.display_wrapper(0) pop_up("List reloaded", self.parent)
def set_processing(self, picture_index: model.Index, set_index: model.Index, pictures_names: [str], folders_names: [str]) -> None: #moved to model """Processes a set. Creates a random id and adds it to the xml file. Moves the set folder to the target folder. Adds the tags to the xml file. Updates the display """ if picture_index + 1 != len(pictures_names) or not self.folders_names: self.display_wrapper(+1) else: #do the real processing folder_id = model.add_name(XML_FILE, "name") model.set_processing(folders_names[set_index], folder_id, self.main_tag_box.get(0.0, tk.END), pictures_names) print("added folder " + folder_id) self.main_tag_box.delete(0.0, tk.END) picture_index.reset() del folders_names[set_index] set_index.mod_max(-1) if folders_names: pictures_names.clear() #j'ai juré, gg les side effects pictures_names += model.build_file_list( model.SETS_DIR + folders_names[set_index]) # ^ d'un autre côté, c'est vrai que c'est plus simple, m'enfin merde picture_index.set_max(len(pictures_names) - 1) self.display_wrapper(0)
def __init__(self, parent: tk.Tk): tk.Frame.__init__(self, parent) self.parent = parent #To modify the root's attribute or call its methods self.pictures_names = model.build_file_list( model.SOURCE_DIR) #List of files to process self.picture_index = model.Index(max=len(self.pictures_names) - 1) self.folders_names = model.build_set_list() #List of sets to process self.set_index = model.Index(max=len(self.folders_names) - 1) self.gif_frames = [ImageTk] self.frame_index = model.Index(0) self.mode = 'single' #Single picture tagging vs sets tagging self.im: Image = None #--- GUI defining self.menu = tk.Menu(self) self.pic_display_canvas = tk.Canvas( self, background='#cccccc', offset='900,900') #Center canvas to display images to tag self.tagging_boxes = tk.Frame(self, background='blue', width=20) self.main_tag_box = tk.Text(self.tagging_boxes, width=20, height=0) #To input tags self.main_tag_box = AutoCompleteTextWidget("a", self.tagging_boxes, width=20, height=0) # TODO self.aux_tag_box = tk.Text( self.tagging_boxes, width=20, height=0) #To input image-specific tags in a set #--- GUI settings self.parent.config(menu=self.menu) self.parent.bind( '<F1>', lambda i: pop_up("Aide", self.parent)) #Instructions (NIY) self.parent.bind('<Control-z>', lambda i: self.rollback()) #Rollback (NIY) self.parent.bind('<Control-F5>', lambda i: self.reload_list()) self.pic_display_canvas.bind('<Button-1>', self.clicked_arrow) self.main_tag_box.bind('<Escape>', lambda i: self.processing_wrapper()) self.menu.add_radiobutton( label="Prev", command=lambda index_mod=-1: self.display_wrapper(index_mod)) self.menu.add_radiobutton( label="Next", command=lambda index_mod=+1: self.display_wrapper(index_mod)) self.menu.add_radiobutton(label="Tags", command=self.tag_display) self.menu.add_radiobutton(label="Settings", command=self.settings) self.menu.add_radiobutton(label="Single", command=lambda: self.switch_mode()) #--- GUI positioning self.tagging_boxes.rowconfigure(0, weight=2) self.tagging_boxes.rowconfigure(1, weight=1) self.main_tag_box.grid(row=0, rowspan=2, sticky=tk.N + tk.S) #,sticky=tk.N+tk.S self.tagging_boxes.grid(row=0, column=0, sticky=tk.N + tk.S) self.pic_display_canvas.grid(row=0, column=1) self.display_wrapper(0)
def change_set(self, index_mod: int) -> None: """Changes the current set (if there are sets to proces)""" self.set_index += index_mod self.picture_index.reset() if self.folders_names: self.pictures_names = model.build_file_list( model.SETS_DIR + self.folders_names[self.set_index]) self.picture_index.set_max(len(self.pictures_names) - 1) self.display_wrapper(0)