-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor.py
More file actions
212 lines (173 loc) · 8.17 KB
/
cursor.py
File metadata and controls
212 lines (173 loc) · 8.17 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import os
import shutil
import sqlite3
import numpy
import tkinter as tk
import customtkinter
from PIL import Image
dbname = 'osu_dir.db'
conn = sqlite3.connect(dbname)
cur = conn.cursor()
FONT_TYPE = 15
APPDIR = os.getcwd()
class CursorFrame(customtkinter.CTkFrame):
def __init__(self, *args, header_name="Cursor", osu_dir, type="cursor", **kwargs):
super().__init__(*args, **kwargs)
self.fonts = (FONT_TYPE, 15)
self.type = type
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(3, weight=1)
# ラベルを表示
self.label = customtkinter.CTkLabel(self, text=self.header_name, font=(FONT_TYPE, 11))
self.label.grid(row=0, column=0, padx=20, sticky="w")
self.create_file_list(f"{APPDIR}\\images\\{self.type}\\")
try:
self.image = customtkinter.CTkImage(light_image=Image.open(fp=self.file_array[0]), size=[100, 100])
self.label2 = customtkinter.CTkLabel(self, height=155, image=self.image, text="")
except:
self.label2 = customtkinter.CTkLabel(self, height=155, text="")
self.label2.grid(row=1, column=1, padx=20, sticky="nsew")
self.button_left = customtkinter.CTkButton(self, text="<", fg_color="#444", hover_color="#333", height=50, width=50, command=self.left_cursor)
self.button_left.grid(row=1, column=0, padx=20)
self.button_right = customtkinter.CTkButton(self, text=">", fg_color="#444", hover_color="#333", height=50, width=50, command=self.right_cursor)
self.button_right.grid(row=1, column=2, padx=20)
if self.type == 'cursor':
self.button_apply = customtkinter.CTkButton(self, text="⟲", width=50, height=28, command=self.apply_default)
self.button_apply.grid(row=3, column=0, pady=(0, 10))
if self.type == 'cursortrail':
self.checkbox_cursormiddle = customtkinter.CTkCheckBox(self, text="", font=(FONT_TYPE, 11), checkbox_width=16, checkbox_height=16, width=0, height=0, variable=tk.BooleanVar(self, False), onvalue=True, offvalue=False)
self.checkbox_cursormiddle.grid(row=0, column=1 , sticky="e")
self.label3 = customtkinter.CTkLabel(self, text="enable cursormiddle", font=(FONT_TYPE, 10))
self.label3.grid(row=0, column=2, sticky="w")
self.button_apply = customtkinter.CTkButton(self, text="Apply", command=self.apply)
self.button_apply.grid(row=3, column=1, pady=(0, 10))
self.button_apply = customtkinter.CTkButton(self, text="@2x", fg_color="#444", hover_color="#333", command=self.apply2x)
self.button_apply.grid(row=2, column=1, pady=(10, 10))
self.button_delete2x = customtkinter.CTkButton(self, text="🗑", fg_color="#700", hover_color="#400", width=50, height=28, command=self.delete2x)
self.button_delete2x.grid(row=3, column=2, pady=(0, 10))
def apply_default(self):
cur.execute('SELECT name FROM currskin')
for r in cur:
curr_skin = r[0]
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/{curr_skin}/{f}', f'{osu_dir}Skins\\{curr_skin}\\{f}')
except:
pass
def apply(self):
cur.execute('SELECT name FROM currskin')
for r in cur:
curr_skin = r[0]
osu_dir = str(self.osu_dir).replace('osu!.exe', '')
file_name = [f'{self.type}.png'
]
cursor_middle = ['cursormiddle.png',
]
try:
self.cursor2x
if self.cursor2x == True:
file_name.append(f'{self.type}@2x.png')
self.cursor2x = False
except:
pass
try:
os.remove(f'{osu_dir}Skins\\{curr_skin}\\{self.type}@2x.png')
except:
pass
if self.type == "cursortrail":
for cm in cursor_middle:
try:
os.remove(f'{osu_dir}Skins\\{curr_skin}\\{cm}')
except:
pass
flag = self.checkbox_cursormiddle.get()
if flag == True:
depth = 4
newImArray = numpy.zeros((1, 1, depth), dtype='uint8')
newIm = Image.fromarray(newImArray)
newIm.save(f'{osu_dir}Skins\\{curr_skin}\\{cursor_middle[0]}')
for f in file_name:
try:
os.remove(f'{osu_dir}Skins\\{curr_skin}\\{f}')
except:
pass
shutil.copy(f'{self.file_array[self.file_no]}', f'{osu_dir}Skins\\{curr_skin}\\{f}')
def apply2x(self):
self.cursor2x = True
def delete2x(self):
cur.execute('SELECT name FROM currskin')
for r in cur:
curr_skin = r[0]
osu_dir = str(self.osu_dir).replace('osu!.exe', '')
os.chdir(osu_dir)
os.chdir(APPDIR)
file_name = {f'{self.type}.png',
f'{self.type}@2x.png',
}
for f in file_name:
try:
os.remove(f'{osu_dir}Skins\\{curr_skin}\\{f}')
except:
pass
def left_cursor(self):
self.change_cursor("Left")
def right_cursor(self):
self.change_cursor("Right")
def change_cursor(self, flag):
self.update_file_list(f'{APPDIR}\\images\\{self.type}\\')
cnt = len(self.file_array)
if cnt == 0: # 画像ファイル配列が空の時何もしない
return
if flag == "Right": # 右キーのとき 配列の次のファイル
self.file_no += 1
if cnt == self.file_no: # 配列上限オーバー時は0に戻る
self.file_no = 0
elif flag == "Left": # 左キーのとき 配列の一個前のファイル
self.file_no -= 1
if self.file_no == -1: # 一番最初より前のとき最後のファイルにする
self.file_no = cnt - 1
else:
return # その他のキーでは何もしない
self.image = customtkinter.CTkImage(light_image=Image.open(fp=self.file_array[self.file_no]), size=[100, 100])
self.label2.configure(image=self.image)
def create_file_list(self, file_path):
self.file_array = []
self.file_no = 0
tmp_arr = os.path.split(file_path)
dir_name = tmp_arr[0]
file_name = tmp_arr[1]
n = 0
for fname in os.listdir(dir_name):
file_ext = os.path.splitext(fname)[1].lower()
if file_ext == ".jpg" or file_ext == ".png" or file_ext == ".tif" or file_ext == ".jpeg" :
self.file_array.append(os.path.join(dir_name ,fname))
if file_name == fname:
self.file_no = n
n += 1
def update_file_list(self, file_path):
self.file_array = []
tmp_arr = os.path.split(file_path)
dir_name = tmp_arr[0]
for fname in os.listdir(dir_name):
file_ext = os.path.splitext(fname)[1].lower()
if file_ext == ".jpg" or file_ext == ".png" or file_ext == ".tif" or file_ext == ".jpeg" :
self.file_array.append(os.path.join(dir_name ,fname))