示例#1
0
 def store_find(self, filters):
     for key, values in iteritems(self._data):
         found = True
         for fkey, fvalue in iteritems(filters):
             if fkey not in values:
                 found = False
                 break
             if values[fkey] != fvalue:
                 found = False
                 break
         if found:
             yield key, values
示例#2
0
 def store_find(self, filters):
     for key, values in iteritems(self.data):
         found = True
         for fkey, fvalue in iteritems(filters):
             if fkey not in values:
                 found = False
                 break
             if values[fkey] != fvalue:
                 found = False
                 break
         if found:
             yield key, values
 def store_put(self, key, values):
     key = self.prefix + '.d.' + key
     pipe = self.r.pipeline()
     pipe.delete(key)
     for k, v in iteritems(values):
         pipe.hset(key, k, dumps(v))
     pipe.execute()
     return True
示例#4
0
    def switch_to(self, screen, **options):
        '''Add a new screen to the ScreenManager and switch to it. The previous
        screen will be removed from the children. `options` are the
        :data:`transition` options that will be changed before the animation
        happens.

        If no previous screens are available, the screen will be used as the
        main one::

            sm = ScreenManager()
            sm.switch_to(screen1)
            # later
            sm.switch_to(screen2, direction='left')
            # later
            sm.switch_to(screen3, direction='right', duration=1.)

        If any animation is in progress, it will be stopped and replaced by
        this one: you should avoid this because the animation will just look
        weird. Use either :meth:`switch` or :data:`current` but not both.

        The `screen` name will be changed if there is any conflict with the
        current screen.

        .. versionadded: 1.8.0
        '''
        assert (screen is not None)

        if not isinstance(screen, Screen):
            raise ScreenManagerException(
                'ScreenManager accepts only Screen widget.')

        # stop any transition that might be happening already
        self.transition.stop()

        # ensure the screen name will be unique
        if screen not in self.children:
            if self.has_screen(screen.name):
                screen.name = self._generate_screen_name()

        # change the transition options
        for key, value in iteritems(options):
            setattr(self.transition, key, value)

        # add and leave if we are set as the current screen
        self.add_widget(screen)
        if self.current_screen is screen:
            return

        old_current = self.current_screen

        def remove_old_screen(transition):
            if old_current in self.children:
                self.remove_widget(old_current)
            transition.unbind(on_complete=remove_old_screen)

        self.transition.bind(on_complete=remove_old_screen)

        self.current = screen.name
示例#5
0
    def load_string(self, string, **kwargs):
        '''Insert a string into the Language Builder and return the root widget
        (if defined) of the kv string.

        :Parameters:
            `rulesonly`: bool, defaults to False
                If True, the Builder will raise an exception if you have a root
                widget inside the definition.
        '''
        kwargs.setdefault('rulesonly', False)
        self._current_filename = fn = kwargs.get('filename', None)

        # put a warning if a file is loaded multiple times
        if fn in self.files:
            Logger.warning('Lang: The file {} is loaded multiples times, '
                           'you might have unwanted behaviors.'.format(fn))

        try:
            # parse the string
            parser = Parser(content=string, filename=fn)

            # merge rules with our rules
            self.rules.extend(parser.rules)
            self._clear_matchcache()

            # add the template found by the parser into ours
            for name, cls, template in parser.templates:
                self.templates[name] = (cls, template, fn)
                Factory.register(name,
                                 cls=partial(self.template, name),
                                 is_template=True,
                                 warn=True)

            # register all the dynamic classes
            for name, baseclasses in iteritems(parser.dynamic_classes):
                Factory.register(name,
                                 baseclasses=baseclasses,
                                 filename=fn,
                                 warn=True)

            # create root object is exist
            if kwargs['rulesonly'] and parser.root:
                filename = kwargs.get('rulesonly', '<string>')
                raise Exception('The file <%s> contain also non-rules '
                                'directives' % filename)

            # save the loaded files only if there is a root without
            # template/dynamic classes
            if fn and (parser.templates or parser.dynamic_classes
                       or parser.rules):
                self.files.append(fn)

            if parser.root:
                widget = Factory.get(parser.root.name)()
                self._apply_rule(widget, parser.root, parser.root)
                return widget
        finally:
            self._current_filename = None
示例#6
0
    def switch_to(self, screen, **options):
        '''Add a new screen in the ScreenManager, and switch to it. The previous
        screen will be removed from the children. `options` are the
        :data:`transition` options that will be changed before the animation
        happens.

        If no previous screens are available, it will just be used as the main
        one::

            sm = ScreenManager()
            sm.switch_to(screen1)
            # later
            sm.switch_to(screen2, direction='left')
            # later
            sm.switch_to(screen3, direction='right', duration=1.)

        If any animation is in progress, it will be stopped and replaced by
        this one: you should avoid it, because the animation will just look
        weird. Use either :meth:`switch` or :data:`current`, but not both.

        `screen` name will be changed if there is any conflict with the current
        screen.

        .. versionadded: 1.8.0
        '''
        assert(screen is not None)

        if not isinstance(screen, Screen):
            raise ScreenManagerException(
                    'ScreenManager accepts only Screen widget.')

        # stop any transition that might be happening already
        self.transition.stop()

        # ensure the screen name will be unique
        if screen not in self.children:
            if self.has_screen(screen.name):
                screen.name = self._generate_screen_name()

        # change the transition options
        for key, value in iteritems(options):
            setattr(self.transition, key, value)

        # add and leave if we are set as the current screen
        self.add_widget(screen)
        if self.current_screen is screen:
            return

        old_current = self.current_screen

        def remove_old_screen(transition):
            if old_current in self.children:
                self.remove_widget(old_current)
            transition.unbind(on_complete=remove_old_screen)
        self.transition.bind(on_complete=remove_old_screen)

        self.current = screen.name
示例#7
0
    def load_string(self, string, **kwargs):
        '''Insert a string into the Language Builder and return the root widget
        (if defined) of the kv string.

        :Parameters:
            `rulesonly`: bool, defaults to False
                If True, the Builder will raise an exception if you have a root
                widget inside the definition.
        '''
        kwargs.setdefault('rulesonly', False)
        self._current_filename = fn = kwargs.get('filename', None)

        # put a warning if a file is loaded multiple times
        if fn in self.files:
            Logger.warning(
                'Lang: The file {} is loaded multiples times, '
                'you might have unwanted behaviors.'.format(fn))

        try:
            # parse the string
            parser = Parser(content=string, filename=fn)

            # merge rules with our rules
            self.rules.extend(parser.rules)
            self._clear_matchcache()

            # add the template found by the parser into ours
            for name, cls, template in parser.templates:
                self.templates[name] = (cls, template, fn)
                Factory.register(name,
                                 cls=partial(self.template, name),
                                 is_template=True, warn=True)

            # register all the dynamic classes
            for name, baseclasses in iteritems(parser.dynamic_classes):
                Factory.register(name, baseclasses=baseclasses, filename=fn,
                                 warn=True)

            # create root object is exist
            if kwargs['rulesonly'] and parser.root:
                filename = kwargs.get('rulesonly', '<string>')
                raise Exception('The file <%s> contain also non-rules '
                                'directives' % filename)

            # save the loaded files only if there is a root without
            # template/dynamic classes
            if fn and (parser.templates or
                       parser.dynamic_classes or parser.rules):
                self.files.append(fn)

            if parser.root:
                widget = Factory.get(parser.root.name)()
                self._apply_rule(widget, parser.root, parser.root)
                return widget
        finally:
            self._current_filename = None
示例#8
0
 def match_rule(fn, index, rule):
     if rule.ctx.filename != fn:
         return
     for prop, prp in iteritems(rule.properties):
         if prp.line != index:
             continue
         yield prp
     for child in rule.children:
         for r in match_rule(fn, index, child):
             yield r
     if rule.canvas_root:
         for r in match_rule(fn, index, rule.canvas_root):
             yield r
     if rule.canvas_before:
         for r in match_rule(fn, index, rule.canvas_before):
             yield r
     if rule.canvas_after:
         for r in match_rule(fn, index, rule.canvas_after):
             yield r
示例#9
0
 def match_rule(fn, index, rule):
     if rule.ctx.filename != fn:
         return
     for prop, prp in iteritems(rule.properties):
         if prp.line != index:
             continue
         yield prp
     for child in rule.children:
         for r in match_rule(fn, index, child):
             yield r
     if rule.canvas_root:
         for r in match_rule(fn, index, rule.canvas_root):
             yield r
     if rule.canvas_before:
         for r in match_rule(fn, index, rule.canvas_before):
             yield r
     if rule.canvas_after:
         for r in match_rule(fn, index, rule.canvas_after):
             yield r
示例#10
0
def load_ast(self, ast, **kwargs):
	kwargs.setdefault('rulesonly', False)
	self._current_filename = fn = kwargs.get('filename', None)

	if fn in self.files:
		Logger.warning(
			'kvlang: The file {} is loaded multiple times, '
		    'you might have unwanted behaviors.'.format(fn))
	
	try:
		parser = ASTParser(ast=ast)
	
		self.rules.extend(parser.rules)
		self._clear_matchcache()
	
		for name, cls, template in parser.templates:
			self.templates[name] = (cls, template, fn)
			Factory.register(name, cls=partial(self.template, name), is_template=True)
	
		for name, baseclasses in iteritems(parser.dynamic_classes):
			Factory.register(name, baseclasses=baseclasses, filename=fn)
		
		if kwargs['rulesonly'] and parser.root:
			filename = kwargs.get('rulesonly', '<string>')
			raise Exception('The file <%s> contains also non-rules '
							'directives' % filename)
		
		if fn and (parser.templates or
				   parser.dynamic_classes or parser.rules):
			self.files.append(fn)
		
		if parser.root:
			widget = Factory.get(parser.root.name)()
			self._apply_rule(widget, parser.root, parser.root)
			return widget
	finally:
		self._current_filename = None
示例#11
0
    def load_string(self, string, **kwargs):
        '''Insert a string into the Language Builder and return the root widget
        (if defined) of the kv string.

        :Parameters:
            `rulesonly`: bool, defaults to False
                If True, the Builder will raise an exception if you have a root
                widget inside the definition.
            `filename`: str, defaults to None
                If specified, the filename used to index the kv rules.

        The filename parameter can be used to unload kv strings in the same way
        as you unload kv files. This can be achieved using pseudo file names
        e.g.::

            Build.load_string("""
                <MyRule>:
                    Label:
                        text="Hello"
            """, filename="myrule.kv")

        can be unloaded via::

            Build.unload_file("myrule.kv")

        '''

        kwargs.setdefault('rulesonly', False)
        self._current_filename = fn = kwargs.get('filename', None)

        # put a warning if a file is loaded multiple times
        if fn in self.files:
            Logger.warning('Lang: The file {} is loaded multiples times, '
                           'you might have unwanted behaviors.'.format(fn))

        try:
            # parse the string
            parser = Parser(content=string, filename=fn)

            # merge rules with our rules
            self.rules.extend(parser.rules)
            self._clear_matchcache()

            # add the template found by the parser into ours
            for name, cls, template in parser.templates:
                self.templates[name] = (cls, template, fn)
                Factory.register(name,
                                 cls=partial(self.template, name),
                                 is_template=True,
                                 warn=True)

            # register all the dynamic classes
            for name, baseclasses in iteritems(parser.dynamic_classes):
                Factory.register(name,
                                 baseclasses=baseclasses,
                                 filename=fn,
                                 warn=True)

            # create root object is exist
            if kwargs['rulesonly'] and parser.root:
                filename = kwargs.get('rulesonly', '<string>')
                raise Exception('The file <%s> contain also non-rules '
                                'directives' % filename)

            # save the loaded files only if there is a root without
            # template/dynamic classes
            if fn and (parser.templates or parser.dynamic_classes
                       or parser.rules):
                self.files.append(fn)

            if parser.root:
                widget = Factory.get(parser.root.name)(__no_builder=True)
                rule_children = []
                widget.apply_class_lang_rules(root=widget,
                                              rule_children=rule_children)
                self._apply_rule(widget,
                                 parser.root,
                                 parser.root,
                                 rule_children=rule_children)

                for child in rule_children:
                    child.dispatch('on_kv_post', widget)
                widget.dispatch('on_kv_post', widget)
                return widget
        finally:
            self._current_filename = None