程序员如何编写适用于多个发行版的可移植UI代码?我正在考虑桌面发行版,而不是专门的/嵌入式发行版.对于编写UI应用程序,您必须假设平台上的某些内容可以作为标准或通过添加的依赖项提供. Linux发行版拥有“最小”UI /小部件标准吗?
在编写代码时,Gnome与KDE的发行版是如何形成的?
我有一个使用Gtk和Webkit的python脚本.以下是我的脚本使用的导入.
import os
import threading
from gi.repository import WebKit
from gi.repository import Gtk
from gi.repository import GLib, GObject
找出我的代码将使用哪些发行版的最佳来源是什么?
解决方法:
编写交叉分发UI时,您不必考虑太多内容.
实际上我唯一能记住的不兼容问题是:
托盘图标或通知区域或应用程序指示器(在Ubuntu中称为)
例如,标准托盘图标(由gtk.StatusIcon创建,默认情况下在Ubuntu的Unity中不起作用
如果找到appindicator模块,最好使用appindicator.Indicator,否则只使用经典的StatusIcon
为了找到分发/操作系统,我写了这样一个函数:
def getOsFullDesc():
name = ''
if os.path.isfile('/etc/lsb-release'):
lines = open('/etc/lsb-release').read().split('\n')
for line in lines:
if line.startswith('DISTRIB_DESCRIPTION='):
name = line.split('=')[1]
if name[0]=='"' and name[-1]=='"':
return name[1:-1]
if os.path.isfile('/suse/etc/SuSE-release'):
return open('/suse/etc/SuSE-release').read().split('\n')[0]
try:
import platform
return ' '.join(platform.dist()).strip().title()
#return platform.platform().replace('-', ' ')
except ImportError:
pass
if os.name=='posix':
osType = os.getenv('OSTYPE')
if osType!='':
return osType
## sys.platform == 'linux2'
return os.name
标签:python,linux,gtk,pygtk
来源: https://codeday.me/bug/20190709/1410430.html