3737from qtpy .QtCore import Qt , QUrl , QSettings
3838from qtpy .QtGui import QDesktopServices , QKeySequence
3939from qtpy .QtWidgets import (QMainWindow , QWidget , QListWidget , QListWidgetItem , QSplitter , QFileDialog , QPushButton ,
40- QDialogButtonBox , QShortcut , QVBoxLayout , QGridLayout , QLineEdit ,
40+ QDialogButtonBox , QShortcut ,
41+ QHBoxLayout , QVBoxLayout , QGridLayout , QLineEdit ,
4142 QCheckBox , QComboBox , QMessageBox , QDialog ,
4243 QInputDialog , QLabel , QGroupBox , QRadioButton ,
4344 QTabWidget )
6061 get_documentation_url ,
6162 URLS ,
6263 RecentlyUsedList ,
63- logger )
64+ logger , list_drives )
6465from larray_editor .arraywidget import ArrayEditorWidget
6566from larray_editor import arrayadapter
6667from larray_editor .commands import EditSessionArrayCommand , EditCurrentArrayCommand
@@ -117,6 +118,9 @@ def __init__(self, data, title=None, readonly=False):
117118 super ().__init__ (parent = None )
118119 layout = QVBoxLayout ()
119120 self .setLayout (layout )
121+ header_layout = self .setup_header_layout ()
122+ if header_layout is not None :
123+ layout .addLayout (header_layout )
120124 array_widget = ArrayEditorWidget (self , data = data , readonly = readonly )
121125 self .array_widget = array_widget
122126 layout .addWidget (array_widget )
@@ -131,6 +135,9 @@ def __init__(self, data, title=None, readonly=False):
131135 # TODO: somehow determine better width
132136 self .resize (self .default_width , self .default_height )
133137
138+ def setup_header_layout (self ):
139+ return None
140+
134141 def closeEvent (self , event ):
135142 logger .debug ('EditorWindow.closeEvent()' )
136143 if self in opened_secondary_windows :
@@ -139,6 +146,37 @@ def closeEvent(self, event):
139146 self .array_widget .close ()
140147
141148
149+ class FileExplorerWindow (EditorWindow ):
150+ name = "File Explorer"
151+
152+ def create_drive_button_clicked_callback (self , drive ):
153+ def callback ():
154+ path = Path (drive )
155+ if not path .exists ():
156+ msg = f"The { drive } drive is currently unavailable !"
157+ QMessageBox .critical (self , "Error" , msg )
158+ return
159+ self .array_widget .set_data (path )
160+ return callback
161+
162+ def setup_header_layout (self ):
163+ drives = list_drives ()
164+ if not drives :
165+ return None
166+
167+ layout = QHBoxLayout ()
168+ for drive in drives :
169+ if drive .endswith ('\\ ' ):
170+ drive = drive [:- 1 ]
171+ button = QPushButton (drive )
172+ button .clicked .connect (
173+ self .create_drive_button_clicked_callback (drive )
174+ )
175+ layout .addWidget (button )
176+ layout .addStretch ()
177+ return layout
178+
179+
142180class AbstractEditorWindow (QMainWindow ):
143181 """Abstract Editor Window"""
144182
@@ -818,10 +856,11 @@ def display_item_in_new_window(self, list_item):
818856 assert isinstance (list_item , QListWidgetItem )
819857 varname = str (list_item .text ())
820858 value = self .data [varname ]
821- self .new_editor_window (value , varname )
859+ self .new_editor_window (value , title = varname )
822860
823- def new_editor_window (self , data , title : str , readonly : bool = False ):
824- window = EditorWindow (data , title = title , readonly = readonly )
861+ def new_editor_window (self , data , title : str = None , readonly : bool = False ,
862+ cls = EditorWindow ):
863+ window = cls (data , title = title , readonly = readonly )
825864 window .show ()
826865 # this is necessary so that the window does not disappear immediately
827866 opened_secondary_windows .append (window )
@@ -1477,7 +1516,7 @@ def load_example(self):
14771516 self ._open_file (filepath )
14781517
14791518 def open_explorer (self ):
1480- self .new_editor_window (Path ('.' ), title = "File Explorer" , readonly = True )
1519+ self .new_editor_window (Path ('.' ), cls = FileExplorerWindow )
14811520
14821521
14831522class ArrayEditorWindow (AbstractEditorWindow ):
0 commit comments