Python kivy.properties() Examples

The following are 8 code examples of kivy.properties(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kivy , or try the search function .
Example #1
Source File: recycleview.py    From garden.recycleview with MIT License 6 votes vote down vote up
def create_view(self, index, viewclass=None):
        """Creates and initializes the view for the data at `index`. The
        returned view is synced with the data, except for the pos/size
        properties.
        """
        if viewclass is None:
            viewclass = self.get_viewclass(index)
        if viewclass is None:
            return
        item = self[index]
        # FIXME: we could pass the data though the constructor, but that wont
        # work for kv-declared classes, and might lead the user to think it can
        # work for reloading as well.
        view = viewclass()
        if viewclass not in _view_base_cache:
            _view_base_cache[viewclass] = isinstance(view, RecycleViewMixin)

        if _view_base_cache[viewclass]:
            view.refresh_view_attrs(self.recycleview, item)
        else:
            for key, value in item.items():
                setattr(view, key, value)
        return view 
Example #2
Source File: backend_kivy.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def _init_toolbar(self):
        '''A Toolbar is created with an ActionBar widget in which buttons are
           added with a specific behavior given by a callback. The buttons
           properties are given by matplotlib.
        '''
        basedir = os.path.join(rcParams['datapath'], 'images')
        actionview = ActionView()
        actionprevious = ActionPrevious(title="Navigation", with_previous=False)
        actionoverflow = ActionOverflow()
        actionview.add_widget(actionprevious)
        actionview.add_widget(actionoverflow)
        actionview.use_separator = True
        self.actionbar.add_widget(actionview)
        id_group = uuid.uuid4()
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                actionview.add_widget(ActionSeparator())
                continue
            fname = os.path.join(basedir, image_file + '.png')
            if text in ['Pan', 'Zoom']:
                action_button = ActionToggleButton(text=text, icon=fname,
                                                   group=id_group)
            else:
                action_button = ActionButton(text=text, icon=fname)
            action_button.bind(on_press=getattr(self, callback))
            actionview.add_widget(action_button) 
Example #3
Source File: inspector.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def show_widget_info(self):
        self.content.clear_widgets()
        widget = self.widget
        treeview = self.treeview
        for node in list(treeview.iterate_all_nodes())[:]:
            node.widget_ref = None
            treeview.remove_node(node)
        if not widget:
            if self.at_bottom:
                Animation(top=60, t='out_quad', d=.3).start(self.layout)
            else:
                Animation(y=self.height - 60, t='out_quad', d=.3).start(
                    self.layout)
            self.widget_info = False
            return
        self.widget_info = True
        if self.at_bottom:
            Animation(top=250, t='out_quad', d=.3).start(self.layout)
        else:
            Animation(top=self.height, t='out_quad', d=.3).start(self.layout)
        for node in list(treeview.iterate_all_nodes())[:]:
            treeview.remove_node(node)

        keys = list(widget.properties().keys())
        keys.sort()
        node = None
        wk_widget = weakref.ref(widget)
        for key in keys:
            text = '%s' % key
            node = TreeViewProperty(text=text, key=key, widget_ref=wk_widget)
            node.bind(is_selected=self.show_property)
            try:
                widget.bind(**{key: partial(
                    self.update_node_content, weakref.ref(node))})
            except:
                pass
            treeview.add_node(node) 
Example #4
Source File: inspector.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def show_widget_info(self):
        self.content.clear_widgets()
        widget = self.widget
        treeview = self.treeview
        for node in list(treeview.iterate_all_nodes())[:]:
            node.widget_ref = None
            treeview.remove_node(node)
        if not widget:
            if self.at_bottom:
                Animation(top=60, t='out_quad', d=.3).start(self.layout)
            else:
                Animation(y=self.height - 60, t='out_quad', d=.3).start(
                    self.layout)
            self.widget_info = False
            return
        self.widget_info = True
        if self.at_bottom:
            Animation(top=250, t='out_quad', d=.3).start(self.layout)
        else:
            Animation(top=self.height, t='out_quad', d=.3).start(self.layout)
        for node in list(treeview.iterate_all_nodes())[:]:
            treeview.remove_node(node)

        keys = list(widget.properties().keys())
        keys.sort()
        node = None
        wk_widget = weakref.ref(widget)
        for key in keys:
            text = '%s' % key
            node = TreeViewProperty(text=text, key=key, widget_ref=wk_widget)
            node.bind(is_selected=self.show_property)
            try:
                widget.bind(**{key: partial(
                    self.update_node_content, weakref.ref(node))})
            except:
                pass
            treeview.add_node(node) 
Example #5
Source File: recycleview.py    From garden.recycleview with MIT License 5 votes vote down vote up
def get_views(self, i_start, i_end):
        '''Gets a 2-tuple of the new and old views for the current viewport.
        The new views are synced to the data except for the size/pos
        properties.
        The old views need to be removed from the layout, and the new views
        added.
        '''
        current_views = self.views
        visible_views = {}
        new_views = []
        dirty_views = self.dirty_views
        get_view = self.get_view
        make_view_dirty = self.make_view_dirty

        # iterate though the visible view
        # add them into the container if not already done
        for index in range(i_start, i_end + 1):
            view = get_view(index)
            if not view:
                continue

            visible_views[index] = view
            current_views.pop(index, None)
            new_views.append((view, index))

        # put all the hidden view as dirty views
        for index, view in current_views.items():
            make_view_dirty(view, index)
        # save the current visible views
        self.views = visible_views
        return new_views, current_views.values() 
Example #6
Source File: statusview.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        super(StatusLabel, self).__init__(**kwargs)
        self.shorten = False

# Simple extension of Kivy's TreeViewLabel so we can add on our own properties
# to it for easier view tracking 
Example #7
Source File: backend_kivy.py    From garden.matplotlib with MIT License 4 votes vote down vote up
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
        offsets, offsetTrans, facecolors, edgecolors,
        linewidths, linestyles, antialiaseds, urls,
        offset_position):
        '''Draws a collection of paths selecting drawing properties from
           the lists *facecolors*, *edgecolors*, *linewidths*,
           *linestyles* and *antialiaseds*. *offsets* is a list of
           offsets to apply to each of the paths. The offsets in
           *offsets* are first transformed by *offsetTrans* before being
           applied.  *offset_position* may be either "screen" or "data"
           depending on the space that the offsets are in.
        '''
        len_path = len(paths[0].vertices) if len(paths) > 0 else 0
        uses_per_path = self._iter_collection_uses_per_path(
            paths, all_transforms, offsets, facecolors, edgecolors)
        # check whether an optimization is needed by calculating the cost of
        # generating and use a path with the cost of emitting a path in-line.
        should_do_optimization = \
            len_path + uses_per_path + 5 < len_path * uses_per_path
        if not should_do_optimization:
            return RendererBase.draw_path_collection(
                self, gc, master_transform, paths, all_transforms,
                offsets, offsetTrans, facecolors, edgecolors,
                linewidths, linestyles, antialiaseds, urls,
                offset_position)
        # Generate an array of unique paths with the respective transformations
        path_codes = []
        for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
            master_transform, paths, all_transforms)):
            transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
            if _mpl_ge_2_0:
                polygons = path.to_polygons(transform, closed_only=False)
            else:
                polygons = path.to_polygons(transform)
            path_codes.append(polygons)
        # Apply the styles and rgbFace to each one of the raw paths from
        # the list. Additionally a transformation is being applied to
        # translate each independent path
        for xo, yo, path_poly, gc0, rgbFace in self._iter_collection(
            gc, master_transform, all_transforms, path_codes, offsets,
            offsetTrans, facecolors, edgecolors, linewidths, linestyles,
            antialiaseds, urls, offset_position):
            list_canvas_instruction = self.get_path_instructions(gc0, path_poly,
                                    closed=True, rgbFace=rgbFace)
            for widget, instructions in list_canvas_instruction:
                widget.canvas.add(PushMatrix())
                widget.canvas.add(Translate(xo, yo))
                widget.canvas.add(instructions)
                widget.canvas.add(PopMatrix()) 
Example #8
Source File: recycleview.py    From garden.recycleview with MIT License 4 votes vote down vote up
def get_view(self, index):
        """Returns a view instance for the data at `index`. It looks through
        the various caches and finally creates a view if it doesn't exist.
        The returned view is synced with the data, except for the pos/size
        properties.
        """
        if index in self.views:
            return self.views[index]

        dirty_views = self.dirty_views
        viewclass = self.get_viewclass(index)
        if viewclass is None:
            return
        rv = self.recycleview
        stale = False
        view = None

        if viewclass in dirty_views:
            dirty_class = dirty_views[viewclass]
            if index in dirty_class:
                # we found ourself in the dirty list, no need to update data!
                view = dirty_class.pop(index)
            elif _cached_views[viewclass]:
                # global cache has this class, update data
                view, stale = _cached_views[viewclass].pop(), True
            elif dirty_class:
                # random any dirty view element - update data
                view, stale = dirty_class.popitem()[1], True
        elif _cached_views[viewclass]:
            # global cache has this class, update data
            view, stale = _cached_views[viewclass].pop(), True

        if view is None:
            # create a fresh one
            view = self.create_view(index, viewclass)

        if stale is True:
            item = self[index]
            if viewclass not in _view_base_cache:
                _view_base_cache[viewclass] = isinstance(view,
                                                         RecycleViewMixin)

            if _view_base_cache[viewclass]:
                view.refresh_view_attrs(rv, item)
            else:
                for key, value in item.items():
                    setattr(view, key, value)

        self.views[index] = view
        return view