274 lines
9.7 KiB
Python
274 lines
9.7 KiB
Python
# coding: gb2312
|
||
from PyQt5.QtCore import QTimer
|
||
from LSZXPagesLibrary.consensus import *
|
||
from LSZXPagesLibrary.home_page_layout_define import HomePageLayoutDefine
|
||
from LSZXPagesLibrary.pop_message_dialog import PopDialogMessage
|
||
from LSZXPagesLibrary.pop_synchronization_dialog import PopDialogSynchronization
|
||
from LSZXPagesLibrary.pop_windows_wifi import PopWindowsWifi
|
||
from LSZXPagesLibrary.tool import format_time
|
||
from PureBackend.global_execrise_backend import GEB
|
||
|
||
|
||
class HomePage(HomePageLayoutDefine):
|
||
|
||
def __init__(self):
|
||
super(HomePage, self).__init__()
|
||
self.eb = GEB().get_geb()
|
||
self.wifi_name = None
|
||
"""**控件行为初始化区**控件行为初始化区**控件行为初始化区**控件行为初始化区**控件行为初始化区**控件行为初始化区"""
|
||
self.sit_up_widget.clicked.connect(self.sit_up_button_action)
|
||
self.pull_up_widget.clicked.connect(self.pull_up_button_action)
|
||
self.hanging_up_widget.clicked.connect(self.hanging_up_button_action)
|
||
self.push_up_widget.clicked.connect(self.push_up_button_action)
|
||
self.runaround_widget.clicked.connect(self.runaround_button_action)
|
||
self.running_widget.clicked.connect(self.running_button_action)
|
||
# 数据同步按钮响应事件
|
||
self.data_synchronization_button.clicked.connect(self.data_synchronization_button_action)
|
||
# 成绩同步按钮响应事件
|
||
self.score_synchronization_button.clicked.connect(self.score_synchronization_button_action)
|
||
# 已连接的WiFi按钮响应事件
|
||
self.wifi_widget.clicked.connect(self.wifi_button_action)
|
||
# 未连接的WiFi按钮绑定事件
|
||
self.wifi_disconnect_widget.clicked.connect(self.wifi_connect_button_action)
|
||
|
||
# WiFi弹窗
|
||
self.wifi_pop_windows = PopWindowsWifi(self)
|
||
self.wifi_pop_windows.connect(self.connect2wifi)
|
||
|
||
# 信息弹窗
|
||
self.message_pop_windows = PopDialogMessage(self)
|
||
self.message_pop_windows.connect(self.message_pop_commit)
|
||
|
||
self.pop_dialog_synchronization = PopDialogSynchronization(self)
|
||
self.pop_dialog_synchronization.connect(self.synchronization_button_action)
|
||
|
||
# 每隔1秒访问一次获取当前链接的WiFi名称接口
|
||
self.timer = QTimer()
|
||
self.timer.timeout.connect(self.get_wifi_name)
|
||
self.timer.start(1000)
|
||
|
||
# 获取并设置进度定时器
|
||
self.status_num = 0
|
||
self.timer_get_processing = QTimer()
|
||
self.timer_get_processing.timeout.connect(self.get_synchronization_processing)
|
||
# self.timer_get_processing.start(1000)
|
||
|
||
self.get_train_info()
|
||
|
||
def start_wifi_detect(self):
|
||
self.timer.start(1000)
|
||
|
||
def stop_wifi_detect(self):
|
||
self.timer.stop()
|
||
|
||
def refresh(self):
|
||
self.start_wifi_detect()
|
||
|
||
def start_get_processing(self):
|
||
self.timer_get_processing.start(50)
|
||
|
||
def stop_get_processing(self):
|
||
self.timer_get_processing.stop()
|
||
|
||
# 获取当前链接的WiFi名称
|
||
def get_wifi_name(self):
|
||
self.wifi_name = self.eb.get_connected_wifi_name()
|
||
if self.wifi_name is not None:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_widget)
|
||
self.timer.stop()
|
||
else:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_disconnect_widget)
|
||
|
||
# 链接WiFi动作
|
||
def connect2wifi(self, wifi_name):
|
||
wifi_connect_state = self.eb.wifi_connect(wifi_name)
|
||
# 如果连接成功则显示蓝色背景的WiFi按钮
|
||
if wifi_connect_state:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_widget)
|
||
else:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_disconnect_widget)
|
||
|
||
# 已连接的WiFi按钮动作
|
||
def wifi_button_action(self):
|
||
self.message_pop_windows.show(
|
||
"当前已连接Wi-Fi:"
|
||
+ str(self.wifi_name)
|
||
+ ",此操作将断开Wi-Fi连接, 是否继续?"
|
||
)
|
||
|
||
# 未连接的WiFi按钮动作(这里应该读取WiFi列表,显示)
|
||
def wifi_connect_button_action(self):
|
||
wifi_list = self.eb.get_wifi_list()
|
||
wifi_list = [
|
||
{"name": wifi}
|
||
for wifi in wifi_list
|
||
]
|
||
self.wifi_pop_windows.show(wifi_list)
|
||
|
||
def message_pop_commit(self):
|
||
state = self.eb.wifi_disconnect()
|
||
# 如果断开连接成功则显示灰色背景的WiFi按钮
|
||
if state:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_disconnect_widget)
|
||
else:
|
||
self.wifi_stacked_widget.setCurrentWidget(self.wifi_widget)
|
||
|
||
def get_train_info(self):
|
||
train_info = self.eb.get_train_info()
|
||
self.standard_value.setText(train_info["standards_display"])
|
||
self.difficulty_value.setText(train_info["difficulty_display"])
|
||
|
||
def sit_up_button_action(self):
|
||
self.stop_wifi_detect()
|
||
# 注入数据
|
||
data = {
|
||
EXERCISE_TYPE: SIT_UP,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: score['situp_score'],
|
||
COUNT: score['situp_count'],
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=PICK_UP_PAGE, data=data)
|
||
|
||
def pull_up_button_action(self):
|
||
self.stop_wifi_detect()
|
||
# 注入数据
|
||
data = {
|
||
EXERCISE_TYPE: PULL_UP,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: score['pullup_score'],
|
||
COUNT: score['pullup_count'],
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=PICK_UP_PAGE, data=data)
|
||
|
||
def hanging_up_button_action(self):
|
||
self.stop_wifi_detect()
|
||
# 注入数据
|
||
data = {
|
||
EXERCISE_TYPE: HANGING,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: score['hanging_score'],
|
||
COUNT: score['hanging_count'],
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=PICK_UP_PAGE, data=data)
|
||
|
||
def push_up_button_action(self):
|
||
self.stop_wifi_detect()
|
||
# 注入数据
|
||
data = {
|
||
EXERCISE_TYPE: PUSH_UP,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: score['pushup_score'],
|
||
COUNT: score['pushup_count'],
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=PICK_UP_PAGE, data=data)
|
||
|
||
def runaround_button_action(self):
|
||
self.stop_wifi_detect()
|
||
# 注入数据
|
||
data = {
|
||
EXERCISE_TYPE: RUNAROUND,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: score['run_bf_score'],
|
||
COUNT: score['run_bf_count'],
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=PICK_UP_PAGE, data=data)
|
||
|
||
def running_button_action(self):
|
||
self.stop_wifi_detect()
|
||
data = {
|
||
EXERCISE_TYPE: RUNNING,
|
||
PERSON_LIST: [
|
||
{
|
||
IS_CHOOSE: False,
|
||
NAME: score["name"],
|
||
ID: score["id"],
|
||
SCORE: int(score['running_score']) if score['running_score'] else None,
|
||
COUNT: format_time(score['running_count']) if score['running_count'] else None,
|
||
CLASS: score['class'],
|
||
BAND_ID: score["band_id"]
|
||
}
|
||
for score in self.eb.get_all_score()
|
||
]
|
||
}
|
||
self.jump2(page_name=RUNNING_PAGE, data=data)
|
||
|
||
def data_synchronization_button_action(self):
|
||
self.pop_dialog_synchronization.show()
|
||
# 启动定时器
|
||
self.start_get_processing()
|
||
# 开启数据同步
|
||
self.eb.waiting_data_synchronization()
|
||
|
||
def score_synchronization_button_action(self):
|
||
# 开启成绩同步
|
||
self.eb.send_score_synchronization_thread()
|
||
self.pop_dialog_synchronization.show()
|
||
# 启动定时器
|
||
self.start_get_processing()
|
||
|
||
def synchronization_button_action(self):
|
||
self.eb.stop_data_synchronization()
|
||
# print('点击取消同步按钮')
|
||
|
||
def get_synchronization_processing(self):
|
||
processing_data = self.eb.get_synchronization_processing()
|
||
task_had_done = processing_data['task_had_done']
|
||
task_num = processing_data['task_number']
|
||
status = processing_data['status']
|
||
if task_num > 0:
|
||
processing = int((task_had_done / task_num) * 100)
|
||
else:
|
||
processing = 0
|
||
self.pop_dialog_synchronization.circle_percentage.set_data(processing)
|
||
if status == 2 or status == 0:
|
||
self.status_num += 1
|
||
if self.status_num >= 3:
|
||
self.stop_get_processing()
|
||
self.pop_dialog_synchronization.close()
|
||
self.status_num = 0
|