当前位置: 首页>>代码示例>>Python>>正文


Python Preferences.email方法代码示例

本文整理汇总了Python中preferences.Preferences.email方法的典型用法代码示例。如果您正苦于以下问题:Python Preferences.email方法的具体用法?Python Preferences.email怎么用?Python Preferences.email使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在preferences.Preferences的用法示例。


在下文中一共展示了Preferences.email方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: App

# 需要导入模块: from preferences import Preferences [as 别名]
# 或者: from preferences.Preferences import email [as 别名]
class App(rumps.App):
    """This is the main class that runs the HipStatus app"""
    def __init__(self):
        super(App, self).__init__("HipStatus")
        self.icon = _menu_bar_icon(0)
        self.preferences = Preferences()
        self._validate_preferences()

        self.keychain = Keychain(self.preferences.email())
        self._validate_keychain()

        self.hipchat = HipChat(self.keychain.read_token())
        self.office365 = Office365(self.preferences.email(), self.keychain.read_o365())

        self.menu_pause_button = rumps.MenuItem("Pause HipStatus", self.timer_pause)
        self.menu_preferences = rumps.MenuItem('Preferences...')

        self.menu = [self.menu_pause_button, rumps.separator, self.menu_preferences, rumps.separator]

        self.menu_preferences_message = rumps.MenuItem("", self.preferences_message)
        if self.preferences.default_message():
            self.menu_preferences_message.title = self.preferences.default_message()
        else:
            self.menu_preferences_message.title = "None..."

        self.menu_preferences_email = rumps.MenuItem("Change email address", self.preferences_update_email)
        self.menu_preferences_o365 = rumps.MenuItem("Update saved Office 365 password", self.preferences_update_o365)
        self.menu_preferences_token = rumps.MenuItem("Update saved HipChat token", self.preferences_update_token)
        self.menu_preferences_get_token = rumps.MenuItem("Get your HipChat token", open_browser)

        self.menu_preferences.add(rumps.MenuItem('Status message...'))
        self.menu_preferences.add(self.menu_preferences_message)
        self.menu_preferences.add(rumps.separator)
        self.menu_preferences.add(rumps.MenuItem('Preferences...'))
        self.menu_preferences.add(self.menu_preferences_email)
        self.menu_preferences.add(self.menu_preferences_o365)
        self.menu_preferences.add(self.menu_preferences_token)
        self.menu_preferences.add(rumps.separator)
        self.menu_preferences.add(self.menu_preferences_get_token)

        self.main_timer = rumps.Timer(self.timer_trigger, 300)
        self.main_timer.start()

    def _validate_preferences(self):
        if not self.preferences.email().strip():
            logging.warning("No email address on record in preferences")
            self.preferences_update_email(None)

    def _validate_keychain(self):
        try:
            self.keychain.read_o365()
        except KeychainValueNotFound:
            logging.warning("Office 365 password not found")
            self.keychain.write_o365("Enter Password")
            self.preferences_update_o365(None, menu_call=False)

        try:
            self.keychain.read_token()
        except KeychainValueNotFound:
            logging.warning("HipChat API token not found")
            self.keychain.write_token("Enter Token")
            self.preferences_update_token(None, menu_call=False)

    @rumps.notifications
    def notification_center(self, info):
        logging.debug("Notification has been clicked")
        if 'update_o365' in info:
            self.preferences_update_o365(None)
        elif 'update_token' in info:
            self.preferences_update_token(None)
        elif 'update_email' in info:
            self.preferences_update_email(None)
        elif 'open_ticket' in info:
            webbrowser.open(info['open_ticket'])
        else:
            pass

    def preferences_message(self, sender):
        text = self.preferences.default_message()
        if text is None:
            text = ''
        prompt = rumps.Window("Leave blank to not set a status message",
                              "Enter a message to display when you are set to 'Do not disturb'", text,
                              dimensions=(275, 25))
        result = prompt.run()
        self.preferences.default_message(result.text)
        if self.preferences.default_message():
            self.menu_preferences_message.title = self.preferences.default_message()
        else:
            self.menu_preferences_message.title = "None..."

    def preferences_update_email(self, sender):
        text = self.preferences.email()
        logging.info("Prompting for new email")
        prompt = rumps.Window("", "Enter your email address", text, dimensions=(275, 25))
        result = prompt.run()
        self.preferences.email(result.text)

    def preferences_update_o365(self, sender, message="", menu_call=True):
        text = self.keychain.read_o365()
#.........这里部分代码省略.........
开发者ID:jamfit,项目名称:HipStatus,代码行数:103,代码来源:hipstatus.py


注:本文中的preferences.Preferences.email方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。