commit about v 0.5.3
release comming(no DEMO)
This commit is contained in:
parent
60e235f14e
commit
e526c90d4b
@ -171,7 +171,7 @@ class CommandLine(widgets.WidgetBase):
|
||||
self.caret.on_text(text)
|
||||
if text in ('\r', '\n'): # goto a new line
|
||||
if self.text[0] == self.command_text:
|
||||
self.dispatch_event('on_command', self.text)
|
||||
self.dispatch_event('on_command', self.text[1:])
|
||||
else:
|
||||
self.dispatch_event('on_message', self.text)
|
||||
self.command_view = -1
|
||||
@ -180,8 +180,13 @@ class CommandLine(widgets.WidgetBase):
|
||||
else:
|
||||
self.text = f'{self.text[:self._text_position]}{text}{self.text[self._text_position:]}' # 插入字符(简单粗暴)
|
||||
self._text_position += 1
|
||||
elif text == 't': # open command line
|
||||
self.editing = not self.editing
|
||||
elif text == 't': # open message line
|
||||
self.editing = True
|
||||
elif text == '/': # open command line
|
||||
self.editing = True
|
||||
self.text = '/'
|
||||
self._text_position = 1
|
||||
self.caret.on_text_motion(key.MOTION_RIGHT)
|
||||
|
||||
def on_text_motion(self, motion):
|
||||
if self.editing:
|
||||
|
@ -11,29 +11,66 @@ GNU Lesser General Public License v3.0(GNU LGPL v3)
|
||||
(have some changes)
|
||||
"""
|
||||
|
||||
__all__ = [
|
||||
'new_thread',
|
||||
'FunctionThread'
|
||||
]
|
||||
|
||||
def new_thread(thread_name: Optional[str or Callable] = None, Daemon=False):
|
||||
|
||||
def copy_signature(target: Callable, origin: Callable) -> Callable:
|
||||
"""
|
||||
Copy the function signature of origin into target
|
||||
"""
|
||||
# https://stackoverflow.com/questions/39926567/python-create-decorator-preserving-function-arguments
|
||||
target.__signature__ = inspect.signature(origin)
|
||||
return target
|
||||
|
||||
|
||||
class FunctionThread(threading.Thread):
|
||||
__NONE = object()
|
||||
|
||||
def __init__(self, target, name, args, kwargs):
|
||||
super().__init__(target=target, args=args, kwargs=kwargs, name=name, daemon=True)
|
||||
self.__return_value = self.__NONE
|
||||
self.__error = None
|
||||
|
||||
def wrapped_target(*args_, **kwargs_):
|
||||
try:
|
||||
self.__return_value = target(*args_, **kwargs_)
|
||||
except Exception as e:
|
||||
self.__error = e
|
||||
raise e from None
|
||||
|
||||
self._target = wrapped_target
|
||||
|
||||
def get_return_value(self, block: bool = False, timeout: Optional[float] = None):
|
||||
if block:
|
||||
self.join(timeout)
|
||||
if self.__return_value is self.__NONE:
|
||||
if self.is_alive():
|
||||
raise RuntimeError('The thread is still running')
|
||||
raise self.__error
|
||||
return self.__return_value
|
||||
|
||||
|
||||
def new_thread(thread_name: Optional[str or Callable] = None):
|
||||
"""
|
||||
Use a new thread to execute the decorated function
|
||||
The function return value will be set to the thread instance that executes this function
|
||||
The name of the thread can be specified in parameter
|
||||
"""
|
||||
|
||||
def wrapper(func):
|
||||
@functools.wraps(func) # to preserve the origin function information
|
||||
def wrap(*args, **kwargs):
|
||||
thread_ = threading.Thread(target=func, args=args, kwargs=kwargs, name=thread_name)
|
||||
thread_.setDaemon(Daemon)
|
||||
thread_.start()
|
||||
crash.all_thread.append(thread_)
|
||||
return thread_
|
||||
|
||||
thread = FunctionThread(target=func, args=args, kwargs=kwargs, name=thread_name)
|
||||
thread.start()
|
||||
crash.all_thread.append(thread)
|
||||
return thread
|
||||
# bring the signature of the func to the wrap function
|
||||
# so inspect.getfullargspec(func) works correctly
|
||||
# https://stackoverflow.com/questions/39926567/python-create-decorator-preserving-function-arguments
|
||||
wrap.__signature__ = inspect.signature(func)
|
||||
copy_signature(wrap, func)
|
||||
wrap.original = func # access this field to get the original function
|
||||
return wrap
|
||||
|
||||
# Directly use @on_new_thread without ending brackets case
|
||||
if isinstance(thread_name, Callable):
|
||||
this_is_a_function = thread_name
|
||||
@ -41,3 +78,4 @@ def new_thread(thread_name: Optional[str or Callable] = None, Daemon=False):
|
||||
return wrapper(this_is_a_function)
|
||||
# Use @on_new_thread with ending brackets case
|
||||
return wrapper
|
||||
|
||||
|
@ -117,6 +117,8 @@ class ClientWindow(pyglet.window.Window):
|
||||
length=int(self.game_config['command']['show']),
|
||||
batch=self.label_batch, group=self.command_group)
|
||||
self.push_handlers(self.command)
|
||||
self.command.set_handler('on_command', self.on_command)
|
||||
self.command.set_handler('on_message', self.on_message)
|
||||
# fps显示
|
||||
self.fps_label = pyglet.text.Label(x=10, y=self.height - 10,
|
||||
anchor_x='left', anchor_y='top',
|
||||
@ -198,16 +200,24 @@ class ClientWindow(pyglet.window.Window):
|
||||
self.label_batch.draw()
|
||||
|
||||
|
||||
"""
|
||||
command line event
|
||||
"""
|
||||
|
||||
def on_command(self, command):
|
||||
self.logger.info(tr.lang('window', 'command.text').format(command))
|
||||
|
||||
def on_message(self, message):
|
||||
self.logger.info(tr.lang('window', 'message.text').format(message))
|
||||
|
||||
"""
|
||||
keyboard and mouse input
|
||||
"""
|
||||
|
||||
def on_mouse_motion(self, x, y, dx, dy) -> None:
|
||||
# self.logger.debug('按键移动 %s %s %s %s' % (x, y, dx, dy))
|
||||
pass
|
||||
|
||||
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers) -> None:
|
||||
# self.logger.debug('按键拖拽 %s %s %s %s %s %s' % (x, y, dx, dy, buttons, modifiers))
|
||||
pass
|
||||
|
||||
def on_mouse_press(self, x, y, button, modifiers) -> None:
|
||||
|
@ -36,6 +36,8 @@
|
||||
'text.new_line': 'new line',
|
||||
'text.motion': 'text move {}',
|
||||
'text.motion_select': 'text select {}',
|
||||
'command.text': 'input command: {}',
|
||||
'message.text': 'input message: {}',
|
||||
'libs.local': 'using local pyglet, version: {}',
|
||||
'libs.outer': 'using global pyglet, version: {}\n(may cause bug)',
|
||||
'fonts.found': 'found fonts in font lib: {}'
|
||||
|
@ -36,6 +36,8 @@
|
||||
'text.new_line': '换行',
|
||||
'text.motion': '光标移动 {}',
|
||||
'text.motion_select': '光标选择 {}',
|
||||
'command.text': '输入命令: {}',
|
||||
'message.text': '输入信息: {}',
|
||||
'libs.local': '正在使用本地 pyglet 库 版本为: {}',
|
||||
'libs.outer': '正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug,因为本地库版本为2.0dev9)',
|
||||
'fonts.found': '在字体列表中找到以下字体库: {}'
|
||||
|
@ -26,10 +26,29 @@
|
||||
- handler of `on_key_press` and `on_key_release` and `on_text`
|
||||
- `game.config` config file
|
||||
- `lang/en-us.json5` now up to date with `lang/zh-CN.json5`
|
||||
- `graphics/frame/AllFrame`
|
||||
- `translate/Lang.翻译` same as `Lang.lang`
|
||||
- `command/CommandLine` to render command line
|
||||
|
||||
### Translate
|
||||
|
||||
- Add
|
||||
- `window`
|
||||
- `message.text`
|
||||
- `command.text`
|
||||
- `text.motion`
|
||||
- `text.motion_select`
|
||||
- `setup.use_time_ns`
|
||||
- `fonts.found`
|
||||
- `client`
|
||||
- `setup.use_time_ns`
|
||||
|
||||
### Command
|
||||
|
||||
- now you can press `t` to call out a message window
|
||||
- or press `/` to open command line
|
||||
- not done
|
||||
- useless until now
|
||||
|
||||
## 20210928 V 0.5.2
|
||||
|
||||
### Change
|
||||
|
BIN
textures/runtime/DR-icon.png
Normal file
BIN
textures/runtime/DR-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
Loading…
Reference in New Issue
Block a user