Exemple #1
0
    def __init__(self, show_id, show_params, root, canvas, showlist, pp_dir,
                 pp_home, pp_profile, command_callback):
        """
            show_id - index of the top level show caling this (for debug only)
            show_params - dictionary section for the menu
            canvas - the canvas that the menu is to be written on
            showlist  - the showlist
            pp_dir - Pi Presents directory
            pp_home - Pi presents data_home directory
            pp_profile - Pi presents profile directory
        """

        # init the common bits
        Show.base__init__(self, show_id, show_params, root, canvas, showlist,
                          pp_dir, pp_home, pp_profile, command_callback)

        # instatiatate the screen driver - used only to access enable and hide click areas
        self.sr = ScreenDriver()

        self.controlsmanager = ControlsManager()

        # init variables
        self.show_timeout_timer = None
        self.track_timeout_timer = None
        self.next_track_signal = False
        self.next_track = None
        self.menu_index = 0
        self.menu_showing = True
        self.req_next = ''
        self.last_menu_index = 0
        self.return_to_zero = False
    def __init__(self, show_id, show_params, root, canvas, showlist, pp_dir,
                 pp_home, pp_profile, command_callback):

        # init the common bits
        Show.base__init__(self, show_id, show_params, root, canvas, showlist,
                          pp_dir, pp_home, pp_profile, command_callback)

        # instatiatate the screen driver - used only to access enable and hide click areas
        self.sr = ScreenDriver()

        self.controlsmanager = ControlsManager()

        # Init variables special to this show
        self.poll_for_interval_timer = None
        self.interval_timer_signal = False
        self.waiting_for_interval = False
        self.interval_timer = None
        self.duration_timer = None

        self.end_trigger_signal = False
        self.next_track_signal = False
        self.previous_track_signal = False
        self.play_child_signal = False
        self.error_signal = False
        self.show_timeout_signal = False

        self.req_next = 'nil'
        self.state = 'closed'

        self.count = 0
        self.interval = 0
        self.duration = 0
        self.controls_list = []
        self.enable_hint = True
Exemple #3
0
    def play(self,show_id,end_callback,show_ready_callback, top=False,command='nil'):

        """ displays the mediashow
              end_callback - function to be called when the menu exits
              ready_callback - callback when menu is ready to display (not used)
              top is True when the show is top level (run from [start])
        """

        #instantiate the arguments
        self.show_id=show_id
        self.end_callback=end_callback
        self.show_ready_callback=show_ready_callback
        self.top=top
        self.command=command
        self.mon.log(self,self.show_params['show-ref']+ ' '+ str(self.show_id)+ ": Starting show")

        # check  data files are available.
        self.media_file = self.pp_profile + "/" + self.show_params['medialist']
        if not os.path.exists(self.media_file):
            self.mon.err(self,"Medialist file not found: "+ self.media_file)
            self.end('error',"Medialist file not found")


        #create a medialist for the mediashow and read it.
        self.medialist=MediaList()
        if self.medialist.open_list(self.media_file,self.showlist.sissue())==False:
            self.mon.err(self,"Version of medialist different to Pi Presents")
            self.end('error',"Version of medialist different to Pi Presents")

        #get controls for this show if top level
        controlsmanager=ControlsManager()
        if self.top==True:
            self.controls_list=controlsmanager.default_controls()
            # and merge in controls from profile
            self.controls_list=controlsmanager.merge_show_controls(self.controls_list,self.show_params['controls'])


        #set up the time of day triggers for the show
        if self.show_params['trigger']in('time','time-quiet'):
            error_text=self.tod.add_times(self.show_params['trigger-input'],id(self),self.tod_start_callback,self.show_params['trigger'])
            if error_text<>'':
                self.mon.err(self,error_text)
                self.end('error',error_text)

        if self.show_params['trigger-end']=='time':
            # print self.show_params['trigger-end-time']
            error_text=self.tod.add_times(self.show_params['trigger-end-time'],id(self),self.tod_end_callback,'n/a')
            if error_text<>'':
                self.mon.err(self,error_text)
                self.end('error',error_text)
                
        if self.show_params['trigger-end']=='duration':
            error_text=self.calculate_duration(self.show_params['trigger-end-time'])
            if error_text<>'':
                self.mon.err(self,error_text)
                self.end('error',error_text)
                
        self.state='closed'
        self.egg_timer=None
        self.wait_for_trigger()
    def track_ready_callback(self, enable_show_background):
        self.mon.trace(self, '')

        # get control bindings for this show
        self.controlsmanager = ControlsManager()
        if self.show_params['disable-controls'] == 'yes':
            self.controls_list = []
        else:
            reason, message, self.controls_list = self.controlsmanager.get_controls(
                self.show_params['controls'])
            if reason == 'error':
                self.mon.err(self, message)
                self.end('error', "error in controls: " + message)
                return
            # print '\nshow controls',self.show_params['controls']

            #merge controls from the track
            controls_text = self.current_player.get_links()
            # print 'current player controls',controls_text
            reason, message, track_controls = self.controlsmanager.parse_controls(
                controls_text)
            if reason == 'error':
                self.mon.err(
                    self, message + " in track: " +
                    self.current_player.track_params['track-ref'])
                self.error_signal = True
                self.what_next_after_showing()
            self.controlsmanager.merge_controls(self.controls_list,
                                                track_controls)

        # show the show background done for every track but quick operation
        if enable_show_background is True:
            self.base_show_show_background()
        else:
            self.base_withdraw_show_background()
        # !!!!!!!!! withdraw the background from the parent show
        if self.previous_shower != None:
            self.previous_shower.base_withdraw_show_background()

        # close the player from the previous track
        if self.previous_player is not None:
            self.mon.trace(
                self, 'hiding previous: ' +
                self.mon.pretty_inst(self.previous_player))
            self.previous_player.hide()
            if self.previous_player.get_play_state() == 'showing':
                self.mon.trace(
                    self, 'closing previous: ' +
                    self.mon.pretty_inst(self.previous_player))
                self.previous_player.close(self.closed_callback)
            else:
                self.mon.trace(self, 'previous is none')
                self.previous_player = None
Exemple #5
0
    def __init__(self, show_id, show_params, root, canvas, showlist, pp_dir,
                 pp_home, pp_profile, command_callback):

        # init the common bits
        Show.base__init__(self, show_id, show_params, root, canvas, showlist,
                          pp_dir, pp_home, pp_profile, command_callback)

        # instatiatate the screen driver - used only to access enable and hide click areas
        self.sr = ScreenDriver()

        # create an instance of PathManager -  only used to parse the links.
        self.path = PathManager()

        self.allowed_links = ('play', 'pause', 'exit', 'return', 'null',
                              'no-command', 'stop')
        # init variables
        self.links = []
        self.track_timeout_timer = None
        self.show_timeout_timer = None
        self.next_track_signal = False
        self.current_track_ref = ''
        self.req_next = ''

        self.controlsmanager = ControlsManager()

        # Init variables special to this show
        self.poll_for_interval_timer = None
        self.interval_timer_signal = False
        self.waiting_for_interval = False
        self.interval_timer = None
        self.duration_timer = None

        self.end_trigger_signal = False
        self.next_track_signal = False
        self.previous_track_signal = False
        self.play_child_signal = False
        self.error_signal = False
        self.show_timeout_signal = False

        self.req_next = 'nil'
        self.state = 'closed'

        self.count = 0
        self.interval = 0
        self.duration = 0
        self.controls_list = []
        self.enable_hint = True
Exemple #6
0
    def __init__(self):

        self.pipresents_issue = "1.2"
        self.pipresents_minorissue = '1.2.3f'
        self.nonfull_window_width = 0.5  # proportion of width
        self.nonfull_window_height = 0.6  # proportion of height
        self.nonfull_window_x = 0  # position of top left corner
        self.nonfull_window_y = 0  # position of top left corner

        StopWatch.global_enable = False

        #****************************************
        # Initialisation
        # ***************************************
        # get command line options
        self.options = command_options()

        # get pi presents code directory
        pp_dir = sys.path[0]
        self.pp_dir = pp_dir

        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()
        # 0  - errors only
        # 1  - errors and warnings
        # 2  - everything
        if self.options['debug'] == True:
            Monitor.global_enable = 2
        else:
            Monitor.global_enable = 0

        # UNCOMMENT THIS TO LOG WARNINGS AND ERRORS ONLY
        # Monitor.global_enable=1

        self.mon.log(
            self,
            "\n\n\n\n\n*****************\nPi Presents is starting, Version:" +
            self.pipresents_minorissue)
        self.mon.log(self, "Version: " + self.pipresents_minorissue)
        self.mon.log(self, " OS and separator:" + os.name + '  ' + os.sep)
        self.mon.log(self, "sys.path[0] -  location of code: " + sys.path[0])
        # self.mon.log(self,"os.getenv('HOME') -  user home directory (not used): " + os.getenv('HOME'))
        # self.mon.log(self,"os.path.expanduser('~') -  user home directory: " + os.path.expanduser('~'))

        # optional other classes used
        self.ppio = None
        self.tod = None

        #get 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"
        self.mon.log(self, "pp_home directory is: " + 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"
        found = False
        for i in range(1, 10):
            self.mon.log(self,
                         "Trying pp_home at: " + home + " (" + str(i) + ')')
            if os.path.exists(home):
                found = True
                self.pp_home = home
                break
            time.sleep(1)
        if found == True:
            self.mon.log(
                self,
                "Found Requested Home Directory, using pp_home at: " + home)
        else:
            self.mon.log(
                self,
                "FAILED to find requested home directory, using default to display error message: "
                + self.pp_home)

        #check profile exists, if not default to error profile inside pipresents
        self.pp_profile = self.pp_home + self.pp_profile_path
        if os.path.exists(self.pp_profile):
            self.mon.log(
                self, "Found Requested profile - pp_profile directory is: " +
                self.pp_profile)
        else:
            self.pp_profile = pp_dir + "/pp_home/pp_profiles/pp_profile"
            self.mon.log(
                self,
                "FAILED to find requested profile, using default to display error message: pp_profile"
            )

        if self.options['verify'] == True:
            val = Validator()
            if val.validate_profile(None, pp_dir, 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.
        if self.rr.read(pp_dir, self.pp_home, self.pp_profile) == False:
            self.end('error', 'cannot find resources.cfg')

        #initialise and read the showlist in the profile
        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')

        # check profile and Pi Presents issues are compatible
        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 'start' 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"])

        self.root = Tk()

        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 and decorations
        if self.options['fullscreen'] == True:

            self.root.attributes('-fullscreen', True)
            os.system('unclutter &')
            self.window_width = self.screen_width
            self.window_height = self.screen_height
            self.window_x = 0
            self.window_y = 0
            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 = int(self.screen_width *
                                    self.nonfull_window_width)
            self.window_height = int(self.screen_height *
                                     self.nonfull_window_height)
            self.window_x = self.nonfull_window_x
            self.window_y = self.nonfull_window_y
            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.screen_height
        self.canvas_width = self.screen_width

        # make sure focus is set.
        self.root.focus_set()

        #define response to main window closing.
        self.root.protocol("WM_DELETE_WINDOW", self.exit_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,
                           highlightthickness=0)
        # self.canvas.pack()
        self.canvas.place(x=0, y=0)

        self.canvas.focus_set()

        # ****************************************
        # INITIALISE THE INPUT DRIVERS
        # ****************************************

        # looks after bindings between symbolic names and internal operations
        controlsmanager = ControlsManager()
        if controlsmanager.read(pp_dir, self.pp_home,
                                self.pp_profile) == False:
            self.end('error', 'cannot find or error in controls.cfg.cfg')
        else:
            controlsmanager.parse_defaults()

        # each driver takes a set of inputs, binds them to symboic names
        # and sets up a callback which returns the symbolic name when an input event occurs/

        # use keyboard driver to bind keys to symbolic names and to set up callback
        kbd = KbdDriver()
        if kbd.read(pp_dir, self.pp_home, self.pp_profile) == False:
            self.end('error', 'cannot find or error in keys.cfg')
        kbd.bind_keys(self.root, self.input_pressed)

        self.sr = ScreenDriver()
        # read the screen click area config file
        if self.sr.read(pp_dir, self.pp_home, self.pp_profile) == False:
            self.end('error', 'cannot find screen.cfg')

        # create click areas on the canvas, must be polygon as outline rectangles are not filled as far as find_closest goes
        reason, message = self.sr.make_click_areas(self.canvas,
                                                   self.input_pressed)
        if reason == 'error':
            self.mon.err(self, message)
            self.end('error', message)

# ****************************************
# 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_gpio import PPIO
            # initialise the GPIO
            self.ppio = PPIO()
            # PPIO.gpio_enabled=False
            if self.ppio.init(pp_dir, self.pp_home, self.pp_profile,
                              self.canvas, 50, self.gpio_pressed) == False:
                self.end('error', 'gpio error')

            # and start polling gpio
            self.ppio.poll()

        #kick off the time of day scheduler
        self.tod = TimeOfDay()
        self.tod.init(pp_dir, self.pp_home, self.canvas, 500)
        self.tod.poll()

        # Create list of start shows initialise them and then run them
        self.run_start_shows()

        #start tkinter
        self.root.mainloop()
Exemple #7
0
    def play(self,
             show_id,
             end_callback,
             ready_callback,
             top=False,
             command='nil'):
        """ starts the hyperlink show at start-track 
              end_callback - function to be called when the show exits
              ready_callback - callback when event-show is ready to display its forst track (not used?)
              top is True when the show is top level (run from [start] or from show control)
              command is not used
        """

        #instantiate arguments
        self.show_id = show_id
        self.end_callback = end_callback
        self.ready_callback = ready_callback
        self.top = top
        self.command = command

        # check data files are available.
        self.medialist_file = self.pp_profile + "/" + self.show_params[
            'medialist']
        if not os.path.exists(self.medialist_file):
            self.mon.err(self,
                         "Medialist file not found: " + self.medialist_file)
            self.end('error', "Medialist file not found")

        #create a medialist object for the hyperlinkshow and read the file into it.
        self.medialist = MediaList()
        if self.medialist.open_list(self.medialist_file,
                                    self.showlist.sissue()) == False:
            self.mon.err(self, "Version of medialist different to Pi Presents")
            self.end('error', "Version of medialist different to Pi Presents")

        #get controls for this show if top level
        controlsmanager = ControlsManager()
        if self.top == True:
            self.controls_list = controlsmanager.default_controls()
            # and merge in controls from profile
            self.controls_list = controlsmanager.merge_show_controls(
                self.controls_list, self.show_params['controls'])

        # read show  links and destinations
        self.first_track_ref = self.show_params['first-track-ref']
        self.home_track_ref = self.show_params['home-track-ref']
        self.timeout_track_ref = self.show_params['timeout-track-ref']

        # state variables and signals
        self.end_hyperlinkshow_signal = False
        self.egg_timer = None
        self.next_track_signal = False
        self.next_track_ref = ''
        self.current_track_ref = ''
        self.current_track_type = ''

        # ready callback for show
        if self.ready_callback <> None:
            self.ready_callback()

        self.canvas.delete('pp-content')
        self.canvas.config(bg='black')

        self.do_first_track()
Exemple #8
0
    def play(self,
             show_id,
             end_callback,
             ready_callback,
             top=False,
             command='nil'):

        #instantiate the arguments
        self.show_id = show_id
        self.end_callback = end_callback
        self.ready_callback = ready_callback
        self.top = top
        self.mon.log(self, "Starting show: " + self.show_params['show-ref'])

        # check  data files are available.
        self.media_file = self.pp_profile + os.sep + self.show_params[
            'medialist']
        if not os.path.exists(self.media_file):
            self.mon.err(self, "Medialist file not found: " + self.media_file)
            self.end_liveshow_signal = True

        self.options = command_options()

        self.pp_live_dir1 = self.pp_home + os.sep + 'pp_live_tracks'
        if not os.path.exists(self.pp_live_dir1):
            os.mkdir(self.pp_live_dir1)

        self.pp_live_dir2 = ''
        if self.options['liveshow'] <> "":
            self.pp_live_dir2 = self.options['liveshow']
            if not os.path.exists(self.pp_live_dir2):
                self.mon.err(
                    self,
                    "live tracks directory not found " + self.pp_live_dir2)
                self.end('error', "live tracks directory not found")

        #create a medialist for the liveshow and read it.
        # it should be empty of anonymous tracks but read it to check its version.
        self.medialist = MediaList()
        if self.medialist.open_list(self.media_file,
                                    self.showlist.sissue()) == False:
            self.mon.err(self, "Version of medialist different to Pi Presents")
            self.end('error', "Version of medialist different to Pi Presents")

        #get control bindings for this show if top level
        controlsmanager = ControlsManager()
        if self.top == True:
            self.controls_list = controlsmanager.default_controls()
            # and merge in controls from profile
            self.controls_list = controlsmanager.merge_show_controls(
                self.controls_list, self.show_params['controls'])

        #set up the time of day triggers for the show
        if self.show_params['trigger-start'] in ('time', 'time-quiet'):
            error_text = self.tod.add_times(
                self.show_params['trigger-start-time'], id(self),
                self.tod_start_callback, self.show_params['trigger-start'])
            if error_text <> '':
                self.mon.err(self, error_text)
                self.end('error', error_text)

        if self.show_params['trigger-end'] == 'time':
            error_text = self.tod.add_times(
                self.show_params['trigger-end-time'], id(self),
                self.tod_end_callback, 'n/a')
            if error_text <> '':
                self.mon.err(self, error_text)
                self.end('error', error_text)

        if self.show_params['trigger-end'] == 'duration':
            error_text = self.calculate_duration(
                self.show_params['trigger-end-time'])
            if error_text <> '':
                self.mon.err(self, error_text)
                self.end('error', error_text)

        self.wait_for_trigger()