def build(self): error_handler() errorvalue = self.textBrowser error_file = open('error.txt', 'r') errors = error_file.readlines() i = 0 while (i < len(errors)): errorvalue.append(errors[i]) i = i + 1 assembler_checker(errors[0])
def open_file(file): try: subprocess.run([str(file.path)], shell=True) except subprocess.CalledProcessError: logging.error(error_handler()) except FileNotFoundError: logging.error(error_handler()) logging.error("File Not Found: {}".format(str(file.path))) except OSError: logging.error(error_handler())
def thread_UI_update(): while param.quit_msg['quit_flag'] == False: time.sleep(0.02) #vol button if param.button_click['volume_down'] == True: #vol- button click param.button_click['volume_down'] = False fun_update_ui('set_to_vol_down') msg_list.msg_to_tx2[7]['VOLUME_IS_DOWN'] = param.param1['volume'] udp_client.send_msg(msg_list.msg_to_tx2[7]) if param.button_click['volume_up'] == True: #vol+ button click param.button_click['volume_up'] = False fun_update_ui('set_to_vol_up') msg_list.msg_to_tx2[6]['VOLUME_IS_UP'] = param.param1['volume'] udp_client.send_msg(msg_list.msg_to_tx2[6]) #mute button if param.button_click['mute'] == True: #mute button click param.button_click['mute'] = False fun_update_ui('set_to_mute') udp_client.send_msg(msg_list.msg_to_tx2[8]) if param.button_click['unmute'] == True: #unmute button click param.button_click['unmute'] = False fun_update_ui('set_to_unmute') udp_client.send_msg(msg_list.msg_to_tx2[9]) #wifi icon if msg_list.msg_from_tx2['WIFI_RSSI'] != -1: # tx2 报错 print('rssi:', msg_list.msg_from_tx2['WIFI_RSSI']) param.param1['rssi'] = msg_list.msg_from_tx2['WIFI_RSSI'] msg_list.msg_from_tx2['WIFI_RSSI'] = -1 msg_list.msg_to_tx2[11]['WIFI_RSSI'] = param.param1['rssi'] fun_update_ui('set_to_wifi') udp_client.send_msg(msg_list.msg_to_tx2[11]) #error icon if msg_list.msg_from_tx2['ERROR_CODE'] != 0: # tx2 报错 msg_list.msg_from_tx2['ERROR_CODE'] = 0 error.error_handler('ERROR_CODE_TX2_ERROR') msg_list.msg_to_tx2[5]['ERROR_CODE'] = 0 udp_client.send_msg(msg_list.msg_to_tx2[5])
def ask_directory(ask_mess): str_res = input(ask_mess) path = Path(str(str_res)) try: os.listdir(str(path)) return True, path except FileNotFoundError: print("Directory \"{}\" is not valid, please enter a valid path: ". format(str(path))) except OSError: logging.error(error_handler()) return False, ""
def loadFrom(cls, path): try: with open(path, 'r') as f: try: preference = json.load(f, object_hook=cls._dico_to_preference) except json.JSONDecodeError: preference = Preference() logging.warning("Invalid json file:\n{}".format( error_handler())) finally: return preference except FileNotFoundError: return Preference()
def saveTo(cls, path, preference): if not path: return directory_path = path.parents[0] try: os.listdir(str(directory_path)) except FileNotFoundError: try: os.makedirs(directory_path) except Exception: logging.error("Can't create {}\n{}".format( directory_path, error_handler())) return with open(path, 'w') as f: data = json.dumps(cls._preference_to_dico(preference), indent=4) print("data: {}".format(data)) f.write(data)
def generate_media_list(directory_path, media_type=MediaType.ANY, reccurent=False): try: medias = [] for path_name, dir_names, file_names in os.walk( directory_path, topdown=True, onerror=error_handler): for file_name in file_names: media = Media(path_name, file_name) if media.type & media_type: medias.append(media) print("Media: {}".format(media.name)) if not reccurent: break return medias except Exception: logging.error(error_handler()) return []
def random_media_list(media_list, media_nb): try: return random.choices(media_list, k=media_nb) except IndexError: logging.error(error_handler()) return []
def random_media(media_list): try: return random.choice(media_list) except IndexError: logging.error(error_handler()) return []
def thread_state_machine(): while param.quit_msg['quit_flag'] == False: time.sleep(0.02) if param.state['reset_raspi_state'] == True: param.state['reset_raspi_state'] = False param.state['raspi_state'] = 'RESET' #ready if param.state['raspi_state'] == 'READY': #list_timer_task[0]['enable'] = True # 开启udp_send任务 set_timer_task(0, True, False) if param.timeout['bootup_greeting_timeout'] == 0: error.error_handler( 'ERROR_CODE_READY_TIMEOUT') # timeout, report error ## just for debug #调试用,后续删掉 param.state['raspi_state'] = 'IDLE' print(param.state['raspi_state']) fun_update_ui('set_to_idle') elif msg_list.msg_from_tx2[ 'SYSTEM_IS_READY'] == True: #recv msg from tx2 msg_list.msg_from_tx2['SYSTEM_IS_READY'] = False param.state['raspi_state'] = 'IDLE' print(param.state['raspi_state']) fun_update_ui('set_to_idle') #idle elif param.state['raspi_state'] == 'IDLE': # 按键启动会议 set_timer_task(0, False, False) if param.button_click[ 'start_meeting'] == True: #start button click param.button_click['start_meeting'] = False #param.timeout['START_LOADING'] = 3 param.state['raspi_state'] = 'START_LOADING' print(param.state['raspi_state']) udp_client.send_msg(msg_list.msg_to_tx2[1]) fun_update_ui('set_to_start_loading') #start loading elif param.state['raspi_state'] == 'START_LOADING': if param.timeout['START_LOADING'] == 0: error.error_handler('ERROR_CODE_START_MEETING_TIMEOUT' ) # timeout, report error ##--> just for debug #调试用,后续删掉 param.state['raspi_state'] = 'RECORDING' print(param.state['raspi_state']) param.param3['old_time'] = datetime.datetime.now() param.param3['new_time'] = param.param3['old_time'] param.param3['pause_time'] = 0 param.param3['time_str'] = '00 : 00 : 00' fun_update_ui('set_to_recording') ##<-- elif msg_list.msg_from_tx2[ 'MEETING_IS_RECORDING'] == True: #recv msg from tx2 msg_list.msg_from_tx2['MEETING_IS_RECORDING'] = False param.state['raspi_state'] = 'RECORDING' print(param.state['raspi_state']) fun_update_ui('set_to_recording') ## initial time param.param3['old_time'] = datetime.datetime.now() param.param3['new_time'] = param.param3['old_time'] param.param3['pause_time'] = 0 param.param3['time_str'] = '00 : 00 : 00' #recording elif param.state['raspi_state'] == 'RECORDING': set_timer_task(1, True, False) if msg_list.msg_from_tx2[ 'TX2_END_MEETING'] == True: # 15m no-face detect tx2 end meeting msg_list.msg_from_tx2['TX2_END_MEETING'] = False #param.timeout['END_LOADING'] = 3 param.state['raspi_state'] = 'END_LOADING' print(param.state['raspi_state']) udp_client.send_msg(msg_list.msg_to_tx2[2]) fun_update_ui('set_to_end_loading') if param.button_click['end_meeting'] == True: #end button click param.button_click['end_meeting'] = False #param.timeout['END_LOADING'] = 3 param.state['raspi_state'] = 'END_LOADING' print(param.state['raspi_state']) udp_client.send_msg(msg_list.msg_to_tx2[2]) fun_update_ui('set_to_end_loading') if param.button_click['pause'] == True: #pause button click param.button_click['pause'] = False udp_client.send_msg(msg_list.msg_to_tx2[3]) param.state['raspi_state'] = 'PAUSED' print(param.state['raspi_state']) fun_update_ui('set_to_pause') #paused elif param.state['raspi_state'] == 'PAUSED': if msg_list.msg_from_tx2[ 'TX2_END_MEETING'] == True: # 15m no-face detect tx2 end meeting msg_list.msg_from_tx2['TX2_END_MEETING'] = False #param.timeout['END_LOADING'] = 3 param.state['raspi_state'] = 'END_LOADING' udp_client.send_msg(msg_list.msg_to_tx2[2]) fun_update_ui('set_to_end_loading') if param.button_click['end_meeting'] == True: #end button click param.button_click['end_meeting'] = False #param.timeout['END_LOADING'] = 3 param.state['raspi_state'] = 'END_LOADING' udp_client.send_msg(msg_list.msg_to_tx2[2]) fun_update_ui('set_to_end_loading') if param.button_click['resume'] == True: #resume button click param.button_click['resume'] = False param.state['raspi_state'] = 'RECORDING' udp_client.send_msg(msg_list.msg_to_tx2[4]) fun_update_ui('set_to_resume') #end loading elif param.state['raspi_state'] == 'END_LOADING': if param.timeout['END_LOADING'] == 0: error.error_handler( 'ERROR_CODE_END_MEETING_TIMEOUT') # timeout, report error ##--> just for debug #调试用,后续删掉 param.state['raspi_state'] = 'END' fun_update_ui('set_to_end') ##<-- elif msg_list.msg_from_tx2[ 'MEETING_IS_END'] == True: #recv msg from tx2 msg_list.msg_from_tx2['MEETING_IS_END'] = False param.state['raspi_state'] = 'END' fun_update_ui('set_to_end') elif param.state['raspi_state'] == 'END': set_timer_task(1, False, False) #end meeting param.state['raspi_state'] = 'IDLE' fun_update_ui('set_to_idle') # 清空之前的按键事件缓存 for key, value in param.button_click.items(): param.button_click[key] = False elif param.state['raspi_state'] == 'RESET': fun_update_ui('set_to_ready') # 清空之前的按键事件缓存 for key, value in param.button_click.items(): param.button_click[key] = False param.state['raspi_state'] = 'READY' else: error.error['error_code'] = error.error_code_list[ 'ERROR_CODE_STATE_UNKNOWN'] pass