Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        screen_resolution = kwargs.get('screen_resolution', None)
        fullscreen = kwargs.get('fullscreen', False)
        fps = kwargs.get('fps', None)
        center = kwargs.get('center', True)

        args = get_args()
        if screen_resolution is None:
            pm = pymouse.PyMouse()
            screen_resolution = pm.screen_size()
            if args.debug:
                print("selected resolution: " + str(screen_resolution))
        ffmpeg = "ffmpeg"
        display = os.getenv("DISPLAY")
        if fps == None:
            fps = get_args().fps
        if fullscreen:
            fmt = screen_resolution
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            scale = "scale=%d:%d" % (self.width, self.height)
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-vf', scale,
                       '-an', '-']
        else:
            fmt = (self.width, self.height)
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-follow_mouse', 'centered',
                       '-draw_mouse', '0',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-an', '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % (command))
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        args = get_args()

        self.location = kwargs.get('location', None)
        center = kwargs.get('center', True)
        if self.location == None:
            return

        # load in a image with ffmpeg and apply fps
        ffmpeg = "ffmpeg"
        fmtstr = "-vf \"scale=%d:%d\""
        fmt = (self.width, self.height)
        filteropts = fmtstr % (fmt)
        command = [ffmpeg,
                   '-loglevel', 'panic',
                   '-i', self.location,
                   filteropts,
                   '-f', 'image2pipe',
                   '-pix_fmt', 'rgb24',
                   '-vcodec', 'rawvideo',
                   '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % (command))
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Ejemplo n.º 3
0
def find_patterns_in_dir(dir):
    args = get_args()
    patterns = []

    # see if dir is already in path. else add it.
    if dir not in sys.path:
        sys.path.append(dir)
    else:
        print("directory in path.")

    # for everything in a directory.
    for item in os.listdir(dir):
        # if it is a source file.
        if item.endswith(".py") and not item.startswith("__"):
            # extract the file name and import it.
            sfile = item.split('.')[0]
            try:
                if args.debug:
                    print("sfile: %s", str(sfile))
                mod = __import__(sfile)
            except Exception as e:
                if args.debug:
                    print("%s:Couldn't import module cause: %s" % (sfile, e))
                traceback.print_exc()
                continue
            # extract classes
            classes = get_pattern_classes(mod)
            # if any found:
            if classes:
                # append the object to patterns
                patterns += classes
    # return the patterns
    return list(set(patterns))
Ejemplo n.º 4
0
    def __init__(self, **kwargs):
        Graphics.__init__(self, **kwargs)

        self.res = kwargs.get('res', 0.001)
        self.scale = kwargs.get('scale', 0.7)

        self.new_params(**kwargs)

        self.mode = kwargs.get('mode', 0)
        self.timer = Timer(3.0)

        self.nice_ones = [(66, 15, 58), (95, 10, 92), (17, 118, 115),
                          (126, 27, 74), (84, 66, 19), (36, 21, 19),
                          (81, 6, 8), (111, 18, 33),
                          (126, 40, 38), (60, 17, 92), (102, 6, 35),
                          (104, 60, 109), (65, 25, 41), (54, 16, 42),
                          (28, 44, 76), (98, 2, 117), (63, 119, 126),
                          (63, 90, 44)]

        args = get_args()
        if args.debug:
            print("[%s] R: %d, r: %d, d:%d \n" %
                  (__file__, self.R, self.r, self.d))

        gcdval = fractions.gcd(self.r, self.R)
        self.turns = self.r // gcdval

        self.prev_pos = None
Ejemplo n.º 5
0
    def __init__(self, plugged=0):
        args = get_args()
        self.pygame.init()
        self.pygame.joystick.init()
        self.joystick = None
        try:
            self.joystick = self.pygame.joystick.Joystick(plugged)
        except Exception as e:
            if args.debug:
                print("PygameController.py:37:", e)
                print("selected: ", plugged)
            self.joystick = None

        if self.joystick:
            self.joystick.init()
            self.num_axis = self.joystick.get_numaxes()
            self.num_buttons = self.joystick.get_numbuttons()
            self.num_hats = self.joystick.get_numhats()
Ejemplo n.º 6
0
    def __init__(self, plugged=0):
        args = get_args()
        self.pygame.init()
        self.pygame.joystick.init()
        self.joystick = None
        try:
            self.joystick = self.pygame.joystick.Joystick(plugged)
        except Exception as e:
            if args.debug:
                print("PygameController.py:37:", e)
                print("selected: ", plugged)
            self.joystick = None

        if self.joystick:
            self.joystick.init()
            self.num_axis = self.joystick.get_numaxes()
            self.num_buttons = self.joystick.get_numbuttons()
            self.num_hats = self.joystick.get_numhats()
Ejemplo n.º 7
0
def load_targets(configfile):
    # this function allows loading of the config files specified by
    # --config=configfile and load patterns defined in there.
    args = get_args()

    # test if the config file exists, if not it's maybe a local file
    # and else it's probably a path description + file.
    basepath = os.path.dirname(os.path.realpath(__file__))
    
    configpath = os.path.join(basepath, "configs")
    if not os.path.exists(configfile):
        configfile = os.path.join(configpath, configfile)

    patternpath = os.path.join(basepath, "Patterns")

    variables = dict()
    for p in find_patterns_in_dir(patternpath):
        variables[p.__name__] = p
    
    if args.debug:
        print("\nfound patterns: ")
        pprint(variables)
        print(" ")

    configlines = ""
    with open(configfile) as f:
        configlines = f.read()

    exec(configlines, variables)

    targets = variables.get('targets', None)
    protocol = variables.get('protocol', None)
    matrixsim = variables.get('matrixsim', None)

    if args.debug:
        print("configfile: %s" % configfile)
        print("protocol: %s" % protocol)
        print("matrixsim: %s" % matrixsim)
        print("targets: %s" % (str(targets)))

    return (targets, protocol, matrixsim)
Ejemplo n.º 8
0
    def __init__(self, **kwargs):
        Graphics.__init__(self, **kwargs)

        self.res = kwargs.get('res', 0.001)
        self.scale = kwargs.get('scale', 0.7)

        self.new_params(**kwargs)

        self.mode = kwargs.get('mode', 0)
        self.timer = Timer(3.0)

        self.nice_ones = [(66, 15, 58),
                          (95, 10, 92),
                          (17, 118, 115),
                          (126, 27, 74),
                          (84, 66, 19),
                          (36, 21, 19),
                          (81, 6, 8),
                          (111, 18, 33),
                          (126, 40, 38),
                          (60, 17, 92),
                          (102, 6, 35),
                          (104, 60, 109),
                          (65, 25, 41),
                          (54, 16, 42),
                          (28, 44, 76),
                          (98, 2, 117),
                          (63, 119, 126),
                          (63, 90, 44)
                          ]

        args = get_args()
        if args.debug:
            print("[%s] R: %d, r: %d, d:%d \n" % (__file__, self.R, self.r, self.d))

        gcdval = fractions.gcd(self.r, self.R)
        self.turns = self.r // gcdval

        self.prev_pos = None
Ejemplo n.º 9
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        dev = kwargs.get('dev', '/dev/video0')
        args = get_args()

        ffmpeg = 'ffmpeg'
        scale = "scale=%d:%d" % (self.width, self.height)

        command = [ffmpeg,
                   '-loglevel', 'panic',
                   '-f', 'v4l2',
                   '-r', '30',
                   '-video_size', '160x120',
                   '-i', dev,
                   '-vf', scale,
                   '-f', 'image2pipe',
                   '-pix_fmt', 'rgb24',
                   '-vcodec', 'rawvideo',
                   '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % command)
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)