Python controller 模块,Controller() 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用controller.Controller()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def render(self, request, doneCallback=None):
        if not getattr(request, 'currentId', 0):
            request.currentId = 0
        request.currentPage = self
        if self.controller is None:
            self.controller = controller.Controller(self.model)
        if doneCallback is not None:
            self.doneCallback = doneCallback
        else:
            self.doneCallback = doSendPage
        self.setupAllStacks()
        template = self.getTemplate(request)
        if template:
            self.d = microdom.parseString(template, caseInsensitive=0, preserveCase=0)
        else:
            if not self.templateFile:
                raise AttributeError, "%s does not define self.templateFile to operate on" % self.__class__
            self.d = self.lookupTemplate(request)
        request.d = self.d
        self.handleDocument(request, self.d)
        return NOT_DONE_YET
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def render(self, request, doneCallback=None):
        if not getattr(request, 'currentId', 0):
            request.currentId = 0
        request.currentPage = self
        if self.controller is None:
            self.controller = controller.Controller(self.model)
        if doneCallback is not None:
            self.doneCallback = doneCallback
        else:
            self.doneCallback = doSendPage
        self.setupAllStacks()
        template = self.getTemplate(request)
        if template:
            self.d = microdom.parseString(template, caseInsensitive=0, preserveCase=0)
        else:
            if not self.templateFile:
                raise AttributeError, "%s does not define self.templateFile to operate on" % self.__class__
            self.d = self.lookupTemplate(request)
        request.d = self.d
        self.handleDocument(request, self.d)
        return NOT_DONE_YET
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_spi(self, spi): 
        if spi:            
            new_spi = Controller.Mock()

            def transfer(pin_ss, address, value = 0x00):        
                response = bytearray(1)

                pin_ss.low()
                response.append(spi.xfer2([address, value])[1])                
                pin_ss.high()

                return response

            new_spi.transfer = transfer
            new_spi.close = spi.close         
            return new_spi
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_spi(self, spi): 
        if spi:
            new_spi = Controller.Mock()  

            def transfer(pin_ss, address, value = 0x00):        
                response = bytearray(1)

                pin_ss.low()

                spi.write(bytes([address]))
                spi.write_readinto(bytes([value]), response)

                pin_ss.high()

                return response

            new_spi.transfer = transfer
            new_spi.close = spi.deinit            
            return new_spi
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_spi(self, spi): 
        if spi:
            new_spi = Controller.Mock()  

            def transfer(pin_ss, address, value = 0x00):        
                response = bytearray(1)

                pin_ss.low()

                spi.write(bytes([address]))
                spi.write_readinto(bytes([value]), response)

                pin_ss.high()

                return response

            new_spi.transfer = transfer
            new_spi.close = spi.deinit            
            return new_spi
项目:pelisalacarta-ce    作者:pelisalacarta-ce    | 项目源码 | 文件源码
def load_controllers():
    controllers=[]
    path=os.path.split(__file__)[0]
    for fname in os.listdir(path):
        mod,ext=os.path.splitext(fname)
        fname=os.path.join(path,fname)
        if os.path.isfile(fname) and ext=='.py' and not mod.startswith('_'):
            try:
              exec "import "+ mod + " as controller"
            except:
              import traceback
              logger.error(traceback.format_exc())

            for c in dir(controller):
                cls=getattr(controller, c);

                if not c.startswith('_') and isclass(cls) and issubclass(cls, Controller) and Controller != cls:
                    controllers.append(cls)
    return controllers
项目:Weather-App    作者:Tomasz-Kluczkowski    | 项目源码 | 文件源码
def begin_get_report(self):
        """Begin getting data for the weather report to display it on 
        the main_canvas.
        The call goes to the Controller first. Then to the Model.

        Returns:
            None
        """
        # Do nothing if no location is entered or an active sub thread
        # is running.
        if (self.v_link["var_loc"].get() == "") \
                or (threading.active_count() > 1):
            return
        # Clear any error status message.
        self.v_link["error_message"] = ""
        self.v_link["var_status"].set("Gathering data, please wait...")
        # Request a report using a Mediating Controller in a new thread.
        report_thread = threading.Thread(target=self.controller.get_report)
        report_thread.start()
项目:addon    作者:alfa-addon    | 项目源码 | 文件源码
def load_controllers():
    controllers = []
    path = os.path.split(__file__)[0]
    for fname in os.listdir(path):
        mod, ext = os.path.splitext(fname)
        fname = os.path.join(path, fname)
        if os.path.isfile(fname) and ext == '.py' and not mod.startswith('_'):
            try:
                exec "import " + mod + " as controller"
            except:
                import traceback
                logger.error(traceback.format_exc())

            for c in dir(controller):
                cls = getattr(controller, c)

                if not c.startswith('_') and isclass(cls) and issubclass(cls, Controller) and Controller != cls:
                    controllers.append(cls)
    return controllers
项目:dist_hyperas    作者:osh    | 项目源码 | 文件源码
def __init__(self, fn):
        self.cfg = json.load(open("target.json"))
        pprint.pprint(self.cfg)

        self.tasks = {
            "active":{},
            "finished":{}
            }
        self.devices = {}

        # launch proceses and go into event loop
        controller.Controller.__init__(self, self.cfg, dh_worker.Worker, self.cfg["devices"])
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_pin(self, pin_id, in_out = GPIO.OUT):
        if pin_id is not None:
            GPIO.setup(pin_id, in_out) 
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id

            if in_out == GPIO.OUT:
                new_pin.low = lambda : GPIO.output(pin_id, GPIO.LOW)
                new_pin.high = lambda : GPIO.output(pin_id, GPIO.HIGH)
            else:
                new_pin.value = lambda : GPIO.input(pin_id)

            return new_pin
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_pin(self, pin_id, in_out = Pin.OUT):
        if pin_id is not None:
            pin = Pin(pin_id, in_out)
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id
            new_pin.value = pin.value

            if in_out == Pin.OUT:
                new_pin.low = lambda : pin.value(0)
                new_pin.high = lambda : pin.value(1)        
            else:
                new_pin.irq = pin.irq 

            return new_pin
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_pin(self, pin_id, in_out = GPIO.OUT):
        if pin_id is not None:
            GPIO.setup(pin_id, in_out) 
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id

            if in_out == GPIO.OUT:
                new_pin.low = lambda : GPIO.output(pin_id, GPIO.LOW)
                new_pin.high = lambda : GPIO.output(pin_id, GPIO.HIGH)
            else:
                new_pin.value = lambda : GPIO.input(pin_id)

            return new_pin
项目:SX127x_driver_for_MicroPython_on_ESP8266    作者:Wei1234c    | 项目源码 | 文件源码
def prepare_pin(self, pin_id, in_out = Pin.OUT):
        if pin_id is not None:
            pin = Pin(pin_id, in_out)
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id
            new_pin.value = pin.value

            if in_out == Pin.OUT:
                new_pin.low = lambda : pin.value(0)
                new_pin.high = lambda : pin.value(1)        
            else:
                new_pin.irq = pin.irq 

            return new_pin
项目:bibtex_diff_checker    作者:mziauddin    | 项目源码 | 文件源码
def call_controller(self):
        """Create the controller instance """
        self.controller = controller.Controller(self)
项目:bibtex_diff_checker    作者:mziauddin    | 项目源码 | 文件源码
def call_controller(self):
        """Create the controller instance """
        self.controller = controller.Controller(self)
项目:bibtex_diff_checker    作者:mziauddin    | 项目源码 | 文件源码
def call_controller(self):
        """Create the controller instance """
        self.controller = controller.Controller(self)
项目:Weather-App    作者:Tomasz-Kluczkowski    | 项目源码 | 文件源码
def __init__(self, master, controller, tip, cnf, **args):
        """Initialise MyButton.

        Args:
            master (tk.widget): Master widget to which MyButton (slave) 
                instance will belong. The master widget is part of 
                the WeatherApp object.
            controller (Controller): controller object which will store 
                all the data required by each segment of the 
                application.
            tip (str): Tooltip text to display in the status_bar_label.
            cnf (dict): Dictionary with the configuration for MyButton.
            **args: Keyword arguments to further initialise the button.

        :Attributes:
        :system (str): Platform on which application is run.
        :cur_bg (str): Current background color of the button.
        :tip (str): Text to display in the status_bar_label of the app.
        :controller (Controller): controller object which will store all
            the data required by each segment of the application. 
            This has to be the same Controller as for the WeatherApp.
        :v_link (dict): Link to access variables in controller.
        """
        super().__init__(master, cnf, **args)
        self.system = platform.system()
        self.cur_bg = self["bg"]
        self.controller = controller
        self.v_link = self.controller.app_data
        self.tip = tip
        # Action on entering the button with mouse.
        self.bind("<Enter>", lambda e: self.enter_button())
        # Action on leaving the button with mouse.
        self.bind("<Leave>", lambda e: self.leave_button())
项目:Weather-App    作者:Tomasz-Kluczkowski    | 项目源码 | 文件源码
def app():
    """Create WeatherApp and Controller objects."""
    _app = WeatherApp()
    controller = Controller()
    _app.controller = controller
    return _app
项目:Weather-App    作者:Tomasz-Kluczkowski    | 项目源码 | 文件源码
def app():
    """Create WeatherApp and Controller objects."""
    _app = WeatherApp()
    controller = Controller()
    _app.controller = controller
    return _app
项目:pylemanager    作者:lucasmenendez    | 项目源码 | 文件源码
def __init__(self, master = None):
        self.controller     = controller.Controller()
        self.current_dir    = path.expanduser(self.current_dir)

        if master is None:
            master = tk.Tk()
            master.geometry("400x400")

        tk.Frame.__init__(self, master)
        self.pack(fill=tk.BOTH, expand=True) 
        self.master.bind("<Button-1>", self.closeContextMenu)
        self.createWidgets()

        self.master.title(self.current_dir + " - Pylemanager")
        self.master.mainloop()
项目:anchore    作者:anchore    | 项目源码 | 文件源码
def run(self):
        self._logger.debug("main image analysis on images: " + str(self.images) + ": begin")
        # analyze image and all of its family members
        success = True
        toanalyze = OrderedDict()

        # calculate all images to be analyzed
        for imageId in self.images:
            coreimage = self.allimages[imageId]
            toanalyze.update(self.selection_strategy.evaluate_familytree(coreimage.anchore_familytree, self.allimages))

        # execute analyzers
        self._logger.debug("images to be analyzed: " + str(toanalyze.keys()))
        for imageId in toanalyze.keys():
            image = toanalyze[imageId]
            success = self.run_analyzers(image)

            if not success:
                self._logger.error("analyzer failed to run on image " + str(image.meta['imagename']) + ", skipping the rest")
                break

        if not success:
            self._logger.error("analyzers failed to run on one or more images.")
            return (False)

        #if not self.skipgates:
        #    # execute gates
        #    self._logger.debug("running gates post-analysis: begin")
        #    for imageId in toanalyze.keys():
        #        c = controller.Controller(anchore_config=self.config, imagelist=[imageId], allimages=self.allimages).run_gates(refresh=True)
        #    self._logger.debug("running gates post-analysis: end")

        self._logger.debug("main image analysis on images: " + str(self.images) + ": end")
        return (success)
项目:cu-perception-manipulation-stack    作者:correlllab    | 项目源码 | 文件源码
def main(limb_name, reset):
    """
    Parameters
    ----------
    limb : str
        Which limb to use. Choices are {'left', 'right'}
    reset : bool
        Whether to use previously saved picking and placing poses or
        to save new ones by using 0g mode and the OK cuff buttons.
    """
    # Initialise ros node
    rospy.init_node("pick_and_place", anonymous=False)
    #pick_pose = []
    #place_pose = []
    #for ii in range(3):
    if reset or not rospy.has_param('~pick_and_place_poses'):
        rospy.loginfo(
            'Saving picking pose for %s limb' % limb_name)
        pick_pose = limb_pose(limb_name)
        rospy.sleep(1)
        place_pose = limb_pose(limb_name)
        rospy.set_param('~pick_and_place_poses',
                        {'pick': pick_pose.tolist(),
                         'place': place_pose.tolist()})
        #rospy.loginfo('pick_pose is %s' % pick_pose)
        #rospy.loginfo('place_pose is %s' % place_pose)
    else:
        pick_pose = rospy.get_param('~pick_and_place_poses/pick')
        place_pose =  rospy.get_param('~pick_and_place_poses/place')

    b = Baxter(limb_name)

    c1 = Controller()

    f = FilterValues()
    f.start_recording()
    #for ii in range(3):
    b.pick(pick_pose, controller=c1)
    b.place(place_pose)

    c1.save_centeringerr()

    f.stop_recording()
    f.convertandsave() #convert to numpy and save the recoreded data
    f.filter()
    f.plot()
项目:cu-perception-manipulation-stack    作者:correlllab    | 项目源码 | 文件源码
def main(limb_name, reset):
    """
    Parameters
    ----------
    limb : str
        Which limb to use. Choices are {'left', 'right'}
    reset : bool
        Whether to use previously saved picking and placing poses or
        to save new ones by using 0g mode and the OK cuff buttons.
    """
    # Initialise ros node
    rospy.init_node("pick_and_place", anonymous=False)

    # Either load picking and placing poses from the parameter server
    # or save them using the 0g mode and the circular buttons on
    # baxter's cuffs
    if reset or not rospy.has_param('~pick_and_place_poses'):
        rospy.loginfo(
            'Saving picking pose for %s limb' % limb_name)
        pick_pose = limb_pose(limb_name)
        rospy.sleep(1)
        place_pose = limb_pose(limb_name)
        # Parameter server can't store numpy arrays, so make sure
        # they're lists of Python floats (specifically not
        # numpy.float64's). I feel that's a bug in rospy.set_param.
        rospy.set_param('~pick_and_place_poses',
                        {'pick': pick_pose.tolist(),
                         'place': place_pose.tolist()})
        #rospy.loginfo('pick_pose is %s' % pick_pose)
        #rospy.loginfo('place_pose is %s' % place_pose)
    else:
        pick_pose = rospy.get_param('~pick_and_place_poses/pick')
        place_pose = rospy.get_param('~pick_and_place_poses/place')

    b = Baxter(limb_name)

    c = Controller()
    c1 = Controller_1()
    c2 = Controller_2()
    #f = FilterValues()
    #f.start_recording()
    for i in range(20):
        print ('this iss the intial pick pose')
        pick_pose[1]= 0.25286245 #change this for every new exp
        print (pick_pose)
        #pick_pose[1] = 0.30986200091872873
        pick_pose[1] += random.uniform(-1,1)*0.00 ##introduce error in endposition (y axis)
        print ('ERROR introduced the intial pick pose')
        print (pick_pose)
        b.pick(pick_pose, controller=c, controller_1=None, controller_2 = c2)
        b.place(place_pose)
    #f.stop_recording()
    #f.filter()
    #f.plot()
    rospy.spin()
项目:Weather-App    作者:Tomasz-Kluczkowski    | 项目源码 | 文件源码
def __init__(self):
        """Initializes WeatherApp class.

        :Attributes:
        :system (str): Platform on which application is run.
        :controller (Controller): Controller class object used for
            passing data between the View (weather_gui) and the Model
            (weather_backend).
        :v_link (dict): Link to access variables in controller.
        :paper (str): color definition in hex number.
        :title (str): Main window title displayed when using
            application.
        :displays (dict) dictionary storing all displays.
        """
        super().__init__()

        self.system = platform.system()
        # Add Controller to the WeatherApp class instance.
        controller = Controller()
        self.controller = controller
        self.v_link = self.controller.app_data
        # Add main application instance as a View to the Controller.
        self.controller.add_view(self)

        # Create a Report object for backend operations.
        report = Report(self.controller)
        # Add it as a Model to the Controller class object.
        self.controller.add_model(report)

        # Configure main window.
        self.paper = "#D5D5D5"
        self.title("The Weather App")
        self.config(bg=self.paper, bd=2, relief="flat")
        # Prevent resizing.
        self.resizable(width=tk.FALSE, height=tk.FALSE)

        # Create set of displays.
        self.displays = {}
        """:type : dict[str, DisplayShort]"""
        keys = ["title", "metric", "imperial"]
        for key in keys:
            self.displays[key] = DisplayShort(self, controller)
            self.displays[key].grid(row=0, column=0, sticky=tk.NSEW)
        self.update_buttons()
        self.update_geometry()

        # Application icon. Linux does not display it at all.
        if self.system == "Windows":

            self.iconbitmap("Data/Icons/app_icon/app_icon48x48.ico")
        # img_icon = ImageTk.PhotoImage(file="app_icon48x48.ico")
        # self.tk.call("wm", "iconphoto", self._w, img_icon)
        self.show_display("title")
        self.displays["title"].loc_combobox.focus()