import os
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
from pathlib import Path
import pyperclip
import configparser
import tkinter.colorchooser as colorchooser
class BBCodeGenerator:
def init(self, root):
self.root = root
self.root.title("JKF NAVIGATION BBCode GENERATOR")
# Lock the window
self.root.resizable(False, False) # Disable resizing
self.root.geometry("600x400") # Set a fixed size
# Initialize variables
self.hentai_title = ""
self.num_episodes = 0
self.menu_url = ""
self.last_url = "" # New variable to store last URL
self.table_color = "336699" # Default value for table color
self.letter_color_available = "Red" # Default value for letter color available
self.letter_color_unavailable = "RoyalBlue" # Default value for letter color unavailable
self.hentai_folder = "C:\\Users\\ewkya\\Desktop\\Temp\\COMIC" # Default folder path
self.start_mod_episode = 1
# Create UI elements
self.setup_ui()
# Define the style-to-button map here
self.style_to_button_map = {
'TableColor': 'simple_table_color_picker',
'LetterColor': 'simple_letter_color_picker',
}
# Create context menu
self.context_menu = tk.Menu(self.root, tearoff=0)
self.context_menu.add_command(label="Cut", command=self.cut)
self.context_menu.add_command(label="Copy", command=self.copy)
self.context_menu.add_command(label="Paste", command=self.paste)
self.context_menu.add_command(label="Clear", command=self.clear)
def setup_ui(self):
# Create tabs
tab_control = ttk.Notebook(self.root)
self.initial_setup_tab = ttk.Frame(tab_control)
self.complex_navigation_tab = ttk.Frame(tab_control)
self.simple_navigation_tab = ttk.Frame(tab_control)
tab_control.add(self.initial_setup_tab, text=' INITIAL SETUP ')
tab_control.add(self.complex_navigation_tab, text=' COMPLEX NAVIGATION CODE GENERATOR ')
tab_control.add(self.simple_navigation_tab, text=' SIMPLE NAVIGATION CODE GENERATOR ')
tab_control.pack(expand=1, fill='both')
# INITIAL SETUP Tab UI
self.setup_initial_setup_ui()
self.setup_complex_navigation_ui()
self.setup_simple_navigation_ui()
# Initialize context menu for each Entry widget
self.add_context_menu(self.title_entry)
self.add_context_menu(self.episodes_entry)
self.add_context_menu(self.menu_url_entry)
self.add_context_menu(self.table_color_entry)
self.add_context_menu(self.letter_color_available_entry)
self.add_context_menu(self.letter_color_unavailable_entry)
self.add_context_menu(self.folder_entry)
self.add_context_menu(self.ini_file_entry)
self.add_context_menu(self.url_entries[0])
self.add_context_menu(self.url_entries[1])
self.add_context_menu(self.url_entries[2])
self.add_context_menu(self.url_entries[3])
self.add_context_menu(self.simple_title_entry)
self.add_context_menu(self.simple_post_url_entry)
self.add_context_menu(self.simple_table_color_entry)
self.add_context_menu(self.simple_letter_color_entry)
self.add_context_menu(self.bbcode_history)
def add_context_menu(self, widget):
widget.bind("<Button-3>", self.show_context_menu)
def show_context_menu(self, event):
self.context_menu.post(event.x_root, event.y_root)
def cut(self):
entry = self.root.focus_get()
if isinstance(entry, tk.Entry) or isinstance(entry, tk.Text):
entry.event_generate("<<Cut>>")
def copy(self):
entry = self.root.focus_get()
if isinstance(entry, tk.Entry) or isinstance(entry, tk.Text):
entry.event_generate("<<Copy>>")
def paste(self):
entry = self.root.focus_get()
if isinstance(entry, tk.Entry) or isinstance(entry, tk.Text):
entry.event_generate("<<Paste>>")
def clear(self):
entry = self.root.focus_get()
if isinstance(entry, tk.Entry) or isinstance(entry, tk.Text):
entry.delete(0, tk.END) if isinstance(entry, tk.Entry) else entry.delete("1.0", tk.END)
def setup_initial_setup_ui(self):
# Hentai Title
ttk.Label(self.initial_setup_tab, text="Hentai Title:").place(x=5, y=5)
self.title_entry = ttk.Entry(self.initial_setup_tab)
self.title_entry.place(x=150, y=5, width=300, height=25)
# Number of Episodes
ttk.Label(self.initial_setup_tab, text="Number of Episodes:").place(x=5, y=35)
self.episodes_entry = ttk.Entry(self.initial_setup_tab)
self.episodes_entry.place(x=150, y=35, width=300, height=25)
# Menu URL
ttk.Label(self.initial_setup_tab, text="Menu URL:").place(x=5, y=65)
self.menu_url_entry = ttk.Entry(self.initial_setup_tab)
self.menu_url_entry.place(x=150, y=65, width=300, height=25)
# Table Color
ttk.Label(self.initial_setup_tab, text="Table Color:").place(x=5, y=95)
self.table_color_entry = ttk.Entry(self.initial_setup_tab)
self.table_color_entry.insert(0, self.table_color)
self.table_color_entry.place(x=150, y=95, width=300, height=25)
# Letter Color (ON)
ttk.Label(self.initial_setup_tab, text="Letter Color (ON):").place(x=5, y=125)
self.letter_color_available_entry = ttk.Entry(self.initial_setup_tab)
self.letter_color_available_entry.insert(0, self.letter_color_available)
self.letter_color_available_entry.place(x=150, y=125, width=300, height=25)
# Letter Color (OFF)
ttk.Label(self.initial_setup_tab, text="Letter Color (OFF):").place(x=5, y=155)
self.letter_color_unavailable_entry = ttk.Entry(self.initial_setup_tab)
self.letter_color_unavailable_entry.insert(0, self.letter_color_unavailable)
self.letter_color_unavailable_entry.place(x=150, y=155, width=300, height=25)
# Hentai Folder
ttk.Label(self.initial_setup_tab, text="Hentai Folder:").place(x=5, y=185)
self.folder_entry = ttk.Entry(self.initial_setup_tab)
self.folder_entry.insert(0, self.hentai_folder)
self.folder_entry.place(x=150, y=185, width=300, height=25)
self.browse_button = ttk.Button(self.initial_setup_tab, text="Browse", command=self.browse_folder)
self.browse_button.place(x=457, y=185, width=100, height=27)
# Initialize Button
self.initialize_button = ttk.Button(self.initial_setup_tab, text="Initialize", command=self.initialize)
self.initialize_button.place(x=3, y=373, anchor=tk.SW, width=120, height=30)
def setup_complex_navigation_ui(self):
# Locate INI File
ttk.Label(self.complex_navigation_tab, text="Locate INI File:").place(x=5, y=16, anchor=tk.W)
self.ini_file_entry = ttk.Entry(self.complex_navigation_tab) # Set fixed width
self.ini_file_entry.place(x=120, y=5, width=300, height=25)
self.browse_ini_button = ttk.Button(self.complex_navigation_tab, text="Browse", command=self.browse_ini_file)
self.browse_ini_button.place(x=427, y=5, width=100, height=27)
# Display Parameters
# Static label for the title
self.title_static_label = ttk.Label(self.complex_navigation_tab, text="Hentai Title: ")
self.title_static_label.place(x=5, y=35, width=300, height=25)
# Dynamic label for the title value
self.title_label = ttk.Label(self.complex_navigation_tab, text="")
self.title_label.place(x=120, y=35, width=300, height=25)
self.episodes_static_label = ttk.Label(self.complex_navigation_tab, text="No. of Episodes: ")
self.episodes_static_label.place(x=5, y=65, width=300, height=25)
self.episodes_label = ttk.Label(self.complex_navigation_tab, text="")
self.episodes_label.place(x=120, y=65, width=300, height=25)
self.start_mod_static_label = ttk.Label(self.complex_navigation_tab, text="New Episode: ")
self.start_mod_static_label.place(x=5, y=95, width=300, height=25)
self.start_mod_label = ttk.Label(self.complex_navigation_tab, text="")
self.start_mod_label.place(x=120, y=95, width=300, height=25)
# URL inputs
self.url_entries = []
for i in range(4):
label = ttk.Label(self.complex_navigation_tab, text=f"Episode URL {i + 1}:")
label.place(x=5, y=130 + i * 30, width=300, height=25)
url_entry = ttk.Entry(self.complex_navigation_tab, width=50) # Fixed width
url_entry.place(x=120, y=130 + i * 30, width=300, height=25)
self.url_entries.append(url_entry)
# Create a frame for dynamic buttons
self.dynamic_buttons_frame = ttk.Frame(self.complex_navigation_tab)
self.dynamic_buttons_frame.place(x=5, y=260, width=478, height=50) # Adjust the size as needed
self.generate_navigation_button = ttk.Button(self.complex_navigation_tab, text="Generate Code", command=self.generate_navigation)
self.generate_navigation_button.place(x=3, y=373, anchor=tk.SW, width=120, height=30)
def setup_simple_navigation_ui(self):
# BBCode history text box
self.bbcode_history = tk.Text(self.simple_navigation_tab, height=10, width=100)
self.bbcode_history.place(x=3, y=5, width=591, height=120)
# Predefined color sets with checkboxes
self.color_set_var1 = tk.BooleanVar(value=True) # Default checked
self.color_set_var2 = tk.BooleanVar()
self.color_set_var3 = tk.BooleanVar()
ttk.Checkbutton(self.simple_navigation_tab, text="Set 1: Table Color: 336699, Letter Color: Red",
variable=self.color_set_var1, command=self.select_color_set).place(x=5, y=140, anchor=tk.W)
ttk.Checkbutton(self.simple_navigation_tab, text="Set 2: Table Color: 241B1B, Letter Color: BF3A3A",
variable=self.color_set_var2, command=self.select_color_set).place(x=5, y=170, anchor=tk.W)
ttk.Checkbutton(self.simple_navigation_tab, text="Set 3: Table Color: C8C8F4, Letter Color: BDD3F7",
variable=self.color_set_var3, command=self.select_color_set).place(x=5, y=200, anchor=tk.W)
# Define a style for colored buttons
style = ttk.Style()
style.layout('Flat.TButton', []) # Removes padding and border
style.configure('Flat.TButton', background='white') # Sets default background
# Input fields for custom colors
ttk.Label(self.simple_navigation_tab, text="Table Color:").place(x=5, y=230)
self.simple_table_color_entry = ttk.Entry(self.simple_navigation_tab, width=40)
self.simple_table_color_entry.insert(0, "336699") # Default value
self.simple_table_color_entry.place(x=100, y=230, width=350, height=25)
self.simple_table_color_picker = ttk.Button(self.simple_navigation_tab, text="", style='Flat.TButton', command=lambda: self.choose_color(self.simple_table_color_entry, 'TableColor'))
self.simple_table_color_picker.place(x=457, y=230, width=30, height=25)
ttk.Label(self.simple_navigation_tab, text="Letter Color:").place(x=5, y=260)
self.simple_letter_color_entry = ttk.Entry(self.simple_navigation_tab, width=40)
self.simple_letter_color_entry.insert(0, "Red") # Default value
self.simple_letter_color_entry.place(x=100, y=260, width=350, height=25)
self.simple_letter_color_picker = ttk.Button(self.simple_navigation_tab, text="", style='Flat.TButton', command=lambda: self.choose_color(self.simple_letter_color_entry, 'LetterColor'))
self.simple_letter_color_picker.place(x=457, y=260, width=30, height=25)
# Update the color picker button background based on the color in the entry
self.simple_table_color_entry.bind('<KeyRelease>', lambda e: self.update_color_button(self.simple_table_color_entry, self.simple_table_color_picker))
self.simple_letter_color_entry.bind('<KeyRelease>', lambda e: self.update_color_button(self.simple_letter_color_entry, self.simple_letter_color_picker))
ttk.Label(self.simple_navigation_tab, text="Title:").place(x=5, y=290)
self.simple_title_entry = ttk.Entry(self.simple_navigation_tab, width=40)
self.simple_title_entry.place(x=100, y=290, width=350, height=25)
ttk.Label(self.simple_navigation_tab, text="Post URL:").place(x=5, y=320)
self.simple_post_url_entry = ttk.Entry(self.simple_navigation_tab, width=40)
self.simple_post_url_entry.place(x=100, y=320, width=350, height=25)
self.simple_enter_button = ttk.Button(self.simple_navigation_tab, text="Enter", command=self.add_navigation_bbcode)
self.simple_enter_button.place(x=596, y=373, anchor=tk.SE, width=120, height=30)
# Copy button next to the display box
self.copy_button = ttk.Button(self.simple_navigation_tab, text="Copy", command=self.copy_bbcode)
self.copy_button.place(x=596, y=143, anchor=tk.E, width=120, height=30)
def choose_color(self, entry, style_name):
color_code = colorchooser.askcolor(title="Choose color")[1]
if color_code:
entry.delete(0, tk.END)
entry.insert(0, color_code)
self.update_color_button(entry, style_name)
def update_color_button(self, entry, style_name):
color_code = entry.get()
style = ttk.Style()
style.configure('Flat.TButton', background=color_code)
button_attribute_name = self.style_to_button_map.get(style_name)
if button_attribute_name:
button = getattr(self, button_attribute_name)
button.config(style='Flat.TButton')
def select_color_set(self):
if self.color_set_var1.get():
self.color_set_var2.set(False)
self.color_set_var3.set(False)
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "336699")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "Red")
elif self.color_set_var2.get():
self.color_set_var1.set(False)
self.color_set_var3.set(False)
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "241B1B")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "BF3A3A")
elif self.color_set_var3.get():
self.color_set_var1.set(False)
self.color_set_var2.set(False)
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "C8C8F4")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "BDD3F7")
def update_color_selection(self):
if self.color_set_var1.get():
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "336699")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "Red")
# Uncheck the other checkboxes
self.color_set_var2.set(False)
self.color_set_var3.set(False)
elif self.color_set_var2.get():
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "241B1B")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "BF3A3A")
# Uncheck the other checkboxes
self.color_set_var1.set(False)
self.color_set_var3.set(False)
elif self.color_set_var3.get():
self.simple_table_color_entry.delete(0, tk.END)
self.simple_table_color_entry.insert(0, "C8C8F4")
self.simple_letter_color_entry.delete(0, tk.END)
self.simple_letter_color_entry.insert(0, "BDD3F7")
# Uncheck the other checkboxes
self.color_set_var1.set(False)
self.color_set_var2.set(False)
def browse_folder(self):
folder_selected = filedialog.askdirectory(initialdir=self.hentai_folder)
if folder_selected:
self.folder_entry.delete(0, tk.END)
self.folder_entry.insert(0, folder_selected)
def browse_ini_file(self):
ini_file = filedialog.askopenfilename(filetypes=[("INI Files", "*.ini")])
if ini_file:
self.ini_file_entry.delete(0, tk.END)
self.ini_file_entry.insert(0, ini_file)
# Load the INI file and update the UI fields
self.load_ini_file(Path(ini_file)) # Use Path to handle the filename
# Call the new method to clear input fields and dynamic buttons
self.clear_inputs_and_buttons() # Call to clear inputs and buttons
def clear_inputs_and_buttons(self):
# Clear all input entries except for the INI file entry
entries = [
self.title_entry,
self.episodes_entry,
self.menu_url_entry,
# Exclude these fields from being cleared
# self.table_color_entry, # Keep this
# self.letter_color_available_entry, # Keep this
# self.letter_color_unavailable_entry, # Keep this
# self.folder_entry, # Keep this
self.simple_title_entry,
self.simple_post_url_entry,
]
for entry in entries:
entry.delete(0, tk.END)
# Clear URL entries
for url_entry in self.url_entries:
url_entry.delete(0, tk.END)
# Clear dynamic buttons
for widget in self.dynamic_buttons_frame.winfo_children():
widget.destroy()
def load_ini_file(self, ini_file: Path):
config = configparser.ConfigParser()
# Use 'utf-8-sig' encoding when reading the INI file
with ini_file.open('r', encoding='utf-8-sig') as f:
config.read_file(f)
# Load Setup section
self.hentai_title = config['Setup']['Title']
self.num_episodes = int(config['Setup']['TotalEpisodes'])
self.start_mod_episode = int(config['Setup']['StartModEpisode'])
self.hentai_folder = config['Setup']['Directory']
self.last_url = config['Setup'].get('lasturl', '0') # Load lasturl
# Update UI labels
self.title_label.config(text=f"{self.hentai_title}")
self.episodes_label.config(text=f"{self.num_episodes}")
self.start_mod_label.config(text=f"{self.start_mod_episode}")
def initialize(self):
# Gather user inputs
self.hentai_title = self.title_entry.get().strip()
self.num_episodes = self.episodes_entry.get().strip()
self.menu_url = self.menu_url_entry.get().strip()
self.table_color = self.table_color_entry.get().strip() or self.table_color
self.letter_color_available = self.letter_color_available_entry.get().strip() or self.letter_color_available
self.letter_color_unavailable = self.letter_color_unavailable_entry.get().strip() or self.letter_color_unavailable
self.hentai_folder = self.folder_entry.get().strip()
# Validate inputs
if not self.hentai_title or not self.num_episodes.isdigit() or not self.menu_url or not self.hentai_folder:
messagebox.showerror("Error", "Please provide all required fields.")
return
self.num_episodes = int(self.num_episodes)
if self.num_episodes <= 0:
messagebox.showerror("Error", "Number of Episodes must be greater than 0.")
return
# File protection warning
self.create_files()
def create_files(self):
# Create necessary files
chapter_file = os.path.join(self.hentai_folder, "chapter.txt")
ini_file = os.path.join(self.hentai_folder, f"{self.hentai_title}.ini")
toc_file = os.path.join(self.hentai_folder, "TOC.txt")
# Check if files exist
for file in [chapter_file, ini_file, toc_file]:
if os.path.exists(file):
if not messagebox.askyesno("File Protection Warning", f"{file} already exists. Overwrite?"):
return
# Create chapter.txt
with open(chapter_file, 'w', encoding='ansi') as f:
f.write("chapter\n")
for i in range(1, self.num_episodes + 1):
f.write(f"{i}\n")
# Create ini file
config = configparser.ConfigParser()
config['Setup'] = {
'Title': self.hentai_title,
'TotalEpisodes': str(self.num_episodes),
'MenuURL': self.menu_url,
'Directory': self.hentai_folder,
'StartModEpisode': '1',
'lasturl': '0', # Add lasturl entry
'TableColor': self.table_color,
'IconColor': 'DeepSkyBlue',
'LetterColorAvailable': self.letter_color_available,
'LetterColorUnavailable': self.letter_color_unavailable
}
config['Thread ID'] = {}
for i in range(1, self.num_episodes + 1):
config['Thread ID'][str(i)] = f"{self.letter_color_unavailable} {self.menu_url}"
with open(ini_file, 'w', encoding='utf-8-sig') as f:
config.write(f)
# Create TOC.txt
self.create_toc(toc_file)
messagebox.showinfo("Success", "Files created successfully!")
def create_toc(self, toc_file):
config = configparser.ConfigParser()
# Load the INI file with utf-8 encoding
with open(os.path.join(self.hentai_folder, f"{self.hentai_title}.ini"), 'r', encoding='utf-8-sig') as f:
config.read_file(f) # Use read_file to read from the file object
with open(toc_file, 'w', encoding='utf-8-sig') as f:
f.write(f"[table=100%,{config['Setup']['TableColor']}]\n")
for i in range(1, self.num_episodes + 1):
url_value = config['Thread ID'][str(i)].split(' ') # Get URL from Thread ID
table_row = "[tr]"
if i == self.num_episodes:
table_row += f"[td][b][color={url_value[0]}]{self.hentai_title} {i} [完][/color][/b][/td]"
else:
table_row += f"[td][b][color={url_value[0]}]{self.hentai_title} {i}[/color][/b][/td]"
if url_value:
table_row += f"[td][url={url_value[1]}][align=center][size=5]⏩[/size][/align][/url][/td][/tr]"
f.write(table_row + "\n")
f.write("[/table]\n")
def generate_navigation(self):
ini_file_path = self.ini_file_entry.get().strip()
if not ini_file_path or not os.path.exists(ini_file_path):
messagebox.showerror("Error", "Please select a valid INI file.")
return
config = configparser.ConfigParser()
config.read(ini_file_path, encoding='utf-8-sig')
navigation_codes = []
total_urls = sum(1 for entry in self.url_entries if entry.get().strip())
for i in range(total_urls):
previous_url = self.url_entries[i - 1].get().strip() if i > 0 else (self.last_url if self.start_mod_episode != 1 else self.url_entries[i].get().strip())
current_url = self.url_entries[i].get().strip()
next_url = self.url_entries[i + 1].get().strip() if i < total_urls - 1 else current_url
bbcode = (
f"[table=100%,{config['Setup']['TableColor']}][tr]\n"
f"[td][align=center][url={next_url}][size=5][color={config['Setup']['IconColor']}]" \
f"◀️[/color][/url][b][size=5][color={config['Setup']['LetterColorAvailable']}]下一集[/color][/size][/b][/align][/td]\n"
f"[td][align=center][b][size=5][color={config['Setup']['LetterColorAvailable']}]" \
f"目錄[/color][/size][/b][url={config['Setup']['MenuURL']}][size=5][color={config['Setup']['IconColor']}]🔢[/color][/url][/align][/td]\n"
f"[td][align=center][b][size=5][color={config['Setup']['LetterColorAvailable']}]上一集[/color][/size][/b]" \
f"[url={previous_url}][size=5][color={config['Setup']['IconColor']}]▶️[/color][/url][/align][/td]\n"
"[/tr][/table]"
)
navigation_codes.append(bbcode)
# Ask for confirmation to overwrite existing files
nav_history_path = os.path.join(os.path.dirname(ini_file_path), "NavHistory.txt")
if os.path.exists(nav_history_path):
if not messagebox.askyesno("Confirm Overwrite", f"{nav_history_path} already exists. Overwrite?"):
return
# Write to NavHistory.txt
with open(nav_history_path, 'a', encoding='utf-8-sig') as f: # Append instead of overwrite
for idx, code in enumerate(navigation_codes, start=self.start_mod_episode):
f.write(f"{idx} = {code}\n")
# Update INI file
self.update_ini_file(ini_file_path, total_urls)
# Generate new TOC.txt based on updated INI content
toc_file = os.path.join(os.path.dirname(ini_file_path), "TOC.txt")
self.create_toc(toc_file)
# Clear dynamic buttons and generate new ones
self.generate_dynamic_buttons(total_urls)
def update_ini_file(self, ini_file_path, total_urls):
config = configparser.ConfigParser()
config.read(ini_file_path, encoding='utf-8-sig')
# Update the INI file with new URLs
start_mod_episode = int(config['Setup']['StartModEpisode'])
available_color = config['Setup']['LetterColorAvailable']
for i in range(total_urls):
episode_line = start_mod_episode + i
if episode_line > int(config['Setup']['TotalEpisodes']):
messagebox.showinfo("End Reached", "The End has been reached.")
return
url_value = self.url_entries[i].get().strip()
config['Thread ID'][str(episode_line)] = f"{available_color} {url_value}"
# Update StartModEpisode
config['Setup']['StartModEpisode'] = str(start_mod_episode + total_urls)
# Determine last URL value by checking all entries
last_url_value = '0' # Default value
for entry in reversed(self.url_entries): # Iterate from last to first
url_value = entry.get().strip()
if url_value: # Check if the entry is not empty
last_url_value = url_value
break # Exit loop upon finding the last non-empty entry
config['Setup']['lasturl'] = last_url_value
with open(ini_file_path, 'w', encoding='utf-8-sig') as configfile:
config.write(configfile)
messagebox.showinfo("Success", "INI file updated successfully!")
def generate_dynamic_buttons(self, total_urls):
# Clear previous buttons
for widget in self.dynamic_buttons_frame.winfo_children():
widget.destroy()
# Ensure there are URLs to process
if total_urls > 0 and self.start_mod_episode >= 1:
button_count = self.start_mod_episode + total_urls - 1
# Add the extra button for the last URL number
if self.start_mod_episode != 1:
extra_button_label = f"Ep. {self.start_mod_episode - 1}"
extra_button = ttk.Button(self.dynamic_buttons_frame, text=extra_button_label, command=self.copy_last_url_number)
extra_button.pack(side=tk.LEFT, padx=2, anchor=tk.W)
for i in range(total_urls):
episode_num = self.start_mod_episode + i
button_label = f"Ep. {episode_num}"
button = ttk.Button(self.dynamic_buttons_frame, text=button_label)
button.pack(side=tk.LEFT, padx=2, anchor=tk.W)
# Bind the button to the copy_navigation_code function
button.bind('<Button-1>', lambda event, idx=i: self.copy_navigation_code(idx))
# Add the TOC button
toc_button = ttk.Button(self.dynamic_buttons_frame, text="TOC", command=self.copy_toc_content)
toc_button.pack(side=tk.RIGHT, padx=0, anchor=tk.E)
# Bind the TOC button to the copy_toc_content function
toc_button.bind('<Button-1>', self.copy_toc_content)
def copy_last_url_number(self):
Entry_URL1 = self.url_entries[0].get().strip()
# Extract the 8-digit number
if "thread-" in Entry_URL1:
start_index = Entry_URL1.find("thread-") + len("thread-")
end_index = start_index + 8 # 8 characters long
extracted_number = Entry_URL1[start_index:end_index]
# Validate that we got an 8-digit number
if extracted_number.isdigit() and len(extracted_number) == 8:
# Copy the number to clipboard
self.root.clipboard_clear()
self.root.clipboard_append(extracted_number)
messagebox.showinfo("Copied", "8-digit number copied to clipboard!")
else:
messagebox.showwarning("Warning", "Could not extract a valid 8-digit number from lasturl.")
else:
messagebox.showwarning("Warning", "lasturl does not contain 'thread-'!")
def copy_toc_content(self, event):
# Get the path to the TOC.txt file
toc_file = os.path.join(os.path.dirname(self.ini_file_entry.get().strip()), "TOC.txt")
# Read the content of the TOC.txt file
with open(toc_file, 'r', encoding='utf-8-sig') as f:
content = f.read()
# Copy the content to the clipboard
pyperclip.copy(content)
messagebox.showinfo("Copied", "TOC content copied to clipboard.")
def copy_navigation_code(self, index):
ini_file_path = self.ini_file_entry.get().strip()
config = configparser.ConfigParser()
config.read(ini_file_path, encoding='utf-8-sig')
navigation_codes = []
total_urls = sum(1 for entry in self.url_entries if entry.get().strip())
for i in range(total_urls):
previous_url = self.url_entries[i - 1].get().strip() if i > 0 else (self.last_url if self.start_mod_episode != 1 else self.url_entries[i].get().strip())
current_url = self.url_entries[i].get().strip()
next_url = self.url_entries[i + 1].get().strip() if i < total_urls - 1 else current_url
bbcode = (
f"[table=100%,{config['Setup']['TableColor']}][tr]\n"
f"[td][align=center][url={next_url}][size=5][color={config['Setup']['IconColor']}]" \
f"◀️[/color][/url][b][size=5][color={config['Setup']['LetterColorAvailable']}]下一集[/color][/size][/b][/align][/td]\n"
f"[td][align=center][b][size=5][color={config['Setup']['LetterColorAvailable']}]" \
f"目錄[/color][/size][/b][url={config['Setup']['MenuURL']}][size=5][color={config['Setup']['IconColor']}]🔢[/color][/url][/align][/td]\n"
f"[td][align=center][b][size=5][color={config['Setup']['LetterColorAvailable']}]上一集[/color][/size][/b]" \
f"[url={previous_url}][size=5][color={config['Setup']['IconColor']}]▶️[/color][/url][/align][/td]\n"
"[/tr][/table]"
)
navigation_codes.append(bbcode)
# Copy the corresponding navigation bbcode to clipboard
if index < len(navigation_codes):
self.root.clipboard_clear()
self.root.clipboard_append(navigation_codes[index])
messagebox.showinfo("Copied", "Navigation code copied to clipboard!")
def copy_bbcode(self):
# Get the entire content from the display box (bbcode_history)
bbcode_content = self.bbcode_history.get("1.0", tk.END).strip()
# Clear the clipboard and copy the content
self.root.clipboard_clear()
self.root.clipboard_append(bbcode_content)
def add_navigation_bbcode(self):
table_color = self.simple_table_color_entry.get().strip()
letter_color = self.simple_letter_color_entry.get().strip()
title = self.simple_title_entry.get().strip()
post_url = self.simple_post_url_entry.get().strip()
# Prepare the initial table lines only if the display is empty
if not self.bbcode_history.get("1.0", tk.END).strip():
display_content = f"[table=100%,{table_color}]\n"
else:
display_content = "\n"
if title and post_url:
display_content += f"[tr][td][url={post_url}][b][color={letter_color}][size=2]{title}[/size][/color][/b][/url][/td][/tr]\n"
# Check the existing content in the display box and add new entry
existing_content = self.bbcode_history.get("1.0", tk.END).strip()
if existing_content:
# Remove the last [/table] if it exists
if existing_content.endswith("[/table]"):
existing_content = existing_content[:-len("[/table]")].strip()
display_content = existing_content + display_content
display_content += "[/table]"
# Update the display box
self.bbcode_history.delete("1.0", tk.END)
self.bbcode_history.insert(tk.END, display_content)
# Clear the Title and Post URL entry boxes
self.simple_title_entry.delete(0, tk.END)
self.simple_post_url_entry.delete(0, tk.END)
if name == "main":
root = tk.Tk()
app = BBCodeGenerator(root)
root.mainloop()
The colors of the Text Color and Table Color do not change separately. Both color will change at the same time. Please help me solve it.