將Ubuntu12.04indicator郵箱圖標刪去並加入新圖標用作Gmail郵件提示


1.刪去 Ubuntu12.04 indicator(叫狀態欄,指示欄之類吧) 郵箱圖標

直接系命令行打

sudo apt-get remove indicator-message
重啓之後郵件圖標就消失


2. 嗯,網上發現一個頗有意思ge插件~ 可以直接用以下代碼... 修改帳號密碼後就呵呵喇。可以加入到開機自啓動(需要本文改動後代碼,鏈接中的以爲未聯網的原因會不顯示)。

http://conjurecode.com/create-indicator-applet-for-ubuntu-unity-with-python/

#!/usr/bin/env python
import sys
import gtk
import appindicator

import imaplib
import re

PING_FREQUENCY = 10             # seconds

USERMAIL = 'zagfai@gmail.com'   # modify it
PASSWORD = ''                   # and it

class CheckGMail:
    def __init__(self):
        self.ind = appindicator.Indicator("new-gmail-indicator",
                                           "indicator-messages",
                                           appindicator.CATEGORY_APPLICATION_STATUS)
        self.ind.set_status(appindicator.STATUS_ACTIVE)
        self.ind.set_attention_icon("new-messages-red")

        self.menu_setup()
        self.ind.set_menu(self.menu)

    def menu_setup(self):
        self.menu = gtk.Menu()

        self.quit_item = gtk.MenuItem("Quit")
        self.quit_item.connect("activate", self.quit)
        self.quit_item.show()
        self.menu.append(self.quit_item)

    def main(self):
        self.check_mail()
        gtk.timeout_add(PING_FREQUENCY * 1000, self.check_mail)
        gtk.main()

    def quit(self, widget):
        sys.exit(0)

    def check_mail(self):
        messages, unread = self.gmail_checker(USERMAIL,PASSWORD)
        if unread > 0:
            self.ind.set_status(appindicator.STATUS_ATTENTION)
        else:
            self.ind.set_status(appindicator.STATUS_ACTIVE)
        return True

    def gmail_checker(self, username, password):
        try:
            i = imaplib.IMAP4_SSL('imap.gmail.com')
            i.login(username, password)
            x, y = i.status('INBOX', '(MESSAGES UNSEEN)')
            messages = int(re.search('MESSAGES\s+(\d+)', y[0]).group(1))
            unseen = int(re.search('UNSEEN\s+(\d+)', y[0]).group(1))
            return (messages, unseen)
        except:
            return False, 0

if __name__ == "__main__":
    indicator = CheckGMail()
    indicator.main()


記得

chmod +x x.py


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页