当前位置: 首页>>代码示例>>Python>>正文


Python graphics.Canvas方法代码示例

本文整理汇总了Python中kivy.graphics.Canvas方法的典型用法代码示例。如果您正苦于以下问题:Python graphics.Canvas方法的具体用法?Python graphics.Canvas怎么用?Python graphics.Canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.graphics的用法示例。


在下文中一共展示了graphics.Canvas方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _highlight

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def _highlight(results):
    from kivy.graphics import Color, Rectangle, Canvas
    from kivy.core.window import Window
    if not hasattr(Window, "_telenium_canvas"):
        Window._telenium_canvas = Canvas()
    _canvas = Window._telenium_canvas

    Window.canvas.remove(_canvas)
    Window.canvas.add(_canvas)

    _canvas.clear()
    with _canvas:
        Color(1, 0, 0, 0.5)
        for widget, bounds in results:
            left, bottom, right, top = bounds
            Rectangle(pos=(left, bottom), size=(right-left, top-bottom)) 
开发者ID:tito,项目名称:telenium,代码行数:18,代码来源:telenium_client.py

示例2: build

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def build(self):
        radius = self.radius

        if not self.canvas_points:
            self.canvas_points = Canvas()
            self.canvas.add(self.canvas_points)
            with self.canvas_points:
                Color(1, 0, 0)
                for marker in points:
                    Rectangle(
                        pos=(marker.x * 600, marker.y * 600), size=(2, 2))

        self.canvas.before.clear()
        with self.canvas.before:
            if self.selection_center:
                Color(0, 1, 0, 0.5)
                x, y = self.selection_center
                r = radius * 600
                r2 = r * 2
                Ellipse(pos=(x - r, y - r), size=(r2, r2))

            if self.selection:
                Color(0, 0, 1)
                for m_id in self.selection:
                    # x = kdbush.coords[m_id * 2]
                    # y = kdbush.coords[m_id * 2 + 1]
                    marker = points[m_id]
                    x = marker.x
                    y = marker.y
                    Rectangle(pos=(x * 600 - 4, y * 600 - 4), size=(8, 8)) 
开发者ID:pythonindia,项目名称:PyCon-Mobile-App,代码行数:32,代码来源:test_kdbush.py

示例3: __init__

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def __init__(self, **kwargs):
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        self._invalid_scale = True
        self._tiles = []
        self._tiles_bg = []
        self._tilemap = {}
        self._layers = []
        self._default_marker_layer = None
        self._need_redraw_all = False
        self._transform_lock = False
        self.trigger_update(True)
        self.canvas = Canvas()
        self._scatter = MapViewScatter()
        self.add_widget(self._scatter)
        with self._scatter.canvas:
            self.canvas_map = Canvas()
            self.canvas_layers = Canvas()
        with self.canvas:
            self.canvas_layers_out = Canvas()
        self._scale_target_anim = False
        self._scale_target = 1.
        self._touch_count = 0
        self.map_source.cache_dir = self.cache_dir
        Clock.schedule_interval(self._animate_color, 1 / 60.)
        self.lat = kwargs.get("lat", self.lat)
        self.lon = kwargs.get("lon", self.lon)
        super(MapView, self).__init__(**kwargs) 
开发者ID:pythonindia,项目名称:PyCon-Mobile-App,代码行数:30,代码来源:view.py

示例4: __init__

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def __init__(self, **kwargs):
        self.canvas = Canvas()
        with self.canvas.before:
            Callback(self._set_blend_func)
        #self.size
        self.fbo_texture = Texture.create(size=self.size,
                                          colorfmt='rgba')

        self.fbo_texture.mag_filter = 'linear'
        self.fbo_texture.min_filter = 'linear'

        with self.canvas:
            #self.cbs = Callback(self.prepare_canvas)
           
            self.fbo = Fbo(size=self.size, texture=self.fbo_texture)
            #Color(0, 0, 0, 1)
            #self.fbo_rect = Rectangle(size=self.size)            


        with self.fbo:
            ClearColor(0.0, 0.0, 0.0, 1.0)
            ClearBuffers()
            self.fbo_rect = Rectangle(size=self.size)


        #self.fbo.shader.source = resource_find('./kivy3dgui/gles2.0/shaders/invert.glsl')
        #with self.fbo.after:
        #    self.cbr = Callback(self.reset_gl_context)
        #    PopMatrix()

        with self.canvas.before:
            Callback(self._set_blend_func)

        # wait that all the instructions are in the canvas to set texture

        self.texture = self.fbo.texture
        try:
            self.size = kwargs.pop("size")
            self.size_hint = kwargs.pop("size_hint")
            self.clear_color = kwargs.pop("clear_color")
            super(FboFloatLayout, self).__init__(**kwargs)
        except:
            print(kwargs) 
开发者ID:kpiorno,项目名称:kivy3dgui,代码行数:45,代码来源:fbowidget.py

示例5: __init__

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def __init__(self, **kwargs):
        # XXX move to style.kv
        kwargs.setdefault('size_hint', (None, None))
        kwargs.setdefault('scale_min', .4)
        kwargs.setdefault('scale_max', 1.6)
        kwargs.setdefault('size', (700, 200))
        kwargs.setdefault('docked', False)
        self._trigger_update_layout_mode = Clock.create_trigger(
            self._update_layout_mode)
        self._trigger_load_layouts = Clock.create_trigger(
            self._load_layouts)
        self._trigger_load_layout = Clock.create_trigger(
            self._load_layout)
        self.bind(
            docked=self.setup_mode,
            have_shift=self._trigger_update_layout_mode,
            have_capslock=self._trigger_update_layout_mode,
            have_special=self._trigger_update_layout_mode,
            layout_path=self._trigger_load_layouts,
            layout=self._trigger_load_layout)
        super(VKeyboard, self).__init__(**kwargs)

        # load all the layouts found in the layout_path directory
        self._load_layouts()

        # ensure we have default layouts
        available_layouts = self.available_layouts
        if not available_layouts:
            Logger.critical('VKeyboard: unable to load default layouts')

        # load the default layout from configuration
        if self.layout is None:
            self.layout = Config.get('kivy', 'keyboard_layout')
        else:
            # ensure the current layout is found on the available layout
            self._trigger_load_layout()

        # update layout mode (shift or normal)
        self._trigger_update_layout_mode()

        # create a top layer to draw active keys on
        with self.canvas:
            self.background_key_layer = Canvas()
            self.active_keys_layer = Canvas() 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:46,代码来源:vkeyboard.py

示例6: __init__

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def __init__(self, **kwargs):
        self._touch = None
        self._trigger_update_from_scroll = Clock.create_trigger(
            self.update_from_scroll, -1)
        # create a specific canvas for the viewport
        from kivy.graphics import PushMatrix, Translate, PopMatrix, Canvas
        self.canvas_viewport = Canvas()
        self.canvas = Canvas()
        with self.canvas_viewport.before:
            PushMatrix()
            self.g_translate = Translate(0, 0)
        with self.canvas_viewport.after:
            PopMatrix()

        super(ScrollView, self).__init__(**kwargs)

        self.register_event_type('on_scroll_start')
        self.register_event_type('on_scroll_move')
        self.register_event_type('on_scroll_stop')

        # now add the viewport canvas to our canvas
        self.canvas.add(self.canvas_viewport)

        effect_cls = self.effect_cls
        if isinstance(effect_cls, string_types):
            effect_cls = Factory.get(effect_cls)
        if self.effect_x is None and effect_cls is not None:
            self.effect_x = effect_cls(target_widget=self._viewport)
        if self.effect_y is None and effect_cls is not None:
            self.effect_y = effect_cls(target_widget=self._viewport)
        self.bind(
            width=self._update_effect_x_bounds,
            height=self._update_effect_y_bounds,
            viewport_size=self._update_effect_bounds,
            _viewport=self._update_effect_widget,
            scroll_x=self._trigger_update_from_scroll,
            scroll_y=self._trigger_update_from_scroll,
            pos=self._trigger_update_from_scroll,
            size=self._trigger_update_from_scroll)

        self._update_effect_widget()
        self._update_effect_x_bounds()
        self._update_effect_y_bounds() 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:45,代码来源:scrollview.py

示例7: create_window

# 需要导入模块: from kivy import graphics [as 别名]
# 或者: from kivy.graphics import Canvas [as 别名]
def create_window(self, *largs):
        '''Will create the main window and configure it.

        .. warning::
            This method is called automatically at runtime. If you call it, it
            will recreate a RenderContext and Canvas. This means you'll have a
            new graphics tree, and the old one will be unusable.

            This method exist to permit the creation of a new OpenGL context
            AFTER closing the first one. (Like using runTouchApp() and
            stopTouchApp()).

            This method has only been tested in a unittest environment and
            is not suitable for Applications.

            Again, don't use this method unless you know exactly what you are
            doing!
        '''
        # just to be sure, if the trigger is set, and if this method is
        # manually called, unset the trigger
        Clock.unschedule(self.create_window)

        # ensure the window creation will not be called twice
        if platform in ('android', 'ios'):
            self._unbind_create_window()

        if not self.initialized:
            from kivy.core.gl import init_gl
            init_gl()

            # create the render context and canvas, only the first time.
            from kivy.graphics import RenderContext, Canvas
            self.render_context = RenderContext()
            self.canvas = Canvas()
            self.render_context.add(self.canvas)

        else:
            # if we get initialized more than once, then reload opengl state
            # after the second time.
            # XXX check how it's working on embed platform.
            if platform == 'linux' or Window.__class__.__name__ == 'WindowSDL':
                # on linux, it's safe for just sending a resize.
                self.dispatch('on_resize', *self.system_size)

            else:
                # on other platform, window are recreated, we need to reload.
                from kivy.graphics.context import get_context
                get_context().reload()
                Clock.schedule_once(lambda x: self.canvas.ask_update(), 0)
                self.dispatch('on_resize', *self.system_size)

        # ensure the gl viewport is correct
        self.update_viewport() 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:55,代码来源:__init__.py


注:本文中的kivy.graphics.Canvas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。