feat: 改回来了(
This commit is contained in:
parent
834d050276
commit
dd29c67941
@ -35,7 +35,7 @@ class _DR_option(Options):
|
|||||||
"""
|
"""
|
||||||
name = 'DR Option'
|
name = 'DR Option'
|
||||||
# runtime options
|
# runtime options
|
||||||
CommandBox_use_TextEntry: bool = False
|
InputBox_use_TextEntry: bool = False
|
||||||
record_threads: bool = True
|
record_threads: bool = True
|
||||||
use_cProfile: bool = False
|
use_cProfile: bool = False
|
||||||
use_local_logging: bool = False
|
use_local_logging: bool = False
|
||||||
|
@ -74,208 +74,206 @@ class TextButton(widgets.WidgetBase):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
if not DR_option.CommandBox_use_TextEntry:
|
if not DR_option.InputBox_use_TextEntry:
|
||||||
class CommandBox(widgets.TextEntry):
|
class InputBox(widgets.WidgetBase):
|
||||||
...
|
"""
|
||||||
# class InputBox(widgets.WidgetBase):
|
input box
|
||||||
# """
|
"""
|
||||||
# input box
|
|
||||||
# """
|
def __init__(self,
|
||||||
#
|
x: int, y: int, width: int, height: int,
|
||||||
# def __init__(self,
|
message: str = '',
|
||||||
# x: int, y: int, width: int, height: int,
|
font_name: str = translate.微软等宽,
|
||||||
# message: str = '',
|
font_size: int = 15,
|
||||||
# font_name: str = translate.微软等宽,
|
font_bold: bool = False,
|
||||||
# font_size: int = 15,
|
font_italic: bool = False,
|
||||||
# font_bold: bool = False,
|
font_stretch: bool = False,
|
||||||
# font_italic: bool = False,
|
font_dpi: int = 100,
|
||||||
# font_stretch: bool = False,
|
text_color: [int, int, int] = (187, 187, 187, 255),
|
||||||
# font_dpi: int = 100,
|
out_line_color: [int, int, int] = (37, 116, 176),
|
||||||
# text_color: [int, int, int] = (187, 187, 187, 255),
|
cursor_color: [int, int, int] = (187, 187, 187),
|
||||||
# out_line_color: [int, int, int] = (37, 116, 176),
|
select_color: [int, int, int] = (63, 115, 255),
|
||||||
# cursor_color: [int, int, int] = (187, 187, 187),
|
out_line: int = 2,
|
||||||
# select_color: [int, int, int] = (63, 115, 255),
|
batch: Batch = None,
|
||||||
# out_line: int = 2,
|
group: Group = None):
|
||||||
# batch: Batch = None,
|
if batch is None:
|
||||||
# group: Group = None):
|
batch = Batch()
|
||||||
# if batch is None:
|
if group is None:
|
||||||
# batch = Batch()
|
group = Group()
|
||||||
# if group is None:
|
super().__init__(x, y, width, height)
|
||||||
# group = Group()
|
self.enabled = False
|
||||||
# super().__init__(x, y, width, height)
|
self._text = message
|
||||||
# self.enabled = False
|
self._cursor_poi = 0
|
||||||
# self._text = message
|
self.font = font.load(name=font_name, size=font_size,
|
||||||
# self._cursor_poi = 0
|
bold=font_bold, italic=font_italic, stretch=font_stretch,
|
||||||
# self.font = font.load(name=font_name, size=font_size,
|
dpi=font_dpi)
|
||||||
# bold=font_bold, italic=font_italic, stretch=font_stretch,
|
self.font_height = self.font.ascent - self.font.descent
|
||||||
# dpi=font_dpi)
|
self.out_bound = out_line
|
||||||
# self.font_height = self.font.ascent - self.font.descent
|
if DR_option.InputBox_use_TextEntry:
|
||||||
# self.out_bound = out_line
|
# 基于IncrementalTextLayout的处理系统
|
||||||
# if DR_option.InputBox_use_TextEntry:
|
self._doc = FormattedDocument(message)
|
||||||
# # 基于IncrementalTextLayout的处理系统
|
# self._doc.set_style()
|
||||||
# self._doc = FormattedDocument(message)
|
self._layout = IncrementalTextLayout(self._doc, self.font, width, height,
|
||||||
# # self._doc.set_style()
|
batch=batch, group=group)
|
||||||
# self._layout = IncrementalTextLayout(self._doc, self.font, width, height,
|
self._input_box = widgets.TextEntry(x, y, width, height,
|
||||||
# batch=batch, group=group)
|
self._doc, self._layout,
|
||||||
# self._input_box = widgets.TextEntry(x, y, width, height,
|
batch=batch, group=group)
|
||||||
# self._doc, self._layout,
|
else:
|
||||||
# batch=batch, group=group)
|
# 基于Label的处理系统
|
||||||
# else:
|
self._input_box = Label(x=x + out_line, y=y + out_line,
|
||||||
# # 基于Label的处理系统
|
width=width, height=self.font_height + self.out_bound * 2,
|
||||||
# self._input_box = Label(x=x + out_line, y=y + out_line,
|
color=text_color,
|
||||||
# width=width, height=self.font_height + self.out_bound * 2,
|
font_name=font_name, font_size=font_size,
|
||||||
# color=text_color,
|
batch=batch, group=group,
|
||||||
# font_name=font_name, font_size=font_size,
|
text=message)
|
||||||
# batch=batch, group=group,
|
self._HTML_box = HTMLLabel(x=x + out_line, y=y + out_line + 30,
|
||||||
# text=message)
|
width=width, height=self.font_height + self.out_bound * 2,
|
||||||
# self._HTML_box = HTMLLabel(x=x + out_line, y=y + out_line + 30,
|
batch=batch, group=group,
|
||||||
# width=width, height=self.font_height + self.out_bound * 2,
|
text=message)
|
||||||
# batch=batch, group=group,
|
self._out_box = Rectangle(x=x - out_line, y=y - out_line,
|
||||||
# text=message)
|
color=out_line_color,
|
||||||
# self._out_box = Rectangle(x=x - out_line, y=y - out_line,
|
width=width + (out_line * 2), height=height + (out_line * 2),
|
||||||
# color=out_line_color,
|
batch=batch, group=group)
|
||||||
# width=width + (out_line * 2), height=height + (out_line * 2),
|
self._光标 = Rectangle(x=x + out_line, y=y + out_line,
|
||||||
# batch=batch, group=group)
|
color=cursor_color,
|
||||||
# self._光标 = Rectangle(x=x + out_line, y=y + out_line,
|
width=1, height=self.font_height,
|
||||||
# color=cursor_color,
|
batch=batch, group=group)
|
||||||
# width=1, height=self.font_height,
|
self._选择框 = Rectangle(x=x, y=y, width=0, height=self.font_height,
|
||||||
# batch=batch, group=group)
|
color=select_color)
|
||||||
# self._选择框 = Rectangle(x=x, y=y, width=0, height=self.font_height,
|
self._选择的字 = Label(x=x, y=y, width=0, height=self.font_height,
|
||||||
# color=select_color)
|
color=text_color,
|
||||||
# self._选择的字 = Label(x=x, y=y, width=0, height=self.font_height,
|
font_name=font_name, font_size=font_size,
|
||||||
# color=text_color,
|
batch=batch, group=group,
|
||||||
# font_name=font_name, font_size=font_size,
|
text='')
|
||||||
# batch=batch, group=group,
|
|
||||||
# text='')
|
"""
|
||||||
#
|
输入框的属性
|
||||||
# """
|
"""
|
||||||
# 输入框的属性
|
|
||||||
# """
|
# 本身属性
|
||||||
#
|
@property
|
||||||
# # 本身属性
|
def text(self) -> str: # 输入框的文本
|
||||||
# @property
|
return self._text
|
||||||
# def text(self) -> str: # 输入框的文本
|
|
||||||
# return self._text
|
@text.setter
|
||||||
#
|
def text(self, value) -> None:
|
||||||
# @text.setter
|
assert type(value) is str, 'Input Box\'s text must be string!'
|
||||||
# def text(self, value) -> None:
|
self._text = value
|
||||||
# assert type(value) is str, 'Input Box\'s text must be string!'
|
self._input_box.text = value
|
||||||
# self._text = value
|
self._HTML_box.text = html.decode_text2HTML(value, show_style=True)
|
||||||
# self._input_box.text = value
|
|
||||||
# self._HTML_box.text = html.decode_text2HTML(value, show_style=True)
|
@property
|
||||||
#
|
def cursor_poi(self) -> int: # 光标位置
|
||||||
# @property
|
return self._cursor_poi
|
||||||
# def cursor_poi(self) -> int: # 光标位置
|
|
||||||
# return self._cursor_poi
|
@cursor_poi.setter
|
||||||
#
|
def cursor_poi(self, value) -> None:
|
||||||
# @cursor_poi.setter
|
assert type(value) is int, 'Input Box\'s cursor poi must be int!'
|
||||||
# def cursor_poi(self, value) -> None:
|
self._cursor_poi = value
|
||||||
# assert type(value) is int, 'Input Box\'s cursor poi must be int!'
|
self._光标.x = self.x + self.out_bound + self._input_box.content_width
|
||||||
# self._cursor_poi = value
|
|
||||||
# self._光标.x = self.x + self.out_bound + self._input_box.content_width
|
# 渲染时属性
|
||||||
#
|
@property
|
||||||
# # 渲染时属性
|
def opacity(self) -> int: # 透明度
|
||||||
# @property
|
return self._input_box.opacity
|
||||||
# def opacity(self) -> int: # 透明度
|
|
||||||
# return self._input_box.opacity
|
@opacity.setter
|
||||||
#
|
def opacity(self, value: int) -> None:
|
||||||
# @opacity.setter
|
assert type(value) is int, 'Input Box\'s opacity must be int!'
|
||||||
# def opacity(self, value: int) -> None:
|
self._input_box.opacity = value
|
||||||
# assert type(value) is int, 'Input Box\'s opacity must be int!'
|
self._out_box.opacity = value
|
||||||
# self._input_box.opacity = value
|
self._选择的字.opacity = value
|
||||||
# self._out_box.opacity = value
|
self._选择框.opacity = value
|
||||||
# self._选择的字.opacity = value
|
self._光标.opacity = value
|
||||||
# self._选择框.opacity = value
|
|
||||||
# self._光标.opacity = value
|
@property
|
||||||
#
|
def visible(self) -> bool: # 是否可见
|
||||||
# @property
|
return self._input_box.visible
|
||||||
# def visible(self) -> bool: # 是否可见
|
|
||||||
# return self._input_box.visible
|
@visible.setter
|
||||||
#
|
def visible(self, value: bool) -> None:
|
||||||
# @visible.setter
|
assert type(value) is bool, 'Input Box\'s visible must be bool!'
|
||||||
# def visible(self, value: bool) -> None:
|
self._input_box.visible = value
|
||||||
# assert type(value) is bool, 'Input Box\'s visible must be bool!'
|
self._out_box.visible = value
|
||||||
# self._input_box.visible = value
|
self._选择的字.visible = value
|
||||||
# self._out_box.visible = value
|
self._选择框.visible = value
|
||||||
# self._选择的字.visible = value
|
self._光标.visible = value
|
||||||
# self._选择框.visible = value
|
|
||||||
# self._光标.visible = value
|
@property
|
||||||
#
|
def value(self) -> str:
|
||||||
# @property
|
return self._text
|
||||||
# def value(self) -> str:
|
|
||||||
# return self._text
|
"""
|
||||||
#
|
事件调用
|
||||||
# """
|
"""
|
||||||
# 事件调用
|
|
||||||
# """
|
def _update_position(self):
|
||||||
#
|
self._input_box.position = self._x + self.out_bound, self._y + self.out_bound
|
||||||
# def _update_position(self):
|
self._out_box.position = self._x - self.out_bound, self._y - self.out_bound
|
||||||
# self._input_box.position = self._x + self.out_bound, self._y + self.out_bound
|
self._光标.position = self._x + self.out_bound, self._y + self.out_bound
|
||||||
# self._out_box.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: str):
|
||||||
# # 输入东西
|
if self.enabled:
|
||||||
# def on_text(self, text: str):
|
if text in ('\r', '\n'):
|
||||||
# if self.enabled:
|
if self.text:
|
||||||
# if text in ('\r', '\n'):
|
self.dispatch_event('on_commit', self.text)
|
||||||
# if self.text:
|
else:
|
||||||
# self.dispatch_event('on_commit', self.text)
|
self.text = f'{self.text[:self.cursor_poi]}{text}{self.text[self.cursor_poi:]}'
|
||||||
# else:
|
self.cursor_poi += len(text)
|
||||||
# self.text = f'{self.text[:self.cursor_poi]}{text}{self.text[self.cursor_poi:]}'
|
|
||||||
# self.cursor_poi += len(text)
|
# 移动光标
|
||||||
#
|
def on_text_motion(self, motion):
|
||||||
# # 移动光标
|
if self.enabled:
|
||||||
# def on_text_motion(self, motion):
|
# 根据按键处理
|
||||||
# if self.enabled:
|
# 单格移动光标(上下左右)
|
||||||
# # 根据按键处理
|
if motion in (key.MOTION_UP, key.MOTION_LEFT): # 往上一个移动
|
||||||
# # 单格移动光标(上下左右)
|
self.cursor_poi = max(0, self._cursor_poi - 1)
|
||||||
# if motion in (key.MOTION_UP, key.MOTION_LEFT): # 往上一个移动
|
elif motion in (key.MOTION_DOWN, key.MOTION_RIGHT): # 往下一个移动
|
||||||
# self.cursor_poi = max(0, self._cursor_poi - 1)
|
self.cursor_poi = min(len(self.text), self._cursor_poi + 1)
|
||||||
# elif motion in (key.MOTION_DOWN, key.MOTION_RIGHT): # 往下一个移动
|
# 大前后移动(开头或结尾)
|
||||||
# self.cursor_poi = min(len(self.text), self._cursor_poi + 1)
|
elif motion in (
|
||||||
# # 大前后移动(开头或结尾)
|
key.MOTION_BEGINNING_OF_LINE, key.MOTION_BEGINNING_OF_FILE, key.MOTION_PREVIOUS_PAGE): # 开头
|
||||||
# elif motion in (
|
self.cursor_poi = 0
|
||||||
# key.MOTION_BEGINNING_OF_LINE, key.MOTION_BEGINNING_OF_FILE, key.MOTION_PREVIOUS_PAGE): # 开头
|
elif motion in (key.MOTION_END_OF_LINE, key.MOTION_END_OF_FILE, key.MOTION_NEXT_PAGE): # 结尾
|
||||||
# self.cursor_poi = 0
|
self.cursor_poi = len(self.text)
|
||||||
# elif motion in (key.MOTION_END_OF_LINE, key.MOTION_END_OF_FILE, key.MOTION_NEXT_PAGE): # 结尾
|
# 删除操作
|
||||||
# self.cursor_poi = len(self.text)
|
elif motion == key.MOTION_BACKSPACE:
|
||||||
# # 删除操作
|
if self.text: # 如果有文字
|
||||||
# elif motion == key.MOTION_BACKSPACE:
|
self.text = f'{self.text[:self.cursor_poi - 1]}{self.text[self.cursor_poi:]}'
|
||||||
# if self.text: # 如果有文字
|
self.cursor_poi = max(0, self._cursor_poi - 1)
|
||||||
# self.text = f'{self.text[:self.cursor_poi - 1]}{self.text[self.cursor_poi:]}'
|
elif motion == key.MOTION_DELETE:
|
||||||
# self.cursor_poi = max(0, self._cursor_poi - 1)
|
if self.text and self.cursor_poi != len(self.text) - 1: # 如果有文字,并且光标不在最后
|
||||||
# elif motion == key.MOTION_DELETE:
|
self.text = f'{self.text[:self.cursor_poi]}{self.text[self.cursor_poi + 1:]}'
|
||||||
# if self.text and self.cursor_poi != len(self.text) - 1: # 如果有文字,并且光标不在最后
|
# 剪贴板操作
|
||||||
# self.text = f'{self.text[:self.cursor_poi]}{self.text[self.cursor_poi + 1:]}'
|
elif motion == key.MOTION_COPY:
|
||||||
# # 剪贴板操作
|
pass
|
||||||
# elif motion == key.MOTION_COPY:
|
elif motion == key.MOTION_PASTE:
|
||||||
# pass
|
paste_text = paste()
|
||||||
# elif motion == key.MOTION_PASTE:
|
self.text = f'{self.text[:self.cursor_poi]}{paste_text}{self.text[self.cursor_poi:]}'
|
||||||
# paste_text = paste()
|
self.cursor_poi += len(paste_text)
|
||||||
# self.text = f'{self.text[:self.cursor_poi]}{paste_text}{self.text[self.cursor_poi:]}'
|
|
||||||
# self.cursor_poi += len(paste_text)
|
def on_text_motion_select(self, motion):
|
||||||
#
|
pass
|
||||||
# def on_text_motion_select(self, motion):
|
|
||||||
# pass
|
def on_mouse_press(self, x, y, buttons, modifiers):
|
||||||
#
|
if self._check_hit(x, y) and self._input_box.visible:
|
||||||
# def on_mouse_press(self, x, y, buttons, modifiers):
|
self.enabled = True
|
||||||
# if self._check_hit(x, y) and self._input_box.visible:
|
else:
|
||||||
# self.enabled = True
|
self.enabled = False
|
||||||
# else:
|
|
||||||
# self.enabled = False
|
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
||||||
#
|
pass
|
||||||
# def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
|
||||||
# pass
|
def on_mouse_release(self, x, y, buttons, modifiers):
|
||||||
#
|
pass
|
||||||
# def on_mouse_release(self, x, y, buttons, modifiers):
|
|
||||||
# pass
|
def on_commit(self, text: str):
|
||||||
#
|
pass
|
||||||
# def on_commit(self, text: str):
|
|
||||||
# pass
|
|
||||||
#
|
InputBox.register_event_type('on_commit')
|
||||||
#
|
|
||||||
# InputBox.register_event_type('on_commit')
|
|
||||||
else:
|
else:
|
||||||
CommandBox = widgets.TextEntry
|
InputBox = widgets.TextEntry
|
||||||
# class InputBox(widgets.TextEntry):
|
# class InputBox(widgets.TextEntry):
|
||||||
# pass
|
# pass
|
||||||
|
@ -17,11 +17,6 @@ import time
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
# from DR
|
|
||||||
from Difficult_Rocket.utils import translate
|
|
||||||
from Difficult_Rocket.command.api import CommandText
|
|
||||||
from Difficult_Rocket.utils.new_thread import new_thread
|
|
||||||
|
|
||||||
# from pyglet
|
# from pyglet
|
||||||
import pyglet
|
import pyglet
|
||||||
from pyglet.text import Label
|
from pyglet.text import Label
|
||||||
@ -29,6 +24,18 @@ from pyglet.window import key
|
|||||||
from pyglet.gui import widgets
|
from pyglet.gui import widgets
|
||||||
from pyglet.graphics import Batch, Group
|
from pyglet.graphics import Batch, Group
|
||||||
|
|
||||||
|
# from DR
|
||||||
|
from Difficult_Rocket.utils import translate
|
||||||
|
from Difficult_Rocket.command.api import CommandText
|
||||||
|
from Difficult_Rocket.utils.new_thread import new_thread
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CommandLineTextEntry(widgets.TextEntry):
|
||||||
|
"""
|
||||||
|
基于 Text Entry 重写的 Command Line
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CommandLine(widgets.WidgetBase):
|
class CommandLine(widgets.WidgetBase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user