我现在愚蠢地试图为Python桌面应用程序维护两个并行代码库,一个使用PyGObject内省GTK 3,一个使用PyGTK for GTK 2.我主要在PyGObject分支上工作,然后我将端口转换到PyGTK分支.由于这些实现之间的所有细微差别,我经常忽略事情并导致我想念和意外释放的破损,只是被用户抓住.
我试图找出一种设计一些单元测试的好方法,这些单元测试最好适合在两个代码库上运行.这不是一个过于复杂的程序,(它本质上是一个图书馆管理工具,想像iTunes):
- Main Window
|- Toolbar with some buttons (add/edit/remove items, configure the program)
|
|- VPaned
|--- Top HPaned
|------ ListView (listing values by which a library of items can be filtered)
|------ ListView (listing the contents of the library
|--- Bottom HPaned
|------ Image (displaying cover art for the currently selected item in the library)
|------ TextView (displaying formatted text describing the currently selected item)
- Edit dialog
- Configuration dialog
- About …
Run Code Online (Sandbox Code Playgroud) 我有一个用Glade(3.18)构建的GUI,它由Python 3程序调用(使用PyGObject).运行程序(Fedora 21)时,我收到很多警告:
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
Run Code Online (Sandbox Code Playgroud)
我该如何修复此警告?我尝试Transient for: main_window
在Glade中填写所有对话窗口的字段,但警告仍然出现.
我试图让pygobject-2.28.6在cygwin中编译(存储库中的版本是2.28.4,这有一些问题).这是./configure的尾部:
checking for GLIB - version >= 2.24.0... yes (version 2.34.3)
checking for ffi... checking for FFI... yes
checking for GIO... yes
checking for GIOUNIX... yes
checking for GI... no
configure: error: Package requirements (glib-2.0 >= 2.24.0
gobject-introspection-1.0 >= 0.10.2
) were not met:
No package 'gobject-introspection-1.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables GI_CFLAGS
and GI_LIBS to avoid the need to call pkg-config.
See …
Run Code Online (Sandbox Code Playgroud) 我正在第一次将程序从PyGTK转换为PyGObject内省,我遇到了一个带有线程的障碍.我有一个需要一些时间才能完成的过程,所以我弹出一个带有进度条的对话框,我使用一个线程来完成这个过程并更新进度条.这对PyGTK工作得很好,但在转换为PyGObject之后,我得到了所有常见的不正确的线程怪异:程序挂起,但它似乎挂在过程的不同部分,等等.所以我得到的印象是事情发生了变化,但我可以弄清楚是什么.
这是一个简单的PyGTK进度条示例:http://aruiz.typepad.com/siliconisland/2006/04/threads_on_pygt.html 如该页面上所示,代码可以正常工作.我把它转换为PyGObject内省,我遇到了与我的程序相同的问题:它挂起,它没有正确更新进度条等.
import threading
import random, time
from gi.repository import Gtk, Gdk
#Initializing the gtk's thread engine
Gdk.threads_init()
class FractionSetter(threading.Thread):
"""This class sets the fraction of the progressbar"""
#Thread event, stops the thread if it is set.
stopthread = threading.Event()
def run(self):
"""Run method, this is the code that runs while thread is alive."""
#Importing the progressbar widget from the global scope
global progressbar
#While the stopthread event isn't setted, the thread keeps going on
while …
Run Code Online (Sandbox Code Playgroud) 我一直在研究python-mpdor的源代码,它提到它是
基于gobject,用于简单的事件处理(在高级客户端类中).
有人可以用简单的语言向我解释究竟是什么Glib
,GObject
以及它们如何相互作用以及它在事件处理中扮演什么角色.
我试着寻找Glib
,GObject
但我没有找到任何基本的解释.我发现的所有解释都非常技术性和技术性,我的意思是不适合初学者.
此外,有人可以指向一些关于和的初学者教程/文章.Glib
GObject
我在Ubuntu 11.10上使用PyCharm 2.5,试图在Python 3.2.2上使用PyGObject 3.0开发一个应用程序.我已经安装了Ubuntu软件包python3-gobject,当我运行我的代码时,它完全按预期工作.
但是,PyCharm似乎无法找到任何PyGObject模块.它说Unresolved refrence: 'Gtk'
当我在我的import语句中将鼠标悬停在Gtk上时,当然没有一个自动完成工作.
这是我的代码:
#!/usr/bin/env python3
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Run Code Online (Sandbox Code Playgroud)
我甚至已经尝试做一个python虚拟环境,然后从源代码安装到PyGObject,然后甚至试图从所有.py文件制作符号链接中site-packages/gi/overrides
来site-packages/gi/repository
,都没有运气.
任何建议将不胜感激!
随着gettext
你要么可以使用默认的系统范围内的区域设置目录,或使用指定一个自己bindtextdomain
.当编译的.mo转换文件在系统的默认位置不可用时,直接从源运行程序时这很有用.
在Python中你会这样做:
import gettext
from gettext import gettext as _
gettext.bindtextdomain('nautilus-image-manipulator', '/path/to/mo/folder')
gettext.textdomain('nautilus-image-manipulator')
Run Code Online (Sandbox Code Playgroud)
其中/path/to/mo/folder
包含熟悉的fr/LC_MESSAGES/nautilus-image-manipulator.mo
结构.这样的电话:
print _("Delete this profile")
Run Code Online (Sandbox Code Playgroud)
从本地.mo文件返回正确翻译的字符串,非常感谢.
在GTK + 2/pygtk中,存在gtk.glade.bindtextdomain
,但我想知道GTK + 3/PyGObject中是否有任何等价物.
为了给你一个具体的例子,这是Nautilus Image Manipulator的UI是如何从它的Glade文件创建的:
from gi.repository import Gtk
builder = Gtk.Builder()
builder.set_translation_domain('nautilus-image-manipulator')
builder.add_from_file(ui_filename)
return builder
Run Code Online (Sandbox Code Playgroud)
不是从Glade文件构建的UI部分(即从代码中设置)显示正确翻译,但Glade文件中的字符串仍显示为英文.
在我看来,在打电话builder.bind_text_domain('nautilus-image-manipulator', '/path/to/mo/folder')
之前我错过了某种呼叫builder.set_translation_domain
......任何想法如何执行此操作?
PyGObject似乎没有真正的文档.本教程尽可能接近.我整个上午一直在努力寻找Gtk.Window
构造函数接受的参数的描述.我似乎无法在Python中做太多反思,因为PyGObject中的所有内容都是动态生成的.
我想要的只是知道我可以传递给这个构造函数的参数!在GTK + 3文档中似乎没有相应的此对象,并且阅读源代码以确定绑定已被证明是一项非常艰巨的任务.有任何想法吗??
我有一个小的python程序,展示了如何为Linux和Windows翻译GTK(pygobject)GUI.一切都在Linux中工作,但在Windows中,非ASCII符号不会在翻译中呈现.
我假设Glade文件和*.mo文件都被正确解码,因为:
以下是英文原版中的界面:
并且德语翻译不使用环境变量或PANGOCAIRO_BACKEND=win32
:
使用环境变量PANGOCAIRO_BACKEND=fontconfig
(PANGOCAIRO_BACKEND=fc
)的德语翻译.第一个标签设置为使用Pango使用Calibri.这肯定是Windows上"ö","ä"和"ü"的字体.
在控制台中,此警告出现在翻译中:Pango-Warning **: Invalid UTF-8 string passed to pango_layout_set_text()
.
这里已经讨论了有关使翻译工作的一些细节:
存储库:
Windows的安装程序:
是否有可能builder.set_translation_domain("pygibank")
使用错误的编码推送翻译?有可能调试这个或有没有人知道如何解决这个问题?
pygobject ×10
python ×7
gtk ×4
gobject ×3
pygtk ×3
gtk3 ×2
python-3.x ×2
cygwin ×1
gettext ×1
glade ×1
glib ×1
installer ×1
localization ×1
pango ×1
pkg-config ×1
pycharm ×1
translation ×1
ubuntu ×1
unit-testing ×1
windows ×1