def __init__(self): # basic config self.on_python_v_info = sys.version_info self.on_python_v = sys.version.split(' ')[0] self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time())) # lang_config self.language = tools.load_file('configs/main.config', 'runtime')['language'] tr.set_language(self.language) # logging config log_config = tools.load_file('configs/logger.toml') file_name = log_config['handlers']['file']['filename'] del log_config['handlers']['file']['datefmt'] log_config['handlers']['file'][ 'filename'] = f'logs/{file_name.format(self.start_time)}' try: logging.config.dictConfig(log_config) self.logger = logging.getLogger('main') except ValueError: # it should be no 'logs/' folder os.mkdir('logs') logging.config.dictConfig(log_config) self.logger = logging.getLogger('main') self.logger.info(tr['main']['logger.mkdir']) self.logger.info(tr['main']['logger.created']) # version check self.python_version_check() self.setup()
def __init__(self, net_mode='local'): start_time = time.time_ns() # logging self.logger = logging.getLogger('client') # config self.config = tools.load_file('./configs/main.toml') # value self.process_id = 'Client' self.process_name = 'Client process' self.process_pid = os.getpid() self.net_mode = net_mode self.caption = tools.name_handler( self.config['window']['caption'], {'version': self.config['runtime']['version']}) self.window = ClientWindow( net_mode=self.net_mode, width=int(self.config['window']['width']), height=int(self.config['window']['height']), fullscreen=tools.format_bool(self.config['window']['full_screen']), caption=self.caption, resizable=tools.format_bool(self.config['window']['resizable']), visible=tools.format_bool(self.config['window']['visible'])) self.logger.info(tr.lang('client', 'setup.done')) end_time = time.time_ns() self.use_time = end_time - start_time self.logger.info( tr.lang('client', 'setup.use_time').format( Decimal(self.use_time) / 1000000000)) self.logger.debug( tr.lang('client', 'setup.use_time_ns').format(self.use_time))
def save_info(self): self.logger.info('save_info start') config_file = tools.load_file('./configs/main.toml') config_file['window']['width'] = self.width config_file['window']['height'] = self.height toml.dump(config_file, open('./configs/main.toml', 'w')) self.logger.info('save_info end')
def set_language(self, language) -> None: try: self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml') self.语言 = language except FileNotFoundError: raise TranslateKeyNotFound( f'{language}\'s language toml file not found')
def __setitem__(self, key, value) -> None: if key == 'language' or key == 'lang': try: self.翻译结果 = tools.load_file(f'configs/lang/{value}.toml') self.语言 = value except FileNotFoundError: if self.直接返回原始数据: return None raise TranslateKeyNotFound( f'{value}\'s language toml file not found') else: raise NotImplementedError
def __init__(self, net_mode='local', Dev: Delivery = Delivery): # father class __init__() # mp.Process.__init__(self) # logging self.logger = logging.getLogger('server') # value self.process_id = 'Server' self.process_name = 'server process' # config self.config = tools.load_file('configs/main.config') self.dev = Dev self.net_mode = net_mode self.logger.info(tr.lang('server', 'setup.done'))
def __init__(self, net_mode='local', *args, **kwargs): start_time = time.time_ns() super().__init__(*args, **kwargs) """ :param dev_list: 共享内存 :param dev_dic: 共享内存 :param logger: logger :param net_mode: 网络模式 # local / ip """ # logging self.logger = logging.getLogger('client') # value self.net_mode = net_mode self.run_input = False # configs pyglet.resource.path = ['/textures/'] pyglet.resource.reindex() self.set_icon(pyglet.image.load('./textures/icon.png')) self.main_config = tools.load_file('./configs/main.toml') self.game_config = tools.load_file('./configs/game.config') # FPS self.FPS = Decimal(int(self.main_config['runtime']['fps'])) self.SPF = Decimal('1') / self.FPS self.fps_log = FpsLogger(stable_fps=int(self.FPS)) # batch self.part_batch = pyglet.graphics.Batch() self.label_batch = pyglet.graphics.Batch() # frame self.frame = pyglet.gui.Frame(self, order=20) self.M_frame = pyglet.gui.MovableFrame(self, modifier=key.LCTRL) # self.DRscreen = DRScreen(self) # setup self.setup() # 命令显示 self.command_group = pyglet.graphics.Group(0) self.command_tree = tree.CommandTree(tree.DR_command) self.input_box = InputBox(x=50, y=30, width=300, height=20, batch=self.label_batch) # 实例化 self.push_handlers(self.input_box) self.input_box.enabled = True # fps显示 self.fps_label = pyglet.text.Label(x=10, y=self.height - 10, width=self.width - 20, height=20, anchor_x='left', anchor_y='top', font_name=translate.微软等宽无线, font_size=20, multiline=True, batch=self.label_batch, group=self.command_group) # 设置刷新率 pyglet.clock.schedule_interval(self.draw_update, float(self.SPF)) # 完成设置后的信息输出 self.logger.info(tr.lang('window', 'setup.done')) self.logger.info( tr.lang('window', 'os.pid_is').format(os.getpid(), os.getppid())) end_time = time.time_ns() self.use_time = end_time - start_time self.logger.info( tr.lang('window', 'setup.use_time').format( Decimal(self.use_time) / 1000000000)) self.logger.debug( tr.lang('window', 'setup.use_time_ns').format(self.use_time)) self.count = 0
def __init__(self, language: str = 'zh-CN') -> None: self.语言 = language self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml') self.默认翻译 = tools.load_file('configs/lang/zh-CN.toml') self.直接返回原始数据 = True