Robot Framework Integrated Development Environment (RIDE)
UsageRunner.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 time
17 from threading import Thread
18 
19 import wx
20 
21 from robotide.usages import commands
22 # import FindUsages, FindResourceUsages, FindVariableUsages
23 from . import usagesdialog
24 # import UsagesDialog, UsagesDialogWithUserKwNavigation, ResourceImportUsageDialog
25 
26 
27 class Usages():
28 
29  def __init__(self, controller, highlight, name=None, kw_info=None):
30  self._name_name = name or controller.name
31  self._kw_info_kw_info = kw_info
32  self._controller_controller = controller
33  self._highlight_highlight = highlight
34  self._dlg_dlg = self._usages_dialog_usages_dialog()
35  self._worker_worker = Thread(target=self._run_run)
36  self._dialog_closed_dialog_closed = False
37 
38  def _usages_dialog(self):
39  if self._controller_controller.name == self._name_name:
40  return usagesdialog.UsagesDialogWithUserKwNavigation(self._name_name, self._highlight_highlight, self._controller_controller)
41  return usagesdialog.UsagesDialog(self._name_name)
42 
43  def show(self):
44  self._dlg_dlg.add_selection_listener(self._highlight_highlight)
45  self._dlg_dlg.Bind(wx.EVT_CLOSE, self._stop_stop)
46  self._dlg_dlg.Show()
47  self._worker_worker.start()
48 
49  def _run(self):
50  wx.CallAfter(self._begin_search_begin_search)
51  for usage in self._find_usages_find_usages():
52  time.sleep(0) # GIVE SPACE TO OTHER THREADS -- Thread.yield in Java
53  if self._dialog_closed_dialog_closed:
54  return
55  wx.CallAfter(self._add_usage_add_usage, usage)
56  wx.CallAfter(self._end_search_end_search)
57 
58  def _find_usages(self):
59  return self._controller_controller.execute(commands.FindUsages(self._name_name, self._kw_info_kw_info))
60 
61  def _begin_search(self):
62  if not self._dialog_closed_dialog_closed:
63  self._dlg_dlg.begin_searching()
64 
65  def _add_usage(self, usage):
66  if not self._dialog_closed_dialog_closed:
67  self._dlg_dlg.add_usage(usage)
68 
69  def _end_search(self):
70  if not self._dialog_closed_dialog_closed:
71  self._dlg_dlg.end_searching()
72 
73  def _stop(self, event):
74  self._dialog_closed_dialog_closed = True
75  event.Skip()
76 
77 
79 
80  def __init__(self, controller, highlight):
81  Usages.__init__(self, controller, highlight)
82 
83  def _usages_dialog(self):
84  return usagesdialog.ResourceImportUsageDialog(self._controller_controller.display_name, self._highlight_highlight, self._controller_controller)
85 
86  def _find_usages(self):
87  return self._controller_controller.execute(commands.FindResourceUsages())
88 
89 
91 
92  def _find_usages(self):
93  return self._controller_controller.execute(commands.FindVariableUsages(self._name_name))
def __init__(self, controller, highlight)
Definition: UsageRunner.py:80
def __init__(self, controller, highlight, name=None, kw_info=None)
Definition: UsageRunner.py:29