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
|
|||
|
"""**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>**<2A>ؼ<EFBFBD><D8BC><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>"""
|
|||
|
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)
|
|||
|
# <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ť<EFBFBD><C5A5>Ӧ<EFBFBD>¼<EFBFBD>
|
|||
|
self.data_synchronization_button.clicked.connect(self.data_synchronization_button_action)
|
|||
|
# <20>ɼ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ť<EFBFBD><C5A5>Ӧ<EFBFBD>¼<EFBFBD>
|
|||
|
self.score_synchronization_button.clicked.connect(self.score_synchronization_button_action)
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>WiFi<46><69>ť<EFBFBD><C5A5>Ӧ<EFBFBD>¼<EFBFBD>
|
|||
|
self.wifi_widget.clicked.connect(self.wifi_button_action)
|
|||
|
# δ<><CEB4><EFBFBD>ӵ<EFBFBD>WiFi<46><69>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
self.wifi_disconnect_widget.clicked.connect(self.wifi_connect_button_action)
|
|||
|
|
|||
|
# WiFi<46><69><EFBFBD><EFBFBD>
|
|||
|
self.wifi_pop_windows = PopWindowsWifi(self)
|
|||
|
self.wifi_pop_windows.connect(self.connect2wifi)
|
|||
|
|
|||
|
# <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
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)
|
|||
|
|
|||
|
# ÿ<><C3BF>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD>ӵ<EFBFBD>WiFi<46><69><EFBFBD>ƽӿ<C6BD>
|
|||
|
self.timer = QTimer()
|
|||
|
self.timer.timeout.connect(self.get_wifi_name)
|
|||
|
self.timer.start(1000)
|
|||
|
|
|||
|
# <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><C3BD>ȶ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
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()
|
|||
|
|
|||
|
# <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD>ӵ<EFBFBD>WiFi<46><69><EFBFBD><EFBFBD>
|
|||
|
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)
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>WiFi<46><69><EFBFBD><EFBFBD>
|
|||
|
def connect2wifi(self, wifi_name):
|
|||
|
wifi_connect_state = self.eb.wifi_connect(wifi_name)
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WiFi<46><69>ť
|
|||
|
if wifi_connect_state:
|
|||
|
self.wifi_stacked_widget.setCurrentWidget(self.wifi_widget)
|
|||
|
else:
|
|||
|
self.wifi_stacked_widget.setCurrentWidget(self.wifi_disconnect_widget)
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>WiFi<46><69>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
def wifi_button_action(self):
|
|||
|
self.message_pop_windows.show(
|
|||
|
"<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Wi-Fi<46><69>"
|
|||
|
+ str(self.wifi_name)
|
|||
|
+ "<EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>Wi-Fi<46><69><EFBFBD><EFBFBD>, <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>?"
|
|||
|
)
|
|||
|
|
|||
|
# δ<><CEB4><EFBFBD>ӵ<EFBFBD>WiFi<46><69>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ö<EFBFBD>ȡWiFi<46>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
|
|||
|
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()
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WiFi<46><69>ť
|
|||
|
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()
|
|||
|
# ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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()
|
|||
|
# ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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()
|
|||
|
# ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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()
|
|||
|
# ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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()
|
|||
|
# ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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()
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
self.start_get_processing()
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
self.eb.waiting_data_synchronization()
|
|||
|
|
|||
|
def score_synchronization_button_action(self):
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
self.eb.send_score_synchronization_thread()
|
|||
|
self.pop_dialog_synchronization.show()
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
self.start_get_processing()
|
|||
|
|
|||
|
def synchronization_button_action(self):
|
|||
|
self.eb.stop_data_synchronization()
|
|||
|
# print('<27><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>ť')
|
|||
|
|
|||
|
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
|