Skip to content

Commit

Permalink
settings_template: Prepare removal of desktop_notifications dependency
Browse files Browse the repository at this point in the history
Related #2273
  • Loading branch information
MattHag committed Sep 18, 2024
1 parent 9aeaa2c commit 01d754c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/logitech_receiver/settings_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import struct
import traceback

from collections.abc import Callable
from time import time

from solaar.i18n import _
Expand Down Expand Up @@ -728,6 +729,15 @@ def build(cls, setting_class, device):


class DpiSlidingXY(settings.RawXYProcessing):
def __init__(
self,
*args,
show_notification: Callable[[str, str], bool],
**kwargs,
):
super().__init__(*args, **kwargs)
self._show_notification = show_notification

def activate_action(self):
self.dpiSetting = next(filter(lambda s: s.name == "dpi" or s.name == "dpi_extended", self.device.settings), None)
self.dpiChoices = list(self.dpiSetting.choices)
Expand All @@ -745,12 +755,11 @@ def setNewDpi(self, newDpiIdx):
self.device.setting_callback(self.device, type(self.dpiSetting), [newDpi])

def displayNewDpi(self, newDpiIdx):
if desktop_notifications.available:
selected_dpi = self.dpiChoices[newDpiIdx]
min_dpi = self.dpiChoices[0]
max_dpi = self.dpiChoices[-1]
reason = f"DPI {selected_dpi} [min {min_dpi}, max {max_dpi}]"
desktop_notifications.show(self.device, reason)
selected_dpi = self.dpiChoices[newDpiIdx]
min_dpi = self.dpiChoices[0]
max_dpi = self.dpiChoices[-1]
reason = f"DPI {selected_dpi} [min {min_dpi}, max {max_dpi}]"
self._show_notification(self.device, reason)

def press_action(self, key): # start tracking
self.starting = True
Expand Down Expand Up @@ -912,7 +921,9 @@ def build(cls, setting_class, device):
if _F.ADJUSTABLE_DPI in device.features:
choices[k.key] = setting_class.choices_universe
if sliding is None:
sliding = DpiSlidingXY(device, name="DpiSlding")
sliding = DpiSlidingXY(
device, name="DpiSliding", show_notification=desktop_notifications.show
)
else:
choices[k.key] = setting_class.choices_divert
if not choices:
Expand Down

0 comments on commit 01d754c

Please sign in to comment.