parent
dfb4ccc93f
commit
cdaffce463
|
@ -35,7 +35,7 @@ from typing import Optional
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
from gi.repository import GObject
|
from gi.repository import GObject
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from logitech_receiver import diversion as _DIV
|
from logitech_receiver import diversion
|
||||||
from logitech_receiver.common import NamedInt
|
from logitech_receiver.common import NamedInt
|
||||||
from logitech_receiver.common import NamedInts
|
from logitech_receiver.common import NamedInts
|
||||||
from logitech_receiver.common import UnsortedNamedInts
|
from logitech_receiver.common import UnsortedNamedInts
|
||||||
|
@ -64,7 +64,7 @@ class RuleComponentWrapper(GObject.GObject):
|
||||||
GObject.GObject.__init__(self)
|
GObject.GObject.__init__(self)
|
||||||
|
|
||||||
def display_left(self):
|
def display_left(self):
|
||||||
if isinstance(self.component, _DIV.Rule):
|
if isinstance(self.component, diversion.Rule):
|
||||||
if self.level == 0:
|
if self.level == 0:
|
||||||
return _("Built-in rules") if not self.editable else _("User-defined rules")
|
return _("Built-in rules") if not self.editable else _("User-defined rules")
|
||||||
if self.level == 1:
|
if self.level == 1:
|
||||||
|
@ -82,7 +82,7 @@ class RuleComponentWrapper(GObject.GObject):
|
||||||
def display_icon(self):
|
def display_icon(self):
|
||||||
if self.component is None:
|
if self.component is None:
|
||||||
return ""
|
return ""
|
||||||
if isinstance(self.component, _DIV.Rule) and self.level == 0:
|
if isinstance(self.component, diversion.Rule) and self.level == 0:
|
||||||
return "emblem-system" if not self.editable else "avatar-default"
|
return "emblem-system" if not self.editable else "avatar-default"
|
||||||
return self.__component_ui().icon_name()
|
return self.__component_ui().icon_name()
|
||||||
|
|
||||||
|
@ -143,17 +143,17 @@ def _populate_model(
|
||||||
return
|
return
|
||||||
if editable is None:
|
if editable is None:
|
||||||
editable = model[it][0].editable if it is not None else False
|
editable = model[it][0].editable if it is not None else False
|
||||||
if isinstance(rule_component, _DIV.Rule):
|
if isinstance(rule_component, diversion.Rule):
|
||||||
editable = editable or (rule_component.source is not None)
|
editable = editable or (rule_component.source is not None)
|
||||||
wrapped = RuleComponentWrapper(rule_component, level, editable=editable)
|
wrapped = RuleComponentWrapper(rule_component, level, editable=editable)
|
||||||
piter = model.insert(it, pos, (wrapped,))
|
piter = model.insert(it, pos, (wrapped,))
|
||||||
if isinstance(rule_component, (_DIV.Rule, _DIV.And, _DIV.Or, _DIV.Later)):
|
if isinstance(rule_component, (diversion.Rule, diversion.And, diversion.Or, diversion.Later)):
|
||||||
for c in rule_component.components:
|
for c in rule_component.components:
|
||||||
ed = editable or (isinstance(c, _DIV.Rule) and c.source is not None)
|
ed = editable or (isinstance(c, diversion.Rule) and c.source is not None)
|
||||||
_populate_model(model, piter, c, level + 1, editable=ed)
|
_populate_model(model, piter, c, level + 1, editable=ed)
|
||||||
if len(rule_component.components) == 0:
|
if len(rule_component.components) == 0:
|
||||||
_populate_model(model, piter, None, level + 1, editable=editable)
|
_populate_model(model, piter, None, level + 1, editable=editable)
|
||||||
elif isinstance(rule_component, _DIV.Not):
|
elif isinstance(rule_component, diversion.Not):
|
||||||
_populate_model(model, piter, rule_component.component, level + 1, editable=editable)
|
_populate_model(model, piter, rule_component.component, level + 1, editable=editable)
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,13 +177,13 @@ def allowed_actions(m: Gtk.TreeStore, it: Gtk.TreeIter) -> AllowedActions:
|
||||||
parent_c = m[parent_it][0].component if wrapped.level > 0 else None
|
parent_c = m[parent_it][0].component if wrapped.level > 0 else None
|
||||||
|
|
||||||
can_wrap = wrapped.editable and wrapped.component is not None and wrapped.level >= 2
|
can_wrap = wrapped.editable and wrapped.component is not None and wrapped.level >= 2
|
||||||
can_delete = wrapped.editable and not isinstance(parent_c, _DIV.Not) and c is not None and wrapped.level >= 1
|
can_delete = wrapped.editable and not isinstance(parent_c, diversion.Not) and c is not None and wrapped.level >= 1
|
||||||
can_insert = wrapped.editable and not isinstance(parent_c, _DIV.Not) and wrapped.level >= 2
|
can_insert = wrapped.editable and not isinstance(parent_c, diversion.Not) and wrapped.level >= 2
|
||||||
can_insert_only_rule = wrapped.editable and wrapped.level == 1
|
can_insert_only_rule = wrapped.editable and wrapped.level == 1
|
||||||
can_flatten = (
|
can_flatten = (
|
||||||
wrapped.editable
|
wrapped.editable
|
||||||
and not isinstance(parent_c, _DIV.Not)
|
and not isinstance(parent_c, diversion.Not)
|
||||||
and isinstance(c, (_DIV.Rule, _DIV.And, _DIV.Or))
|
and isinstance(c, (diversion.Rule, diversion.And, diversion.Or))
|
||||||
and wrapped.level >= 2
|
and wrapped.level >= 2
|
||||||
and len(c.components)
|
and len(c.components)
|
||||||
)
|
)
|
||||||
|
@ -242,7 +242,7 @@ class ActionMenu:
|
||||||
p2 = self._menu_paste(m, it, below=True)
|
p2 = self._menu_paste(m, it, below=True)
|
||||||
p2.set_label(_("Paste below"))
|
p2.set_label(_("Paste below"))
|
||||||
menu.append(p2)
|
menu.append(p2)
|
||||||
elif enabled_actions.insert_only_rule and isinstance(_rule_component_clipboard, _DIV.Rule):
|
elif enabled_actions.insert_only_rule and isinstance(_rule_component_clipboard, diversion.Rule):
|
||||||
p = self._menu_paste(m, it)
|
p = self._menu_paste(m, it)
|
||||||
menu.append(p)
|
menu.append(p)
|
||||||
if enabled_actions.c is None:
|
if enabled_actions.c is None:
|
||||||
|
@ -252,7 +252,7 @@ class ActionMenu:
|
||||||
p2 = self._menu_paste(m, it, below=True)
|
p2 = self._menu_paste(m, it, below=True)
|
||||||
p2.set_label(_("Paste rule below"))
|
p2.set_label(_("Paste rule below"))
|
||||||
menu.append(p2)
|
menu.append(p2)
|
||||||
elif enabled_actions.insert_root and isinstance(_rule_component_clipboard, _DIV.Rule):
|
elif enabled_actions.insert_root and isinstance(_rule_component_clipboard, diversion.Rule):
|
||||||
p = self._menu_paste(m, m.iter_nth_child(it, 0))
|
p = self._menu_paste(m, m.iter_nth_child(it, 0))
|
||||||
p.set_label(_("Paste rule"))
|
p.set_label(_("Paste rule"))
|
||||||
menu.append(p)
|
menu.append(p)
|
||||||
|
@ -296,7 +296,7 @@ class ActionMenu:
|
||||||
parent_it = m.iter_parent(it)
|
parent_it = m.iter_parent(it)
|
||||||
parent_c = m[parent_it][0].component
|
parent_c = m[parent_it][0].component
|
||||||
idx = parent_c.components.index(c)
|
idx = parent_c.components.index(c)
|
||||||
if isinstance(c, _DIV.Not):
|
if isinstance(c, diversion.Not):
|
||||||
parent_c.components = [*parent_c.components[:idx], c.component, *parent_c.components[idx + 1 :]]
|
parent_c.components = [*parent_c.components[:idx], c.component, *parent_c.components[idx + 1 :]]
|
||||||
children = [next(m[it].iterchildren())[0].component]
|
children = [next(m[it].iterchildren())[0].component]
|
||||||
else:
|
else:
|
||||||
|
@ -324,8 +324,8 @@ class ActionMenu:
|
||||||
idx = 0
|
idx = 0
|
||||||
else:
|
else:
|
||||||
idx = parent_c.components.index(c)
|
idx = parent_c.components.index(c)
|
||||||
if isinstance(new_c, _DIV.Rule) and wrapped.level == 1:
|
if isinstance(new_c, diversion.Rule) and wrapped.level == 1:
|
||||||
new_c.source = _DIV._file_path # new rules will be saved to the YAML file
|
new_c.source = diversion._file_path # new rules will be saved to the YAML file
|
||||||
idx += int(below)
|
idx += int(below)
|
||||||
parent_c.components.insert(idx, new_c)
|
parent_c.components.insert(idx, new_c)
|
||||||
self._populate_model_func(m, parent_it, new_c, level=wrapped.level, pos=idx)
|
self._populate_model_func(m, parent_it, new_c, level=wrapped.level, pos=idx)
|
||||||
|
@ -334,7 +334,7 @@ class ActionMenu:
|
||||||
m.remove(it) # remove placeholder in the end
|
m.remove(it) # remove placeholder in the end
|
||||||
new_iter = m.iter_nth_child(parent_it, idx)
|
new_iter = m.iter_nth_child(parent_it, idx)
|
||||||
self.tree_view.get_selection().select_iter(new_iter)
|
self.tree_view.get_selection().select_iter(new_iter)
|
||||||
if isinstance(new_c, (_DIV.Rule, _DIV.And, _DIV.Or, _DIV.Not)):
|
if isinstance(new_c, (diversion.Rule, diversion.And, diversion.Or, diversion.Not)):
|
||||||
self.tree_view.expand_row(m.get_path(new_iter), True)
|
self.tree_view.expand_row(m.get_path(new_iter), True)
|
||||||
|
|
||||||
def _menu_do_insert_new(self, _mitem, m, it, cls, initial_value, below=False):
|
def _menu_do_insert_new(self, _mitem, m, it, cls, initial_value, below=False):
|
||||||
|
@ -345,37 +345,37 @@ class ActionMenu:
|
||||||
elements = [
|
elements = [
|
||||||
_("Insert"),
|
_("Insert"),
|
||||||
[
|
[
|
||||||
(_("Sub-rule"), _DIV.Rule, []),
|
(_("Sub-rule"), diversion.Rule, []),
|
||||||
(_("Or"), _DIV.Or, []),
|
(_("Or"), diversion.Or, []),
|
||||||
(_("And"), _DIV.And, []),
|
(_("And"), diversion.And, []),
|
||||||
[
|
[
|
||||||
_("Condition"),
|
_("Condition"),
|
||||||
[
|
[
|
||||||
(_("Feature"), _DIV.Feature, rule_conditions.FeatureUI.FEATURES_WITH_DIVERSION[0]),
|
(_("Feature"), diversion.Feature, rule_conditions.FeatureUI.FEATURES_WITH_DIVERSION[0]),
|
||||||
(_("Report"), _DIV.Report, 0),
|
(_("Report"), diversion.Report, 0),
|
||||||
(_("Process"), _DIV.Process, ""),
|
(_("Process"), diversion.Process, ""),
|
||||||
(_("Mouse process"), _DIV.MouseProcess, ""),
|
(_("Mouse process"), diversion.MouseProcess, ""),
|
||||||
(_("Modifiers"), _DIV.Modifiers, []),
|
(_("Modifiers"), diversion.Modifiers, []),
|
||||||
(_("Key"), _DIV.Key, ""),
|
(_("Key"), diversion.Key, ""),
|
||||||
(_("KeyIsDown"), _DIV.KeyIsDown, ""),
|
(_("KeyIsDown"), diversion.KeyIsDown, ""),
|
||||||
(_("Active"), _DIV.Active, ""),
|
(_("Active"), diversion.Active, ""),
|
||||||
(_("Device"), _DIV.Device, ""),
|
(_("Device"), diversion.Device, ""),
|
||||||
(_("Host"), _DIV.Host, ""),
|
(_("Host"), diversion.Host, ""),
|
||||||
(_("Setting"), _DIV.Setting, [None, "", None]),
|
(_("Setting"), diversion.Setting, [None, "", None]),
|
||||||
(_("Test"), _DIV.Test, next(iter(_DIV.TESTS))),
|
(_("Test"), diversion.Test, next(iter(diversion.TESTS))),
|
||||||
(_("Test bytes"), _DIV.TestBytes, [0, 1, 0]),
|
(_("Test bytes"), diversion.TestBytes, [0, 1, 0]),
|
||||||
(_("Mouse Gesture"), _DIV.MouseGesture, ""),
|
(_("Mouse Gesture"), diversion.MouseGesture, ""),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
_("Action"),
|
_("Action"),
|
||||||
[
|
[
|
||||||
(_("Key press"), _DIV.KeyPress, "space"),
|
(_("Key press"), diversion.KeyPress, "space"),
|
||||||
(_("Mouse scroll"), _DIV.MouseScroll, [0, 0]),
|
(_("Mouse scroll"), diversion.MouseScroll, [0, 0]),
|
||||||
(_("Mouse click"), _DIV.MouseClick, ["left", 1]),
|
(_("Mouse click"), diversion.MouseClick, ["left", 1]),
|
||||||
(_("Set"), _DIV.Set, [None, "", None]),
|
(_("Set"), diversion.Set, [None, "", None]),
|
||||||
(_("Execute"), _DIV.Execute, [""]),
|
(_("Execute"), diversion.Execute, [""]),
|
||||||
(_("Later"), _DIV.Later, [1]),
|
(_("Later"), diversion.Later, [1]),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -405,7 +405,7 @@ class ActionMenu:
|
||||||
|
|
||||||
def _menu_create_rule(self, m, it, below=False) -> Gtk.MenuItem:
|
def _menu_create_rule(self, m, it, below=False) -> Gtk.MenuItem:
|
||||||
menu_create_rule = Gtk.MenuItem(_("Insert new rule"))
|
menu_create_rule = Gtk.MenuItem(_("Insert new rule"))
|
||||||
menu_create_rule.connect("activate", self._menu_do_insert_new, m, it, _DIV.Rule, [], below)
|
menu_create_rule.connect("activate", self._menu_do_insert_new, m, it, diversion.Rule, [], below)
|
||||||
menu_create_rule.show()
|
menu_create_rule.show()
|
||||||
return menu_create_rule
|
return menu_create_rule
|
||||||
|
|
||||||
|
@ -434,14 +434,14 @@ class ActionMenu:
|
||||||
c = wrapped.component
|
c = wrapped.component
|
||||||
parent_it = m.iter_parent(it)
|
parent_it = m.iter_parent(it)
|
||||||
parent_c = m[parent_it][0].component
|
parent_c = m[parent_it][0].component
|
||||||
if isinstance(c, _DIV.Not): # avoid double negation
|
if isinstance(c, diversion.Not): # avoid double negation
|
||||||
self.menu_do_flatten(_mitem, m, it)
|
self.menu_do_flatten(_mitem, m, it)
|
||||||
self.tree_view.expand_row(m.get_path(parent_it), True)
|
self.tree_view.expand_row(m.get_path(parent_it), True)
|
||||||
elif isinstance(parent_c, _DIV.Not): # avoid double negation
|
elif isinstance(parent_c, diversion.Not): # avoid double negation
|
||||||
self.menu_do_flatten(_mitem, m, parent_it)
|
self.menu_do_flatten(_mitem, m, parent_it)
|
||||||
else:
|
else:
|
||||||
idx = parent_c.components.index(c)
|
idx = parent_c.components.index(c)
|
||||||
self._menu_do_insert_new(_mitem, m, it, _DIV.Not, c, below=True)
|
self._menu_do_insert_new(_mitem, m, it, diversion.Not, c, below=True)
|
||||||
self.menu_do_delete(_mitem, m, m.iter_nth_child(parent_it, idx))
|
self.menu_do_delete(_mitem, m, m.iter_nth_child(parent_it, idx))
|
||||||
self._on_update()
|
self._on_update()
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ class ActionMenu:
|
||||||
c = wrapped.component
|
c = wrapped.component
|
||||||
parent_it = m.iter_parent(it)
|
parent_it = m.iter_parent(it)
|
||||||
parent_c = m[parent_it][0].component
|
parent_c = m[parent_it][0].component
|
||||||
if isinstance(parent_c, _DIV.Not):
|
if isinstance(parent_c, diversion.Not):
|
||||||
new_c = cls([c], warn=False)
|
new_c = cls([c], warn=False)
|
||||||
parent_c.component = new_c
|
parent_c.component = new_c
|
||||||
m.remove(it)
|
m.remove(it)
|
||||||
|
@ -475,9 +475,9 @@ class ActionMenu:
|
||||||
menu_sub_rule = Gtk.MenuItem(_("Sub-rule"))
|
menu_sub_rule = Gtk.MenuItem(_("Sub-rule"))
|
||||||
menu_and = Gtk.MenuItem(_("And"))
|
menu_and = Gtk.MenuItem(_("And"))
|
||||||
menu_or = Gtk.MenuItem(_("Or"))
|
menu_or = Gtk.MenuItem(_("Or"))
|
||||||
menu_sub_rule.connect("activate", self.menu_do_wrap, m, it, _DIV.Rule)
|
menu_sub_rule.connect("activate", self.menu_do_wrap, m, it, diversion.Rule)
|
||||||
menu_and.connect("activate", self.menu_do_wrap, m, it, _DIV.And)
|
menu_and.connect("activate", self.menu_do_wrap, m, it, diversion.And)
|
||||||
menu_or.connect("activate", self.menu_do_wrap, m, it, _DIV.Or)
|
menu_or.connect("activate", self.menu_do_wrap, m, it, diversion.Or)
|
||||||
submenu_wrap.append(menu_sub_rule)
|
submenu_wrap.append(menu_sub_rule)
|
||||||
submenu_wrap.append(menu_and)
|
submenu_wrap.append(menu_and)
|
||||||
submenu_wrap.append(menu_or)
|
submenu_wrap.append(menu_or)
|
||||||
|
@ -490,7 +490,7 @@ class ActionMenu:
|
||||||
|
|
||||||
wrapped = m[it][0]
|
wrapped = m[it][0]
|
||||||
c = wrapped.component
|
c = wrapped.component
|
||||||
_rule_component_clipboard = _DIV.RuleComponent().compile(c.data())
|
_rule_component_clipboard = diversion.RuleComponent().compile(c.data())
|
||||||
|
|
||||||
def menu_do_cut(self, _mitem, m, it):
|
def menu_do_cut(self, _mitem, m, it):
|
||||||
global _rule_component_clipboard
|
global _rule_component_clipboard
|
||||||
|
@ -511,7 +511,7 @@ class ActionMenu:
|
||||||
c = _rule_component_clipboard
|
c = _rule_component_clipboard
|
||||||
_rule_component_clipboard = None
|
_rule_component_clipboard = None
|
||||||
if c:
|
if c:
|
||||||
_rule_component_clipboard = _DIV.RuleComponent().compile(c.data())
|
_rule_component_clipboard = diversion.RuleComponent().compile(c.data())
|
||||||
self._menu_do_insert(_mitem, m, it, new_c=c, below=below)
|
self._menu_do_insert(_mitem, m, it, new_c=c, below=below)
|
||||||
self._on_update()
|
self._on_update()
|
||||||
|
|
||||||
|
@ -604,13 +604,13 @@ class DiversionDialog:
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
for c in self.selected_rule_edit_panel.get_children():
|
for c in self.selected_rule_edit_panel.get_children():
|
||||||
self.selected_rule_edit_panel.remove(c)
|
self.selected_rule_edit_panel.remove(c)
|
||||||
_DIV.load_config_rule_file()
|
diversion.load_config_rule_file()
|
||||||
self.model = self._create_model()
|
self.model = self._create_model()
|
||||||
self.view.set_model(self.model)
|
self.view.set_model(self.model)
|
||||||
self.view.expand_all()
|
self.view.expand_all()
|
||||||
|
|
||||||
def _save_yaml_file(self):
|
def _save_yaml_file(self):
|
||||||
if _DIV._save_config_rule_file():
|
if diversion._save_config_rule_file():
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
self.save_btn.set_sensitive(False)
|
self.save_btn.set_sensitive(False)
|
||||||
self.discard_btn.set_sensitive(False)
|
self.discard_btn.set_sensitive(False)
|
||||||
|
@ -656,10 +656,10 @@ class DiversionDialog:
|
||||||
|
|
||||||
def _create_model(self):
|
def _create_model(self):
|
||||||
model = Gtk.TreeStore(RuleComponentWrapper)
|
model = Gtk.TreeStore(RuleComponentWrapper)
|
||||||
if len(_DIV.rules.components) == 1:
|
if len(diversion.rules.components) == 1:
|
||||||
# only built-in rules - add empty user rule list
|
# only built-in rules - add empty user rule list
|
||||||
_DIV.rules.components.insert(0, _DIV.Rule([], source=_DIV._file_path))
|
diversion.rules.components.insert(0, diversion.Rule([], source=diversion._file_path))
|
||||||
_populate_model(model, None, _DIV.rules.components)
|
_populate_model(model, None, diversion.rules.components)
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def _create_view_columns(self):
|
def _create_view_columns(self):
|
||||||
|
@ -725,7 +725,7 @@ class DiversionDialog:
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
enabled_actions.insert_only_rule
|
enabled_actions.insert_only_rule
|
||||||
and isinstance(_rule_component_clipboard, _DIV.Rule)
|
and isinstance(_rule_component_clipboard, diversion.Rule)
|
||||||
and e.keyval in [Gdk.KEY_v, Gdk.KEY_V]
|
and e.keyval in [Gdk.KEY_v, Gdk.KEY_V]
|
||||||
):
|
):
|
||||||
self._action_menu.menu_do_paste(
|
self._action_menu.menu_do_paste(
|
||||||
|
@ -733,7 +733,7 @@ class DiversionDialog:
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
enabled_actions.insert_root
|
enabled_actions.insert_root
|
||||||
and isinstance(_rule_component_clipboard, _DIV.Rule)
|
and isinstance(_rule_component_clipboard, diversion.Rule)
|
||||||
and e.keyval in [Gdk.KEY_v, Gdk.KEY_V]
|
and e.keyval in [Gdk.KEY_v, Gdk.KEY_V]
|
||||||
):
|
):
|
||||||
self._action_menu.menu_do_paste(None, m, m.iter_nth_child(it, 0))
|
self._action_menu.menu_do_paste(None, m, m.iter_nth_child(it, 0))
|
||||||
|
@ -760,11 +760,11 @@ class DiversionDialog:
|
||||||
if e.keyval == Gdk.KEY_exclam:
|
if e.keyval == Gdk.KEY_exclam:
|
||||||
self._action_menu.menu_do_negate(None, m, it)
|
self._action_menu.menu_do_negate(None, m, it)
|
||||||
elif e.keyval == Gdk.KEY_ampersand:
|
elif e.keyval == Gdk.KEY_ampersand:
|
||||||
self._action_menu.menu_do_wrap(None, m, it, _DIV.And)
|
self._action_menu.menu_do_wrap(None, m, it, diversion.And)
|
||||||
elif e.keyval == Gdk.KEY_bar:
|
elif e.keyval == Gdk.KEY_bar:
|
||||||
self._action_menu.menu_do_wrap(None, m, it, _DIV.Or)
|
self._action_menu.menu_do_wrap(None, m, it, diversion.Or)
|
||||||
elif e.keyval in [Gdk.KEY_r, Gdk.KEY_R] and (state & Gdk.ModifierType.SHIFT_MASK):
|
elif e.keyval in [Gdk.KEY_r, Gdk.KEY_R] and (state & Gdk.ModifierType.SHIFT_MASK):
|
||||||
self._action_menu.menu_do_wrap(None, m, it, _DIV.Rule)
|
self._action_menu.menu_do_wrap(None, m, it, diversion.Rule)
|
||||||
if enabled_actions.flatten and e.keyval in [Gdk.KEY_asterisk, Gdk.KEY_KP_Multiply]:
|
if enabled_actions.flatten and e.keyval in [Gdk.KEY_asterisk, Gdk.KEY_KP_Multiply]:
|
||||||
self._action_menu.menu_do_flatten(None, m, it)
|
self._action_menu.menu_do_flatten(None, m, it)
|
||||||
|
|
||||||
|
@ -1076,7 +1076,7 @@ class UnsupportedRuleComponentUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class RuleUI(RuleComponentUI):
|
class RuleUI(RuleComponentUI):
|
||||||
CLASS = _DIV.Rule
|
CLASS = diversion.Rule
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
@ -1094,7 +1094,7 @@ class RuleUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class AndUI(RuleComponentUI):
|
class AndUI(RuleComponentUI):
|
||||||
CLASS = _DIV.And
|
CLASS = diversion.And
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
@ -1108,7 +1108,7 @@ class AndUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class OrUI(RuleComponentUI):
|
class OrUI(RuleComponentUI):
|
||||||
CLASS = _DIV.Or
|
CLASS = diversion.Or
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
@ -1122,7 +1122,7 @@ class OrUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class LaterUI(RuleComponentUI):
|
class LaterUI(RuleComponentUI):
|
||||||
CLASS = _DIV.Later
|
CLASS = diversion.Later
|
||||||
MIN_VALUE = 0.01
|
MIN_VALUE = 0.01
|
||||||
MAX_VALUE = 100
|
MAX_VALUE = 100
|
||||||
|
|
||||||
|
@ -1157,7 +1157,7 @@ class LaterUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class NotUI(RuleComponentUI):
|
class NotUI(RuleComponentUI):
|
||||||
CLASS = _DIV.Not
|
CLASS = diversion.Not
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
@ -1171,7 +1171,7 @@ class NotUI(RuleComponentUI):
|
||||||
|
|
||||||
|
|
||||||
class ActionUI(RuleComponentUI):
|
class ActionUI(RuleComponentUI):
|
||||||
CLASS = _DIV.Action
|
CLASS = diversion.Action
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def icon_name(cls):
|
def icon_name(cls):
|
||||||
|
@ -1335,9 +1335,9 @@ class SetValueControl(Gtk.HBox):
|
||||||
self.unsupported_label.show()
|
self.unsupported_label.show()
|
||||||
|
|
||||||
|
|
||||||
def _all_settings():
|
def create_all_settings(all_settings: list[Setting]) -> dict[str, Setting]:
|
||||||
settings = {}
|
settings = {}
|
||||||
for s in sorted(SETTINGS, key=lambda setting: setting.label):
|
for s in sorted(all_settings, key=lambda setting: setting.label):
|
||||||
if s.name not in settings:
|
if s.name not in settings:
|
||||||
settings[s.name] = [s]
|
settings[s.name] = [s]
|
||||||
else:
|
else:
|
||||||
|
@ -1406,7 +1406,7 @@ class _DeviceUI:
|
||||||
|
|
||||||
|
|
||||||
class ActiveUI(_DeviceUI, ConditionUI):
|
class ActiveUI(_DeviceUI, ConditionUI):
|
||||||
CLASS = _DIV.Active
|
CLASS = diversion.Active
|
||||||
label_text = _("Device is active and its settings can be changed.")
|
label_text = _("Device is active and its settings can be changed.")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1415,7 +1415,7 @@ class ActiveUI(_DeviceUI, ConditionUI):
|
||||||
|
|
||||||
|
|
||||||
class DeviceUI(_DeviceUI, ConditionUI):
|
class DeviceUI(_DeviceUI, ConditionUI):
|
||||||
CLASS = _DIV.Device
|
CLASS = diversion.Device
|
||||||
label_text = _("Device that originated the current notification.")
|
label_text = _("Device that originated the current notification.")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1424,7 +1424,7 @@ class DeviceUI(_DeviceUI, ConditionUI):
|
||||||
|
|
||||||
|
|
||||||
class HostUI(ConditionUI):
|
class HostUI(ConditionUI):
|
||||||
CLASS = _DIV.Host
|
CLASS = diversion.Host
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
|
@ -1454,7 +1454,7 @@ class HostUI(ConditionUI):
|
||||||
|
|
||||||
|
|
||||||
class _SettingWithValueUI:
|
class _SettingWithValueUI:
|
||||||
ALL_SETTINGS = _all_settings()
|
ALL_SETTINGS = create_all_settings(SETTINGS)
|
||||||
MULTIPLE = [Kind.MULTIPLE_TOGGLE, Kind.MAP_CHOICE, Kind.MULTIPLE_RANGE]
|
MULTIPLE = [Kind.MULTIPLE_TOGGLE, Kind.MAP_CHOICE, Kind.MULTIPLE_RANGE]
|
||||||
ACCEPT_TOGGLE = True
|
ACCEPT_TOGGLE = True
|
||||||
|
|
||||||
|
@ -1785,7 +1785,7 @@ class _SettingWithValueUI:
|
||||||
|
|
||||||
|
|
||||||
class SetUI(_SettingWithValueUI, ActionUI):
|
class SetUI(_SettingWithValueUI, ActionUI):
|
||||||
CLASS = _DIV.Set
|
CLASS = diversion.Set
|
||||||
ACCEPT_TOGGLE = True
|
ACCEPT_TOGGLE = True
|
||||||
|
|
||||||
label_text = _("Change setting on device")
|
label_text = _("Change setting on device")
|
||||||
|
@ -1801,7 +1801,7 @@ class SetUI(_SettingWithValueUI, ActionUI):
|
||||||
|
|
||||||
|
|
||||||
class SettingUI(_SettingWithValueUI, ConditionUI):
|
class SettingUI(_SettingWithValueUI, ConditionUI):
|
||||||
CLASS = _DIV.Setting
|
CLASS = diversion.Setting
|
||||||
ACCEPT_TOGGLE = False
|
ACCEPT_TOGGLE = False
|
||||||
|
|
||||||
label_text = _("Setting on device")
|
label_text = _("Setting on device")
|
||||||
|
@ -1817,30 +1817,30 @@ class SettingUI(_SettingWithValueUI, ConditionUI):
|
||||||
|
|
||||||
|
|
||||||
COMPONENT_UI = {
|
COMPONENT_UI = {
|
||||||
_DIV.Rule: RuleUI,
|
diversion.Rule: RuleUI,
|
||||||
_DIV.Not: NotUI,
|
diversion.Not: NotUI,
|
||||||
_DIV.Or: OrUI,
|
diversion.Or: OrUI,
|
||||||
_DIV.And: AndUI,
|
diversion.And: AndUI,
|
||||||
_DIV.Later: LaterUI,
|
diversion.Later: LaterUI,
|
||||||
_DIV.Process: rule_conditions.ProcessUI,
|
diversion.Process: rule_conditions.ProcessUI,
|
||||||
_DIV.MouseProcess: rule_conditions.MouseProcessUI,
|
diversion.MouseProcess: rule_conditions.MouseProcessUI,
|
||||||
_DIV.Active: ActiveUI,
|
diversion.Active: ActiveUI,
|
||||||
_DIV.Device: DeviceUI,
|
diversion.Device: DeviceUI,
|
||||||
_DIV.Host: HostUI,
|
diversion.Host: HostUI,
|
||||||
_DIV.Feature: rule_conditions.FeatureUI,
|
diversion.Feature: rule_conditions.FeatureUI,
|
||||||
_DIV.Report: rule_conditions.ReportUI,
|
diversion.Report: rule_conditions.ReportUI,
|
||||||
_DIV.Modifiers: rule_conditions.ModifiersUI,
|
diversion.Modifiers: rule_conditions.ModifiersUI,
|
||||||
_DIV.Key: rule_conditions.KeyUI,
|
diversion.Key: rule_conditions.KeyUI,
|
||||||
_DIV.KeyIsDown: rule_conditions.KeyIsDownUI,
|
diversion.KeyIsDown: rule_conditions.KeyIsDownUI,
|
||||||
_DIV.Test: rule_conditions.TestUI,
|
diversion.Test: rule_conditions.TestUI,
|
||||||
_DIV.TestBytes: rule_conditions.TestBytesUI,
|
diversion.TestBytes: rule_conditions.TestBytesUI,
|
||||||
_DIV.Setting: SettingUI,
|
diversion.Setting: SettingUI,
|
||||||
_DIV.MouseGesture: rule_conditions.MouseGestureUI,
|
diversion.MouseGesture: rule_conditions.MouseGestureUI,
|
||||||
_DIV.KeyPress: rule_actions.KeyPressUI,
|
diversion.KeyPress: rule_actions.KeyPressUI,
|
||||||
_DIV.MouseScroll: rule_actions.MouseScrollUI,
|
diversion.MouseScroll: rule_actions.MouseScrollUI,
|
||||||
_DIV.MouseClick: rule_actions.MouseClickUI,
|
diversion.MouseClick: rule_actions.MouseClickUI,
|
||||||
_DIV.Execute: rule_actions.ExecuteUI,
|
diversion.Execute: rule_actions.ExecuteUI,
|
||||||
_DIV.Set: SetUI,
|
diversion.Set: SetUI,
|
||||||
type(None): RuleComponentUI, # placeholders for empty rule/And/Or
|
type(None): RuleComponentUI, # placeholders for empty rule/And/Or
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue