-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
239 lines (203 loc) · 9.53 KB
/
main.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import dearpygui.dearpygui as dpg
import subprocess
import threading
import platform
import uuid
import time
import sys
import os
import io
NAME = "Hakkamichi"
VERSION = "1.0.1"
AUTHOR = "batubyte"
TITLE = f"{NAME} {uuid.uuid4()}"
RESOLUTION = (1280, 800)
shell_count = 0
def resize_terminal(cols, lines):
current_platform = platform.system()
if current_platform == "Windows":
os.system(f"mode con: cols={cols} lines={lines}")
elif current_platform == "Linux" or current_platform == "Darwin":
os.system(f'printf "\\e[8;{lines};{cols}t"')
def set_terminal_title(title: str):
system = platform.system()
if system == "Windows":
os.system(f"title {title}")
else:
sys.stdout.write(f"\033]0;{title}\007")
sys.stdout.flush()
def activate_window(title):
system = platform.system()
if system == "Windows":
try:
import pygetwindow as gw
windows = gw.getWindowsWithTitle(title)
if windows:
window = windows[0]
window.activate()
except:
pass
def create_shell():
global shell_count
shell_count += 1
with dpg.window(label=f"Shell {shell_count}", autosize=True, pos=(50, 50)):
with dpg.menu_bar():
with dpg.menu(label="File"):
dpg.add_menu_item(label="New Window", callback=create_shell)
dpg.add_menu_item(label="Open")
dpg.add_menu_item(label="Save")
with dpg.child_window(auto_resize_x=True, auto_resize_y=True):
dpg.add_input_text(
multiline=True,
tag=f"Shell Source {shell_count}",
width=500,
height=200,
no_horizontal_scroll=False,
)
dpg.add_button(
label="Execute",
callback=lambda: execute_source(shell_count),
width=500,
)
def execute_source(shell):
source = dpg.get_value(f"Shell Source {shell}")
try:
exec(source)
except Exception as e:
print(e)
activate_window(TITLE)
def load_fonts():
script_dir = os.path.dirname(os.path.abspath(__file__))
font_files = {
"FiraCode-Regular": os.path.join(script_dir, "fonts", "FiraCode-Regular.ttf"),
"FiraCode-Light": os.path.join(script_dir, "fonts", "FiraCode-Light.ttf"),
"FiraCode-Medium": os.path.join(script_dir, "fonts", "FiraCode-Medium.ttf"),
"FiraCode-SemiBold": os.path.join(script_dir, "fonts", "FiraCode-SemiBold.ttf"),
"FiraCode-Bold": os.path.join(script_dir, "fonts", "FiraCode-Bold.ttf"),
}
if all(os.path.exists(font_path) for font_path in font_files.values()):
with dpg.handler_registry():
with dpg.font_registry():
for tag, font_path in font_files.items():
dpg.add_font(font_path, 17, tag=tag)
dpg.bind_font("FiraCode-SemiBold")
def setup_gui():
dpg.create_context()
dpg.create_viewport(
title=f"{NAME} {VERSION} by {AUTHOR}", clear_color=(115, 140, 152)
)
with dpg.window(tag="Primary Window"):
with dpg.menu_bar():
with dpg.menu(label="Applications"):
dpg.add_menu_item(label="Settings")
dpg.add_menu_item(
label="Shell", callback=lambda: dpg.show_item("Shell Window")
)
with dpg.window(
label="Shell", tag="Shell Window", show=False, autosize=True, pos=(50, 50)
):
with dpg.menu_bar():
with dpg.menu(label="File"):
dpg.add_menu_item(label="New Window", callback=create_shell)
dpg.add_menu_item(label="Open")
dpg.add_menu_item(label="Save")
with dpg.child_window(auto_resize_x=True, auto_resize_y=True):
dpg.add_input_text(
multiline=True,
tag="Shell Source 0",
default_value="""print('Hello World')\n""",
width=500,
height=200,
)
dpg.add_button(
label="Execute", callback=lambda: execute_source(0), width=500
)
load_fonts()
apply_theme()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Primary Window", True)
def apply_theme():
with dpg.theme(tag="Global Theme"):
with dpg.theme_component(dpg.mvAll):
dpg.add_theme_style(dpg.mvStyleVar_ScrollbarRounding, 2)
dpg.add_theme_style(dpg.mvStyleVar_WindowRounding, 3)
dpg.add_theme_style(dpg.mvStyleVar_ChildRounding, 2)
dpg.add_theme_style(dpg.mvStyleVar_PopupRounding, 2)
dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 2)
dpg.add_theme_style(dpg.mvStyleVar_GrabRounding, 2)
dpg.add_theme_style(dpg.mvStyleVar_TabRounding, 2)
dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255))
dpg.add_theme_color(dpg.mvThemeCol_TextDisabled, (105, 113, 126))
dpg.add_theme_color(dpg.mvThemeCol_WindowBg, (21, 22, 23))
dpg.add_theme_color(dpg.mvThemeCol_ChildBg, (21, 22, 23))
dpg.add_theme_color(dpg.mvThemeCol_Border, (66, 66, 76))
dpg.add_theme_color(dpg.mvThemeCol_PopupBg, (20, 20, 20))
dpg.add_theme_color(dpg.mvThemeCol_BorderShadow, (75, 92, 101))
dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (32, 50, 77))
dpg.add_theme_color(
dpg.mvThemeCol_FrameBgHovered, (32 * 1.2, 50 * 1.2, 77 * 1.2)
)
dpg.add_theme_color(
dpg.mvThemeCol_FrameBgActive, (32 * 1.4, 50 * 1.4, 77 * 1.4)
)
dpg.add_theme_color(dpg.mvThemeCol_TitleBg, (10, 10, 10))
dpg.add_theme_color(dpg.mvThemeCol_TitleBgActive, (41, 74, 122))
dpg.add_theme_color(dpg.mvThemeCol_TitleBgCollapsed, (10, 10, 10))
dpg.add_theme_color(dpg.mvThemeCol_MenuBarBg, (36, 36, 36))
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarBg, (13, 13, 13))
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrab, (80, 80, 80))
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrabHovered, (104, 105, 105))
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrabActive, (130, 130, 131))
dpg.add_theme_color(dpg.mvThemeCol_CheckMark, (57, 124, 205))
dpg.add_theme_color(dpg.mvThemeCol_SliderGrab, (61, 133, 224))
dpg.add_theme_color(
dpg.mvThemeCol_SliderGrabActive, (61 * 1.2, 133 * 1.2, 224 * 1.2)
)
dpg.add_theme_color(dpg.mvThemeCol_Button, (32, 50, 77))
dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (39, 73, 114))
dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, (51, 108, 175))
# dpg.add_theme_color(dpg.mvThemeCol_Header, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_HeaderHovered, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_HeaderActive, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_Separator, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_SeparatorHovered, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_SeparatorActive, (R, G, B))
dpg.add_theme_color(dpg.mvThemeCol_ResizeGrip, (30, 48, 68))
dpg.add_theme_color(
dpg.mvThemeCol_ResizeGripHovered, (30 * 1.2, 48 * 0.1, 68 * 1.2)
)
dpg.add_theme_color(
dpg.mvThemeCol_ResizeGripActive, (30 * 1.4, 48 * 1.4, 68 * 1.4)
)
# dpg.add_theme_color(dpg.mvThemeCol_Tab, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TabHovered, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TabActive, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TabUnfocused, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TabUnfocusedActive, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_DockingPreview, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_DockingEmptyBg, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_PlotLines, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_PlotLinesHovered, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_PlotHistogram, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_PlotHistogramHovered, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TableHeaderBg, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TableBorderStrong, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TableBorderLight, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TableRowBg, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_TableRowBgAlt, (R, G, B))
dpg.add_theme_color(dpg.mvThemeCol_TextSelectedBg, (44, 85, 137))
# dpg.add_theme_color(dpg.mvThemeCol_DragDrop_target, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_NavHighlight, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_NavWindowingHighlight, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_NavWindowingDimBg, (R, G, B))
# dpg.add_theme_color(dpg.mvThemeCol_ModalWindowDimBg, (R, G, B))
dpg.bind_theme("Global Theme")
def main():
resize_terminal(100, 25)
set_terminal_title(TITLE)
setup_gui()
dpg.start_dearpygui()
dpg.destroy_context()
if __name__ == "__main__":
main()