Exemplo n.º 1
0
def quit_on_keyboard(cam_streams_to_stop):
    if draw.check_keypress_end():
        draw.destroy()
        for cam_stream_to_stop in cam_streams_to_stop:
            cam_stream_to_stop.stop_stream()
        sys.exit(0)
Exemplo n.º 2
0
def sigterm_handler(_signo, _stack_frame):
    draw.destroy()
    sys.exit(0)
Exemplo n.º 3
0
def draw_screen(cam_streams_to_stop, cam_streams_to_draw, resolution,
                nr_of_columns, fixed_width, fixed_height, autostretch):

    resolution_width = int(resolution[0])
    resolution_height = int(resolution[1])
    nr_of_columns = int(nr_of_columns)

    #First stop all running streams
    for cam_stream_to_stop in cam_streams_to_stop:
        cam_stream_to_stop.stop_stream()

    #Setup global pygame_noconnectable_surface
    global pygame_noconnectable_surface

    #Start algorithm to start new streams
    fields = len(cam_streams_to_draw)
    if fields == 0:
        logger.error("No connectable streams detected")
        #Check if pygame_noconnectable_surface already exists before redrawing
        try:
            pygame_noconnectable_surface.get_parent()
        except:
            logger.debug(
                "pygame_noconnectable_surface does not exist, draw it")
            draw.destroy()
            pygamescreen = draw.init(resolution)
            pygame_noconnectable_surface = draw.placeholder(
                0, 0, resolution_width, resolution_height,
                "images/noconnectable.png", pygamescreen)
        return
    else:
        draw.destroy()
        #Reset pygame_noconnectable_surface
        pygame_noconnectable_surface = 0
        pygamescreen = draw.init(resolution)

    logger.debug("number of fields= " + str(fields))

    #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 = resolution_width / nr_of_columns
    default_fieldheight = int(resolution_height / nr_of_rows)

    normal_fieldwidth = default_fieldwidth
    normal_fieldheight = default_fieldheight

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

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

    currentrow = 1
    currentwindow = 1
    currentrowlength = nr_of_columns

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

    for cam_stream in cam_streams_to_draw:

        if currentwindow > currentrowlength:
            #This is a new row event
            x1 = 0
            x2 = normal_fieldwidth
            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
            x2 = normal_fieldwidth

        #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 fixed_width is None and 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 = resolution_width
            else:
                #Start calculation to display placeholders
                free_horizontal_pixels = resolution_width - x2
                if free_horizontal_pixels > 0:
                    logger.debug(
                        "We have some 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",
                                         pygamescreen)
                        count_placeholders = count_placeholders + 1
                        placeholder_x = placeholder_x + normal_fieldwidth

        logger.debug("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], pygamescreen)
        cam_stream.printcoordinates()

        currentwindow = currentwindow + 1