1414)
1515
1616from pyqt_openai import TEXT_FILE_EXT_LIST , QFILEDIALOG_DEFAULT_DIRECTORY
17+ from pyqt_openai .config_loader import CONFIG_MANAGER
1718from pyqt_openai .lang .translations import LangClass
1819from pyqt_openai .util .common import getSeparator
1920
@@ -29,14 +30,15 @@ def __init__(self, parent=None):
2930 self .__initUi ()
3031
3132 def __initVal (self ):
32- self .__dirLblPrefix = LangClass .TRANSLATIONS ["Directory" ]
33- self .__curDirName = ""
33+ self .__directory_label_prefix = LangClass .TRANSLATIONS ["Directory" ]
34+ self .__current_directory_name = ""
35+ self .__extension = CONFIG_MANAGER .get_general_property ("llama_index_supported_formats" )
3436
3537 def __initUi (self ):
3638 lbl = QLabel (LangClass .TRANSLATIONS ["Files" ])
3739 setDirBtn = QPushButton (LangClass .TRANSLATIONS ["Set Directory" ])
3840 setDirBtn .clicked .connect (self .setDirectory )
39- self .__dirLbl = QLabel (self .__dirLblPrefix )
41+ self .__dirLbl = QLabel (self .__directory_label_prefix )
4042
4143 lay = QHBoxLayout ()
4244 lay .addWidget (lbl )
@@ -60,6 +62,15 @@ def __initUi(self):
6062 lay .setContentsMargins (0 , 0 , 0 , 0 )
6163 self .setLayout (lay )
6264
65+ def setExtension (self , ext ):
66+ # Set extension
67+ self .__extension = ext
68+ CONFIG_MANAGER .set_general_property ("llama_index_supported_formats" , ext )
69+
70+ # Refresh list based on new extension
71+ self .__listWidget .clear ()
72+ self .setDirectory (self .__current_directory_name , called_from_btn = False )
73+
6374 def setDirectory (self , directory = None , called_from_btn = True ):
6475 try :
6576 if called_from_btn :
@@ -74,28 +85,28 @@ def setDirectory(self, directory=None, called_from_btn=True):
7485 self .__listWidget .clear ()
7586 filenames = list (
7687 filter (
77- lambda x : os .path .splitext (x )[- 1 ] in TEXT_FILE_EXT_LIST ,
88+ lambda x : os .path .splitext (x )[- 1 ] in self . __extension ,
7889 os .listdir (directory ),
7990 )
8091 )
8192 self .__listWidget .addItems (filenames )
8293 self .itemUpdate .emit (len (filenames ) > 0 )
83- self .__curDirName = directory
84- self .__dirLbl .setText (self .__curDirName .split ("/" )[- 1 ])
94+ self .__current_directory_name = directory
95+ self .__dirLbl .setText (self .__current_directory_name .split ("/" )[- 1 ])
8596
8697 self .__listWidget .setCurrentRow (0 )
8798 # activate event as clicking first item (because this selects the first item anyway)
8899 self .clicked .emit (
89100 os .path .join (
90- self .__curDirName , self .__listWidget .currentItem ().text ()
101+ self .__current_directory_name , self .__listWidget .currentItem ().text ()
91102 )
92103 )
93104 self .onDirectorySelected .emit ()
94105 except Exception as e :
95106 print (e )
96107
97108 def getDirectory (self ):
98- return self .__curDirName
109+ return self .__current_directory_name
99110
100111 def __sendDirectory (self , item ):
101- self .clicked .emit (os .path .join (self .__curDirName , item .text ()))
112+ self .clicked .emit (os .path .join (self .__current_directory_name , item .text ()))
0 commit comments