0.6.1 developing

This commit is contained in:
shenjackyuanjie 2021-11-20 21:05:28 +08:00
parent fd343d877f
commit 635fd668dd
5 changed files with 62 additions and 23 deletions

View File

@ -24,6 +24,7 @@ error_format = {
}
if __name__ == '__main__':
# 如果Python版本小于3.10就不导入pyjion
print(f'{__file__=}')
print(f'{sys.path[0]=}')
print(f'{sys.argv[0]=}')

View File

@ -14,6 +14,7 @@ gitee: @shenjackyuanjie
version = '0.6.1'
__version__ = version
playing = False
if playing:

View File

@ -23,6 +23,8 @@ import configparser
from typing import List
from xml.dom.minidom import parse
import Difficult_Rocket
if __name__ == '__main__': # been start will not run this
sys.path.append('/bin/libs')
sys.path.append('/bin')
@ -54,21 +56,20 @@ def load_file(file_name: str, stack=None) -> dict:
if (f_type == 'json5') or (f_type == 'json'):
try:
with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
rd = json5.load(jf)
rd = json5.load(jf, encoding='uft-8')
# json_file = open(file_name, 'r', encoding='utf-8')
# rd = json5.load(json_file, encoding='utf-8')
# json_file.close()
except UnicodeDecodeError:
with open(file_name, 'r', encoding='gbk') as jf:
rd = json5.load(jf)
tools_logger.info('文件 %s 解码错误已重新使用gbk编码打开' % file_name)
if stack is not None:
rd = rd[stack]
return rd
elif f_type == 'xml':
xml_load = parse(file_name)
if stack is not None:
xml_get = xml_load.getElementsByTagName(stack)
return xml_get
else:
return xml_load
rd = xml_load.getElementsByTagName(stack)
elif (f_type == 'config') or (f_type == 'conf') or (f_type == 'ini'):
cp = configparser.ConfigParser() # cp -> config parser
cp.read(file_name) # config parser -> reader
@ -79,7 +80,6 @@ def load_file(file_name: str, stack=None) -> dict:
rd[section][data] = cp[section][data]
if stack:
rd = rd[stack]
return rd
except FileNotFoundError:
log = 'no {} file was found!: \n file name: {} \n file type: {} \n stack: {}'.format(f_type, file_name, f_type, stack)
tools_logger.error(log)
@ -92,6 +92,7 @@ def load_file(file_name: str, stack=None) -> dict:
log = 'some error has been found!\n error type: {} \n file name: {} \n file type: {} \n stack: {}'.format(type(exp), file_name, f_type, stack)
tools_logger.error(log)
raise
return rd
# main config

View File

@ -197,9 +197,9 @@ class ClientWindow(pyglet.window.Window):
def FPS_update(self, tick: Decimal):
now_FPS = pyglet.clock.get_fps()
self.fps_log.update_tick(tick)
self.fps_label.text = f'FPS: {now_FPS:_>10.1f} \n{self.fps_log.max_fps:_>10.1f} {self.fps_log.min_fps:>5.1f}'
self.fps_label.text = f'FPS: {now_FPS:_>10.1f} \n{1/tick} \n{self.fps_log.max_fps:_>10.1f} {self.fps_log.min_fps:>5.1f}'
def on_draw(self):
def on_draw(self, *dt):
self.clear()
self.draw_batch()

View File

@ -13,7 +13,7 @@ gitee: @shenjackyuanjie
from Difficult_Rocket import translate
from libs import pyglet
# from libs import pyglet
from libs.pyglet import font
from libs.pyglet.text import Label
from libs.pyglet.gui import widgets
@ -53,7 +53,10 @@ class InputBox(widgets.WidgetBase):
message: str = '',
font_name: str = translate.鸿蒙简体,
font_size: int = 15,
blod: bool = False,
font_bold: bool = False,
font_italic: bool = False,
font_stretch: bool = False,
font_dpi: int = 100,
text_color: [int, int, int] = (0, 0, 0, 255),
out_line_color: [int, int, int] = (255, 255, 255),
cursor_color: [int, int, int] = (255, 255, 255),
@ -62,10 +65,13 @@ class InputBox(widgets.WidgetBase):
group: Group = Group()):
super().__init__(x, y, width, height)
self._text = message
self.text = self._text
self.字体 = font.load(name=font_name, size=font_size, blod=blod)
self.字高 = self.字体.ascent - self.字体.descent
self.外框距离 = out_line
self._text_position = 0
self.font = font.load(name=font_name, size=font_size,
blod=font_bold, italic=font_italic, stretch=font_stretch,
dpi=font_dpi)
self.font_height = self.font.ascent - self.font.descent0
self._select_position = [self.x, self.y, self.x, self.y + self.font_height]
self.out_bound = out_line
self._输入框 = Label(x=x + out_line, y=y + out_line,
width=width, height=height,
color=text_color,
@ -78,8 +84,15 @@ class InputBox(widgets.WidgetBase):
batch=batch, group=group)
self._光标 = Rectangle(x=x + out_line, y=y + out_line,
color=cursor_color,
width=1, height=self.字高,
width=1, height=self.font_height,
batch=batch, group=group)
self._选择框 = Rectangle(x=x, y=y, width=0, height=self.font_height,
color=(63, 115, 255))
self._选择的字 = Label(x=x, y=y, width=0, height=self.font_height,
color=text_color,
font_name=font_name, font_size=font_size,
batch=batch, group=group,
text='')
"""
输入框的属性
@ -95,6 +108,21 @@ class InputBox(widgets.WidgetBase):
self._text = value
self._输入框.text = value
@property
def select_position(self):
return self._select_position
@select_position.setter
def select_position(self, value):
if value > len(self.text):
value = len(self.text)
if value > 0:
self._select_position = self.x
for glyphs in self.font.get_glyphs(self.text)[:value]:
self._select_position += glyphs.width
else:
self._select_position = self.x
@property
def opacity(self):
return self._输入框.opacity
@ -106,16 +134,21 @@ class InputBox(widgets.WidgetBase):
self._外框.opacity = value
self._光标.opacity = value
@property
def value(self):
return self._text
"""
事件调用
"""
def _update_position(self):
self._输入框.position = self._x + self.外框距离, self._y + self.外框距离
self._外框.position = self._x - self.外框距离, self._y - self.外框距离
self._光标.position = self._x + self.外框距离, self._y + self.外框距离
self._输入框.position = self._x + self.out_bound, self._y + self.out_bound
self._外框.position = self._x - self.out_bound, self._y - self.out_bound
self._光标.position = self._x + self.out_bound, self._y + self.out_bound
def on_text(self, text):
if self.enabled:
pass
def on_text_motion(self, motion):
@ -125,7 +158,10 @@ class InputBox(widgets.WidgetBase):
pass
def on_mouse_press(self, x, y, buttons, modifiers):
pass
if self._check_hit(x, y):
self.enabled = True
else:
self.enabled = False
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
pass