def __init__(self): # Initialize a new AppIndicator self.indicator = appindicator.Indicator( "natural-scrolling-indicator", "natural-scrolling-status-not-activated", appindicator.CATEGORY_APPLICATION_STATUS) media_path = "%s/media/" % naturalscrollingconfig.get_data_path() self.indicator.set_icon_theme_path(media_path) self.indicator.set_attention_icon( "natural-scrolling-status-activated") menu = IndicatorMenu() self.indicator.set_menu(menu) # Initialize the UDev client udev_observator = UDevObservator() udev_observator.on_update_execute(menu.refresh) udev_observator.start() # Force the first refresh of the menu in order to populate it. menu.refresh(udev_observator.gather_devices()) # When something change in GConf, push it to the Indicator menu # in order to update the status of the device as checked or unchecked GConfSettings().server().on_update_fire(menu.update_check_menu_item) # Initialize GConf in order to be up-to-date with existing devices GConfSettings().initialize(udev_observator.gather_devices())
def __init__(self): # Initialize a new AppIndicator self.indicator = appindicator.Indicator( "natural-scrolling-indicator", "natural-scrolling-status-not-activated", appindicator.CATEGORY_APPLICATION_STATUS) media_path = "%s/media/" % naturalscrollingconfig.get_data_path() self.indicator.set_icon_theme_path(media_path) self.indicator.set_attention_icon("natural-scrolling-status-activated") menu = IndicatorMenu() self.indicator.set_menu(menu) # Initialize the UDev client udev_observator = UDevObservator() udev_observator.on_update_execute(menu.refresh) udev_observator.start() # Force the first refresh of the menu in order to populate it. menu.refresh(udev_observator.gather_devices()) # When something change in GConf, push it to the Indicator menu # in order to update the status of the device as checked or unchecked GConfSettings().server().on_update_fire(menu.update_check_menu_item) # Initialize GConf in order to be up-to-date with existing devices GConfSettings().initialize(udev_observator.gather_devices())
class Indicator(object): # Singleton _instance = None _init_done = False watchman = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Indicator, cls).__new__(cls, *args, **kwargs) return cls._instance def __init__(self): LOGGER.debug("Indicator initialization") # Initialize a new AppIndicator self.indicator = appindicator.Indicator( "natural-scrolling-indicator", "natural-scrolling-status-not-activated", appindicator.CATEGORY_APPLICATION_STATUS) media_path = "%s/media/" % naturalscrollingconfig.get_data_path() self.indicator.set_icon_theme_path(media_path) self.indicator.set_attention_icon( "natural-scrolling-status-activated") self.menu = IndicatorMenu() self.menu.indicator = self self.indicator.set_menu(self.menu) # Initialize the UDev client udev_observator = UDevObservator() udev_observator.on_update_execute(self.menu.refresh) udev_observator.start() # Force the first refresh of the menu in order to populate it. self.menu.refresh(udev_observator.gather_devices()) # When something change in GConf, push it to the Indicator menu # in order to update the status of the device as checked or unchecked GConfSettings().server().on_update_fire(self.menu.update_check_menu_item) # Initialize GConf in order to be up-to-date with existing devices GConfSettings().initialize(udev_observator.gather_devices()) def status_attention(self): self.set_status(appindicator.STATUS_ATTENTION) def status_active(self): self.set_status(appindicator.STATUS_ACTIVE) @property def isreversed(self): return self.menu.enabled def check_scrolling(self): if self.isreversed: self.indicator.set_status(appindicator.STATUS_ATTENTION) else: self.indicator.set_status(appindicator.STATUS_ACTIVE) return True def refresh_loop(self): if not UDevObservator().gather_devices(): LOGGER.debug("Refresh loop - FAILED") return True LOGGER.debug("Refresh loop - SUCCESS") bool_int = 1 if self.isreversed else 0 LOGGER.debug("Reverting once to %s" % (1 - bool_int)) self.menu.set_scrolling_state(1 - bool_int) time.sleep(1) LOGGER.debug("Reverting twice to %s" % bool_int) self.menu.set_scrolling_state(bool_int) return False def refresh(self): LOGGER.debug("Refresh loop initiated...") if self.refresh_loop(): gtk.timeout_add(10 * 1000, self.refresh_loop) def start(self): self.check_scrolling() self.menu.watchman = WakeDetector() self.menu.watchman.start(self.refresh) try: gtk.main() except KeyboardInterrupt: pass