编写跨分发用户界面时,不需要考虑太多东西。
实际上,我记得的唯一不兼容问题是:
托盘图标或通知区或应用程序指示器(在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
本文探讨了在编写跨分发用户界面时遇到的兼容性问题,特别是托盘图标在不同操作系统中的适配。作者提供了一个检查操作系统类型的函数,并建议在Ubuntu Unity中使用appindicator模块来解决托盘图标不兼容的问题。该函数通过读取系统文件来识别Linux发行版,如Ubuntu或SUSE。
1242

被折叠的 条评论
为什么被折叠?



