Exemple #1
0
 def refresh_image_from_url(self):
     if self.imageurl:
         # This is an imageurl instead of a camerastream, do not start omxplayer stuff
         if self.is_connectable():
             try:
                  image_str = urllib2.urlopen(self.url).read()
                 image_str = self._urllib2open_wrapper().read()
                 # create a file object (stream)
                 self.image_file = io.BytesIO(image_str)
                 self.calculate_field_geometry()
                 draw.placeholder(self.coordinates[0], self.coordinates[1], self.normal_fieldwidth, self.normal_fieldheight, self.image_file, self.pygamescreen)
             except Exception as e:
                 #Do not crash rpisurv if there is something wrong with loading the image at this time
                 logger.error("CameraStream: This stream " + self.name + " refresh_image_from_url " + repr(e))
Exemple #2
0
 def show_status(self):
     self.normal_fieldwidth=self.coordinates[2] - self.coordinates[0]
     self.normal_fieldheight=self.coordinates[3] - self.coordinates[1]
     draw.placeholder(self.coordinates[0], self.coordinates[1], self.normal_fieldwidth, self.normal_fieldheight, "images/connecting.png", self.pygamescreen)
Exemple #3
0
    def update_screen(self):

        # Other option to compare could be with to convert the list into a set: print set(connectable_camera_streams) == set(previous_connectable_camera_streams)
        # Only re-draw screen if something is changed or try redrawing if there is no camerastream that is connectable OR if we change the screen from cached to not cached or vice versa
        if cmp(self.connectable_camera_streams,
               self.previous_connectable_camera_streams) != 0 or len(
                   self.previous_connectable_camera_streams
               ) == 0 or self.previous_cached != self.cached:
            logger.debug("Screen: " + self.name +
                         " Connectable camera streams changed from " +
                         str(len(self.previous_connectable_camera_streams)) +
                         " to " + str(len(self.connectable_camera_streams)) +
                         " or we change from previous_cached value: " +
                         str(self.previous_cached) +
                         " to current cached value: " + str(self.cached) +
                         ", screen: " + self.name + " needs update/redraw")

            #Stop all running streams only when some streams are not connectable
            if cmp(self.connectable_camera_streams,
                   self.previous_connectable_camera_streams) != 0 or len(
                       self.previous_connectable_camera_streams) == 0:
                for cam_stream_to_stop in self.cam_streams_to_stop:
                    cam_stream_to_stop.stop_stream()

            nr_of_columns = int(self.nr_of_columns)

            # Start algorithm to start new streams
            fields = len(self.cam_streams_to_draw)
            logger.debug("Screen: " + self.name + " number of fields= " +
                         str(fields))

            if fields == 0:
                if not self.cached:
                    #Draw no connectable placeholder
                    draw.placeholder(0, 0, self.resolution_width,
                                     self.resolution_height,
                                     "images/noconnectable.png",
                                     self.pygamescreen)
                    self.previous_connectable_camera_streams = self.connectable_camera_streams
                    self.previous_cached = self.cached
                return
            else:
                # Only destroy all placeholders when fields are not 0, this to prevent showing black screen flapping when noconnectable is shown fullscreen
                self.destroy_all_placeholder()

            #If you have less fields than columns then only set fields amount columns
            if fields <= nr_of_columns:
                nr_of_columns = fields

            #We calculate needed numbers of rows based on how many fields we have and how many columns per row we want
            nr_of_rows = math.ceil(float(fields) / nr_of_columns)

            default_fieldwidth = self.resolution_width / nr_of_columns
            default_fieldheight = int(self.resolution_height / nr_of_rows)

            normal_fieldwidth = default_fieldwidth
            normal_fieldheight = default_fieldheight

            if self.fixed_width is not None:
                total_actual_width = nr_of_columns * self.fixed_width
                if not total_actual_width > self.resolution_width:
                    normal_fieldwidth = self.fixed_width
                    logger.debug(
                        "Screen: Detected advanced fixed_width config option, setting normal_fieldwidth to "
                        + str(normal_fieldwidth))
                else:
                    logger.error(
                        "Screen: Total sum of advanced fixed_width (nr_columns * fixed_width) option ("
                        + str(total_actual_width) +
                        ") is more then available width (" +
                        str(self.resolution_width) +
                        "), falling back to autocalculated width: " +
                        str(normal_fieldwidth))

            if self.fixed_height is not None:
                total_actual_height = nr_of_rows * self.fixed_height
                if not total_actual_height > self.resolution_height:
                    normal_fieldheight = self.fixed_height
                    logger.debug(
                        "Screen: Detected advanced fixed_height config option, setting normal_fieldheight to "
                        + str(normal_fieldheight))
                else:
                    logger.error(
                        "Screen: Total sum of advanced fixed_height (nr rows * fixed_height) option ("
                        + str(total_actual_height) +
                        ") is more then available height (" +
                        str(self.resolution_height) +
                        "), falling back to autocalculated height: " +
                        str(normal_fieldheight))

            currentrow = 1
            currentwindow = 1
            currentrowlength = nr_of_columns

            if self.cached:
                #cached means, warm the camerastreams offscreen, so they can be swapped onscreen when rotate is called
                offset = self.resolution_width
                logger.debug("Screen: This screen: " + self.name +
                             " is updated in cache with offset:" + str(offset))
            else:
                offset = 0

            x1 = 0 + offset
            y1 = 0
            x2 = normal_fieldwidth + offset
            y2 = normal_fieldheight

            for cam_stream in self.cam_streams_to_draw:

                if currentwindow > currentrowlength:
                    #This is a new row event
                    x1 = 0 + offset
                    x2 = normal_fieldwidth + offset
                    y1 = y1 + normal_fieldheight
                    y2 = y2 + normal_fieldheight

                    currentrow = currentrow + 1
                    #Next row ends when we are at following currentwindow index number
                    currentrowlength = currentrowlength + nr_of_columns
                else:
                    #This is a window in the same row
                    x1 = x1 + normal_fieldwidth
                    x2 = x2 + normal_fieldwidth

                #If this is the first field/window override some settings
                if currentwindow == 1:
                    x1 = 0 + offset
                    x2 = normal_fieldwidth + offset

                #If this is the last field and we still have some screen space left, horizontally stretch it to use all space
                if currentwindow == fields:
                    if self.fixed_width is None and self.autostretch is True:
                        #Sometimes this will override to the same value if the window end was already at the end of the screen
                        #Other times it will really override to the end of the screen
                        x2 = self.resolution_width + offset
                    else:
                        #Start calculation to display placeholders
                        free_horizontal_pixels = self.resolution_width - x2
                        #If we have some unused screen space and this Screen is not a cached screen then start drawing placeholders
                        if free_horizontal_pixels > 0 and not self.cached:
                            logger.debug(
                                "Screen: We have " +
                                str(free_horizontal_pixels) +
                                " free_horizontal_pixels unused screen and autostretch is disabled. Start drawing placeholders"
                            )
                            nr_of_placeholders = free_horizontal_pixels / normal_fieldwidth
                            count_placeholders = 0
                            placeholder_x = x1 + normal_fieldwidth
                            placeholder_y = y1
                            while count_placeholders < nr_of_placeholders:
                                draw.placeholder(placeholder_x, placeholder_y,
                                                 normal_fieldwidth,
                                                 normal_fieldheight,
                                                 "images/placeholder.png",
                                                 self.pygamescreen)
                                count_placeholders = count_placeholders + 1
                                placeholder_x = placeholder_x + normal_fieldwidth

                logger.debug("Screen: cam stream name =" + cam_stream.name)
                cam_stream_name = "cam_stream" + str(currentwindow)
                # x1 #x coordinate upper left corner
                # y1 #y coordinate upper left corner
                # x2 #x coordinate absolute where window should end, count from left to right
                # y2 #y coordinate from where window should end, count from top to bottom of screen
                cam_stream.start_stream([x1, y1, x2, y2], self.pygamescreen,
                                        self.cached)
                #Debug test
                #cam_stream.set_videopos([x1 + 50 ,y1 +50 ,x2 +50 ,y2 +50])
                cam_stream.printcoordinates()

                currentwindow = currentwindow + 1
        else:
            logger.debug(
                "Screen: Connectable camera streams stayed the same, from " +
                str(len(self.previous_connectable_camera_streams)) + " to " +
                str(len(self.connectable_camera_streams)) + ", screen: " +
                self.name + " does not need full redraw")

        self.previous_connectable_camera_streams = self.connectable_camera_streams
        self.previous_cached = self.cached

        #refresh all placeholders that were created on the screen itself, but do not do this if we are running in cache
        if not self.cached:
            draw.refresh()
Exemple #4
0
 def show_status(self):
     self.calculate_field_geometry()
     draw.placeholder(self.coordinates[0], self.coordinates[1],
                      self.normal_fieldwidth, self.normal_fieldheight,
                      "images/connecting.png", self.pygamescreen)