def save(self): """Commits the image and annotation to new files. Saves the image and annotation as png files with an alpha channel for merging later. If the image is new, it also adds it to the database. """ # parameters for the PIL annotations done in tandem with the seen tkinter annotations self.font = ImageFont.truetype("calibrib.ttf", 20) bounds = self.screenshot_canvas.bbox("text") self.draw.text((bounds[0], bounds[1]), fill = 'white', font = self.font, text = self.text_annotation) #takes the bottom left coordinate of text and places the text on the pillow drawing if self.new == True: # if the image is being saved from LilSnippy FileManagement(self.folder_path).save_image(self.body_info, self.im, self.annotation) from markings import GridMark GridMark(self.marker_canvas, self.folder_path, self.body_info) else: # if the annotations are being edited from Image Viewer self.annotation.save(self.folder_path + self.body_info["annotation_file_name"]) self.destroy() number = FileManagement(self.folder_path).count_bodies(config.all_bodies, False, False, False, False) if number == 300: # opens a popup at 300 biondi bodies done done_screen = tk.Toplevel() done_screen.grab_set() success_label = tk.Label(done_screen, text = "You have finished annotating 300 bodies.") success_label.pack(side = 'top') close_button = tk.Button(done_screen, text = "OK", command = lambda: done_screen.destroy()) close_button.pack(side = "bottom")
def update_finished(self, grid_id): """Updates the database of a finished grid square. Sends the grid square over to the database to be marked as complete and be remembered for future use of the folder Args: grid_id (str): The grid square letter marked as complete """ fin = self.var_fin.get() FileManagement(self.folder_path).finish_grid(grid_id, fin) self.final_order = FileManagement(self.folder_path).get_grid()
def main(): # Get and prepare the input file file_manager = FileManagement() file = file_manager.input_file_get(assembler_file_path) assembler_list = file_manager.file_list_get(file) assembler_list = file_manager.remove_whitespaces(assembler_list) assembler_list_original = assembler_list.copy() #print(*assembler_list, sep = "\n") #file_manager.file_print(file) file_manager.input_file_close(file) #print(assembler_list) #input() decoder = Decoder() output_list, pattern = decoder.sequitur_algorithm(assembler_list) #pprint.pprint(output_list) #pprint.pprint(pattern) # Get the compression rates original_size = len(assembler_list_original) compressed_size = len(output_list) for i in pattern: compressed_size += len(pattern[i]) compression_rate = original_size / compressed_size #compression_rate = compressed_size / original_size space_saving = (1 - compressed_size / original_size) * 100 # Print out the results print("Original size: ", original_size) print("Compressed size: ", compressed_size) print("Compression rate ", compression_rate) print("Space saving {} %".format(space_saving))
def update_count(self): self.body_count.set( FileManagement(self.folder_path).count_bodies( config.all_bodies, False, False, False, False)) self.body_count_label.configure( text="{0} Bodies Annotated".format(self.body_count.get())) self.master.after(2000, self.update_count)
def delete_image(self, body_info): """Deletes current image. Deletes the currently selected image's data from the database and resets the information frame and button list to reflect the changes. Args: body_info (tuple): Tuple of the information of the body to be deleted """ name = body_info["body_name"] number = body_info["body_number"] time = body_info["time"] fm = FileManagement(self.folder_path) fm.delete_img(name, number) # refreshes the button list to reflect the new changes self._remake_button_list() self.filter() self.information_frame.destroy() # clear the body canvas self.biondi_image_canvas.delete("all") # deletes the associated marker on the gridfile tag = "m" + str(time) self.marker_canvas.delete(tag) self.marker_canvas.update()
def generalized_main(): FileManager = FileManagement() FileConsider = FileConsiderations() ZIPMetrics = GeneralMedianVals() DATEMetrics = GeneralMedianVals() input_file = sys.argv[1] output_path = sys.argv[2] report = FileManager.file_input(input_file) for line in report: FileConsider.set_flags(line) if FileConsider.check_flags() == False: continue elif FileConsider.check_flags() == "consider_for_zip": ZIPMetrics.medianvals(line, line[0], line[10][0:5]) ZIPMetrics.update_median_out(line[0], line[10][0:5]) continue elif FileConsider.check_flags() == "consider_for_date": DATEMetrics.medianvals(line, line[0], line[13]) continue elif FileConsider.check_flags() == "consider_for_zipdate": ZIPMetrics.medianvals(line, line[0], line[10][0:5]) ZIPMetrics.update_median_out(line[0], line[10][0:5]) DATEMetrics.medianvals(line, line[0], line[13]) continue FileManager.file_output(outputpath=output_path, outputname="medianvals_by_zip.txt", data=ZIPMetrics.median_out) DATEMetrics.calculate_medianvals() FileManager.file_output(outputpath=output_path, outputname="medianvals_by_date.txt", data=DATEMetrics.median_out)
def show_ignored(self): ignored = FileManagement(self.folder_path).query_all_ignored() if self.ignored_var.get() == False: for coords in ignored: tag = "i{0}{1}".format(coords[0], coords[1]) self.marker_canvas.delete(tag) else: for coords in ignored: GridIgnored(self.marker_canvas, self.folder_path, coords[0], coords[1])
def confirm(): """Exports images to folder_path. Takes case name and folder path and exports biondi images to the designated folder. """ if self.case_name.get() == "" or self.new_folder_path.get() == "/": return else: FileManagement(self.folder_path).export_case( self.new_folder_path.get(), self.case_name.get()) export.destroy()
def initiate_markers(self): """Initializes marker info in FileManagment. Creates a marker for every body on the application's startup. Iterates through the bodies in the database to do so. Also creates a marker for every ignored marker """ data = FileManagement(self.folder_path).query_images( config.all_bodies, False, False, False, False) for i in data: body_info = {} x = 0 for choice in ("time", "body_name", "body_number", "x", "y"): body_info[choice] = i[x] x += 1 GridMark(self.marker_canvas, self.folder_path, body_info) # generates ignored markers ignored = FileManagement(self.folder_path).query_all_ignored() for coord in ignored: GridIgnored(self.marker_canvas, self.folder_path, coord[0], coord[1])
def get_data(self): """Retrieves user inputs. Takes the user inputs from the popup and enters them into a data dictionary. This dictionary is later entered into the database. """ time_added = int(time()) body_file_name = str(self.body_type.get()) + "_" + str(time_added) annotation_file_name = body_file_name + "_ANNOTATION" fm = FileManagement(self.folder_path) data = { "time": time_added, "annotator_name": self.annotator.get(), "body_name": self.body_type.get(), "body_number": fm.count_bodies([self.body_type.get()], False, False, False, False) + 1, "x": self.canvas_x, "y": self.canvas_y, "grid_id": self.grid_id, "GR": self.var_GR.get(), "MAF": self.var_MAF.get(), "MP": self.var_MP.get(), "unsure": self.var_unsure.get(), "notes": self.notes.get(), "body_file_name": body_file_name + ".png", "annotation_file_name": annotation_file_name + ".png", "angle": None, "log": None, "dprong1": None, "lprong2": None } return data
def create_ignored_marker(event): """Event method that adds an ignored marker. x and y are the coords of where the mouse clicked. Then converted to canvas coordinates which is used to add a marker. """ x = event.x y = event.y canvas_x = self.marker_canvas.canvasx(x) canvas_y = self.marker_canvas.canvasy(y) coords = (canvas_x, canvas_y) GridIgnored(self.marker_canvas, self.folder_path, canvas_x, canvas_y) FileManagement(self.folder_path).add_ignored(coords)
def show_select_markers(self): """Toggles which markers get shown based on the filter Takes seconday_selection and body_selection and shows the markers based on those requirements from FileManagement. """ all_data = FileManagement(self.folder_path).query_images( config.all_bodies, False, False, False, False) for i in all_data: self.grid_canvas.delete("m" + str(i[0])) bodies = self._get_body_selection() secondary_selection = self._get_secondary_selection() data = FileManagement(self.folder_path).query_images( bodies, secondary_selection[0], secondary_selection[1], secondary_selection[2], secondary_selection[3]) for i in data: body_info = {} x = 0 for choice in ("time", "body_name", "body_number", "x", "y"): body_info[choice] = i[x] x += 1 GridMark(self.marker_canvas, self.folder_path, body_info)
def main(): FileManager = FileManagement() FileConsider = FileConsiderations() Metrics = MedianVals() input_file = sys.argv[1] output_path = sys.argv[2] #report = FileManager.file_input(input_file) report = (line.strip().split("|") for line in open(input_file, 'r')) for line in report: FileConsider.set_flags(line) if FileConsider.check_flags() == False: continue elif FileConsider.check_flags() == "consider_for_zip": Metrics.medianvals_by_zip(line) continue elif FileConsider.check_flags() == "consider_for_date": Metrics.medianvals_by_date(line) continue elif FileConsider.check_flags() == "consider_for_zipdate": Metrics.medianvals_by_zip(line) Metrics.medianvals_by_date(line) continue # for line in report: # FileConsider.set_flags(line) # if FileConsider.check_flags() == False: # continue # elif FileConsider.check_flags() == "consider_for_zip": # Metrics.medianvals_by_zip(line) # continue # elif FileConsider.check_flags() == "consider_for_date": # Metrics.medianvals_by_date(line) # continue # elif FileConsider.check_flags() == "consider_for_zipdate": # Metrics.medianvals_by_zip(line) # Metrics.medianvals_by_date(line) # continue FileManager.file_output(outputpath=output_path, outputname="medianvals_by_zip.txt", data=Metrics.medianzip_out) Metrics.calculate_medianvals_by_date() FileManager.file_output(outputpath=output_path, outputname="medianvals_by_date.txt", data=Metrics.mediandate_out)
def main(): FileManager = FileManagement() FileConsider = FileConsiderations() Metrics = MedianVals() input_file = sys.argv[1] output_path = sys.argv[2] #input_file = input_path #input_file = input_path + "itcont.txt" report = FileManager.file_input(input_file) #count = 0 #loop_time = time.time() for line in report: #if count % 1000 == 0: # print(str(count)+"th line, time per 1000 lines = ---- %s seconds ----" %(time.time() - loop_time)) # loop_time = time.time() #count += 1 FileConsider.set_flags(line) if FileConsider.check_flags() == False: continue elif FileConsider.check_flags() == "consider_for_zip": Metrics.medianvals_by_zip(line) continue elif FileConsider.check_flags() == "consider_for_date": Metrics.medianvals_by_date(line) continue elif FileConsider.check_flags() == "consider_for_zipdate": Metrics.medianvals_by_zip(line) Metrics.medianvals_by_date(line) continue #print('writing zips') FileManager.file_output(outputpath=output_path, outputname="medianvals_by_zip.txt", data=Metrics.medianzip_out) #print('calculating dates') #calculate_time = time.time() Metrics.calculate_medianvals_by_date() #print("time to calculate medianvals_by_date = ----------- %s seconds ------------" % (time.time() - calculate_time)) #print('writing dates') FileManager.file_output(outputpath=output_path, outputname="medianvals_by_date.txt", data=Metrics.mediandate_out)
def ok(self): if (self.l == []) | (self.d == None): return self.body_info["log"], self.body_info["dprong1"], self.body_info["lprong2"] = self.calc_log() if self.new: ScreenshotEditor(self.body_info, self.folder_path, self.marker_canvas, self.im, True) else: info = (self.body_info["body_name"], self.body_info["GR"], self.body_info["MAF"], self.body_info["MP"], self.body_info["unsure"], self.body_info["notes"], self.body_info["angle"], self.body_info["log"], self.body_info["dprong1"], self.body_info["lprong2"], self.body_info["time"]) FileManagement(self.folder_path).edit_info(info) self.destroy()
def open_file(self, time): """Brings up the relevant file information. When clicking a button, open_file brings up the annotation and body image to show in the biondi_image_canvas as well as shows the information about that specific body. Args: Time (int): Time added of selected body in unix time. """ body_info = FileManagement(self.folder_path).get_image_time(time) self.clear_information_canvas() self.show_information(body_info) self.open_annotation_image(body_info) self.marker_canvas.itemconfig("m" + str(time), fill="red") if self.previous_body_time != 0: self.marker_canvas.itemconfig("m" + str(self.previous_body_time), fill="white") self.previous_body_time = time
def create_buttons(self, body_param, GR_param, MAF_param, MP_param, unsure_param): """Creates the buttons in the button list. Create a series of buttons reflecting the filter options which the user can click to bring up the relevant information and images for the body selected. Args: body_param (list): A list of all the selected bodies for filtering. Enter self.all_bodies for a selection of all the body types. GR_param (bool): True if sorting by GR. MAF_param (bool): True if sorting by MAF. MP_param (bool): True if sorting by MP. unsure_param (bool): True if sorting by unsure. """ # queries a list of all the selected bodies fm = FileManagement(self.folder_path) data = fm.query_images(body_param, GR_param, MAF_param, MP_param, unsure_param) # loops through generating bodies for i in data: time = i[0] name = i[1] number = i[2] body_name = "{} {}".format(name, number) # each button takes a different command depending on its selected data btn = tk.Button(self.interior, height=1, width=20, relief=tk.FLAT, bg="gray99", fg="purple3", font="Dosis", text=body_name, command=lambda i=time: self.open_file(i)) btn.pack(padx=10, pady=5, side=tk.TOP)
def __init__(self, master, main_canvas, folder_path, width, height): tk.Frame.__init__(self) self.master = master self.main_canvas = main_canvas self.folder_path = folder_path self.final_order = FileManagement(self.folder_path).get_grid() self.width = width self.height = height self.rows = 7 self.columns = 7 bools = [ i[1] for i in self.final_order ] # creates a list of just the booleans of whether grid is finished self.i = next((i for i, j in enumerate(bools) if j == False), 0) # finds the first instance of false and jumps to that self.v = tk.StringVar() self.v.set(str(self.final_order[self.i][0])) self.text = tk.Label(self, text="Current Grid Square:") self.text.grid(row=0, column=1) self.current_grid = tk.Label(self, text=self.v.get()) self.current_grid.grid(row=1, column=1) self.forward_button = tk.Button(self, text=">", command=self.forward) self.forward_button.grid(row=2, column=2) self.backward_button = tk.Button(self, text="<", command=self.backward) self.backward_button.grid(row=2, column=0) self.jumpto_button = tk.Button(self, text="Jump to", command=self.move_canvas) self.jumpto_button.grid(row=2, column=1) self.make_check_button()
def confirm_function(self, name, folder_path, file_path, nf): """Initializes a new folder and creates a success label Calls FileManagement to initate a folder with a grid image file and annotator initials. Creates a success window on completion. Args: folder_path (str): Path to folder where images will be saved selected from the askdirectory. file_path (str): Path to the gridfile image to be copied into the saving folder. nf (tk.Toplevel): Toplevel window to select the folder path and file path. """ if folder_path == "" or file_path == "" or name == "": return nf.destroy() FileManagement(folder_path + "/").initiate_folder(file_path, name) done_screen = tk.Toplevel() success_label1 = tk.Label(done_screen, text="Folder sucessfully initialized!") success_label1.grid(row=0, column=0, sticky='nswe') def init_confirm(): done_screen.destroy() self.welcome_label1.destroy() self.welcome_label2.destroy() self.welcome_label3.destroy() self.button_frame.destroy() i = Application(root, path=folder_path) close_button = tk.Button(done_screen, text="OK", command=lambda: init_confirm()) close_button.grid(row=3, column=0, sticky='s')
def test_zero_padding7(self): file = FileManagement() file.name = 'E' file.zero_padding() self.assertEqual(file.name, 'E.py')
def __init__(self, mainframe, path): self.master = mainframe #initializes the main frame tk.Frame.__init__(self, master=mainframe) self.master.title('Imaris Screenshot Tool') self.folder_path = path + "/" #coord bar self.mousex = tk.IntVar(value=0) self.mousey = tk.IntVar(value=0) self.coord_label = tk.Label(self.master, text="X: {0} Y: {1}".format( self.mousex.get(), self.mousey.get())) self.coord_label.grid(row=3, column=0, sticky="sw") # body count try: self.body_count = tk.IntVar( value=FileManagement(self.folder_path).count_bodies( config.all_bodies, False, False, False, False)) except: # incase the case is not initiated error_screen = tk.Toplevel() error_screen.focus_get() error_label1 = tk.Label( error_screen, text="Unable to open file. May not be initialized.") error_label2 = tk.Label(error_screen, text="Press okay to exit the system.") error_label1.grid(row=0, column=0, sticky='nswe') error_label2.grid(row=2, column=0, sticky='nswe') close_button = tk.Button(error_screen, text="OK", command=lambda: sys.exit()) close_button.grid(row=3, column=0, sticky='s') self.body_count_label = tk.Label(self.master, text="{0} Bodies Annotated".format( self.body_count.get())) self.body_count_label.grid(row=3, column=0, sticky="se") self.update_count() # Create canvas and put image on it self.canvas = tk.Canvas(self.master, highlightthickness=0) self.marker_canvas = self.canvas self.grid_canvas = self.canvas self.canvas.grid(row=1, column=0, sticky='nswe') self.grid_canvas.grid(row=1, column=0, sticky='nswe') self.marker_canvas.grid(row=1, column=0, sticky='nswe') self.canvas.update() # wait till canvas is created vbar = tk.Scrollbar(self.master, orient='vertical', command=self.canvas.yview) hbar = tk.Scrollbar(self.master, orient='horizontal', command=self.canvas.xview) vbar.grid(row=1, column=1, sticky='ns') hbar.grid(row=2, column=0, sticky='we') self.canvas.configure(xscrollcommand=hbar.set, yscrollcommand=vbar.set, xscrollincrement='2', yscrollincrement='2') self.canvas.update() # Make the canvas expandable self.master.rowconfigure(1, weight=1) self.master.columnconfigure(0, weight=1) # Bind events to the Canvas self.canvas.bind('<MouseWheel>', self.verti_wheel) self.canvas.bind('<Shift-MouseWheel>', self.hori_wheel) self.canvas.bind('<Button-3>', self.open_popup) self.canvas.bind('<Motion>', self.update_coords) self.image = Image.open(self.folder_path + "gridfile.jpg") # open image self.width, self.height = self.image.size self.container = self.canvas.create_rectangle(0, 0, self.width, self.height, width=0) self.show_image() #self.master.geometry(str(600) + "x" + str(600)) self.rows = 7 self.columns = 7 self.create_grid() self.initiate_markers() #option bar self.option_bar = OptionBar(self.master, self.folder_path, self.marker_canvas, self.grid_canvas) self.option_bar.grid(row=0, column=0, sticky='nswe') #grid window grid_window = GridWindow(self.master, self.canvas, self.folder_path, self.width, self.height) grid_window.grid(row=4, column=0)
import os import shutil from paths import path_abc # 同フォルダに必要なパスが書かれたファイルを用意 from file_management import FileManagement for foldername, subfolders, filenames in os.walk(path_abc): for filename in filenames: file = FileManagement() file.path = foldername + '\\' + filename file.name = filename file.zero_padding() ''' shutil.move(hoge, fuga)はファイルやフォルダに対し移動及び名前の変更をするため、 print(hoge, fuga)で大丈夫なことを必ず確認した後にコメントアウトを消し、実行する ''' # shutil.move(file.path, foldername + '\\' + file.name) print(file.path, foldername + '\\' + file.name)
def _on_click(self, event): self.marker_canvas.delete(self.tag) coords = (self.canvas_x, self.canvas_y) FileManagement(self.folder_path).delete_ignored(coords)
help="Use compressed addresses", action='store_true', required=False) parser.add_argument('--version', action='version', version='Version : 1.01') args = parser.parse_args() if args.input: inputfile = args.input if args.output: outputfile = args.output # We initialize file management file = FileManagement(outputfile, inputfile) # A list with the contents of the dictionary is retrieved. wordlist = file.read_dictionary() # The scan object is initialized with the list of dictionary contents. scan = Scan(file, wordlist) # Start the scan and get the result. try: if args.compressed: print('Compressed Addresses : ON') result = scan.launch(compressed=True) else: result = scan.launch() # We write the result in a output file if not result: print('We didn\'t find anything !')
def test_zero_padding1(self): file = FileManagement() file.name = '1A' file.zero_padding() self.assertEqual(file.name, '001A.py')
def test_zero_padding3(self): file = FileManagement() file.name = '3AC' file.zero_padding() self.assertEqual(file.name, '3AC.py')
def test_zero_padding6(self): file = FileManagement() file.name = '100D' file.zero_padding() self.assertEqual(file.name, '100D.py')
def test_zero_padding5(self): file = FileManagement() file.name = '99F' file.zero_padding() self.assertEqual(file.name, '099F.py')
def __init__(self, master, canvas_x, canvas_y, marker_canvas, height, width, columns, rows, folder_path): self.master = master self.marker_canvas = marker_canvas self.height = height self.width = width self.columns = columns self.rows = rows self.canvas_x = canvas_x self.canvas_y = canvas_y self.folder_path = folder_path self.annotator = tk.StringVar( value=FileManagement(self.folder_path).get_annotator_name()) self.body_type = tk.StringVar() self.body_type.set("drop") self.var_GR = tk.BooleanVar() self.var_MAF = tk.BooleanVar() self.var_MP = tk.BooleanVar() self.var_unsure = tk.BooleanVar() self.grid_id = self.get_grid(self.canvas_x, self.canvas_y) self.notes = tk.StringVar() marker = tk.Toplevel() #create window marker.title("popup") marker.grab_set() dropdown = ttk.Combobox(marker, values=config.all_bodies, textvariable=self.body_type) grC = tk.Checkbutton(marker, text="GR", anchor="w", variable=self.var_GR, onvalue=True, offvalue=False) mafC = tk.Checkbutton(marker, text="MAF", anchor="w", variable=self.var_MAF, onvalue=True, offvalue=False) mpC = tk.Checkbutton(marker, text="MP", anchor="w", variable=self.var_MP, onvalue=True, offvalue=False) unsure = tk.Checkbutton(marker, text="UNSURE", variable=self.var_unsure, onvalue=True, offvalue=False) note_label = tk.Label(marker, text="Notes:") note_entry = tk.Entry(marker, textvariable=self.notes) button_ok = tk.Button(marker, text="OK", padx=5, pady=5, anchor="se", command=lambda: self.draw(marker)) annotator_entry = tk.Entry(marker, textvariable=self.annotator) dropdown.grid(row=0, column=0) grC.grid(row=0, column=1, sticky='w') mafC.grid(row=1, column=1, sticky='w') mpC.grid(row=2, column=1, sticky='w') unsure.grid(row=0, column=2) note_label.grid(row=3, column=0) note_entry.grid(row=3, column=1) button_ok.grid(row=4, column=2) annotator_entry.grid(row=4, column=0)
def test_zero_padding2(self): file = FileManagement() file.name = '02B' file.zero_padding() self.assertEqual(file.name, '02B.py')