-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
96 lines (82 loc) · 3.29 KB
/
__init__.py
File metadata and controls
96 lines (82 loc) · 3.29 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
import random,win32gui,os
from .StrTools import *
from .Widgets import *
class Console():
def __init__(self):
#get hwnd
self.number = int(random.random()*10**16)
os.system("title {}".format(self.number))
self.hwnd = win32gui.FindWindow(None,"{}".format(self.number))
while self.hwnd == 0:
self.hwnd = win32gui.FindWindow(None,"{}".format(self.number))
#init
self.width = os.get_terminal_size().columns
self.height = os.get_terminal_size().lines
self.widgets = [] #控件列表 [name,options,position]
self.colors = [] #颜色 二维列表 [ansi,x,y,length]
self.screen = [] #最终输出的屏幕,三维列表
self.funcs = [] #每帧要执行的函数
# 1st dimension: each row
# 2nd dimension: each glyphs
# 3rd dimension: the unicode(? of the glyph and its color [color, uni]
self.ScreenReset()
#打印屏幕
def blit(self):
#解析(内存爆炸)
#组件
for widget in self.widgets:
name, options, position = widget
#pack
if position == ["center"]:
x = int(self.width/2)
y = int(self.height/2)
else:
x,y = position
#widgets
if name == "HrefLine":
for i in range(self.height):
self.screen[i][x][1] ="|"
elif name == "Button":
pass
elif name == "Label":
i = 0
for text in options["text"]:
self.screen[y][x+i][1] = text
i += 1
for i in range(options["height"]):
self.colors.append([options["fill"],x,y+i,options["width"]])
#颜色
for color in self.colors:
name, x, y, length = color
for i in range(length):
self.screen[y][x+i][0] = name
#返回首行
print('\033[{}A\033[{}D'.format(self.height*2,self.width*2), end='')
print('\r' +'\n'.join(MergeList(self.screen)),end='')
def GetWindowRect(self):
left, top, right, bottom = win32gui.GetWindowRect(self.hwnd)
return (left,top,right,bottom)
def SetGeometry(self,width,height,x,y):
pass
def ScreenReset(self):
self.screen = [[["\033[0m", "\x20"] for i in range(self.width)] for i in range(self.height)]
def EventLoop(self):
"""事件循环"""
Console.ScreenReset(self)
Console.blit(self)
#更新窗口大小
while 1:
if self.width != os.get_terminal_size().columns or self.height != os.get_terminal_size().lines:
try:
self.width = os.get_terminal_size().columns
self.height = os.get_terminal_size().lines
except:
pass
os.system("cls")#回到首行
for functions in self.funcs:
functions()
Console.ScreenReset(self)
Console.blit(self)
def AddFunc(self,function):
#if not function : return None
self.funcs.append(function)