-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow_utils.py
123 lines (101 loc) · 3.13 KB
/
window_utils.py
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
from help_texts import HOW_TO_USE
from tkinter import ttk
from typing import List
import tkinter
import win32gui
import os
import json
SUBS_LANGS_DICT = {
'Russia': 'rus',
'US': 'eng',
'Saudi Arabia': 'ara',
'Germany': 'ger',
'Latin America': 'spa',
'France': 'fre',
'Italy': 'ita',
'Brasil': 'por'
}
def wait():
pass
def on_closing():
raise SystemExit
def on_closing_help(
master: tkinter.Tk,
help_window: tkinter.Tk
):
master.nametowidget('help').config(state='normal')
help_window.destroy()
def buttons_freeze(master: tkinter.Tk, BUTTONS: List):
for button in BUTTONS:
if button != 'help':
master.nametowidget(button).config(state='disabled')
master.protocol('WM_DELETE_WINDOW', wait)
def buttons_active(master: tkinter.Tk, BUTTONS: List):
for button in BUTTONS:
master.nametowidget(button).config(state='normal')
master.protocol('WM_DELETE_WINDOW', on_closing)
def is_reaper_run():
hwnd = win32gui.FindWindow(
'REAPERwnd',
None
)
if not hwnd:
tkinter.messagebox.showerror(
'REAPER выключен',
'Сначала включите REAPER'
)
raise SystemExit
def show_help_window(master: tkinter.Tk):
master.nametowidget('help').config(state='disabled')
master_geometry_x = master.geometry().split('+')[0].split('x')[0]
master_geometry_y = master.geometry().split('+')[0].split('x')[1]
master_position = master.geometry().split('x')[1].split('+')[1:]
x = int(master_position[0]) + int(master_geometry_x) + 6
y = master_position[1]
help_window = tkinter.Toplevel(master)
help_window.title('HOW TO USE')
help_window.geometry(f'615x{master_geometry_y}+{x}+{y}')
help_window.resizable(False, False)
help_window.protocol(
'WM_DELETE_WINDOW',
lambda: on_closing_help(master, help_window)
)
text_field = tkinter.Text(
help_window,
background='#ffc0cb',
padx=6,
pady=3,
)
text_field.insert('1.0', HOW_TO_USE)
text_field.configure(state='disabled')
scrollbar = ttk.Scrollbar(
help_window,
orient='vertical',
command=text_field.yview
)
text_field.configure(yscrollcommand=scrollbar.set)
scrollbar.pack(side='right', fill='y')
text_field.pack(side='left', fill='both', expand=True)
help_window.focus_force()
help_window.mainloop()
def set_geometry(master: tkinter.Tk):
width = 380
height = 453
s_width = master.winfo_screenwidth()
s_height = master.winfo_screenheight()
upper = s_height // 8
x = (s_width - width) // 2
y = (s_height - height) // 2
return f'{width}x{height}+{x}+{y - upper}'
def get_subs_langs():
if not os.path.exists('subs_langs.json'):
with open('subs_langs.json', 'w+') as json_file:
data = {}
for key, value in SUBS_LANGS_DICT.items():
data[key] = value
json.dump(data, json_file)
with open('subs_langs.json', 'r') as json_file:
data = json.load(json_file)
return data
if __name__ == '__main__':
pass