Robot Framework Integrated Development Environment (RIDE)
action.py
Go to the documentation of this file.
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.
15 
16 
17 def ActionFactory(action_info):
18  if action_info.is_separator():
19  return _MenuSeparator(action_info)
20  return Action(action_info)
21 
22 
23 class _Registrable():
24 
25  def __init__(self, action_info):
26  self._registered_to_registered_to = []
27  self.actionaction = None
28  self.shortcutshortcut = None
29  self.iconicon = None
30  self._insertion_point_insertion_point = action_info.insertion_point
31  self._enabled_enabled = True
32  self._enabled_status_listeners_enabled_status_listeners = []
33 
34  disable = enable = lambda event: None
35 
36  def is_separator(self):
37  return False
38 
39  def get_insertion_index(self, menu):
40  return self._insertion_point_insertion_point.get_index(menu)
41 
42  def register(self, registerer):
43  self._registered_to_registered_to.append(registerer)
44 
45  def unregister(self):
46  for registerer in self._registered_to_registered_to:
47  registerer.unregister(self)
48  self._registered_to_registered_to = []
49 
50  def has_action(self):
51  return self.actionaction is not None
52 
53  def has_shortcut(self):
54  return bool(self.shortcutshortcut)
55 
56  def has_icon(self):
57  return self.iconicon is not None
58 
59  def inform_changes_in_enabled_status(self, listener):
60  self._enabled_status_listeners_enabled_status_listeners.append(listener)
61 
62 
63 
72 
73  def __init__(self, action_info):
74  _Registrable.__init__(self, action_info)
75  self.menu_namemenu_name = action_info.menu_name
76  self.namename = action_info.name
77  self.actionactionaction = action_info.action
78  self.containercontainer = action_info.container
79  self.shortcutshortcutshortcut = action_info.shortcut
80  self.iconiconicon = action_info.icon
81  self.docdoc = action_info.doc
82  # print("DEBUG: Action: %s::%s" % (self.menu_name,self.name))
83 
84  def get_shortcut(self):
85  return self.shortcutshortcutshortcut.printable
86 
87  def act(self, event):
88  if self.is_activeis_active():
89  self.actionactionaction(event)
90 
91 
92  def disable(self):
93  self._enabled_enabled_enabled = False
94  self._inform_changes_in_enabled_status_inform_changes_in_enabled_status()
95 
96 
97  def enable(self):
98  self._enabled_enabled_enabled = True
99  self._inform_changes_in_enabled_status_inform_changes_in_enabled_status()
100 
102  for listener in self._enabled_status_listeners_enabled_status_listeners:
103  listener.enabled_status_changed(self)
104 
105  def is_active(self):
106  if self._is_always_inactive_is_always_inactive() or not self._enabled_enabled_enabled:
107  return False
108  if self._is_always_active_is_always_active():
109  return True
110  return self._container_is_active_container_is_active()
111 
113  return self.actionactionaction is None
114 
115  def _is_always_active(self):
116  return self.containercontainer is None
117 
119  if not self.containercontainer.IsShownOnScreen():
120  return False
121  widget = self.containercontainer.FindFocus()
122  while widget:
123  if widget == self.containercontainer.Parent:
124  return True
125  widget = widget.GetParent()
126  return False
127 
128 
130 
131  def __init__(self, action_info):
132  _Registrable.__init__(self, action_info)
133  self.menu_namemenu_name = action_info.menu_name
134  self.namename = '---'
135 
136  def is_separator(self):
137  return True
Acts based on user actions if action is enabled.
Definition: action.py:71
def enable(self)
Enables action and related menu item, toolbar button and shortcut.
Definition: action.py:97
def __init__(self, action_info)
Definition: action.py:73
def act(self, event)
Definition: action.py:87
def _container_is_active(self)
Definition: action.py:118
def _inform_changes_in_enabled_status(self)
Definition: action.py:101
def __init__(self, action_info)
Definition: action.py:131
def inform_changes_in_enabled_status(self, listener)
Definition: action.py:59
def get_insertion_index(self, menu)
Definition: action.py:39
def __init__(self, action_info)
Definition: action.py:25
def register(self, registerer)
Definition: action.py:42
def ActionFactory(action_info)
Definition: action.py:17