出自学会忍受孤独
前几天和一个同事谈到PyGTK的问题,就准备着手学习一下。在涉及到编程环境时,自然地想到了limodou兄的UliPad。
不过在使用中, 发现在Linux下在状态栏中没有内存信息,判断条件也只是判断到Windows的环境,这可能和limodou在Windows下进行开发有关吧。虽然 这点信息不重要,但我不想在Linux下就比Windows下的功能“少”一点,于是学习了一下,修改了2个文件:MainFrame.py和 MyStatusBar.py,新增加了一个文件PCInfo(我把它放到modules中了),把这个功能给添加上去了。顺便把缓存的信息也给加上了, 呵呵。
为以后可能要“自作主张”地显示更多的信息,就把文件命名为了PCInfo.py。下面把代码给附上(我的Swiftfox不能添加图片):
蓝色为新增或修改的代码,我的ulipad放在了/opt下面:[code]#!/usr/bin/env python
#coding=utf-8
# /opt/ulipad/modules/PCInfo.py
def memInfo():
ram = open("/proc/meminfo")
ramlines = ram.readlines()
ramInfo = {'cachedRam': 0,
'freeRam': 0,
'totalRam': 0
}
for element in ramlines:
if element.split(" ")[0] == "MemTotal:":
ramInfo['totalRam'] = int(element.split(" ")[-2])/1024
elif element.split(" ")[0] == "MemFree:":
ramInfo['freeRam'] = int(element.split(" ")[-2])/1024
elif element.split(" ")[0] == "Cached:":
ramInfo['cachedRam'] = int(element.split(" ")[-2])/1024
else:
pass
ram.close()
return ramInfo
----------------------------------
# /opt/ulipad/mixins/MainFrame.py
...
def OnIdle(self):
try:
while not self.closeflag:
if not self.app.wxApp.IsActive():
self.callplugin('on_idle_non_active', self)
time.sleep(0.1)
else:
if wx.Platform == '__WXMSW__':
wx.CallAfter(self.SetStatusText, "%dM" % (wx.GetFreeMemory()/1024/1024), 5)
# Add one more column to the statusbar to show Mem info on Linux Platform
#
elif wx.Platform == '__WXGTK__':
from modules import PCInfo
myRam = PCInfo.memInfo()
ramStr = "空闲: %dM/%dM 缓存: %dM" % (myRam['freeRam'], myRam['totalRam'], myRam['cachedRam'])
wx.CallAfter(self.SetStatusText, ramStr, 5)
self.callplugin('on_idle', self)
time.sleep(0.5)
except:
pass
...
------------------------------------------
# /opt/ulipad/modules/MyStatusBar.py
...
class MyStatusBar(wx.StatusBar):
def __init__(self, parent):
wx.StatusBar.__init__(self, parent, -1)
if wx.Platform == '__WXMSW__':
self.SetFieldsCount(6)
self.SetStatusWidths([-1, 70, 60, 40, 60, 45])
elif wx.Platform == '__WXGTK__':
self.SetFieldsCount(6)
self.SetStatusWidths([-1, 70, 60, 40, 60, 220])
else:
self.SetFieldsCount(5)
...[/code]

