-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.py
More file actions
123 lines (101 loc) · 4.39 KB
/
collection.py
File metadata and controls
123 lines (101 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import sqlite3
import shutil
import customtkinter
import tkinter as tk
dbname = 'osu_dir.db'
conn = sqlite3.connect(dbname)
cur = conn.cursor()
FONT_TYPE = 15
APPDIR = os.getcwd()
class CollectionFrame(customtkinter.CTkFrame):
def __init__(self, *args, header_name="Collection", osu_dir, **kwargs):
super().__init__(*args, **kwargs)
self.fonts = (FONT_TYPE, 15)
self.header_name = header_name
self.osu_dir = osu_dir
self.setup_form()
def setup_form(self):
# 行方向のマスのレイアウト設定
self.grid_rowconfigure(1, weight=1)
# 列方向のマスのレイアウト設定
self.grid_columnconfigure(0, weight=1)
self.tabview = customtkinter.CTkTabview(master=self, width=250, height=30)
self.tabview.grid(row=1, column=0, padx=20, pady=(0, 10), sticky="e")
self.tabview.add("選択")
self.tabview.add("追加")
# ラベルを表示
self.label = customtkinter.CTkLabel(self, text=self.header_name, font=(FONT_TYPE, 11))
self.label.grid(row=0, column=0, padx=20, sticky="w")
# Selectタブ
self.get_collections()
self.combobox = customtkinter.CTkComboBox(self.tabview.tab("選択"), width=150, height=28, values=self.collection_array, state='readonly', command=self.combobox_callback)
self.combobox.set("Select collection")
self.combobox.grid(row=1, column=0, padx=20, sticky="ew")
self.button_apply = customtkinter.CTkButton(self.tabview.tab("選択"), text="Apply", fg_color="#444", width=50, state='readonly', command=self.apply_collection)
self.button_apply.grid(row=1, column=1, padx=(20, 10), pady=5, sticky="w")
# Addタブ
self.entry_add = customtkinter.CTkEntry(self.tabview.tab("追加"), width=150, height=28)
self.entry_add.grid(row=1, column=0, padx=20, sticky="ew")
self.button_add = customtkinter.CTkButton(self.tabview.tab("追加"), text="Add", width=50, command=self.add_collection)
self.button_add.grid(row=1, column=1, padx=(20, 10), pady=5, sticky="w")
def combobox_callback(self, choice):
self.button_apply.configure(state='normal', fg_color='#1f6AA5')
self.choice = choice
def add_collection(self):
cur.execute('SELECT name FROM currskin')
for r in cur:
curr_skin = r[0]
name = self.entry_add.get()
try:
os.makedirs(f"./images/collections/{name}")
except:
tk.messagebox.showerror(title="Skin Tools", message="Failed to create folder.")
osu_dir = str(self.osu_dir).replace('osu!.exe', '')
os.chdir(osu_dir)
os.chdir(APPDIR)
file_name = {'cursor.png',
'cursortrail.png',
'cursormiddle.png',
}
for f in file_name:
try:
shutil.copy(f'{osu_dir}Skins\\{curr_skin}\\{f}', f'./images/collections/{name}/{f}')
except:
pass
self.get_collections()
self.combobox.configure(values=self.collection_array)
def apply_collection(self):
cur.execute('SELECT name FROM currskin')
for r in cur:
curr_skin = r[0]
try:
self.choice
except:
return
osu_dir = str(self.osu_dir).replace('osu!.exe', '')
file_name = {'cursor.png',
'cursortrail.png',
'cursormiddle.png',
}
for f in file_name:
try:
os.remove(f'{osu_dir}Skins\\{curr_skin}\\{f}')
except:
pass
try:
shutil.copy(f'./images/collections/{self.choice}/{f}', f'{osu_dir}Skins\\{curr_skin}\\{f}')
except:
pass
def get_collections(self):
self.collection_array = []
dir = "./images/collections/"
for d in os.listdir(dir):
if os.path.isdir(os.path.join(dir, d)):
self.collection_array.append(d)