Esempio n. 1
0
    def callback(self, cmd, msg):
        self._home.publish_msg(cmd, u"正在截图...")

        Sound.play(Res.get_res_path("sound/com_shoot"))

        save_path="data/capture/"
        save_name, thumbnail_name = CameraHelper().take_a_photo(save_path)
        # for test
        # save_name = "2015_05_02_164052.jpg"
        if save_name is None:
            self._home.publish_msg(cmd, u"截图失败")
            INFO("capture faild.")
            return True
        img_url, thumbnail_url = self._upload_image(
                save_path + save_name,
                save_path + thumbnail_name,
                )
        if img_url is None:
            self._home.publish_msg(cmd, u"截图失败")
            INFO("capture faild.")
            return True
        else:
            self._home.publish_msg(
                    cmd,
                    msg=img_url,
                    cmd_type="capture"
                    )
        return True
Esempio n. 2
0
    def callback(self, cmd, action, target, msg):
        if msg is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None

        if msg.endswith(u'点') or \
           msg.endswith(u'分'):
            t = Util.gap_for_timestring(msg)
        elif msg.endswith(u"秒"):
            t = int(Util.cn2dig(msg[:-1]))
        elif msg.endswith(u"分钟"):
            t = int(Util.cn2dig(msg[:-2])) * 60
        elif msg.endswith(u"小时"):
            t = int(Util.cn2dig(msg[:-2])) * 60 * 60
        else:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False
        if t is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None
        DEBUG("thread wait for %d sec" % (t, ))
        self._home.publish_msg(cmd, action + target + msg)

        threading.current_thread().waitUtil(t)
        if threading.current_thread().stopped():
            return False
        self._home.setResume(True)
        count = 7
        Sound.play(Res.get_res_path("sound/com_bell"), True, count)
        self._home.setResume(False)
        return True
Esempio n. 3
0
    def callback(self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        if pre_value == "new" or pre_value == "set":
            if msg is None:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False, None

            if msg.endswith(u'点') or \
                msg.endswith(u'分'):
                t = Util.gap_for_timestring(msg)
            else:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False
            if t is None:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False, None

            INFO("alarm wait for %d sec" % (t, ))
            self._home.publish_msg(cmd, action + target + msg)

            threading.current_thread().waitUtil(t)
            if threading.current_thread().stopped():
                return False
            self._home.setResume(True)
            count = 7
            Sound.play( Res.get_res_path("sound/com_bell") , True, count)
            self._home.setResume(False)
            return True
Esempio n. 4
0
    def callback(self, cmd, action, target, msg):
        if msg is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None

        if msg.endswith(u'点') or \
           msg.endswith(u'分'):
            t = Util.gap_for_timestring(msg)
        elif msg.endswith(u"秒"):
            t = int(Util.cn2dig(msg[:-1]))
        elif msg.endswith(u"分钟"):
            t = int(Util.cn2dig(msg[:-2]))*60
        elif msg.endswith(u"小时"):
            t = int(Util.cn2dig(msg[:-2]))*60*60
        else:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False
        if t is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None
        DEBUG("thread wait for %d sec" % (t, ))
        self._home.publish_msg(cmd, action + target + msg)

        threading.current_thread().waitUtil(t)
        if threading.current_thread().stopped():
            return False
        self._home.setResume(True)
        count = 7
        Sound.play( Res.get_res_path("sound/com_bell") , True, count)
        self._home.setResume(False)
        return True
Esempio n. 5
0
    def callback(self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        
        if pre_value == "new":
            path = "usr/memo/"
            try:
                os.makedirs(path)
            except OSError as exc:
                if exc.errno == errno.EEXIST and os.path.isdir(path):
                    pass
                else:
                    ERROR(exc)
                    self._home.publish_msg(cmd, u"录音错误")
                    return False

            self._home.setResume(True)
            filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3"
            record = self._global_context["recorder"]
            self._home.publish_msg(cmd, u"录音开始...")
            record(filepath)
            self._home.publish_msg(cmd, u"录音结束")
            Sound.play(
                        Res.get_res_path("sound/com_stop")
                        )
            self._home.setResume(False)
        return True
Esempio n. 6
0
    def callback(self, cmd, msg):
        self._home.publish_msg(cmd, u"正在截图...")

        Sound.notice(Res.get_res_path("sound/com_shoot"))

        save_path="data/capture/"
        save_name, thumbnail_name = CameraHelper().take_a_photo(save_path)
        # for test
        # save_name = "2015_05_02_164052.jpg"
        if save_name is None:
            self._home.publish_msg(cmd, u"截图失败")
            INFO("capture faild.")
            return True
        img_url, thumbnail_url = self._upload_image(
                save_path + save_name,
                save_path + thumbnail_name,
                )
        if img_url is None:
            self._home.publish_msg(cmd, u"截图失败")
            INFO("upload capture faild.")
            return True
        else:
            self._home.publish_msg(
                    cmd,
                    msg=img_url,
                    cmd_type="capture"
                    )
        return True
Esempio n. 7
0
 def _stop_callback(self, command, stop):
     DEBUG(" _stop_callback: %s" % command)
     Sound.play(Res.get_res_path("sound/com_stop"), inqueue=True)
     if "stop" in self._registered_callbacks:
         callbacks = self._registered_callbacks["stop"]
         if stop in callbacks:
             callbacks[stop](stop=stop)
Esempio n. 8
0
    def callback(self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        if pre_value == "new" or pre_value == "set":
            if msg is None:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False, None

            if msg.endswith(u'点') or \
                msg.endswith(u'分'):
                t = Util.gap_for_timestring(msg)
            else:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False
            if t is None:
                self._home.publish_msg(cmd, u"时间格式错误")
                return False, None

            INFO("alarm wait for %d sec" % (t, ))
            self._home.publish_msg(cmd, action + target + msg)

            threading.current_thread().waitUtil(t)
            if threading.current_thread().stopped():
                return False
            self._home.setResume(True)
            count = 7
            Sound.play( Res.get_res_path("sound/com_bell") , True, count)
            self._home.setResume(False)
            return True
Esempio n. 9
0
    def callback(self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        
        if pre_value == "new":
            path = "usr/memo/"
            try:
                os.makedirs(path)
            except OSError as exc:
                if exc.errno == errno.EEXIST and os.path.isdir(path):
                    pass
                else:
                    ERROR(exc)
                    self._home.publish_msg(cmd, u"录音错误")
                    return False

            self._home.setResume(True)
            filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3"
            record = self._global_context["recorder"]
            self._home.publish_msg(cmd, u"录音开始...")
            record(filepath)
            self._home.publish_msg(cmd, u"录音结束")
            Sound.play(
                        Res.get_res_path("sound/com_stop")
                        )
            self._home.setResume(False)
        return True
Esempio n. 10
0
    def callback(
            self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        if pre_value == "new":
            path = "usr/message/"
            try:
                os.makedirs(path)
            except OSError as exc:
                if exc.errno == errno.EEXIST and os.path.isdir(path):
                    pass
                else:
                    ERROR(exc)
                    return False

            self._home.setResume(True)
            filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3"
            Sound.play(Res.get_res_path("sound/com_stop"))
            record = self._global_context["recorder"]
            self._home.publish_msg(cmd, u"录音开始...")
            record(filepath)
            self._home.publish_msg(cmd, u"录音结束")
            self._home.setResume(False)
        elif pre_value == "play":
            self._home.setResume(True)

            play = self._global_context["player"]
            for idx, filepath in enumerate(glob.glob("usr/message/*.mp3")):
                # self._speaker.speak(u'第%d条留言' % (idx + 1))
                INFO(u'第%d条留言:%s' % (idx + 1, filepath))
                play(filepath)
                play(Res.get_res_path("sound/com_stop"))

            self._home.setResume(False)
        elif pre_value == "remove":
            filelist = glob.glob("usr/message/*.mp3")
            for f in filelist:
                os.remove(f)
                INFO("remove:%s" % (f, ))
            Sound.play(
                        Res.get_res_path("sound/com_trash")
                        )
        return True
Esempio n. 11
0
    def callback(
            self,
            cmd,
            action=None,
            target=None,
            msg=None, 
            pre_value=None):
        if pre_value == "new":
            path = "usr/message/"
            try:
                os.makedirs(path)
            except OSError as exc:
                if exc.errno == errno.EEXIST and os.path.isdir(path):
                    pass
                else:
                    ERROR(exc)
                    return False

            self._home.setResume(True)
            filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3"
            Sound.play(Res.get_res_path("sound/com_stop"))
            record = self._global_context["recorder"]
            self._home.publish_msg(cmd, u"录音开始...")
            record(filepath)
            self._home.publish_msg(cmd, u"录音结束")
            self._home.setResume(False)
        elif pre_value == "play":
            self._home.setResume(True)

            play = self._global_context["player"]
            for idx, filepath in enumerate(glob.glob("usr/message/*.mp3")):
                # self._speaker.speak(u'第%d条留言' % (idx + 1))
                INFO(u'第%d条留言:%s' % (idx + 1, filepath))
                play(filepath)
                play(Res.get_res_path("sound/com_stop"))

            self._home.setResume(False)
        elif pre_value == "remove":
            filelist = glob.glob("usr/message/*.mp3")
            for f in filelist:
                os.remove(f)
                INFO("remove:%s" % (f, ))
            Sound.play(
                        Res.get_res_path("sound/com_trash")
                        )
        return True
Esempio n. 12
0
 def callback(self,
         action=None,
         target=None,
         msg=None, 
         pre_value=None):
     if pre_value == "play":
         if msg is None or not msg.endswith(u"次"):
             count = 1
         else:
             count = int(Util.cn2dig(msg[:-1]))
         self._home.setResume(True)
         play = self._global_context["player"]
         play(Res.get_res_path("sound/com_warn"), loop=count)
         self._home.setResume(False)
     return True
Esempio n. 13
0
 def callback(self,
         action=None,
         target=None,
         msg=None, 
         pre_value=None):
     if pre_value == "play":
         if msg is None or not msg.endswith(u"次"):
             count = 1
         else:
             count = int(Util.cn2dig(msg[:-1]))
         self._home.setResume(True)
         play = self._global_context["player"]
         play(Res.get_res_path("sound/com_warn"), loop=count)
         self._home.setResume(False)
     return True