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


Python Notifier.auto_brightness方法代码示例

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


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

示例1: AutoBrightnessService

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import auto_brightness [as 别名]
class AutoBrightnessService(dbus.service.Object):
    def __init__(self):
        path = '/com/github/sheinz/autobrightness'
        bus_loop = DBusQtMainLoop(set_as_default=True)
        self._bus = dbus.SessionBus(mainloop=bus_loop)

        name = dbus.service.BusName('com.github.sheinz.autobrightness',
                                    bus=self._bus)

        dbus.service.Object.__init__(self, name, path)
        self.notifier = Notifier(self._bus)
        self._auto = False
        self._als = AmbientLightSensor()
        self._br_ctrl = BrightnessCtrl(self._bus)
        self._process_timer = QtCore.QTimer()
        self._process_timer.timeout.connect(self.process)

    @property
    def auto(self):
        return self._auto

    @auto.setter
    def auto(self, value):
        self._auto = value
        self.notifier.auto_brightness(self._auto)
        if self._auto:
            self._als.start()
            self._br_ctrl.start()
            self._process_timer.start(1000)
        else:
            self._als.stop()
            self._br_ctrl.stop()
            self._process_timer.stop()

    def process(self):
        value = self._als.get_value()
        print('Light sensor: %d' % value)
        if value == 0:
            value = 1
        self._br_ctrl.set_screen_brightness(value)
        if value < 5:
            self._br_ctrl.set_keyboard_light(True)
        else:
            self._br_ctrl.set_keyboard_light(False)

    def stop(self):
        self._process_timer.stop()
        self._als.stop()
        self._br_ctrl.stop()

    @dbus.service.method(dbus_interface='com.github.sheinz.autobrightness')
    def up(self):
        value = self._br_ctrl.screen_brightness_up()
        self.notifier.brightness(value)

    @dbus.service.method(dbus_interface='com.github.sheinz.autobrightness')
    def down(self):
        value = self._br_ctrl.screen_brightness_down()
        self.notifier.brightness(value)

    @dbus.service.method(dbus_interface='com.github.sheinz.autobrightness')
    def auto_toggle(self):
        self.auto = not self.auto

    @dbus.service.method(dbus_interface='com.github.sheinz.autobrightness')
    def exit(self):
        sys.exit()
开发者ID:sheinz,项目名称:auto-brightness,代码行数:69,代码来源:auto-brightness-service.py


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