Esempio n. 1
0
    def confirm_fruit(self, selected):
        self.timeout_timer.stop()
        confirm_resp = http_client.confirm_goods(selected.recordId,
                                                 selected.goodsId)
        if confirm_resp:
            self.set_imagebutton_disable(confirm_resp.results['goodsName'])
            # self.to_show_fruits_info(confirm_resp.results)
            self.db_api.confirm_fruit(selected.id, confirm_resp.results)
            self.db_api.select_fruit(selected.id)
            self.timeout_timer.start(3000)
        else:
            task_id = self.db_api.get_device_task_id()
            self.db_api.update_task_status(task_id, 'network_disconnection')

            req_id = utils.generate_uuid()
            logger.info("new req id generate %s" % req_id)
            self.db_api.update_device_req_id(req_id)

            self.db_api.update_device_status('idle')
            logger.info('network_disconnection, change device status to idle.')
            if not os.system('ping -c 5 -i 0.2 baidu.com'):
                logger.error('Failed to create order.')
                self.mesgbox.create_order_fail()
                self.mesgbox.show()
            else:
                logger.error('network connect to Failed ')
                self.mesgbox.network_fail()
                self.mesgbox.show()
Esempio n. 2
0
    def get_identify_resp(self, identify_resp, weight):
        req_id = self.db_api.get_device_req_id()
        task_id = self.db_api.get_device_task_id()

        self.db_api.update_task_identified_info(task_id,
                                                identify_resp.record_id,
                                                identify_resp.code,
                                                identify_resp.msg, weight)
        if identify_resp.code == 0:
            logger.info("identified code 0.")
            for fruit in identify_resp.results:
                fruit['id'] = utils.generate_uuid()
                fruit['reqId'] = req_id
                fruit['taskId'] = task_id
                fruit['recordId'] = identify_resp.record_id
                self.db_api.insert_fruit(fruit)
            # 切换到展示识别结果界面
            self.screen.recognition_result_win.update(weight)
            self.screen.procedure_dialog.delay_hide(
                self.screen.recognition_result_win)
        else:
            # 日志记录识别失败
            logger.warn("Identity interface response code not 0.")
            # 切换到识别失败界面
            self.screen.procedure_dialog.show_unidentified_ui()
            self.db_api.update_task_status(task_id, 'unidentified')
            self.db_api.update_device_status('idle')
Esempio n. 3
0
 def steady_weight_callback(self, steady_weight):
     logger.info("Weight is steady %s g" % steady_weight)
     if self.screen.procedure_dialog.practice_mode:
         frame = self.capture_thread.get_one_frame()
         cur_str_time = time.strftime("%Y%m%d%H%M%S")
         current_timestamp = self.screen.procedure_dialog.file_path
         file_path = self.capture_thread.save_image_to_file(
             frame,
             cur_str_time + '.jpg',
             current_timestamp,
             return_path=True)
         # 更新界面图像
         self.screen.procedure_dialog.shop_image.setStyleSheet(
             "QLabel{background-image: url(%s)}" % file_path)
         self.screen.procedure_dialog.if_success.setText('')
         logger.info("take photo finished.")
         self.db_api.update_device_status('idle')
     else:
         self.screen.procedure_dialog.show_recogniting_ui()
         req_id = self.db_api.get_device_req_id()
         task_id = utils.generate_uuid()
         self.db_api.insert_task({
             'id': task_id,
             'reqId': req_id,
             'status': 'taking_photo'
         })
         self.db_api.update_device_task_id(task_id)
         image = self.capture_thread.take_one_photo()
         self.db_api.update_task_status(task_id, 'identifying')
         self.http_client.set_info([image], steady_weight)
         self.http_client.start()
         logger.info("take photo finished.")
Esempio n. 4
0
 def run(self):
     while True:
         if self.check_steady() and self.db_api.get_device_status() in [
                 'continue_weight', 'idle'
         ]:
             self.db_api.update_device_status('running')
             task_id = utils.generate_uuid()
             logger.info("new task id generate %s" % task_id)
             self.db_api.update_device_task_id(task_id)
             self.steady_weight_signal.emit(self.last_steady)
         self.msleep(150)
Esempio n. 5
0
 def show_advertisment_ui(self):
     self.if_success.hide()
     self.practice_mode = False
     self.hide_button_show_procedure()
     self.advertisement_button.show()
     self.change_status_label.hide()
     self.advertisement_button.setStyleSheet(
         "QPushButton{border-image: url(%s)}" %
         self.image_advertisement_path)
     req_id = utils.generate_uuid()
     logger.info("new req id generate %s" % req_id)
     self.db_api.update_device_req_id(req_id)
Esempio n. 6
0
 def print_goods(self):
     self.timer_print.stop()
     req_id = self.db_api.get_device_req_id()
     selected_fruits = self.db_api.get_selected_fruits_by_req_id(req_id)
     # get order info
     order = self.db_api.get_order_by_req_id(req_id)
     self.printer.print_order(order, selected_fruits)
     logger.info("Print receipt page finished.")
     new_req_id = utils.generate_uuid()
     self.db_api.update_device_req_id(new_req_id)
     logger.info("New req id generate %s" % new_req_id)
     self.db_api.update_device_status('idle')
     logger.info('User has payed, change device status to idle.')
Esempio n. 7
0
    def timeout_handler(self):
        self.timeout_timer.stop()
        task_id = self.db_api.get_device_task_id()
        self.db_api.update_task_status(task_id, 'select_timeout')
        logger.warning('timeout waiting user select, return guide dialog now.')

        new_req_id = utils.generate_uuid()
        self.db_api.update_device_req_id(new_req_id)
        logger.info("new req id generate %s" % new_req_id)

        self.db_api.update_device_status('idle')
        logger.warning('update device status to idle.')

        self.procedure_dialog.show_guide_ui()
        self.timer.start(300)
Esempio n. 8
0
    def return_home(self):
        # self.hide_all_dialog()
        task_id = self.db_api.get_device_task_id()
        self.db_api.update_task_status(task_id, 'canceled')

        new_req_id = utils.generate_uuid()
        self.db_api.update_device_req_id(new_req_id)
        logger.info("new req id generate %s" % new_req_id)

        self.db_api.update_device_status('idle')

        self.procedure_dialog.show_guide_ui()
        self.recognition_result_win.timeout_timer.stop()
        self.pay_way_dialog.lineEdit.clearFocus()

        self.timeout_timer.start(300)
Esempio n. 9
0
 def timeout_handler(self):
     self.timeout_timer.stop()
     if self.running_dialog == 'guide':
         logger.warning('%s seconds, timeout waiting user to weight, '
                        'return advertisement dialog.' % self.guide_timeout)
         req_id = utils.generate_uuid()
         logger.info("new req id generate %s" % req_id)
         self.db_api.update_device_req_id(req_id)
         self.show_advertisment_ui()
     elif self.running_dialog == 'advertisment':
         self.show_advertisment_ui()
     elif self.running_dialog == 'unidentified':
         logger.info('%s seconds, identified failed notice finished.' %
                     self.unidentified_timeout)
         self.show_guide_ui()
     else:
         self.hide()
Esempio n. 10
0
    def timeout_pay(self):
        # 支付超时
        # self.label_time.hide()
        self.pay_notice_bg.hide()
        # self.label_code.hide()
        # self.label_bg.hide()
        self.label_success.setStyleSheet("QLabel{border-image: url(%s)}" %
                                         self.image_fail_path)
        self.label_success.show()
        task_id = self.db_api.get_device_task_id()
        self.db_api.update_task_status(task_id, 'payment_timeout')

        req_id = utils.generate_uuid()
        logger.info("new req id generate %s" % req_id)
        self.db_api.update_device_req_id(req_id)

        self.db_api.update_device_status('idle')
        logger.info('timeout waiting user pay, change device status to idle.')
Esempio n. 11
0
    def create_order(self, qrcode_type):
        # 0 error  1 ali 2 Wechat
        device_req_id = self.db_api.get_device_req_id()
        selected_fruits_list = self.db_api.get_selected_fruits_by_req_id(
            device_req_id)
        fruits_record_id = [
            selected_fruit.recordId for selected_fruit in selected_fruits_list
        ]
        order_info = http_client.create_order(fruits_record_id)
        if order_info:
            order_info['id'] = order_info['orderNo']
            order_info['reqId'] = device_req_id
            order_info['pay_way'] = str(qrcode_type)
            self.db_api.insert_order(order_info)
            self.label_time.setText(_translate("Dialog", "", None))
            # self.label_code.show()
            # self.label_bg.show()

        else:
            task_id = self.db_api.get_device_task_id()
            self.db_api.update_task_status(task_id, 'network_disconnection')

            req_id = utils.generate_uuid()
            logger.info("new req id generate %s" % req_id)
            self.db_api.update_device_req_id(req_id)

            self.db_api.update_device_status('idle')
            logger.info('network_disconnection, change device status to idle.')

            if not os.system('ping -c 5 -i 0.2 baidu.com'):
                logger.error('Failed to create order.')
                self.mesgbox.create_order_fail()
                self.mesgbox.show()
            else:
                logger.error('network connect to Failed ')
                self.mesgbox.network_fail()
                self.mesgbox.show()
        return order_info