File indexing completed on 2024-11-10 05:11:08

0001 import re
0002 import sys
0003 import json
0004 from os.path import dirname, join
0005 from adapt.intent import IntentBuilder
0006 from mycroft import MycroftSkill, intent_handler, intent_file_handler
0007 from mycroft.messagebus.message import Message
0008 
0009 class SkillExample(MycroftSkill):
0010     """ 
0011     Example Skill Showcasing All Delegates
0012     """
0013     def __init__(self):
0014         super().__init__("SkillExample")
0015     
0016     def initialize(self):
0017         # Handle Menu and Navigation
0018         self.gui.register_handler('skillExample.menu', self.handle_gui_example_menu)
0019         self.gui.register_handler('skillExample.simpleText', self.handle_gui_example_one_intent)
0020         self.gui.register_handler('skillExample.simpleImage', self.handle_gui_example_two_intent)
0021         self.gui.register_handler('skillExample.paginatedText', self.handle_gui_example_three_intent)
0022         self.gui.register_handler('skillExample.slidingImage', self.handle_gui_example_four_intent)
0023         self.gui.register_handler('skillExample.proportionalDelegate', self.handle_gui_example_five_intent)
0024         self.gui.register_handler('skillExample.listView', self.handle_gui_example_six_intent)
0025         self.gui.register_handler('skillExample.eventsExample', self.handle_gui_example_seven_intent)        
0026         
0027         # Handle example events
0028         self.gui.register_handler('skillExample.colorChange', self.change_color_event)
0029     
0030     @intent_file_handler('gui.example.one')
0031     def handle_gui_example_one_intent(self, message):
0032         """ 
0033         Example Intent Showcasing Basic UI Text
0034         """
0035         self.gui.show_text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec placerat varius turpis porta scelerisque. Nam feugiat, lectus a ultricies tempus, mi sem tempor felis, vitae laoreet nisi ipsum vitae mauris.")
0036     
0037     @intent_file_handler('gui.example.two')
0038     def handle_gui_example_two_intent(self, message):
0039         """ 
0040         Example Intent Showcasing Basic UI Image
0041         """
0042         self.gui.show_image("https://source.unsplash.com/1920x1080/?+random")
0043 
0044     @intent_file_handler('gui.example.three')
0045     def handle_gui_example_three_intent(self, message):
0046         """ 
0047         Example Intent Showcasing Paginated UI Text
0048         """
0049         self.gui['sampleText'] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Egestas sed tempus urna et pharetra pharetra massa massa ultricies. Aliquam sem et tortor consequat id porta nibh. Amet est placerat in egestas erat imperdiet sed. Ut ornare lectus sit amet est placerat in egestas erat. Iaculis eu non diam phasellus vestibulum lorem sed risus ultricies. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Vulputate eu scelerisque felis imperdiet proin fermentum. Neque convallis a cras semper auctor neque. Pharetra magna ac placerat vestibulum lectus mauris ultrices eros in. Phasellus faucibus scelerisque eleifend donec pretium vulputate. Malesuada bibendum arcu vitae elementum curabitur vitae nunc. Tellus id interdum velit laoreet id donec. Diam donec adipiscing tristique risus nec. Nisi lacus sed viverra tellus in hac habitasse platea. Amet venenatis urna cursus eget nunc scelerisque viverra mauris in. Sit amet nisl suscipit adipiscing bibendum est ultricies. Nec ultrices dui sapien eget mi proin sed. Egestas dui id ornare arcu odio ut sem nulla. Rhoncus aenean vel elit scelerisque. Neque gravida in fermentum et sollicitudin. Pellentesque massa placerat duis ultricies lacus sed. Nunc id cursus metus aliquam eleifend mi. Eu feugiat pretium nibh ipsum consequat nisl. Aenean euismod elementum nisi quis eleifend quam adipiscing vitae. Est ante in nibh mauris cursus mattis. Sagittis eu volutpat odio facilisis mauris sit amet. At consectetur lorem donec massa sapien faucibus. Odio facilisis mauris sit amet. Quis ipsum suspendisse ultrices gravida dictum fusce. Sagittis nisl rhoncus mattis rhoncus urna neque viverra justo nec. Eget mi proin sed libero enim sed faucibus. Interdum velit euismod in pellentesque massa. Et netus et malesuada fames. Velit aliquet sagittis id consectetur purus. Condimentum lacinia quis vel eros donec ac odio tempor orci. Amet consectetur adipiscing elit pellentesque habitant. Eleifend mi in nulla posuere sollicitudin aliquam ultrices sagittis orci. Nisi porta lorem mollis aliquam ut porttitor leo a diam. Egestas integer eget aliquet nibh praesent tristique. Velit scelerisque in dictum non. Id volutpat lacus laoreet non curabitur gravida arcu ac. Suspendisse interdum consectetur libero id faucibus nisl tincidunt eget. Ipsum a arcu cursus vitae congue mauris. Duis at consectetur lorem donec massa. Orci sagittis eu volutpat odio facilisis mauris. Eget mauris pharetra et ultrices neque ornare. Commodo nulla facilisi nullam vehicula ipsum a. Arcu risus quis varius quam quisque. Gravida in fermentum et sollicitudin. Lacus laoreet non curabitur gravida arcu ac tortor dignissim. Netus et malesuada fames ac turpis. Ipsum dolor sit amet consectetur adipiscing. Tellus elementum sagittis vitae et leo duis ut diam quam. Vitae et leo duis ut diam quam nulla. Risus pretium quam vulputate dignissim. Justo laoreet sit amet cursus sit amet dictum sit. Blandit libero volutpat sed cras. Lacus sed viverra tellus in. Ornare lectus sit amet est placerat in egestas erat. Tortor dignissim convallis aenean et tortor at. Tempus quam pellentesque nec nam aliquam. Nisi scelerisque eu ultrices vitae auctor eu augue ut lectus. Consequat id porta nibh venenatis cras sed felis eget. Massa enim nec dui nunc mattis enim ut. Dignissim enim sit amet venenatis urna. Ac tincidunt vitae semper quis lectus nulla at. Sed felis eget velit aliquet sagittis. Vel turpis nunc eget lorem dolor sed viverra. Non consectetur a erat nam at lectus. Iaculis eu non diam phasellus vestibulum. Dolor sit amet consectetur adipiscing elit ut aliquam purus sit. Libero justo laoreet sit amet cursus sit. Tellus pellentesque eu tincidunt tortor. Maecenas volutpat blandit aliquam etiam erat velit scelerisque in. Semper risus in hendrerit gravida rutrum quisque non tellus orci. Diam in arcu cursus euismod quis viverra nibh cras pulvinar. Habitasse platea dictumst quisque sagittis purus sit amet volutpat consequat. Elit ut aliquam purus sit. Dui faucibus in ornare quam viverra orci sagittis eu. Purus ut faucibus pulvinar elementum integer. Condimentum lacinia quis vel eros donec ac odio tempor. At in tellus integer feugiat scelerisque varius morbi. Augue eget arcu dictum varius duis. Aliquam sem et tortor consequat id. Bibendum arcu vitae elementum curabitur vitae. Massa sed elementum tempus egestas sed sed. Suscipit adipiscing bibendum est ultricies. Etiam tempor orci eu lobortis."
0050         self.gui.show_page("paginationExample.qml")
0051 
0052     @intent_file_handler('gui.example.four')
0053     def handle_gui_example_four_intent(self, message):
0054         """ 
0055         Example Intent Showcasing Sliding Image UI
0056         """
0057         self.gui['sampleImage'] = "https://source.unsplash.com/1920x1080/?+random"
0058         self.gui.show_page("slidingExample.qml")
0059 
0060     @intent_file_handler('gui.example.five')
0061     def handle_gui_example_five_intent(self, message):
0062         """ 
0063         Example Intent Showcasing Proportional Delegate and Autofit Label
0064         """
0065         self.gui['sampleText'] = "Loading.."
0066         self.gui.show_page("proportionalDelegateExample.qml")    
0067 
0068     @intent_file_handler('gui.example.six')
0069     def handle_gui_example_six_intent(self, message):
0070         """ 
0071         Example Intent Showcasing Advanced QML Skills with List and JSON Models
0072         """
0073         sampleObject = {}
0074         sampleList = [{ "text": "Praesent id leo felis", "image": "https://c1.staticflickr.com/8/7246/13792463963_817450e973_b.jpg"}, {"text": "Cras egestas tempus tempus", "image": "https://c1.staticflickr.com/8/7246/13792463963_817450e973_b.jpg"}, {"text": "Habitasse platea dictumst", "image": "https://c1.staticflickr.com/8/7246/13792463963_817450e973_b.jpg"}]
0075         sampleObject['lorem'] = sampleList
0076         self.gui['sampleBlob'] = sampleObject
0077         self.gui['background'] = "https://source.unsplash.com/1920x1080/?+random"
0078         self.gui.show_page("listViewExample.qml")
0079 
0080     @intent_file_handler('gui.example.seven')
0081     def handle_gui_example_seven_intent(self, message):
0082         """
0083         Example Intent Showcasing Events Between Skill and Display
0084         """
0085         self.gui.show_page("eventsExample.qml")
0086         
0087     def change_color_event(self, message):
0088         """
0089         Change Color Event
0090         """
0091         self.gui['fooColor'] = message.data['color']
0092         self.gui.show_page("eventsExample.qml")
0093         
0094     @intent_file_handler('gui.example.menu')
0095     def handle_gui_example_menu(self, message):
0096         """
0097         Build and Show Skill Example Menu To Run Test
0098         """
0099         menuObject = {}
0100         menuList = [{
0101             "exampleIcon": "beamerblock",
0102             "exampleLabel": "Simple Text Example",
0103             "exampleEvent": "skillExample.simpleText"
0104             },
0105             {
0106             "exampleIcon": "beamerblock",
0107             "exampleLabel": "Simple Image Example",
0108             "exampleEvent": "skillExample.simpleImage"
0109             },
0110             {
0111             "exampleIcon": "beamerblock",
0112             "exampleLabel": "Paginated Text Example",
0113             "exampleEvent": "skillExample.paginatedText"  
0114             },
0115             {
0116             "exampleIcon": "beamerblock",
0117             "exampleLabel": "Sliding Image Example",
0118             "exampleEvent": "skillExample.slidingImage"
0119             },
0120             {
0121             "exampleIcon": "beamerblock",
0122             "exampleLabel": "Proportion Delegate & Autofit Label",
0123             "exampleEvent": "skillExample.proportionalDelegate"
0124             },
0125             {
0126             "exampleIcon": "beamerblock",
0127             "exampleLabel": "Cards ListView",
0128             "exampleEvent": "skillExample.listView"
0129             },
0130             {
0131             "exampleIcon": "beamerblock",
0132             "exampleLabel": "Events Example",
0133             "exampleEvent": "skillExample.eventsExample"
0134             }]
0135         menuObject['menuItems'] = menuList
0136         self.gui['menuBlob'] = menuObject
0137         self.gui.show_page("exampleMenu.qml")
0138         
0139         
0140     def stop(self):
0141         pass
0142 
0143 
0144 def create_skill():
0145     return SkillExample()