class Ziggy(MycroftSkill): def __init__(self): """ The __init__ method is called when the Skill is first constructed. It is often used to declare variables or perform setup actions, however it cannot utilise MycroftSkill methods as the class does not yet exist. """ super(Ziggy, self).__init__(name="ZiggyAI") def initialize(self): # Make Import For TimeData try: time_date_path = "/opt/mycroft/skills/skill-date-time.builderjer/__init__.py" time_date_id = "skilldatetime" datetimeskill = load_skill_module(time_date_path, time_date_id) from datetimeskill import TimeSkill self.dt_skill = TimeSkill() except: print("Failed To Import DateTime Skill") @intent_handler( IntentBuilder('ShowHomeScreen').require('HomeScreenKeyword')) def handle_show_home_screen_intent(self, message): """ This is an Adapt intent handler, it is triggered by a keyword.""" self.speak("show home screen") @intent_handler('HomeScreen.intent') def handle_how_are_you_intent(self, message): """ This is a Padatious intent handler. It is triggered using a list of sample phrases.""" self.speak("home screen intent") @resting_screen_handler("ZiggyMain") def handle_idle(self, message): self.log.info("Ziggy main home screen") self.gui.clear() self.gui["title"] = self.name self.gui["time"] = self.dt_skill.get_display_current_time() self.gui["date"] = self.dt_skill.get_display_date() self.gui["weekday"] = self.dt_skill.get_weekday() self.gui.show_page("idle.qml") # # @intent_handler(IntentBuilder('HelloWorldIntent') # .require('HelloWorldKeyword')) # def handle_hello_world_intent(self, message): # """ Skills can log useful information. These will appear in the CLI and # the skills.log file.""" # self.log.info("There are five types of log messages: " # "info, debug, warning, error, and exception.") # self.speak_dialog("hello.world") def stop(self): pass
class MycroftHomescreen(MycroftSkill): # The constructor of the skill, which calls MycroftSkill's constructor def __init__(self): super(MycroftHomescreen, self).__init__(name="MycroftHomescreen") self.skill_manager = None self.notifications_model = [] self.notifications_storage_model = [] self.wallpaper_folder = path.dirname(__file__) + '/ui/wallpapers/' self.selected_wallpaper = self.settings.get("wallpaper", "default.png") self.wallpaper_collection = [] def initialize(self): now = datetime.datetime.now() callback_time = datetime.datetime( now.year, now.month, now.day, now.hour, now.minute) + datetime.timedelta(seconds=60) self.schedule_repeating_event(self.update_dt, callback_time, 10) self.skill_manager = SkillManager(self.bus) # Handler Registeration For Notifications self.add_event("homescreen.notification.set", self.handle_display_notification) self.gui.register_handler("homescreen.notification.set", self.handle_display_notification) self.gui.register_handler("homescreen.notification.pop.clear", self.handle_clear_notification_data) self.gui.register_handler("homescreen.notification.pop.clear.delete", self.handle_clear_delete_notification_data) self.gui.register_handler("homescreen.notification.storage.clear", self.handle_clear_notification_storage) self.gui.register_handler("homescreen.notification.storage.item.rm", self.handle_clear_notification_storage_item) self.collect_wallpapers() # Import Date Time Skill As Date Time Provider # TODO - replace with Skills API call in 21.02 root_dir = self.root_dir.rsplit("/", 1)[0] try: time_date_path = str( root_dir) + "/mycroft-date-time.mycroftai/__init__.py" time_date_id = "datetimeskill" datetimeskill = load_skill_module(time_date_path, time_date_id) from datetimeskill import TimeSkill self.dt_skill = TimeSkill() except: self.log.info("Failed To Import DateTime Skill") ##################################################################### # Homescreen Registeration & Handling @resting_screen_handler("Mycroft Homescreen") def handle_idle(self, _): self.log.debug('Activating Time/Date resting page') self.gui['time_string'] = self.dt_skill.get_display_current_time() self.gui['date_string'] = self.dt_skill.get_display_date() self.gui['weekday_string'] = self.dt_skill.get_weekday() self.gui['month_string'] = self.dt_skill.get_month_date() self.gui['year_string'] = self.dt_skill.get_year() self.gui['build_date'] = self.build_info.get('build_date', '') self.gui['selected_wallpaper'] = self.selected_wallpaper self.gui['notification'] = {} self.gui["notification_model"] = { "storedmodel": self.notifications_storage_model, "count": len(self.notifications_storage_model), } self.gui.show_page("idle.qml") def handle_idle_update_time(self): self.gui["time_string"] = self.dt_skill.get_display_current_time() self.gui["date_string"] = self.dt_skill.get_display_date() self.gui["weekday_string"] = self.dt_skill.get_weekday() self.gui["month_string"] = self.dt_skill.get_month_date() self.gui["year_string"] = self.dt_skill.get_year() def update_dt(self): self.gui["time_string"] = self.dt_skill.get_display_current_time() self.gui["date_string"] = self.dt_skill.get_display_date() self.gui["weekday_string"] = self.dt_skill.get_weekday() self.gui["month_string"] = self.dt_skill.get_month_date() self.gui["year_string"] = self.dt_skill.get_year() ##################################################################### # Build Info @property def build_info(self): """The /etc/mycroft/build-info.json file as a Dict.""" data = {} filename = "/etc/mycroft/build-info.json" if (self.config_core["enclosure"].get("development_device") and Path(filename).is_file()): with open(filename, "r") as build_info: data = json.loads(build_info.read()) return data ##################################################################### # Wallpaper Manager def collect_wallpapers(self): for dirname, dirnames, filenames in os.walk(self.wallpaper_folder): self.wallpaper_collection = filenames @intent_file_handler("change.wallpaper.intent") def change_wallpaper(self, message): # Get Current Wallpaper idx current_idx = self.get_wallpaper_idx(self.selected_wallpaper) collection_length = len(self.wallpaper_collection) - 1 if not current_idx == collection_length: fidx = current_idx + 1 self.selected_wallpaper = self.wallpaper_collection[fidx] self.settings["wallpaper"] = self.wallpaper_collection[fidx] else: self.selected_wallpaper = self.wallpaper_collection[0] self.settings["wallpaper"] = self.wallpaper_collection[0] self.gui['selected_wallpaper'] = self.selected_wallpaper def get_wallpaper_idx(self, filename): try: index_element = self.wallpaper_collection.index(filename) return index_element except ValueError: return None ##################################################################### # Manage notifications def handle_display_notification(self, message): """ Get Notification & Action """ notification_message = { "sender": message.data.get("sender", ""), "text": message.data.get("text", ""), "action": message.data.get("action", ""), "type": message.data.get("type", ""), } if notification_message not in self.notifications_model: self.notifications_model.append(notification_message) self.gui["notifcation_counter"] = len(self.notifications_model) self.gui["notification"] = notification_message time.sleep(2) self.bus.emit(Message("homescreen.notification.show")) def handle_clear_notification_data(self, message): """ Clear Pop Notification """ notification_data = message.data.get("notification", "") self.notifications_storage_model.append(notification_data) for i in range(len(self.notifications_model)): if (self.notifications_model[i]["sender"] == notification_data["sender"] and self.notifications_model[i]["text"] == notification_data["text"]): if not len(self.notifications_model) > 0: del self.notifications_model[i] self.notifications_model = [] else: del self.notifications_model[i] break self.gui["notification_model"] = { "storedmodel": self.notifications_storage_model, "count": len(self.notifications_storage_model), } self.gui["notification"] = {} def handle_clear_delete_notification_data(self, message): """ Clear Pop Notification & Delete Notification Data """ notification_data = message.data.get("notification", "") for i in range(len(self.notifications_model)): if (self.notifications_model[i]["sender"] == notification_data["sender"] and self.notifications_model[i]["text"] == notification_data["text"]): if not len(self.notifications_model) > 0: del self.notifications_model[i] self.notifications_model = [] else: del self.notifications_model[i] break def handle_clear_notification_storage(self, _): """ Clear All Notification Storage Model """ self.notifications_storage_model = [] self.gui["notification_model"] = { "storedmodel": self.notifications_storage_model, "count": len(self.notifications_storage_model), } def handle_clear_notification_storage_item(self, message): """ Clear Single Item From Notification Storage Model """ notification_data = message.data.get("notification", "") for i in range(len(self.notifications_storage_model)): if (self.notifications_storage_model[i]["sender"] == notification_data["sender"] and self.notifications_storage_model[i]["text"] == notification_data["text"]): self.notifications_storage_model.pop(i) self.gui["notification_model"] = { "storedmodel": self.notifications_storage_model, "count": len(self.notifications_storage_model), } def stop(self): pass
class AndroidHomescreen(MycroftSkill): # The constructor of the skill, which calls MycroftSkill's constructor def __init__(self): super(AndroidHomescreen, self).__init__(name="AndroidHomescreen") self.allSkills = [] self.enabledAndroidSkills = [] self.androidSkillsList = [] self.androidSkillObject = {} self.skill_manager = None def initialize(self): self.add_event("pixabay.gallery.set_wallpaper", self.set_wallpaper) now = datetime.datetime.now() callback_time = (datetime.datetime(now.year, now.month, now.day, now.hour, now.minute) + datetime.timedelta(seconds=60)) self.schedule_repeating_event(self.update_dt, callback_time, 10) self.skill_manager = SkillManager(self.bus) # Make Import For TimeData root_dir = self.root_dir.rsplit('/', 1)[0] try: time_date_path = str( root_dir) + "/mycroft-date-time.mycroftai/__init__.py" time_date_id = "datetimeskill" datetimeskill = load_skill_module(time_date_path, time_date_id) from datetimeskill import TimeSkill self.dt_skill = TimeSkill() except: print("Failed To Import DateTime Skill") @resting_screen_handler('AndroidHomescreen') def handle_idle(self, message): self.gui.clear() self.generate_homescreen_icons() self.log.debug('Activating Time/Date resting page') self.gui['time_string'] = self.dt_skill.get_display_current_time() self.gui['ampm_string'] = '' self.gui['date_string'] = self.dt_skill.get_display_date() self.gui['weekday_string'] = self.dt_skill.get_weekday() self.gui['month_string'] = self.dt_skill.get_month_date() self.gui['year_string'] = self.dt_skill.get_year() self.gui['skillLauncher'] = self.androidSkillObject self.gui.show_page('homescreen.qml') def handle_idle_update_time(self): self.gui['time_string'] = self.dt_skill.get_display_current_time() def generate_homescreen_icons(self): self.androidSkillsList.clear() skill_directories = self.skill_manager._get_skill_directories() print(skill_directories) for x in range(len(skill_directories)): if skill_directories[x] not in self.allSkills: self.allSkills.append(skill_directories[x]) for x in range(len(self.allSkills)): skill_dir = self.allSkills[x] skill_android_file_resource = skill_dir + "/android.json" if path.exists(skill_android_file_resource) and path.isfile( skill_android_file_resource): with open(skill_android_file_resource) as f: print("I AM IN EXPAND ANDROID RESOURCE FILE") expand_file = json.load(f) icon_path = skill_dir + expand_file["android_icon"] display_name = expand_file["android_name"] invoke_handler = expand_file["android_handler"] if not any( d.get('skillPath', None) == skill_dir for d in self.androidSkillsList): self.androidSkillsList.append({ "skillPath": skill_dir, "skillIconPath": icon_path, "skillDisplayName": display_name, "skillHandler": invoke_handler }) print(self.androidSkillsList) try: sort_on = "skillDisplayName" decorated = [(dict_[sort_on], dict_) for dict_ in self.androidSkillsList] decorated.sort() result = [dict_ for (key, dict_) in decorated] print(result) except Exception: print("Error Sorting Application List") try: self.androidSkillObject["skillList"] = result except Exception: print("Error Getting Application List") def update_dt(self): self.gui['time_string'] = self.dt_skill.get_display_current_time() self.gui['date_string'] = self.dt_skill.get_display_date() def set_wallpaper(self, message): self.gui['wallpaper_path'] = message.data["imagePath"] def set_default_wallpaper(self, message): self.gui['wallpaper_path'] = self.root_dir + "/ui/img/seaside.jpg" def stop(self): pass