python具有高可移植性,Gtk/python与可移植性

本文探讨了在编写跨分发用户界面时遇到的兼容性问题,特别是托盘图标在不同操作系统中的适配。作者提供了一个检查操作系统类型的函数,并建议在Ubuntu Unity中使用appindicator模块来解决托盘图标不兼容的问题。该函数通过读取系统文件来识别Linux发行版,如Ubuntu或SUSE。
摘要由CSDN通过智能技术生成

编写跨分发用户界面时,不需要考虑太多东西。

实际上,我记得的唯一不兼容问题是:

托盘图标或通知区或应用程序指示器(在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值