1
+ import os
2
+
1
3
from qtpy .QtCore import Qt
2
- from qtpy .QtWidgets import QVBoxLayout , QToolButton , QMenu , QAction , QWidget , QHBoxLayout
4
+ from qtpy .QtWidgets import QVBoxLayout , QFileDialog , QToolButton , QMenu , QAction , QWidget , QHBoxLayout
3
5
4
6
from pyqt_openai .chat_widget .textEditPropmtGroup import TextEditPropmtGroup
5
7
from pyqt_openai .propmt_command_completer .commandSuggestionWidget import CommandSuggestionWidget
@@ -68,10 +70,15 @@ def __initUi(self):
68
70
supportPromptCommandAction .setCheckable (True )
69
71
supportPromptCommandAction .toggled .connect (self .__supportPromptCommand )
70
72
73
+ readingFilesAction = QAction ('Upload Files...' , self )
74
+ readingFilesAction .setCheckable (True )
75
+ readingFilesAction .toggled .connect (self .__readingFiles )
76
+
71
77
# Add the actions to the menu
72
78
menu .addAction (beginningAction )
73
79
menu .addAction (endingAction )
74
80
menu .addAction (supportPromptCommandAction )
81
+ menu .addAction (readingFilesAction )
75
82
76
83
# Connect the button to the menu
77
84
settingsBtn .setMenu (menu )
@@ -183,4 +190,22 @@ def __showEnding(self, f):
183
190
184
191
def __supportPromptCommand (self , f ):
185
192
self .__commandEnabled = f
186
- self .__textEditGroup .setCommandEnabled (f )
193
+ self .__textEditGroup .setCommandEnabled (f )
194
+
195
+ def __readingFiles (self ):
196
+ filenames = QFileDialog .getOpenFileNames (self , 'Find' , '' , 'All Files (*.*)' )
197
+ if filenames [0 ]:
198
+ filenames = filenames [0 ]
199
+ source_context = ''
200
+ for filename in filenames :
201
+ base_filename = os .path .basename (filename )
202
+ source_context += f'=== { base_filename } start ==='
203
+ source_context += '\n ' * 2
204
+ with open (filename , 'r' , encoding = 'utf-8' ) as f :
205
+ source_context += f .read ()
206
+ source_context += '\n ' * 2
207
+ source_context += f'=== { base_filename } end ==='
208
+ source_context += '\n ' * 2
209
+ prompt_context = f'== Source Start ==\n { source_context } == Source End =='
210
+
211
+ self .__textEditGroup .getGroup ()[1 ].setText (prompt_context )
0 commit comments