def on_upload_document(self): ''' Slot raised when the user clicks to upload a supporting document. ''' document_str = QApplication.translate( "SupportingDocuments", "Specify the Document File Location") documents = self.select_file_dialog(document_str) cbo_index = self.doc_type_cbo.currentIndex() doc_id = self.doc_type_cbo.itemData(cbo_index) for doc in documents: self.supporting_doc_manager.insertDocumentFromFile( doc, doc_id, self.social_tenure, self.current_party_count) # Set last path if len(documents) > 0: doc = documents[0] fi = QFileInfo(doc) dir_path = fi.absolutePath() set_last_document_path(dir_path) model_objs = self.supporting_doc_manager.model_objects() self.onUploadDocument.emit(model_objs)
def on_upload_document(self): ''' Slot raised when the user clicks to upload a supporting document. ''' document_str = QApplication.translate( "SupportingDocuments", "Specify the Document File Location" ) documents = self.select_file_dialog(document_str) cbo_index = self.doc_type_cbo.currentIndex() doc_id = self.doc_type_cbo.itemData(cbo_index) for doc in documents: self.supporting_doc_manager.insertDocumentFromFile( doc, doc_id, self.social_tenure, self.current_party_count ) # Set last path if len(documents) > 0: doc = documents[0] fi = QFileInfo(doc) dir_path = fi.absolutePath() set_last_document_path(dir_path) model_objs = self.supporting_doc_manager.model_objects() self.onUploadDocument.emit(model_objs)
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 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)
def _add_file(self): """ Adds plot import file data settings into the file table view """ fpath = QFileInfo(self._plot_file.file_path).path() extensions = " ".join(self._plot_file.file_extensions()) fpath = QFileDialog.getOpenFileName( self, "Workflow Manager - Plot Add Files", fpath, "Plot Import files {}".format(extensions)) if fpath and fpath not in self._plot_file.file_paths: try: # Check if its a PDF and can be uploaded i.e. no other # existing field books if self._plot_file.is_pdf(fpath) and \ not self._can_upload_field_book(): return self._plot_file.set_file_path(fpath) set_last_document_path(fpath) if not self.model.results: self._load(self.model, self._plot_file) else: self._insert_file() # If field book then validate and upload in the background if self._plot_file.is_pdf(fpath): self._upload_field_book(fpath) except (IOError, OSError, Exception) as e: self._show_critical_message( "Workflow Manager - Plot Add Files", "Failed to load: {}".format(e)) else: self._file_table_view.verticalHeader().setDefaultSectionSize( 21) self._file_table_view.horizontalHeader().\ setStretchLastSection(True)