히스토리 무제한 보기/엑셀로 저장
#1
by highnoon1 - opened
12345625 unmodified lines3233343536373847 unmodified lines86878889909192931 unmodified line9596979899100101102103104105106107108109110111112113114115116117118import tkinter as tkimport tkinter.ttk as ttkfrom tkinter import filedialogimport osimport csvimport random25 unmodified linesimport pandas as pdimport webbrowserfrom collections import OrderedDictBASE_URL="https://api.novelai.net"copyright_keys = copyright_list_reformatted.copyright_listcharacter_keys = list(cd.character_dictionary.keys())47 unmodified linesdef history_queue(image, prompt, seed):global historyhistory.append([image, prompt, seed])if len(history) > 5:history.pop(0)def show_history():global history1 unmodified line# 새로운 toplevel 창 생성history_window = tk.Toplevel(window)history_window.title("History")# history_window에서 썸네일과 텍스트를 표시할 grid 설정for index, (image, prompt, seed) in enumerate(history):# 이미지를 썸네일로 변환image.thumbnail((192, 192)) # 가로 세로 100픽셀로 조정photo = ImageTk.PhotoImage(image)# 썸네일 이미지 라벨 생성image_label = tk.Label(history_window, image=photo)image_label.image = photo # 참조를 유지image_label.grid(row=index, column=0)# prompt와 seed를 결합한 텍스트 생성text_prompt = prompt + ' Seed: ' + str(seed)text_widget = tk.Text(history_window, height=10, width=75) # UI 사이즈에 맞게 width와 height 조절text_widget.insert('1.0', text_prompt)text_widget.grid(row=index, column=1)text_widget.config(state='disabled') # 텍스트 위젯을 읽기 전용으로 설정def generate(width, height, positive, negative, button):global temp_clipboard_image1234567825 unmodified lines3435363738394041424347 unmodified lines9192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431 unmodified line145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200import tkinter as tkimport tkinter.ttk as ttkfrom tkinter import filedialogfrom tkinter import Canvas, Scrollbar, Frame, Buttonfrom PIL import Image, ImageTkimport osimport csvimport random25 unmodified linesimport pandas as pdimport webbrowserfrom collections import OrderedDictimport platformimport iofrom openpyxl import Workbookfrom openpyxl.drawing.image import Image as OpenpyxlImageBASE_URL="https://api.novelai.net"copyright_keys = copyright_list_reformatted.copyright_listcharacter_keys = list(cd.character_dictionary.keys())47 unmodified linesdef history_queue(image, prompt, seed):global historyhistory.append([image, prompt, seed])def save_to_excel():workbook = Workbook()sheet = workbook.activesheet['A1'] = 'Prompt'sheet['B1'] = 'Seed'sheet['C1'] = 'Image'image_objects = [] # BytesIO 객체를 추적하기 위한 리스트# history 데이터를 반복하며 Excel에 저장for index, (pil_image, prompt, seed) in enumerate(history, start=1):row_num = index + 1 # 행 번호 (Excel 행은 1부터 시작)# 프롬프트와 시드 삽입sheet.cell(row=row_num, column=1, value=prompt)sheet.cell(row=row_num, column=2, value=seed)# PIL 이미지를 BytesIO 객체에 PNG 형식으로 저장output = io.BytesIO()pil_image.save(output, format='PNG')output.seek(0)image_objects.append(output) # 리스트에 추가# Openpyxl 이미지 생성 및 시트에 추가img = OpenpyxlImage(output)img.anchor = f'C{row_num}' # 이미지를 C열에 고정sheet.add_image(img)# 이미지 크기에 따라 행 높이 및 열 너비 조정scale_factor = 0.75sheet.row_dimensions[row_num].height = pil_image.height * scale_factorsheet.column_dimensions['C'].width = pil_image.width * scale_factor / 7# A열과 B열 크기 조정sheet.column_dimensions['A'].width = 50sheet.column_dimensions['B'].width = 15# 워크북 저장workbook.save("history_with_images.xlsx")# 모든 BytesIO 객체 닫기for img_obj in image_objects:img_obj.close()print("엑셀 파일에 저장됨")def show_history():global history1 unmodified line# 새로운 toplevel 창 생성history_window = tk.Toplevel(window)history_window.title("History")# 창의 크기history_window.geometry("1920x1080")# Scrollable Canvas 설정canvas = Canvas(history_window)scrollbar = Scrollbar(history_window, orient="vertical", command=canvas.yview)scrollable_frame = Frame(canvas)# 스크롤 이벤트 바인딩def _on_mousewheel(event):canvas.yview_scroll(int(-1*(event.delta/120)), "units")if platform.system() == "Windows":history_window.bind_all("<MouseWheel>", _on_mousewheel)else:history_window.bind_all("<Button-4>", _on_mousewheel)history_window.bind_all("<Button-5>", _on_mousewheel)def on_frame_configure(event):canvas.configure(scrollregion=canvas.bbox("all"))scrollable_frame.bind("<Configure>", on_frame_configure)canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")canvas.configure(yscrollcommand=scrollbar.set)# history_window에서 썸네일과 텍스트를 표시할 grid 설정for index, (image, prompt, seed) in enumerate(history):# 이미지를 썸네일로 변환image.thumbnail((192, 192))photo = ImageTk.PhotoImage(image)# 썸네일 이미지 라벨 생성image_label = tk.Label(scrollable_frame, image=photo)image_label.image = photo # 참조를 유지image_label.grid(row=index, column=0)# prompt와 seed를 결합한 텍스트 생성text_prompt = prompt + ' Seed: ' + str(seed)text_widget = tk.Text(scrollable_frame, height=10, width=75)text_widget.insert('1.0', text_prompt)text_widget.grid(row=index, column=1)text_widget.config(state='disabled') # 텍스트 위젯을 읽기 전용으로 설정save_button = Button(history_window, text="Save to Excel", command=save_to_excel)save_button.pack()# Canvas와 Scrollbar를 pack하여 UI에 추가canvas.pack(side="left", fill="both", expand=True)scrollbar.pack(side="right", fill="y")def generate(width, height, positive, negative, button):global temp_clipboard_image
Danbooru Prompt Selector/.py_version/prompt_selector_1215.py+90-8