- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个函数使用 plyer.facades.Wifi
库来检查 wifi 状态。该函数根据 wifi 的状态将 BooleanProperty
变量 is_wifi
更改为 True
或 False
。 BooleanProperty
变量在 Kv-Language
脚本中绑定(bind)到一个 ActionLabel
,它根据状态更改图像。然后使用 Kivy 的 Clock.schedule_interval()
调度该函数。
主要问题是我在安排函数回调时收到 ValueError: callback must be a callable, got None
。
我试过:1] 在初始化时调度函数。2] 在用户登录时调用初始化后的调度事件。
from plyer import wifi
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
class TheLogger(FloatLayout):
is_wifi = BooleanProperty(wifi.is_enabled())
def __init__(self, **kwargs):
super().__init__(**kwargs)
def wifi_is_enabled(self): #Scheduling a callback of this function
print('checking connection')
try:
if wifi.is_enabled():
self.is_wifi = True
else:
self.is_wifi = False
except OSError:
pass
class LoginApp(App):
title = 'Login'
def build(self):
self.icon = 'sign_in_5243564.png'
rt = TheLogger()
Clock.schedule_interval(rt.wifi_is_enabled(), 0.5) #scheduling callback of wifi_is_enabled() function
return rt
Builder.load_string('''
<TheLogger>:
un_input: user_in
ScreenManager:
id: _screen_manager
Screen:
name: 'choice'
ActionBar:
pos_hint: {'top': 1, 'right': 1}
canvas:
Color:
rgba: (0,0.4,0.51,1)
Rectangle:
pos: self.pos
size: self.size
ActionView:
use_separator: True
ActionPrevious:
title: "Sign Out"
with_previous: True
app_icon: ''
color: (1,1,1,1)
on_release: app.root.sign_out()
ActionLabel: #ActionLabel source with If else block code on callback
text: ''
Image:
source: 'green_wifi_connected_5456.png' if root.is_wifi else 'red_ic_signal_wifi_off_48px_352130.png'
center_y: self.parent.center_y
center_x: self.parent.center_x
size: self.parent.width /1, self.parent.height/ 1
allow_stretch: True
''')
我希望该函数能够无误地安排回调。
最佳答案
Clock.schedule_interval(rt.wifi_is_enabled(), 0.5)
这段代码等同于:
callback = rt.wifi_is_enabled()
Clock.schedule_interval(callback, 0.5)
你现在看到问题了吗? callback 的值为 None,这是您尝试安排的内容。
你需要调度函数本身,而不是它的返回值:
Clock.schedule_interval(rt.wifi_is_enabled, 0.5)
请注意,该函数将自动接收一个位置参数,其中包含自上次运行/计划以来的时间。您的函数将需要接受此参数,即使它会忽略它。
关于python - 如何按计划修复 ' ValueError: callback must be a callable, got None' Kivy.clock 回调函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57242416/
我正在尝试找出这两个部分之间的区别,这似乎与 question 重复,但那里给出的答案并没有解释很多,所以我想要一个更详细和简洁的解释。 最佳答案 拆分是出于安全原因。默认情况下(过去仅在 -Wl,-
ELF 格式的 .got 和 .got.plt 部分有什么区别? 最佳答案 我之前的评论是对的: I think .got is for relocations regarding global 'v
我知道在典型的 ELF 二进制文件中,函数是通过过程链接表 (PLT) 调用的。函数的 PLT 条目通常包含到全局偏移表 (GOT) 条目的跳转。该条目将首先引用一些代码以将实际函数地址加载到 GOT
我知道在典型的 ELF 二进制文件中,函数是通过过程链接表 (PLT) 调用的。函数的 PLT 条目通常包含到全局偏移表 (GOT) 条目的跳转。该条目将首先引用一些代码以将实际函数地址加载到 GOT
我对 SICP 1.37 的迭代解决方案是 (define (con-frac n d k) (define (iter i result) (if (= 1 i) res
我正在尝试开始部署,但收到此错误 error: error validating "httpd-basic-deployment.yaml": error validating data: Valid
获取错误 ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 - "inconsistent dataty
我在没有全局偏移表的情况下编译多个 PIC 文件时遇到问题。 使用以下参数编译第一个文件 onefile.c 时,程序集不包含对 GOT 的引用: arm-none-eabi-gcc.exe firs
Your smiling at me is my daily dose of magic. 你嫣然的微笑是我每日享受到的魅力。 you hold a piece of me no matte
我是 Twilio 的新手。我正在尝试使用本教程将 SMS 转发到电子邮件地址: https://www.twilio.com/blog/2017/07/forward-incoming-sms-me
谁能帮我在 GWT 上创建离线 map ,我听说过 OpenLayers,但我没有找到任何源代码,你对此有什么想法吗?谢谢。 最佳答案 您将需要GWT-Openlayers Wrapper对于 Ope
我正在处理一些在编译为 PIC(位置无关代码)时速度变慢 70-80% 的代码,并且正在寻找缓解问题的方法。问题的很大一部分是 gcc 坚持在每个函数中插入以下内容: call __i686.get_
我编写了一个自定义 hamcrest 匹配器,用于检查列表中的文件是否已被复制。该列表可能很长(1000 个以上文件),因此如果缺少一个文件,我不希望匹配器打印出整个列表。 我可以为丢失的文件进行自定
我的意思是在模块中定义的非静态全局变量,而不是在外部。 为什么一定要通过GOT引用呢?为什么不使用相对地址?(因为.data 段中的全局变量和.text 段中的引用之间的距离是一个常量,它也是位置无关
当我在阅读时 http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/#id
某些特定于平台的功能(例如 SSE 或 AVX)的可用性可以在运行时确定,如果不想为不同的功能编译和发布不同的对象,这将非常有用。 例如,以下代码允许我检查 AVX 并使用 gcc 进行编译,它提供了
我如何检查互联网连接是否成功(Wifi/3G/其他) 如果用户没有 Wifi 连接,我已经向用户显示错误,但我如何才能确保用户确实获得了 3G 连接如果他们希望在没有 Wifi 连接的情况下连接使用应
这是示例程序集文件,test.s .global main main: mov __progname@GOT, %eax // failed to compile mov __
mysqldump:得到错误:1449:使用锁表时指定为定义者的用户('root'@'192.200.1.16')不存在 请给出上述错误的解决方案。 最佳答案 最好使用第一个mysqldump和--s
前言:本篇为笔者学习极客时间《深入浅出计算机组成》过程中的部分疑问和解疑记录,因为这一块问题笔者学习过程中搜索所得答案较少,故留此博客。 1. 编译、链接和加载 我们知道,“C 语言代码 - 汇编代码
我是一名优秀的程序员,十分优秀!