Robot Framework Integrated Development Environment (RIDE)
fileexplorerplugin.py
Go to the documentation of this file.
1 # Copyright 2020- Robot Framework Foundation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import wx
16 from wx import Colour
17 from wx.lib.agw import customtreectrl
18 from wx.lib.agw.aui import GetManager
19 
20 from ..controller.project import Project
21 from ..pluginapi import Plugin
22 from ..pluginapi.plugin import ActionInfo
23 
24 
25 
27  datafile = property(lambda self: self.get_selected_datafileget_selected_datafile())
28  defaults = {"opened": True,
29  "docked": True
30  }
31 
32  def __init__(self, application, controller=None):
33  Plugin.__init__(self, application, default_settings=self.defaultsdefaults)
34  self.settingssettings = application.settings._config_obj['Plugins']['File Explorer']
35  self._parent_parent = wx.App.Get().GetTopWindow()
36  self._filemgr_filemgr = self.filemgrfilemgr
37  self._filemgr_filemgr.SetThemeEnabled(True)
38  self._mgr_mgr = GetManager(self._filemgr_filemgr)
39  self._controller_controller = controller
40 
41  def register_frame(self, parent=None):
42  if parent:
43  self._parent_parent = parent
44 
45  if self._mgr_mgr.GetPane("file_manager") in self._mgr_mgr._panes:
46  register = self._mgr_mgr.InsertPane
47  else:
48  register = self._mgr_mgr.AddPane
49 
50  register(self._filemgr_filemgr, wx.lib.agw.aui.AuiPaneInfo().Name("file_manager").
51  Caption("Files").LeftDockable(True).CloseButton(True))
52 
53  self._mgr_mgr.Update()
54 
55  def enable(self):
56  self.register_actionregister_action(ActionInfo('View','View File Explorer', self.OnShowFileExplorerOnShowFileExplorer,
57  shortcut='F11',
58  doc='Show File Explorer panel',
59  position=1))
60  # self.save_setting('opened', True)
61  if self.opened:
62  self.OnShowFileExplorerOnShowFileExplorer(None)
63 
64  def close_tree(self):
65  self._mgr_mgr.DetachPane(self._filemgr_filemgr)
66  self._filemgr_filemgr.Hide()
67  self._mgr_mgr.Update()
68  self.save_settingsave_setting('opened', False)
69 
70  def disable(self):
71  self.close_treeclose_tree()
72  # self.save_setting('opened', False)
73  self.unsubscribe_allunsubscribe_all()
74  self.unregister_actionsunregister_actions()
75 
76  def is_focused(self):
77  return self._filemgr_filemgr.HasFocus()
78 
79  def OnShowFileExplorer(self, event):
80  if not self._parent_parent:
81  self._parent_parent = wx.App.Get().GetWindow() # self.frame
82  if not self._filemgr_filemgr: # This is not needed because file explorer is always created
83  self._filemgr_filemgr = FileExplorer(self._parent_parent, self._controller_controller)
84 
85  self._pane_pane = self._mgr_mgr.GetPane(self._filemgr_filemgr)
86  HTML_BACKGROUND = self.settingssettings.get('background help', (240, 242, 80))
87  HTML_FOREGROUND = self.settingssettings.get('foreground text', (7, 0, 70))
88  HTML_FONT_FACE = self.settingssettings.get('font face', '')
89  HTML_FONT_SIZE = self.settingssettings.get('font size', 11)
90  self._filetreectrl_filetreectrl = self._filemgr_filemgr.GetTreeCtrl()
91  self._filemgr_filemgr.Show(True)
92  self._filemgr_filemgr.SetMinSize(wx.Size(200, 225))
93  self._mgr_mgr.DetachPane(self._filemgr_filemgr)
94  self._mgr_mgr.AddPane(self.filemgrfilemgr,
95  wx.lib.agw.aui.AuiPaneInfo().Name("file_manager").
96  Caption("Files").LeftDockable(True).
97  CloseButton(True))
98  self._filemgr_filemgr.SetBackgroundStyle(wx.BG_STYLE_SYSTEM)
99  self._filemgr_filemgr.SetBackgroundColour(HTML_BACKGROUND)
100  self._filemgr_filemgr.SetForegroundColour(HTML_FOREGROUND)
101  self.fontfont = self._filemgr_filemgr.GetFont()
102  self.fontfont.SetFaceName(HTML_FONT_FACE)
103  self.fontfont.SetPointSize(HTML_FONT_SIZE)
104  self._filemgr_filemgr.SetFont(self.fontfont)
105  self._filemgr_filemgr.Refresh()
106  self._filetreectrl_filetreectrl.SetBackgroundColour(HTML_BACKGROUND)
107  self._filetreectrl_filetreectrl.SetForegroundColour(HTML_FOREGROUND)
108  self._filetreectrl_filetreectrl.SetFont(self.fontfont)
109  self._filetreectrl_filetreectrl.Refresh()
110  self._filemgr_filemgr.Raise()
111  self._mgr_mgr.Update()
112  self.save_settingsave_setting('opened', True)
113  self._update_tree_update_tree()
114 
115  def _update_tree(self):
116  if not self._filemgr_filemgr:
117  return
118  self._filemgr_filemgr.update_tree()
119 
120 
121 class FileExplorer(wx.GenericDirCtrl):
122 
123  def __init__(self, parent, controller=None):
124  wx.GenericDirCtrl.__init__(self, parent, id=-1, size=(200, 225), style=wx.DIRCTRL_3D_INTERNAL)
125  self._controller_controller = controller
126  self.SetThemeEnabled(True)
127  self.Refresh()
128 
129  def update_tree(self):
130  if isinstance(self._controller_controller, Project):
131  if self._controller_controller.data and len(self._controller_controller.data.directory) > 1:
132  self.SelectPath(self._controller_controller.data.source)
133  try:
134  self.ExpandPath(self._controller_controller.data.source)
135  except Exception:
136  pass
137  self.Refresh()
138  self.Update()
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 get_selected_datafile(self)
Returns the data file that is currently selected in the tree.
Definition: plugin.py:286
def unsubscribe_all(self)
Stops to listen to all messages this plugin has subscribed to.
Definition: plugin.py:411
def register_action(self, action_info)
Registers a menu entry and optionally a shortcut and a toolbar icon.
Definition: plugin.py:205
def unregister_actions(self)
Unregisters all actions registered by this plugin.
Definition: plugin.py:230
def save_setting(self, name, value, override=True, delay=0)
Saves the specified setting into the RIDE configuration file.
Definition: plugin.py:148
Provides a tree view for Files and Folders.
def __init__(self, application, controller=None)
def disable(self)
Called by RIDE when the plugin is disabled.
def enable(self)
This method is called by RIDE when the plugin is enabled.
def __init__(self, parent, controller=None)