Enforce rules on RuleComponentUI subclasses
Enforce create_widgets and collect_values. Related #2273
This commit is contained in:
parent
dd13993ff3
commit
8bc42d20fb
|
@ -1818,7 +1818,7 @@ class SettingUI(_SettingWithValueUI, ConditionUI):
|
||||||
_SettingWithValueUI._on_update(self, *_args)
|
_SettingWithValueUI._on_update(self, *_args)
|
||||||
|
|
||||||
|
|
||||||
COMPONENT_UI = {
|
COMPONENT_UI: dict[Any, RuleComponentUI] = {
|
||||||
diversion.Rule: RuleUI,
|
diversion.Rule: RuleUI,
|
||||||
diversion.Not: NotUI,
|
diversion.Not: NotUI,
|
||||||
diversion.Or: OrUI,
|
diversion.Or: OrUI,
|
||||||
|
@ -1843,7 +1843,7 @@ COMPONENT_UI = {
|
||||||
diversion.MouseClick: rule_actions.MouseClickUI,
|
diversion.MouseClick: rule_actions.MouseClickUI,
|
||||||
diversion.Execute: rule_actions.ExecuteUI,
|
diversion.Execute: rule_actions.ExecuteUI,
|
||||||
diversion.Set: SetUI,
|
diversion.Set: SetUI,
|
||||||
type(None): RuleComponentUI, # placeholders for empty rule/And/Or
|
# type(None): RuleComponentUI, # placeholders for empty rule/And/Or
|
||||||
}
|
}
|
||||||
|
|
||||||
_all_devices = AllDevicesInfo()
|
_all_devices = AllDevicesInfo()
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
## You should have received a copy of the GNU General Public License along
|
## You should have received a copy of the GNU General Public License along
|
||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
import abc
|
||||||
|
|
||||||
from contextlib import contextmanager as contextlib_contextmanager
|
from contextlib import contextmanager as contextlib_contextmanager
|
||||||
|
from typing import Any
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
@ -47,7 +49,7 @@ class CompletionEntry(Gtk.Entry):
|
||||||
liststore.append((v,))
|
liststore.append((v,))
|
||||||
|
|
||||||
|
|
||||||
class RuleComponentUI:
|
class RuleComponentUI(abc.ABC):
|
||||||
CLASS = diversion.RuleComponent
|
CLASS = diversion.RuleComponent
|
||||||
|
|
||||||
def __init__(self, panel, on_update: Callable = None):
|
def __init__(self, panel, on_update: Callable = None):
|
||||||
|
@ -58,15 +60,17 @@ class RuleComponentUI:
|
||||||
self._on_update_callback = (lambda: None) if on_update is None else on_update
|
self._on_update_callback = (lambda: None) if on_update is None else on_update
|
||||||
self.create_widgets()
|
self.create_widgets()
|
||||||
|
|
||||||
def create_widgets(self):
|
@abc.abstractmethod
|
||||||
|
def create_widgets(self) -> dict:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def show(self, component, editable=True):
|
def show(self, component, editable=True):
|
||||||
self._show_widgets(editable)
|
self._show_widgets(editable)
|
||||||
self.component = component
|
self.component = component
|
||||||
|
|
||||||
def collect_value(self):
|
@abc.abstractmethod
|
||||||
return None
|
def collect_value(self) -> Any:
|
||||||
|
pass
|
||||||
|
|
||||||
@contextlib_contextmanager
|
@contextlib_contextmanager
|
||||||
def ignore_changes(self):
|
def ignore_changes(self):
|
||||||
|
@ -105,5 +109,5 @@ class RuleComponentUI:
|
||||||
for c in self.panel.get_children():
|
for c in self.panel.get_children():
|
||||||
self.panel.remove(c)
|
self.panel.remove(c)
|
||||||
|
|
||||||
def update_devices(self):
|
def update_devices(self): # noqa: B027
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue