- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 GTK 创建多线程。需要 Gtk.gdk,但我收到关于没有 gdk 属性的错误。我正在使用带有 Raspbian 的 Raspberry Pi。
这就是我导入 GTK 库的方式。
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
from gi.repository import Gtk
except:
print("GTK Not Available")
sys.exit(1)
Gtk.gdk.threads_init()
这是我收到的错误。
AttributeError'gi.repository.Gtk' object has no attribute 'gdk'
有什么想法吗?
更新:我正在学习本教程 http://faq.pygtk.org/index.py?req=show&file=faq14.023.htp它们同时使用 GObject.threads_init() 和 Gtk.gdk.threads_init()。我使用 GObject 没问题,但使用 gdk。
最佳答案
我认为旧式 gtk.gdk.threads_init()
的等价物是:
from gi.repository import Gdk
Gdk.threads_init()
但是,作为 FAQ warns ,线程不是实现此目标的干净方法。更好的方法是使用 GObject.idle_add
在 GUI 空闲时运行函数。
"""Show a shell command's output in a gtk.TextView without freezing the UI"""
import os
import locale
import subprocess
import shlex
import gi.repository.Gtk as gtk
from gi.repository import GObject
PIPE = subprocess.PIPE
encoding = locale.getpreferredencoding()
def utf8conv(x):
return unicode(x, encoding).encode('utf8')
class MyWindow:
def __init__(self):
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC)
textview = gtk.TextView()
textbuffer = textview.get_buffer()
sw.add(textview)
win = gtk.Window()
win.resize(300, 500)
win.connect('delete-event', gtk.main_quit)
self.button_sim = gtk.Button(u"Press me!")
self.button_abort = gtk.Button("Abort")
self.button_quit = gtk.Button("Quit")
command = 'ls -R %s' % (os.getcwd(),)
self.button_sim.connect(
"clicked", self.on_button_clicked, textview, textbuffer, command)
self.button_abort.connect("clicked", self.on_abort)
self.button_quit.connect("clicked", self.main_quit)
vbox = gtk.VBox()
vbox.pack_start(self.button_sim, expand=False, fill=False, padding=0)
vbox.pack_start(self.button_abort, expand=False, fill=False, padding=0)
vbox.pack_start(self.button_quit, expand=False, fill=False, padding=0)
vbox.pack_start(sw, expand=True, fill=True, padding=0)
win.add(vbox)
win.show_all()
def read_output(self, view, buffer, command):
yield True # allow the UI to refresh
proc = subprocess.Popen(
shlex.split(command), stderr=PIPE, stdout=PIPE)
while True:
if self.job_aborted:
print('user aborted')
proc.terminate()
break
try:
line = proc.stdout.readline()
if line:
it = buffer.get_end_iter()
buffer.place_cursor(it)
buffer.insert(it, utf8conv(line))
view.scroll_to_mark(buffer.get_insert(), 0.1,
use_align=False, xalign=0.5, yalign=0.5)
except IOError:
pass
yield True
yield False
def on_button_clicked(self, button, view, buffer, command):
self.job_aborted = False
GObject.idle_add(self.read_output(view, buffer, command).next)
def on_abort(self, button):
self.job_aborted = True
def main_quit(self, obj):
self.job_aborted = True
gtk.main_quit()
if __name__ == "__main__":
app = MyWindow()
gtk.main()
关于python - 'gi.repository.Gtk' 对象没有属性 'gdk',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728170/
在过去的几个月里,我一直在使用 Bzr 对我的项目进行版本控制。我是唯一的开发人员,目前我只有一个本地项目目录中的所有内容,我提交并同步到 DriveHQ。 我现在想到了一些可能会打破这条主线的大规模
我在一个多模块项目中使用 Maven 3.2.3。我想生成一个 checkstyle 和 findbugs 报告,所以我配置了以下内容:
我注意到 Repository 通常通过以下任一方式实现: 方法一 void Add(object obj); void Remove(object obj); object GetBy(int id
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 5年前关闭。 Improve thi
这是我的设置的详细信息: Gitlab 版本:5.2操作系统:Centos 6.3我在创建新项目 (/projects/new) 时导入现有存储库。 创建了一个新的 EMPTY 项目,但是没有导入存储
我的文件夹结构如下: repo1 | |---file1 |---fold1 | |---file2 |---repo2 | | |---file3 假设我有两
假设我有一个 TeacherRepository,需要根据下面的代码使用 CourseRepository。 Teacher 和 Course 形成多对多的关系。教师和类(class)不形成聚合。您会
我要同样的 repositories我在 buildscript.repositories 中指定的阻止与依赖项相同的存储库 repositories堵塞。请看我的例子: 正常 buidldscrip
是否使用 @EnableJpaRepositories 或 jpa:repositories(在 xml 上)让开发人员不要使用 Spring 的 @Repository 标签?当我查看 Spring
我是 git 和 Github 的新手。我已经了解了很多术语(推送、 pull 、提交、分支等),但我将主要使用通俗的说法来解释我最初的期望。 我假设过程是: 1.) Create a git rep
安装 Nexus Repository Manager OSS 3 后,我没有看到用于通过网页上传工件的选项Artifact Upload。 在 Nexus Repository Manager OS
CMS 和 DMS 有什么区别?两者都存储日期,可以访问数据,它们有什么不同?可以使用 apache Jack Rabbit 代替 Alfresco 吗? 最佳答案 我会根据管理数据的可变性来区分这两
在我的earlier question我问的是如何为使用 EF 等 ORM 框架构建的大型应用程序实现存储库/工作单元模式。 我现在无法解决的一个后续问题是将包含业务逻辑的代码放在哪里,但仍然足够低级
我正在尝试为 nuget git 存储库(我刚刚从中克隆)创建 pull 请求。我已经进行了本地提交。 但是当我尝试创建 pull 请求时,出现以下错误: Could not find any rel
我已经看到了下面的问题。 git diff between cloned and original remote repository 我的问题是如何在 SourceTree 中看到这个差异结果(而不
我在通过 Subversion (SVN) 中的 checkin 自动在 Review Board 中创建新的评论条目时遇到了困难。我创建了一个提交后 Hook ,当手动运行时会出现以下异常: Fai
我在尝试集成 Spring Data 时遇到此错误。完整的堆栈跟踪是 nested exception is org.xml.sax.SAXParseException; systemId: http
通知:https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-repository-email.html 触发器:https://
我正在学习 Laravel 中的存储库设计模式,我正在使用 https://github.com/andersao/l5-repository去做这件事。 但是在我将文件夹 prettus 复制/粘贴
我最近开始了一个使用现有数据库(Oracle)和 MVC 4 的项目。已经进行了很多编码..但是代码中没有“策略”..只有 DB -> ORM -> Controller。因此,我正在尝试为开发添加一
我是一名优秀的程序员,十分优秀!