def on_upload_multiple_files(self): """ Browse and select multiple supporting documents. """ last_doc_path = last_document_path() if not last_doc_path: last_doc_path = '~/' docs_dir = QFileDialog.getExistingDirectory( self, 'Browse Supporting Documents Source Directory', last_doc_path) if not docs_dir: return # Check if there are files in the selected directory dir = QDir(docs_dir) els = dir.entryList(QDir.NoDot | QDir.NoDotDot | QDir.Files) if len(els) == 0: QMessageBox.warning( self, 'Supporting Documents', self.tr('There are no files in the selected directory.')) return doc_types = self.tbw_documents.document_types() dir_doc_dlg = DirDocumentTypeSelector(docs_dir, doc_types, self) res = dir_doc_dlg.exec_() if res == QDialog.Accepted: # Get document types selected by the user selected_doc_types = dir_doc_dlg.selected_document_types self.tbw_documents.upload_document(selected_doc_types)
def _set_file_path(self): """ Sets plot import file absolute path """ fpath = last_document_path() if not fpath or not QFile.exists(fpath): fpath = "." self._plot_file.set_file_path(fpath)
def _load_source_document_directory_selector(self): #Load file dialog for selecting source documents directory title = self.tr('Select Source Document Directory') def_path = self.txtRootFolder.text() #Use the last set source document directory if not def_path: def_path = last_document_path() sel_doc_path = QFileDialog.getExistingDirectory(self, title, def_path) if sel_doc_path: normalized_path = QDir.fromNativeSeparators(sel_doc_path) self.txtRootFolder.clear() self.txtRootFolder.setText(normalized_path)
def select_file_dialog(self, title): """ Displays a file dialog for a user to specify a source document :param title: The title of the file dialog :type title: String """ # Get last path for supporting documents last_path = last_document_path() if last_path is None: last_path = '/home' files = QFileDialog.getOpenFileNames( iface.mainWindow(), title, last_path, "Source Documents (*.jpg *.jpeg *.png *.bmp *.tiff *.svg)") return files
def _load_source_document_directory_selector(self): #Load file dialog for selecting source documents directory title = self.tr('Select Source Document Directory') def_path = self.txtRootFolder.text() #Use the last set source document directory if not def_path: def_path = last_document_path() sel_doc_path = QFileDialog.getExistingDirectory(self, title, def_path) if sel_doc_path: normalized_path = QDir.fromNativeSeparators(sel_doc_path) self.txtRootFolder.clear() self.txtRootFolder.setText(normalized_path)
def browse_holders_file(self): """ Browse the holders file in the file directory. """ last_doc_path = last_document_path() if not last_doc_path: last_doc_path = '~/' holders_file = QFileDialog.getOpenFileName( self, 'Browse Holders File', last_doc_path, 'Excel File (*.xls *xlsx);;CSV (Comma Delimited) (*.csv)') if holders_file: set_last_document_path(holders_file) self.lnEdit_hld_path.setText(holders_file) self.load_holders_file()
def _on_add_supporting_document(self): #Slot raised when the user select to add a supporting document if self.count == 0: return select = self.tr('Select') supporting_docs_str = 'Supporting Documents' title = u'{0} {1} {2}'.format( select, self.current_document_type(), supporting_docs_str ) filter_str = u'{0} (*.jpg *.jpeg *.png *.bmp *.tiff *.svg)'.format( supporting_docs_str ) #Get last path for supporting documents last_path = last_document_path() if last_path is None: last_path = '/home' else: dir = QDir(last_path) if not dir.exists(): last_path = '/home' source_docs = QFileDialog.getOpenFileNames( self, title, last_path, filter_str ) doc_type_id = self._cbo_doc_type.itemData(self._cbo_doc_type.currentIndex()) parent_entity = self._entity_supporting_doc.parent_entity for doc in source_docs: self.source_document_manager.insertDocumentFromFile( doc, doc_type_id, parent_entity ) #Set last path if len(source_docs) > 0: doc = source_docs[0] fi = QFileInfo(doc) dir_path = fi.absolutePath() set_last_document_path(dir_path)
def select_file_dialog(self, title): """ Displays a file dialog for a user to specify a source document :param title: The title of the file dialog :type title: String """ # Get last path for supporting documents last_path = last_document_path() if last_path is None: last_path = '/home' files = QFileDialog.getOpenFileNames( iface.mainWindow(), title, last_path, "Source Documents (*.jpg *.jpeg *.png *.bmp *.tiff *.svg)" ) return files
def on_browse_activate(self, link): """ Slot raised when the Browse link has been clicked. Open the dialog for browsing files then raises the 'browsed' signal. :param link: Hyperlink stored in the link property, which is not applied in this case. :type link: str """ sender = self.sender() if not self._is_sender_valid(sender): return doc_info = sender.property(self._doc_prop) # Clear error hints row_idx = doc_info.row_num self.clear_error_success_hints(row_idx) last_doc_path = last_document_path() if not last_doc_path: last_doc_path = '~/' doc_file_path = QFileDialog.getOpenFileName( self, u'Browse {0}'.format(doc_info.document_type), last_doc_path, self.file_filters ) if doc_file_path: # Update registry setting set_last_document_path(doc_file_path) # Update the source file name doc_info.source_filename = doc_file_path # Upload document content self.upload_document(doc_file_path, doc_info.document_type) # Emit signal self.browsed.emit(doc_info)