def init_show( self, show_id, selected_show, show_canvas, ): if selected_show['type'] == "mediashow": return MediaShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "radiomediashow": return RadioMediaShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "liveshow": return LiveShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "radiobuttonshow": return RadioButtonShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "hyperlinkshow": return HyperlinkShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "menu": return MenuShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "artmediashow": return ArtMediaShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) elif selected_show['type'] == "artliveshow": return ArtLiveShow(show_id, selected_show, self.root, show_canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile, ShowManager.command_callback) else: return None
def play_selected_track(self, selected_track): """ selects the appropriate player from type field of the medialist and computes the parameters for that type selected track is a dictionary for the track/show """ self.delete_eggtimer() if self.show_params['progress'] == "manual": self.display_eggtimer(self.resource('mediashow', 'm04')) # is menu required if self.show_params['has-child'] == "yes": self.enable_child = True else: self.enable_child = False #dispatch track by type self.player = None self.shower = None track_type = selected_track['type'] self.mon.log( self, self.show_params['show-ref'] + ' ' + str(self.show_id) + ": Track type is: " + track_type) if track_type == "video": # create a videoplayer track_file = self.complete_path(selected_track) self.player = VideoPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.ready_callback, enable_menu=self.enable_child) elif track_type == "audio": # create a audioplayer track_file = self.complete_path(selected_track) self.player = AudioPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.ready_callback, enable_menu=self.enable_child) elif track_type == "web": # create a browser track_file = self.complete_path(selected_track) self.player = BrowserPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.ready_callback, enable_menu=self.enable_child) elif track_type == "image": track_file = self.complete_path(selected_track) # images played from menus don't have children self.player = ImagePlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.ready_callback, enable_menu=self.enable_child) elif track_type == "message": # bit odd because MessagePlayer is used internally to display text. text = selected_track['text'] self.player = MessagePlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(text, self.showlist, self.end_player, self.ready_callback, enable_menu=self.enable_child) elif track_type == "show": # get the show from the showlist index = self.showlist.index_of_show(selected_track['sub-show']) if index >= 0: self.showlist.select(index) selected_show = self.showlist.selected_show() else: self.mon.err( self, "Show not found in showlist: " + selected_track['sub-show']) self.end('error', "Unknown show") if selected_show['type'] == "mediashow": self.shower = MediaShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command=self.direction) elif selected_show['type'] == "liveshow": self.shower = LiveShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "radiobuttonshow": self.shower = RadioButtonShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "hyperlinkshow": self.shower = HyperlinkShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "menu": self.shower = MenuShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') else: self.mon.err(self, "Unknown Show Type: " + selected_show['type']) self.end('error' "Unknown show type") else: self.mon.err(self, "Unknown Track Type: " + track_type) self.end('error', "Unknown track type")
def start_show(self, show_ref): show_index = self.showlist.index_of_show(show_ref) if show_index < 0: return 'error', "Show not found in showlist: " + show_ref show = self.showlist.show(show_index) index = self.register_show(show_ref) self.mon.log( self, self.show_params['show-ref'] + ' ' + str(self.show_id) + ": Starting show " + show_ref + ' ' + str(index)) if self.show_running(index): self.mon.log(self, "show already running " + show_ref) return 'normal', 'this concurrent show already running' if show['type'] == "mediashow": show_obj = MediaShow(show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.set_running(index, show_obj) show_obj.play(index, self._end_play_show, None, top=True, command='nil') return 'normal', 'concurrent show started' if show['type'] == "radiobuttonshow": show_obj = RadioButtonShow(show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.set_running(index, show_obj) show_obj.play(index, self._end_play_show, None, top=True, command='nil') return 'normal', 'concurrent show started' if show['type'] == "hyperlinkshow": show_obj = HyperlinkShow(show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.set_running(index, show_obj) show_obj.play(index, self._end_play_show, None, top=True, command='nil') return 'normal', 'concurrent show started' elif show['type'] == "menu": show_obj = MenuShow(show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.set_running(index, show_obj) show_obj.play(index, self._end_play_show, None, top=True, command='nil') return 'normal', 'concurrent show started' elif show['type'] == "liveshow": show_obj = LiveShow(show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.set_running(index, show_obj) show_obj.play(index, self._end_play_show, None, top=True, command='nil') return 'normal', 'concurrent show started' else: return 'error', "unknown show type in start concurrent show - " + show[ 'type']
def __init__(self): self.pipresents_issue="1.1" StopWatch.global_enable=False #**************************************** # INTERPRET COMMAND LINE # *************************************** self.options=command_options() pp_dir=sys.path[0] if not os.path.exists(pp_dir+"/pipresents.py"): tkMessageBox.showwarning("Pi Presents","Bad Application Directory") exit() #Initialise logging Monitor.log_path=pp_dir self.mon=Monitor() self.mon.on() if self.options['debug']==True: Monitor.global_enable=True else: Monitor.global_enable=False self.mon.log (self, "Pi Presents is starting") #self.show=None # create profile for pp_editor test files if already not there. if not os.path.exists(pp_dir+"/pp_home/pp_profiles/pp_editor"): self.mon.log(self,"Making pp_editor directory") os.makedirs(pp_dir+"/pp_home/pp_profiles/pp_editor") #profile path from -p option if self.options['profile']<>"": self.pp_profile_path="/pp_profiles/"+self.options['profile'] else: self.pp_profile_path = "/pp_profiles/pp_profile" #get directory containing pp_home from the command, if self.options['home'] =="": home = os.path.expanduser('~')+ os.sep+"pp_home" else: home = self.options['home'] + os.sep+ "pp_home" #check if pp_home exists. # try for 10 seconds to allow usb stick to automount # fall back to pipresents/pp_home self.pp_home=pp_dir+"/pp_home" for i in range (1, 10): self.mon.log(self,"Trying pp_home at: " + home + " " + str(i)) if os.path.exists(home): self.mon.log(self,"Using pp_home at: " + home) self.pp_home=home break time.sleep (1) #check profile exists, if not default to error profile inside pipresents self.pp_profile=self.pp_home+self.pp_profile_path if not os.path.exists(self.pp_profile): self.pp_profile=pp_dir+"/pp_home/pp_profiles/pp_profile" if self.options['verify']==True: val =Validator() if val.validate_profile(None,self.pp_home,self.pp_profile,self.pipresents_issue,False) == False: tkMessageBox.showwarning("Pi Presents","Validation Failed") exit() # open the resources self.rr=ResourceReader() # read the file, done once for all the other classes to use. self.rr.read(pp_dir,self.pp_home) #initialise the showlists and read the showlists self.showlist=ShowList() self.showlist_file= self.pp_profile+ "/pp_showlist.json" if os.path.exists(self.showlist_file): self.showlist.open_json(self.showlist_file) else: self.mon.err(self,"showlist not found at "+self.showlist_file) self._end('error','showlist not found') if float(self.showlist.sissue())<>float(self.pipresents_issue): self.mon.err(self,"Version of profile " + self.showlist.sissue() + " is not same as Pi Presents, must exit") self._end('error','wrong version of profile') # get the starter show from the showlist index = self.showlist.index_of_show('start') if index >=0: self.showlist.select(index) self.starter_show=self.showlist.selected_show() else: self.mon.err(self,"Show [start] not found in showlist") self._end('error','start show not found') # ******************** # SET UP THE GUI # ******************** #turn off the screenblanking and saver if self.options['noblank']==True: call(["xset","s", "off"]) call(["xset","s", "-dpms"]) # control display of window decorations if self.options['fullscreen']<>"partial": self.root = Tk(className="fspipresents") os.system('unclutter &') else: self.root = Tk(className="pipresents") self.title='Pi Presents - '+ self.pp_profile self.icon_text= 'Pi Presents' self.root.title(self.title) self.root.iconname(self.icon_text) self.root.config(bg='black') # get size of the screen self.screen_width = self.root.winfo_screenwidth() self.screen_height = self.root.winfo_screenheight() # set window dimensions self.window_height=self.screen_height self.window_width=self.screen_width self.window_x=0 self.window_y=0 if self.options['fullscreen']<>"partial": bar=self.options['fullscreen'] # allow just 2 pixels for the hidden taskbar if bar in ('left','right'): self.window_width=self.screen_width-2 else: self.window_height=self.screen_height-2 if bar =="left": self.window_x=2 if bar =="top": self.window_y=2 self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y)) self.root.attributes('-zoomed','1') else: self.window_width=self.screen_width-200 self.window_height=self.screen_height-200 self.window_x=50 self.root.geometry("%dx%d%+d%+d" % (self.window_width,self.window_height,self.window_x,self.window_y)) #canvas covers the whole window self.canvas_height=self.window_height self.canvas_width=self.window_width # make sure focus is set. self.root.focus_set() #define response to main window closing. self.root.protocol ("WM_DELETE_WINDOW", self.on_break_key) # Always use CTRL-Break key to close the program as a get out of jail self.root.bind("<Break>",self.e_on_break_key) #pass all other keys along to 'shows' and hence to 'players' self.root.bind("<Escape>", self._escape_pressed) self.root.bind("<Up>", self._up_pressed) self.root.bind("<Down>", self._down_pressed) self.root.bind("<Return>", self._return_pressed) self.root.bind("<space>", self._pause_pressed) self.root.bind("p", self._pause_pressed) #setup a canvas onto which will be drawn the images or text self.canvas = Canvas(self.root, bg='black') self.canvas.config(height=self.canvas_height, width=self.canvas_width) #self.canvas.grid(row=1,columnspan=2) self.canvas.pack() # make sure focus is set on canvas. self.canvas.focus_set() # **************************************** # INITIALISE THE APPLICATION AND START # **************************************** self.shutdown_required=False #kick off GPIO if enabled by command line option if self.options['gpio']==True: from pp_buttons import Buttons # initialise the buttons connected to GPIO self.Buttons=Buttons self.buttons = Buttons(self.root,20,self.button_pressed) self.buttons.poll() # kick off the initial show self.show=None # get the start show from the showlist index = self.showlist.index_of_show(self.starter_show['start-show']) if index >=0: self.showlist.select(index) self.start_show=self.showlist.selected_show() else: self.mon.err(self,"Show not found in showlist: "+ self.starter_show['start-show']) self._end('error','show not found in showlist') if self.start_show['type']=="mediashow": self.show= MediaShow(self.start_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.show.play(self._end_play_show,top=True,command='nil') self.root.mainloop( ) elif self.start_show['type']=="menu": self.show= MenuShow(self.start_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.show.play(self._end_play_show,top=True,command='nil') self.root.mainloop( ) elif self.start_show['type']=="liveshow": self.show= LiveShow(self.start_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.show.play(self._end_play_show,top=True,command='nil') self.root.mainloop( ) else: self.mon.err(self,"unknown mediashow type in start show - "+ self.start_show['type']) self._end('error','unknown mediashow type')
def play_selected_track(self, selected_track): """ selects the appropriate player from type field of the medialist and computes the parameters for that type selected track is a dictionary for the track/show """ if self.timeout_running <> None: self.canvas.after_cancel(self.timeout_running) self.timeout_running = None # self.canvas.delete(ALL) self.display_eggtimer(self.resource('hyperlinkshow', 'm01')) self.current_track_type = selected_track['type'] #read the show links. Track links will be added by ready_callback links_text = self.show_params['links'] reason, message, self.links = self.path.parse_links(links_text) if reason == 'error': self.mon.err(self, message + " in show") self.end('error', message) #start timeout for the track if required if self.current_track_ref <> self.first_track_ref and int( self.show_params['timeout']) <> 0: self.timeout_running = self.canvas.after( int(self.show_params['timeout']) * 1000, self.timeout_callback) # dispatch track by type self.player = None self.shower = None track_type = selected_track['type'] self.mon.log(self, "Track type is: " + track_type) if track_type == "video": # create a videoplayer track_file = self.complete_path(selected_track) self.player = VideoPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.page_callback, enable_menu=False) elif track_type == "audio": # create a audioplayer track_file = self.complete_path(selected_track) self.player = AudioPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.page_callback, enable_menu=False) elif track_type == "image": track_file = self.complete_path(selected_track) self.player = ImagePlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play( track_file, self.showlist, self.end_player, self.page_callback, enable_menu=False, ) elif track_type == "web": # create a browser track_file = self.complete_path(selected_track) self.player = BrowserPlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(track_file, self.showlist, self.end_player, self.page_callback, enable_menu=False) elif track_type == "message": # bit odd because MessagePlayer is used internally to display text. text = selected_track['text'] self.player = MessagePlayer(self.show_id, self.root, self.canvas, self.show_params, selected_track, self.pp_dir, self.pp_home, self.pp_profile) self.player.play(text, self.showlist, self.end_player, self.page_callback, enable_menu=False) elif track_type == "show": self.enable_click_areas() # get the show from the showlist index = self.showlist.index_of_show(selected_track['sub-show']) if index >= 0: self.showlist.select(index) selected_show = self.showlist.selected_show() else: self.mon.err( self, "Show not found in showlist: " + selected_track['sub-show']) self.end("Unknown show") if selected_show['type'] == "mediashow": self.shower = MediaShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "liveshow": self.shower = LiveShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "radiobuttonshow": self.shower = RadioButtonShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "hyperlinkshow": self.shower = HyperlinkShow(selected_show, self.root, self.canvas, self.showlist, self, pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') elif selected_show['type'] == "menu": self.shower = MenuShow(selected_show, self.root, self.canvas, self.showlist, self.pp_dir, self.pp_home, self.pp_profile) self.shower.play(self.show_id, self.end_shower, self.ready_callback, top=False, command='nil') else: self.mon.err(self, "Unknown Show Type: " + selected_show['type']) self.end("Unknown show type") else: self.mon.err(self, "Unknown Track Type: " + track_type) self.end("Unknown track type")
def _play_selected_track(self,selected_track): """ selects the appropriate player from type field of the medialist and computes the parameters for that type selected track is a dictionary for the track/show """ #remove menu and show working..... self.canvas.delete(ALL) if self.menu_timeout_running<>None: self.canvas.after_cancel(self.menu_timeout_running) self.menu_timeout_running=None self._display_eggtimer(self.resource('menushow','m01')) # dispatch track by type self.player=None self.shower=None track_type = selected_track['type'] self.mon.log(self,"Track type is: "+ track_type) if track_type=="video": # create a videoplayer track_file=self.complete_path(selected_track) self.player=VideoPlayer(self.canvas,self.show,selected_track) self.player.play(track_file, self._end_player, self._delete_eggtimer, enable_menu=False) elif track_type=="image": # images played from menus don't have children enable_child=False track_file=self.complete_path(selected_track) self.player=ImagePlayer(self.canvas,self.show,selected_track) self.player.play(track_file, self._end_player, self._delete_eggtimer, enable_menu=enable_child, ) elif track_type=="message": # bit odd because MessagePlayer is used internally to display text. text=selected_track['text'] self.player=MessagePlayer(self.canvas,self.show,selected_track) self.player.play(text, self._end_player, self._delete_eggtimer, enable_menu=False ) elif track_type=="show": # get the show from the showlist index = self.showlist.index_of_show(selected_track['sub-show']) if index >=0: self.showlist.select(index) selected_show=self.showlist.selected_show() else: self.mon.err(self,"Show not found in showlist: "+ selected_track['sub-show']) self._end("Unknown show") if selected_show['type']=="mediashow": self.shower= MediaShow(selected_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.shower.play(self._end_shower,top=False,command='nil') elif selected_show['type']=="liveshow": self.shower= LiveShow(selected_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.shower.play(self.end_shower,top=False,command='nil') elif selected_show['type']=="menu": self.shower= MenuShow(selected_show, self.canvas, self.showlist, self.pp_home, self.pp_profile) self.shower.play(self._end_shower,top=False,command='nil') else: self.mon.err(self,"Unknown Show Type: "+ selected_show['type']) self._end("Unknown show type") else: self.mon.err(self,"Unknown Track Type: "+ track_type) self._end("Unknown track type")