Esempio n. 1
0
    def start(self):
        """
        Starts the modules, views classes.

        Arguments:
        - self: The main object pointer.
        """

        if self.cfg is None:
            self.cfg = settings.load()

        if not self.dbusd.start():
            self.httpd.start()

        if self.cfg.getboolean("main", "startCam"):
            # Lets start the module
            idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
            self.idm = idm.Module(self)
            self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))

            gobject.timeout_add(10, self.update_frame)
            gobject.timeout_add(10, self.update_pointers)

            debug.info("mousetrap", "Idm loaded and started")

        # Lets build the interface
        self.itf = MainGui(self)
        self.itf.build_interface()
        self.itf.load_addons()
        debug.info("mousetrap", "MouseTrap's Interface Builded and Loaded")

        gobject.threads_init()
        self.loop.run()
Esempio n. 2
0
    def start(self):
        """
        Starts the modules, views classes.

        Arguments:
        - self: The main object pointer.
        """

        if self.cfg is None:
            conf_created, self.cfg = settings.load()

        self.proc_args()

        if not self.dbusd.start():
            self.httpd.start()

        if self.cfg.getboolean("main", "startCam"):
            # Lets start the module
            idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
            self.idm = idm.Module(self)
            self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))

            gobject.timeout_add(150, self.update_frame)
            gobject.timeout_add(50, self.update_pointers)

            debug.info("mousetrap", "Idm loaded and started")

        # Lets build the interface
        self.itf = MainGui(self)
        self.itf.build_interface()
        self.itf.load_addons()

        if conf_created:
            from ui import settings_gui
            settings_gui.showPreffGui(self)

        debug.info("mousetrap", "MouseTrap's Interface Built and Loaded")

        gobject.threads_init()
        self.loop.run()
Esempio n. 3
0
class Controller():
    """
    MouseTrap's Controller Class
    """

    def __init__(self):
        """
        The MouseTrap controller init class

        Arguments:
        - self: The main object pointer.
        """

        # We don't want to load the settings each time we need them. do we?
        self.cfg = None

        self.loop = gobject.MainLoop()
        self.httpd = httpd.HttpdServer(20433)
        self.dbusd = dbusd.DbusServer()


    def start(self):
        """
        Starts the modules, views classes.

        Arguments:
        - self: The main object pointer.
        """

        if self.cfg is None:
            self.cfg = settings.load()

        if not self.dbusd.start():
            self.httpd.start()

        if self.cfg.getboolean("main", "startCam"):
            # Lets start the module
            idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
            self.idm = idm.Module(self)
            self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))

            gobject.timeout_add(10, self.update_frame)
            gobject.timeout_add(10, self.update_pointers)

            debug.info("mousetrap", "Idm loaded and started")

        # Lets build the interface
        self.itf = MainGui(self)
        self.itf.build_interface()
        self.itf.load_addons()
        debug.info("mousetrap", "MouseTrap's Interface Builded and Loaded")

        gobject.threads_init()
        self.loop.run()

    def script(self):
        """
        Returns the main script class object.

        Arguments:
        - self: The main object pointer.
        """
        return ScriptClass()

    def update_frame(self):
        """
        Updates the User Interface frame with the latest capture.

        Arguments:
        - self: The main object pointer.
        """
        self.itf.update_frame(self.idm.get_capture(), self.idm.get_pointer())
        return True

    def update_pointers(self):
        """
        Gets the new mouse pointer position based on the las calcs.

        Arguments:
        - self: The main object pointer.
        """
        #This may screw up the forehead IDM, but I would argue that forehead.py should include this!
        if self.idm.track_object:
            self.itf.script.update_items(self.idm.get_pointer())
        return True
Esempio n. 4
0
class Controller():
    """
    MouseTrap's Controller Class
    """

    def __init__(self):
        """
        The MouseTrap controller init class

        Arguments:
        - self: The main object pointer.
        """

        # We don't want to load the settings each time we need them. do we?
        self.cfg = None

        self.loop = gobject.MainLoop()
        self.httpd = httpd.HttpdServer(20433)
        self.dbusd = dbusd.DbusServer()


    def start(self):
        """
        Starts the modules, views classes.

        Arguments:
        - self: The main object pointer.
        """

        if self.cfg is None:
            conf_created, self.cfg = settings.load()

        self.proc_args()

        if not self.dbusd.start():
            self.httpd.start()

        if self.cfg.getboolean("main", "startCam"):
            # Lets start the module
            idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
            self.idm = idm.Module(self)
            self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))

            gobject.timeout_add(150, self.update_frame)
            gobject.timeout_add(50, self.update_pointers)
            
            debug.info("mousetrap", "Idm loaded and started")

        # Lets build the interface
        self.itf = MainGui(self)
        self.itf.build_interface()
        self.itf.load_addons()
        
        if conf_created:
            from ui import settings_gui
            settings_gui.showPreffGui(self)
            
        debug.info("mousetrap", "MouseTrap's Interface Built and Loaded")

        gobject.threads_init()
        self.loop.run()

    def proc_args(self):
        """
        Process the startup flags

        Arguments:
        - self: The main object pointer.
        """
   
        arguments = sys.argv[1:]
        if len(arguments) == 1:
            arguments = arguments[0].split()

        env.flags = dict((key[0], {"section" : sec}) for sec in self.cfg.sections() 
                                                    for key in self.cfg.items(sec))

        try:
            # ? for help
            # e for enable
            # d for disable
            # t for mouse tiemout
            opts, args = getopt.getopt(
                arguments,
                "?hve:d:s:",
                ["help",
                 "version",
                 "enable=",
                 "disable=",
                 "set="])

            for opt, val in opts:
               
                key = False

                # This will change the default video device input
                if opt in ("-s", "--set"):
                    key, value = val.strip().split("-")
                    
                if opt in ("-e", "--enable"):
                    key, value = [val.strip(), "True"]

                if opt in ("-d", "--disable"):
                    key, value = [val.strip(), "False"]

                if key in env.flags:
                    self.cfg.set(env.flags[key]["section"], key, value)
                elif key:
                    self.usage()
                    self.quit(2)
                         
                if opt in ("-v", "--version"):
                    print(env.version)
                    self.quit(0)
                    
                # This will show the usage of mouseTrap
                if opt in ("-?", "-h", "--help"):
                    self.usage()
                    self.quit(0)
                    
        except getopt.GetoptError, err:
            print str(err)
            self.usage()
            self.quit(2)
            pass
Esempio n. 5
0
class Controller():
    """
    MouseTrap's Controller Class
    """
    def __init__(self):
        """
        The MouseTrap controller init class

        Arguments:
        - self: The main object pointer.
        """

        # We don't want to load the settings each time we need them. do we?
        self.cfg = None

        self.loop = gobject.MainLoop()
        self.httpd = httpd.HttpdServer(20433)
        self.dbusd = dbusd.DbusServer()

    def start(self):
        """
        Starts the modules, views classes.

        Arguments:
        - self: The main object pointer.
        """

        if self.cfg is None:
            conf_created, self.cfg = settings.load()

        self.proc_args()

        if not self.dbusd.start():
            self.httpd.start()

        if self.cfg.getboolean("main", "startCam"):
            # Lets start the module
            idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
            self.idm = idm.Module(self)
            self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))

            gobject.timeout_add(150, self.update_frame)
            gobject.timeout_add(50, self.update_pointers)

            debug.info("mousetrap", "Idm loaded and started")

        # Lets build the interface
        self.itf = MainGui(self)
        self.itf.build_interface()
        self.itf.load_addons()

        if conf_created:
            from ui import settings_gui
            settings_gui.showPreffGui(self)

        debug.info("mousetrap", "MouseTrap's Interface Built and Loaded")

        gobject.threads_init()
        self.loop.run()

    def proc_args(self):
        """
        Process the startup flags

        Arguments:
        - self: The main object pointer.
        """

        arguments = sys.argv[1:]
        if len(arguments) == 1:
            arguments = arguments[0].split()

        env.flags = dict((key[0], {
            "section": sec
        }) for sec in self.cfg.sections() for key in self.cfg.items(sec))

        try:
            # ? for help
            # e for enable
            # d for disable
            # t for mouse tiemout
            opts, args = getopt.getopt(
                arguments, "?hve:d:s:",
                ["help", "version", "enable=", "disable=", "set="])

            for opt, val in opts:

                key = False

                # This will change the default video device input
                if opt in ("-s", "--set"):
                    key, value = val.strip().split("-")

                if opt in ("-e", "--enable"):
                    key, value = [val.strip(), "True"]

                if opt in ("-d", "--disable"):
                    key, value = [val.strip(), "False"]

                if key in env.flags:
                    self.cfg.set(env.flags[key]["section"], key, value)
                elif key:
                    self.usage()
                    self.quit(2)

                if opt in ("-v", "--version"):
                    print(env.version)
                    self.quit(0)

                # This will show the usage of mouseTrap
                if opt in ("-?", "-h", "--help"):
                    self.usage()
                    self.quit(0)

        except getopt.GetoptError, err:
            print str(err)
            self.usage()
            self.quit(2)
            pass