马上做好了啊啊啊啊
This commit is contained in:
parent
6ea0407275
commit
d41b41b883
@ -74,6 +74,10 @@ class NumWidget:
|
|||||||
def value(self) -> int:
|
def value(self) -> int:
|
||||||
return int(self.label.text)
|
return int(self.label.text)
|
||||||
|
|
||||||
|
@value.setter
|
||||||
|
def value(self, value: int) -> None:
|
||||||
|
self.label.text = str(value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display(self) -> bool:
|
def display(self) -> bool:
|
||||||
return self._display
|
return self._display
|
||||||
@ -139,6 +143,7 @@ class MainWindow(Window):
|
|||||||
self.on_middle = False
|
self.on_middle = False
|
||||||
self.middle_base = (0, 0)
|
self.middle_base = (0, 0)
|
||||||
self.drag_speed = 0
|
self.drag_speed = 0
|
||||||
|
self.drag_start = None
|
||||||
|
|
||||||
self.name_info_displays = {}
|
self.name_info_displays = {}
|
||||||
self.init_name_dispaly()
|
self.init_name_dispaly()
|
||||||
@ -165,7 +170,8 @@ class MainWindow(Window):
|
|||||||
group=cover_group,
|
group=cover_group,
|
||||||
)
|
)
|
||||||
self.main_frame.add_calculate_func(
|
self.main_frame.add_calculate_func(
|
||||||
self.num_cover, lambda rec, width, height, window: (37 + 8 * 65, height - 143)
|
self.num_cover,
|
||||||
|
lambda rec, width, height, window: (37 + 8 * 65, height - 143),
|
||||||
)
|
)
|
||||||
# 从大到小
|
# 从大到小
|
||||||
num_group = Group(parent=self.num_group, order=10)
|
num_group = Group(parent=self.num_group, order=10)
|
||||||
@ -278,7 +284,7 @@ class MainWindow(Window):
|
|||||||
self.num_hints[0].y = self.height - (173 + 30 * 6)
|
self.num_hints[0].y = self.height - (173 + 30 * 6)
|
||||||
# 剩下的需要先判断那个是中间的
|
# 剩下的需要先判断那个是中间的
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
data = sorted(enumerate(x.value for x in self.display_dict[NumStatus(i)]))
|
data = sorted(enumerate(x.value for x in self.display_dict[NumStatus(i)]), key=lambda x: x[1])
|
||||||
middle_index = data[1][0]
|
middle_index = data[1][0]
|
||||||
self.num_hints[i].y = self.height - (173 + 30 * middle_index)
|
self.num_hints[i].y = self.height - (173 + 30 * middle_index)
|
||||||
|
|
||||||
@ -363,19 +369,50 @@ class MainWindow(Window):
|
|||||||
self.update_num_display()
|
self.update_num_display()
|
||||||
return
|
return
|
||||||
self.num_slide += dy
|
self.num_slide += dy
|
||||||
print(self.num_cover.y, self.num_slide, dy)
|
|
||||||
self.update_num_display()
|
self.update_num_display()
|
||||||
|
|
||||||
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
|
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
|
||||||
self.update_slide(int(scroll_y) * 10)
|
self.update_slide(int(scroll_y) * -10)
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, button, modifiers):
|
def on_mouse_press(self, x, y, button, modifiers):
|
||||||
self.middle_base = (x, y)
|
self.middle_base = (x, y)
|
||||||
if not button & mouse.MIDDLE: # 中键
|
if not button & mouse.MIDDLE: # 中键
|
||||||
self.on_middle = False
|
self.on_middle = False
|
||||||
|
if button & mouse.LEFT:
|
||||||
|
# 捏起
|
||||||
|
for idx, widget in self.num_dict.items():
|
||||||
|
if widget.aabb(x, y):
|
||||||
|
self.drag_start = idx
|
||||||
|
print(f"捏起 {idx}")
|
||||||
|
break
|
||||||
|
|
||||||
def on_mouse_release(self, x, y, button, modifiers):
|
def on_mouse_release(self, x, y, button, modifiers):
|
||||||
self.on_middle = False
|
self.on_middle = False
|
||||||
|
if button & mouse.LEFT:
|
||||||
|
find = []
|
||||||
|
if self.drag_start: # 有开始目标
|
||||||
|
for idx, target_widget in self.num_dict.items():
|
||||||
|
if target_widget.aabb(x, y):
|
||||||
|
if idx == self.drag_start:
|
||||||
|
# 如果是自己, 就不做任何操作
|
||||||
|
continue
|
||||||
|
# 搜索对面那个, 修改双方显示内容
|
||||||
|
# 交换 value
|
||||||
|
find = [self.drag_start, idx]
|
||||||
|
break
|
||||||
|
if find:
|
||||||
|
print(f"交换 {find}")
|
||||||
|
(
|
||||||
|
self.num_dict[find[0]].value,
|
||||||
|
self.num_dict[find[1]].value,
|
||||||
|
) = find[1], find[0]
|
||||||
|
# 交换键
|
||||||
|
self.num_dict[find[0]], self.num_dict[find[1]] = (
|
||||||
|
self.num_dict[find[1]],
|
||||||
|
self.num_dict[find[0]],
|
||||||
|
)
|
||||||
|
self.drag_start = None
|
||||||
|
self.update_num_display()
|
||||||
|
|
||||||
def on_mouse_leave(self, x, y):
|
def on_mouse_leave(self, x, y):
|
||||||
self.on_middle = False
|
self.on_middle = False
|
||||||
@ -389,8 +426,11 @@ class MainWindow(Window):
|
|||||||
return
|
return
|
||||||
drag_y = y - self.middle_base[1]
|
drag_y = y - self.middle_base[1]
|
||||||
# 取个对数, 保证不会太快
|
# 取个对数, 保证不会太快
|
||||||
# drag_y = math.log(abs(drag_y) + 1, 2) * (1 if drag_y > 0 else -1)
|
|
||||||
self.drag_speed = int(drag_y)
|
self.drag_speed = int(drag_y)
|
||||||
|
if self.drag_start:
|
||||||
|
# 拖动
|
||||||
|
self.num_dict[self.drag_start].x = x - 17
|
||||||
|
self.num_dict[self.drag_start].y = y - 7
|
||||||
|
|
||||||
def on_resize(self, width, height):
|
def on_resize(self, width, height):
|
||||||
super().on_resize(width, height)
|
super().on_resize(width, height)
|
||||||
|
Loading…
Reference in New Issue
Block a user