KIVY Canvas¶

Canvas¶

Jump to API ⇓

Module: kivy.graphics.instructions

Added in 1.0.0

The Canvas is the root object used for drawing by a Widget. Check the class documentation for more information about the usage of Canvas.
画布是一个 基类对象 被用来以一个组件的方式画画。 检查  类文档来获取canvas画画使用的更多信息

APIHide Description ⇑

class kivy.graphics.instructions.Callback(callback=None**kwargs

Bases: kivy.graphics.instructions.Instruction

A Callback is an instruction that will be called when the drawing operation is performed. When adding instructions to a canvas, you can do this:
一个回收信号,这是一个将当画画操作被执行时一个回收信号被召唤用法说明。  当添加用法说明到一个画布时,  你可以这么做:

with self.canvas:Color(1, 1, 1)Rectangle(pos=self.pos, size=self.size)Callback(self.my_callback)

The definition of the callback must be:

def my_callback(self, instr):print('I have been called!')

Warning

Note that if you perform many and/or costly calls to callbacks, you might potentially slow down the rendering performance significantly.
注意 如果你执行许多 并行 /或者单行  占运行的召唤到回收信号里, 你可能潜在地降低了渲染执行效率。

The updating of your canvas does not occur until something new happens. From your callback, you can ask for an update:
更新你的画布 并不出现 知道某个玩意新发生时。  从你的回调里你可以寻求一个更新:

with self.canvas:self.cb = Callback(self.my_callback)
# then later in the code
self.cb.ask_update()

If you use the Callback class to call rendering methods of another toolkit, you will have issues with the OpenGL context. The OpenGL state may have been manipulated by the other toolkit, and as soon as program flow returns to Kivy, it will just break. You can have glitches, crashes, black holes might occur, etc. To avoid that, you can activate the reset_context option. It will reset the OpenGL context state to make Kivy’s rendering correct after the call to your callback.
如果你使用回调类来召唤渲染其他的工具箱方法, 你将有些问题伴随着OpenGL 内容。 OpenGL 的状态可以被其他的工具包操控, 并且项目一传播信号返回给Kivy,就会break。  你可以有一些小故障、猛撞、黑洞可能会出现等等。 为了避免那些, 你可以激活reset_context 选项。 它将设置重新设置OpenGL 内容状态来 确保Kivy渲染正确地在召唤你地回调信号之后。

Warning

The reset_context is not a full OpenGL reset. If you have issues regarding that, please contact us.
reset_context 不是一个完整的OpenGL 重新设定。 如果你有一些问题关于那, 请联系我们。

ask_update(self

Inform the parent canvas that we’d like it to update on the next frame. This is useful when you need to trigger a redraw due to some value having changed for example.
通知父类画布我们想来更新下副画。 这是有用的当你需要引用一个重新绘画因为一些值被改变了。

New in version 1.0.4.

callback¶

Property for getting/setting func.
属性来获取/设定 功能。

reset_context¶

Set this to True if you want to reset the OpenGL context for Kivy after the callback has been called.
设置这到True 如果你想来重新设定OpenGL 内容为了Kivy在回调信号被接收后。

class kivy.graphics.instructions.Canvas(**kwargs

Bases: kivy.graphics.instructions.CanvasBase

instructions that you want to be used for drawing.

Note

The Canvas supports Python’s with statement and its enter & exit semantics.

Usage of a canvas without the with statement:

self.canvas.add(Color(1., 1., 0))
self.canvas.add(Rectangle(size=(50, 50)))

Usage of a canvas with Python’s with statement:

with self.canvas:Color(1., 1., 0)Rectangle(size=(50, 50))

add(selfInstruction c

Append an Instruction to our list. If the canvas contains an after group, then this instruction is inserted just before the after group, which remains last. This is different from how insert() works, which can insert anywhere.

after¶

Property for getting the ‘after’ group.

ask_update(self

Inform the canvas that we’d like it to update on the next frame. This is useful when you need to trigger a redraw due to some value having changed for example.

before¶

Property for getting the ‘before’ group.

clear(self

Clears every Instruction in the canvas, leaving it clean.

draw(self

Apply the instruction to our window.

has_after¶

Property to see if the after group has already been created.

New in version 1.7.0.

has_before¶

Property to see if the before group has already been created.

New in version 1.7.0.

opacity¶

Property to get/set the opacity value of the canvas.

New in version 1.4.1.

The opacity attribute controls the opacity of the canvas and its children. Be careful, it’s a cumulative attribute: the value is multiplied to the current global opacity and the result is applied to the current context color.

For example: if your parent has an opacity of 0.5 and a child has an opacity of 0.2, the real opacity of the child will be 0.5 * 0.2 = 0.1.

Then, the opacity is applied on the shader as:

frag_color = color * vec4(1.0, 1.0, 1.0, opacity);

remove(selfInstruction c

class kivy.graphics.instructions.CanvasBase¶

Bases: kivy.graphics.instructions.InstructionGroup

CanvasBase provides the context manager methods for the Canvas.

class kivy.graphics.instructions.ContextInstruction(**kwargs

Bases: kivy.graphics.instructions.Instruction

that don’t have a direct visual representation, but instead modify the current Canvas’ state, e.g. texture binding, setting color parameters, matrix manipulation and so on.

class kivy.graphics.instructions.Instruction(**kwargs

Bases: kivy.event.ObjectWithUid

usage only, don’t use it directly.

flag_data_update(self

flag_update(selfint do_parent=1

group¶

group: unicode

proxy_ref¶

Return a proxy reference to the Instruction i.e. without creating a reference of the widget. See weakref.proxy for more information.

New in version 1.7.2.

class kivy.graphics.instructions.InstructionGroup(**kwargs

Bases: kivy.graphics.instructions.Instruction

of graphics instructions. It can be used directly as follows:

blue = InstructionGroup() blue.add(Color(0, 0, 1, 0.2)) blue.add(Rectangle(pos=self.pos, size=(100, 100)))

green = InstructionGroup() green.add(Color(0, 1, 0, 0.4)) green.add(Rectangle(pos=(100, 100), size=(100, 100)))

# Here, self should be a Widget or subclass [self.canvas.add(group) for group in [blue, green]]

add(selfInstruction c

Add a new Instruction to our list.

children¶

children: list

clear(self

Remove all the Instructions.

get_group(selfunicode groupname

Return an iterable for all the Instructions with a specific group name.

indexof(selfInstruction c

insert(selfint indexInstruction c

Insert a new Instruction into our list at index.

length(self

remove(selfInstruction c

Remove an existing Instruction from our list.

remove_group(selfunicode groupname

Remove all Instructions with a specific group name.

class kivy.graphics.instructions.RenderContext(*args**kwargs

Bases: kivy.graphics.instructions.Canvas

  • The vertex shader

  • The fragment shader

  • The default texture

  • The state stack (color, texture, matrix…)

shader¶

Return the shader attached to the render context.

use_parent_frag_modelview¶

If True, the parent fragment modelview matrix will be used.

New in version 1.10.1: rc = RenderContext(use_parent_frag_modelview=True)

use_parent_modelview¶

If True, the parent modelview matrix will be used.

New in version 1.7.0.

Before:

rc['modelview_mat'] = Window.render_context['modelview_mat']

Now:

rc = RenderContext(use_parent_modelview=True)

use_parent_projection¶

If True, the parent projection matrix will be used.

New in version 1.7.0.

Before:

rc['projection_mat'] = Window.render_context['projection_mat']

Now:

rc = RenderContext(use_parent_projection=True)

class kivy.graphics.instructions.VertexInstruction(**kwargs

Bases: kivy.graphics.instructions.Instruction

that have a direct visual representation on the canvas, such as Rectangles, Triangles, Lines, Ellipse and so on.

source¶

This property represents the filename to load the texture from. If you want to use an image as source, do it like this:

with self.canvas:Rectangle(source='mylogo.png', pos=self.pos, size=self.size)

Here’s the equivalent in Kivy language:

<MyWidget>:canvas:Rectangle:source: 'mylogo.png'pos: self.possize: self.size

Note

The filename will be searched for using the kivy.resources.resource_find() function.

tex_coords¶

This property represents the texture coordinates used for drawing the vertex instruction. The value must be a list of 8 values.

A texture coordinate has a position (u, v), and a size (w, h). The size can be negative, and would represent the ‘flipped’ texture. By default, the tex_coords are:

[u, v, u + w, v, u + w, v + h, u, v + h]

You can pass your own texture coordinates if you want to achieve fancy effects.

Warning

The default values just mentioned can be negative. Depending on the image and label providers, the coordinates are flipped vertically because of the order in which the image is internally stored. Instead of flipping the image data, we are just flipping the texture coordinates to be faster.

texture¶

Property that represents the texture used for drawing this Instruction. You can set a new texture like this:

from kivy.core.image import Imagetexture = Image('logo.png').texture
with self.canvas:Rectangle(texture=texture, pos=self.pos, size=self.size)

Usually, you will use the source attribute instead of the texture.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/26308.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

3. 打造个性化可爱怪物表情包:详细步骤教学

表情符号已经成为当今互联网对话中不可或缺的元素&#xff0c;一句话加上一个笑脸符号&#xff0c;语气就大不同。表情符号与我们一道稳步发展&#xff0c;成为鲜活和丰富情感的必要交流工具。通过表情符号&#xff0c;几个像素就能以有趣、清晰、能引起情感共鸣的方式表达我们…

【Python入门与进阶】Python对列表进行排序

在Python中&#xff0c;列表&#xff08;list&#xff09;是一种常用的数据结构&#xff0c;用于存储一系列有序的元素。有多种方法可以对列表进行排序&#xff1a; 使用 sort() 方法&#xff1a; sort() 是列表的一个内建方法&#xff0c;它会在原列表上进行排序&#xff0c;不…

Linux系统编程——进程间通信(管道与共享内存)

目录 一&#xff0c;进程间通信预备 二&#xff0c;匿名管道 2.1 管道原理 2.2 匿名管道原理 2.3 pidof工具 ​编辑 2.4 pipe() 2.6 管道的四种情况 2.8 进程池 三&#xff0c;命名管道 3.1 关于命名管道 3.2 mkfifo命令创建命名管道 3.3 mkfifo系统接口创建命名管…

你好,Jetpack Compose

文章目录 为什么选 Jetpack Compose先决条件新建项目新建虚拟设备运行项目 为什么选 Jetpack Compose Jetpack Compose 是 Android 开发最新的、现代化的 UI 框架开发者几乎只需要使用 Kotlin 一门语言即可完成 App 开发&#xff08;Java 是基础&#xff0c;有些源码是 Java 写…

JS :深拷贝解析与实现(附structuredClone语法测试)

浅拷贝简介 深拷贝是创建一个新对象&#xff0c;这个新对象包含原对象所有属性的全新拷贝&#xff0c;无论是基本数据类型还是引用类型的数据都会被完全复制一份&#xff0c;新旧对象间不存在任何关联&#xff0c;彼此独立。 前言 OK&#xff0c;最近又又又在学习JS的过程中…

SwiftUI六组合复杂用户界面

代码下载 应用的首页是一个纵向滚动的地标类别列表&#xff0c;每一个类别内部是一个横向滑动列表。随后将构建应用的页面导航&#xff0c;这个过程中可以学习到如果组合各种视图&#xff0c;并让它们适配不同的设备尺寸和设备方向。 下载起步项目并跟着本篇教程一步步实践&a…

69. UE5 RPG 使用Gameplay Cue 实现技能表现效果

在上一章中&#xff0c;我们实现了敌人的攻击技能的特效和音效。如果我们在多人模式下打开&#xff0c;发现&#xff0c;其它客户端看不到对应的效果。 造成这种问题的原因是因为敌人的技能是运行在服务器端的&#xff0c;它只复制到拥有它的客户端&#xff0c;而敌人的效果对于…

30、 shell脚本进阶

shell脚本ifcase 一、条件测试 1.1、条件测试&#xff1a;$?----返回码&#xff0c;判断命令或者脚本是否执行成功&#xff08;最近的一条&#xff09; 0 true 为真就是成功 成立 非0 false 失败或者异常。 二、test命令 test命令&#xff1a;可以进行条件测试&#xff…

Python内存管理与垃圾回收机制

目录 一、引言 二、Python内存管理概述 三、引用计数机制 四、垃圾回收机制 标记-清除&#xff08;Mark-and-Sweep&#xff09; 分代收集&#xff08;Generational Collection&#xff09; 五、内存泄漏与优化 六、总结 一、引言 Python作为一门高级编程语言&#xff…

Wells Fargo 借助 MongoDB 推出下一代银行卡支付

MongoDB客户案例导读 MongoDB以其灵活的数据模型、高性能的实时分析能力和可扩展的分布式架构&#xff0c;帮助Wells Fargo富国银行显著提升了数据处理效率和业务响应速度&#xff0c;为其大型机现代化和数字化转型提供了强有力的技术支撑。 金融服务市场正在经历一场变革&am…

像备份Windows一样简单的ghost软件!

数据的安全性对于个人用户和企业来说都至关重要。尤其是运行着重要服务的Linux系统,一旦遇到系统崩溃或硬件故障,如果没有及时的备份,可能会导致不可估量的损失。这时,一款强大而易用的备份还原工具就显得尤为重要。G4L(Ghost for Linux)就是这样一款专为Linux系统设计的…

2024年数字技术与智慧教育国际会议(DTSE 2024,7月26-28)

2024年数字技术与智慧教育国际会议&#xff08;DTSE 2024&#xff09;将于2024年7月26日在广东省广州市召开&#xff0c;本次会议专注于“数字技术与智慧教育”领域&#xff0c; 将汇集全球范围内的学者、研究人员以及教育技术开发者&#xff0c;共同探索和分享该领域内的最新学…

实验12 路由重分布

实验12 路由重分布 一、 原理描述二、 实验目的三、 实验内容四、 实验配置五、 实验步骤 一、 原理描述 在大型网络的组建过程中&#xff0c;隶属不同机构的网络部分往往会根据自身的实际情况来选用路由协议。例如&#xff0c;有些网络规模很小&#xff0c;为了管理简单&…

Java数据结构与算法(盛水的容器贪心算法)

前言 . - 力扣(LeetCode) 贪心算法(Greedy Algorithm)是一种在每一步选择中都采取当前状态下最优或最佳的选择,以期望通过一系列的局部最优选择达到全局最优解的算法。贪心算法的核心思想是贪心选择性质和最优子结构性质。 贪心算法的基本步骤 建立模型:将问题分解为一…

比特币私钥公钥地址生成

比特币私钥公钥地址生成算法 原理 实现 #!coding:utf8#author:yqq #date:2019/3/4 0004 14:35 #description: 比特币地址生成算法import hashlib import ecdsa import os#2019-05-15 添加私钥限制范围 g_b58 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz#g…

Linux Radix tree简介

文章目录 前言一、Radix tree简介二、Operations2.1 Lookup2.2 Insertion2.3 Deletion 三、Linux内核API3.1 初始化3.2 radix_tree_insert/delete3.3 radix_tree_preload3.4 radix_tree_lookup3.5 radix_tree_tag_set3.6 radix_tree_tagged 四、address_space4.1 简介4.2 相应数…

rinetd端口转发工具查询

公司一服务器&#xff0c;端口7003映射到该服务器的7003端口&#xff0c;公网链接可以访问到tomcat服务器&#xff0c;但是该服务器没有tomcat应用。 该服务器可能做了端口转发。 通过命令&#xff1a;lsof -i :7003 查看command 一列发现是rinetd。遂了解Rinetd为端口转发工…

使用Arrays.asList 报错Nullpointerexception 需要提前对参数进行判空

//为什么这样的时候会报空指针异常**Arrays.asList 这里这个方法中的参数为空**String[] checkedResourceNos1 dto.getCheckedResourceNos();List<String> checkedResourceNos null; //需要在这里**判断是否为空**&#xff0c;**不为空才能**调**用Arrays.asList转化为…

Oracle数据库-重点信息查询方法

文章目录 一、数据库信息及查询方法1.1是否为RAC1.2 数据库存储容量大小1.3 在线会话数1.4 最大分区数1.5 最大存储过程行数1.6 单表最大行数1.7 最大单表大小1.8 表总数量1.9 无主键表的数量1.10 字段数超过200的宽表1.11 关注CPU耗时高的SQL 一、数据库信息及查询方法 1.1是…

Linux 下 自动补全功能

在一下Linux发行版本中&#xff0c;比如说openEuler系统是没有命令补全功能的&#xff0c;为方便起见&#xff0c;故增加命令补全功能 # 安装bash-completion软件包&#xff0c;这个包提供了bash shell的自动补全功能支持 yum install -y bash-completion# 将docker命令的自动…