Robot Framework Integrated Development Environment (RIDE)
plugin.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 import inspect
17 
18 import wx
19 
20 from .. import utils
21 from ..action.actioninfo import ActionInfo
22 from ..publish import PUBLISHER
23 
24 
25 
50 class Plugin():
51  tree = property(lambda self: self.__frame__frame.tree,
52  doc='Provides access to the suite and resource tree')
53  filemgr = property(lambda self: self.__frame__frame.filemgr,
54  doc='Provides access to the files and folders explorer')
55  menubar = property(lambda self: self.__frame__frame.GetMenuBar(),
56  doc='Provides access to the application menubar')
57  toolbar = property(lambda self: self.__frame__frame.GetToolBar(),
58  doc='Provides access to the application toolbar')
59  notebook = property(lambda self: self.__frame__frame.notebook,
60  doc='Provides access to the tabbed notebook')
61  model = property(lambda self: self.__app__app.model,
62  doc='Provides access to the data model')
63  frame = property(lambda self: self.__frame__frame,
64  doc='Reference to the RIDE main frame')
65  datafile = property(lambda self: self.get_selected_datafileget_selected_datafile(),
66  doc='Currently selected datafile')
67  global_settings = property(lambda self: self.__app__app.settings,
68  doc='Settings read from settings.cfg')
69 
70 
108  def __init__(self, application, name=None, doc=None, metadata=None,
109  default_settings=None, initially_enabled=True):
110  self.namename = name or utils.name_from_class(self, drop='Plugin')
111  self.docdoc = self._get_doc_get_doc(doc)
112  self.metadatametadata = metadata or {}
113  self.initially_enabledinitially_enabled = initially_enabled
114  self._save_timer_save_timer = None
115  self.__app__app = application
116  self.__frame__frame = application.frame
117  self.__namespace__namespace = application.namespace
118  self.__settings__settings = application.settings['Plugins'].add_section(self.namename)
119  self.__settings__settings.set_defaults(default_settings)
120  self.__actions__actions = []
121 
122  def _get_doc(self, given_doc):
123  if given_doc:
124  return given_doc
125  if self.__doc____doc__ == Plugin.__doc__:
126  return ''
127  return inspect.getdoc(self) or ''
128 
129 
134  def __getattr__(self, name):
135  if '__settings' not in name and self.__settings__settings.has_setting(name):
136  return self.__settings__settings[name]
137  raise AttributeError("No attribute or settings with name '%s' found" % name)
138 
139 
148  def save_setting(self, name, value, override=True, delay=0):
149  self.__settings__settings.set(name, value, autosave=delay == 0, override=override)
150  self._delay_saving_delay_saving(delay)
151 
152  def _delay_saving(self, delay):
153  if not delay:
154  return
155  delay = delay * 1000
156  if not self._save_timer_save_timer:
157  self._save_timer_save_timer = wx.CallLater(delay, self._save_setting_after_delay_save_setting_after_delay)
158  else:
159  self._save_timer_save_timer.Restart(delay)
160 
162  self.__settings__settings.save()
163  self._save_timer_save_timer = None
164 
165 
170  def enable(self):
171  pass
172 
173 
177  def disable(self):
178  pass
179 
180 
187  def config_panel(self, parent):
188  return None
189 
190 
205  def register_action(self, action_info):
206  action = self.__frame__frame.actions.register_action(action_info)
207  self.__actions__actions.append(action)
208  return action
209 
210  def register_shortcut(self, shortcut, callback):
211  action_info = ActionInfo(None, None, action=callback, shortcut=shortcut)
212  action = self.__frame__frame.actions.register_shortcut(action_info)
213  self.__actions__actions.append(action)
214  return action
215 
216 
223  def register_actions(self, action_infos):
224  return [self.register_actionregister_action(info) for info in action_infos]
225 
226  def register_search_action(self, description, handler, icon, default=False):
227  self.__frame__frame.toolbar.register_search_handler(description, handler, icon, default=default)
228 
229 
231  for action in self.__actions__actions:
232  action.unregister()
233  self.__actions__actions = []
234 
235 
240  def add_tab(self, tab, title, allow_closing=True):
241  self.notebooknotebook.add_tab(tab, title, allow_closing)
242 
243 
244  def show_tab(self, tab):
245  self.notebooknotebook.show_tab(tab)
246 
247 
248  def delete_tab(self, tab):
249  self.notebooknotebook.delete_tab(tab)
250 
251 
252  def allow_tab_closing(self, tab):
253  self.notebooknotebook.allow_closing(tab)
254 
255 
256  def disallow_tab_closing(self, tab):
257  self.notebooknotebook.disallow_closing(tab)
258 
259 
260  def tab_is_visible(self, tab):
261  return self.notebooknotebook.tab_is_visible(tab)
262 
263 
269  return self.__app__app.ok_to_open_new()
270 
271 
275  def open_suite(self, path):
276  self.__frame__frame.open_suite(path)
277 
278 
287  if not self.treetree:
288  return
289  return self.treetree.get_selected_datafile()
290 
291 
297  self.__frame__frame.save(self.treetree.get_selected_datafile_controller())
298 
299 
301  return self.__frame__frame.has_unsaved_changes()
302 
303 
305  self.__frame__frame.save_all()
306 
307 
308 
315  def get_selected_item(self):
316  if not self.treetree:
317  return
318  return self.treetree.get_selected_item()
319 
320 
321  def content_assist_values(self, value=''):
322  return self.__namespace__namespace.get_suggestions_for(self.get_selected_itemget_selected_item(), value)
323 
324 
325  def get_user_keyword(self, name):
326  keyword_info = self.__namespace__namespace.find_user_keyword(self.datafiledatafile, name)
327  return keyword_info.item if keyword_info else None
328 
329 
331  if not self.treetree:
332  return
333  self.treetree.select_user_keyword_node(uk)
334 
335 
336  def get_keyword(self, name):
337  return self.__namespace__namespace.find_keyword(self.datafiledatafile, name)
338 
339 
343  def get_keyword_details(self, name):
344  return self.__namespace__namespace.keyword_details(self.datafiledatafile, name)
345 
346 
350  def is_user_keyword(self, name):
351  return self.__namespace__namespace.is_user_keyword(self.datafiledatafile, name)
352 
353 
354  def is_library_keyword(self, name):
355  return self.__namespace__namespace.is_library_keyword(self.datafiledatafile, name)
356 
357 
358  def all_testcases(self):
359  return self.modelmodel.all_testcases()
360 
361 
369  self.__namespace__namespace.register_content_assist_hook(hook)
370 
371 
375  def get_plugins(self):
376  return self.__app__app.get_plugins()
377 
378 
385  def publish(self, topic, data):
386  PUBLISHER.publish(topic, data)
387 
388 
396  def subscribe(self, listener, *topics):
397  for topic in topics:
398  PUBLISHER.subscribe(listener, topic)
399 
400 
406  def unsubscribe(self, listener, *topics):
407  for topic in topics:
408  PUBLISHER.unsubscribe(listener, topic)
409 
410 
411  def unsubscribe_all(self):
412  PUBLISHER.unsubscribe_all(self)
413 
414 
419  def register_editor(self, item_class, editor_class, activate=True):
420  self.__app__app.register_editor(item_class, editor_class, activate)
421 
422 
423  def unregister_editor(self, item_class, editor_class):
424  self.__app__app.unregister_editor(item_class, editor_class)
425 
426 
430  def set_active_editor(self, item_class, editor_class):
431  self.__app__app.activate_editor(item_class, editor_class)
432 
433 
437  def get_editors(self, item_class):
438  return self.__app__app.get_editors(item_class)
439 
440 
441  def get_editor(self, item_class):
442  return self.__app__app.get_editor(item_class)
443 
444 
445  def highlight_cell(self, tcuk, obj=None, row=-1, column=-1):
446  if not self.treetree:
447  return
448  self.treetree.select_node_by_data(tcuk)
449  self.__app__app.editor.highlight_cell(obj, row, column)
450 
451 
452  def highlight(self, data, text):
453  if not self.treetree:
454  return
455  self.treetree.highlight(data, text)
Used to create menu entries, keyboard shortcuts and/or toolbar buttons.
Definition: actioninfo.py:176
Entry point to RIDE plugin API – all plugins must extend this class.
Definition: plugin.py:50
def all_testcases(self)
Returns all test cases from all suites in one, unsorted list.
Definition: plugin.py:358
def register_content_assist_hook(self, hook)
Allows plugin to insert values in content assist dialog.
Definition: plugin.py:368
def save_all_unsaved_changes(self)
Saves all the data files that are modified.
Definition: plugin.py:304
def highlight_cell(self, tcuk, obj=None, row=-1, column=-1)
Highlight a specific row/column of a test case or user keyword.
Definition: plugin.py:445
def new_suite_can_be_opened(self)
Checks are there modified files and asks user what to do if there are.
Definition: plugin.py:268
def delete_tab(self, tab)
Deletes the tab added using add_tab.
Definition: plugin.py:248
def is_user_keyword(self, name)
Returns whether name is a user keyword of current datafile.
Definition: plugin.py:350
def get_editors(self, item_class)
Return all registered editors for the given model item class.
Definition: plugin.py:437
def get_selected_datafile(self)
Returns the data file that is currently selected in the tree.
Definition: plugin.py:286
def add_tab(self, tab, title, allow_closing=True)
Adds the tab with the title to the tabbed notebook and shows it.
Definition: plugin.py:240
def save_selected_datafile(self)
Saves the data file that is currently selected in the tree.
Definition: plugin.py:296
def subscribe(self, listener, *topics)
Start to listen to messages with the given topics.
Definition: plugin.py:396
def select_user_keyword_node(self, uk)
Selects node containing the given uk in the tree.
Definition: plugin.py:330
def disable(self)
Called by RIDE when the plugin is disabled.
Definition: plugin.py:177
def get_keyword_details(self, name)
Returns details (documentation, source) of keyword with name name.
Definition: plugin.py:343
def register_editor(self, item_class, editor_class, activate=True)
Register editor_class as an editor class for model items of type item_class
Definition: plugin.py:419
def register_actions(self, action_infos)
Registers multiple menu entries and shortcuts/icons.
Definition: plugin.py:223
def _get_doc(self, given_doc)
Definition: plugin.py:122
def unsubscribe_all(self)
Stops to listen to all messages this plugin has subscribed to.
Definition: plugin.py:411
def set_active_editor(self, item_class, editor_class)
Activates the specified editor to be used with the specified model item.
Definition: plugin.py:430
def get_keyword(self, name)
Returns the keyword object with the given name or None.
Definition: plugin.py:336
def allow_tab_closing(self, tab)
Allows closing a tab that has been created using allow_closing=False.
Definition: plugin.py:252
def is_library_keyword(self, name)
Returns whether name is a keyword imported by current datafile.
Definition: plugin.py:354
def get_user_keyword(self, name)
Returns user keyword instance whose name is name or None.
Definition: plugin.py:325
def register_action(self, action_info)
Registers a menu entry and optionally a shortcut and a toolbar icon.
Definition: plugin.py:205
def _delay_saving(self, delay)
Definition: plugin.py:152
def content_assist_values(self, value='')
Returns content assist values for currently selected item.
Definition: plugin.py:321
def config_panel(self, parent)
Called by RIDE to get the plugin configuration panel.
Definition: plugin.py:187
def disallow_tab_closing(self, tab)
Disallows closing a tab by use.
Definition: plugin.py:256
def unregister_editor(self, item_class, editor_class)
Unregisters editor_class as an editor class for model items of type item_class
Definition: plugin.py:423
def unregister_actions(self)
Unregisters all actions registered by this plugin.
Definition: plugin.py:230
def get_selected_item(self)
Returns the item that is currently selected in the tree.
Definition: plugin.py:315
def show_tab(self, tab)
Makes the tab added using add_tab visible.
Definition: plugin.py:244
def save_setting(self, name, value, override=True, delay=0)
Saves the specified setting into the RIDE configuration file.
Definition: plugin.py:148
def get_editor(self, item_class)
Return the current editor class for the given model item class.
Definition: plugin.py:441
def register_search_action(self, description, handler, icon, default=False)
Definition: plugin.py:226
def __init__(self, application, name=None, doc=None, metadata=None, default_settings=None, initially_enabled=True)
Initialize the plugin with the provided data.
Definition: plugin.py:109
def highlight(self, data, text)
Highlight a specific text of a given data's edito.
Definition: plugin.py:452
def open_suite(self, path)
Opens a test suite specified by the path.
Definition: plugin.py:275
def __getattr__(self, name)
Provides convenient attribute access to saved settings.
Definition: plugin.py:134
def publish(self, topic, data)
Publishes a message with given topic and client data.
Definition: plugin.py:385
def unsubscribe(self, listener, *topics)
Stops listening to messages with the given topics.
Definition: plugin.py:406
def enable(self)
This method is called by RIDE when the plugin is enabled.
Definition: plugin.py:170
def register_shortcut(self, shortcut, callback)
Definition: plugin.py:210
def get_plugins(self)
Returns list containing plugin wrapper for every loaded plugin.
Definition: plugin.py:375
def tab_is_visible(self, tab)
Returns is the tab added using add_tab visible or not.
Definition: plugin.py:260
def is_unsaved_changes(self)
Returns True if there is any unsaved changes, otherwise False.
Definition: plugin.py:300