Coverage for src/robotide/pluginapi/tree_aware_plugin_mixin.py: 75%
24 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
1# Copyright 2008-2015 Nokia Networks
2# Copyright 2016- Robot Framework Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16from ..publish.messages import RideTreeAwarePluginAdded 1ab
19class TreeAwarePluginMixin(object): 1ab
20 """
21 Mixin to help solve if tree aware plugin has focus
23 The plugin that inherits this Mixin must be a Plugin and also it must
24 offer a method #is_focused -> bool
26 To properly initialize this Mixin the Plugin in question must
27 #add_self_as_tree_aware_plugin
29 To properly teardown this Mixin the Plugin in question must
30 #remove_self_from_tree_aware_plugins
32 To check if one of the other three aware plugins has focus
33 #is_focus_on_tree_aware_plugin
35 NOTE: Could be used for more generic purpose for grouping
36 plugins and interacting with them
37 """
39 _tree_aware_plugins_set = None 1ab
41 def is_focus_on_tree_aware_plugin(self): 1ab
42 return any(twb.is_focused() for twb in self._tree_aware_plugins)
44 def add_self_as_tree_aware_plugin(self): 1ab
45 RideTreeAwarePluginAdded(plugin=self).publish() 1ac
46 self.subscribe(self._tree_aware_plugin_added, RideTreeAwarePluginAdded) 1ac
48 def remove_self_from_tree_aware_plugins(self): 1ab
49 self.unsubscribe(self._tree_aware_plugin_added, RideTreeAwarePluginAdded)
50 for other in self._tree_aware_plugins:
51 other.remove_tree_aware_plugin(self)
53 def add_tree_aware_plugin(self, other): 1ab
54 self._tree_aware_plugins.add(other)
56 def remove_tree_aware_plugin(self, other): 1ab
57 self._tree_aware_plugins.remove(other)
59 def _tree_aware_plugin_added(self, message): 1ab
60 self.add_tree_aware_plugin(message.plugin)
61 message.plugin.add_tree_aware_plugin(self)
63 @property 1ab
64 def _tree_aware_plugins(self): 1ab
65 if self._tree_aware_plugins_set is None:
66 self._tree_aware_plugins_set = set()
67 return self._tree_aware_plugins_set