class Open_File_Dialog(QtGui.QDialog): MESSAGE = QtCore.QT_TR_NOOP( "<p>Message boxes have a caption, a text, and up to " "three buttons, each with standard or custom texts.</p>" "<p>Click a button or press Esc.</p>") def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.openFilesPath = QtCore.QString() self.errorMessageDialog = QtGui.QErrorMessage(self) frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel self.openFileNameLabel = QtGui.QLabel() self.openFileNameLabel.setFrameStyle(frameStyle) self.openFileNameButton = QtGui.QPushButton(self.tr("Open File")) self.connect(self.openFileNameButton, QtCore.SIGNAL("clicked()"), self.setOpenFileName) layout = QtGui.QGridLayout() layout.setColumnStretch(1, 1) layout.setColumnMinimumWidth(1, 250) layout.addWidget(self.openFileNameButton, 0, 0) layout.addWidget(self.openFileNameLabel, 0, 1) self.setLayout(layout) self.setWindowTitle(self.tr("Open File:")) def setOpenFileName(self): ''' This is the line of code you are looking for!!!!!!!!!!!!!!!!!!!!!!!! ''' fileName = QtGui.QFileDialog.getOpenFileName( self, self.tr("QFileDialog.getOpenFileName()"), self.openFileNameLabel.text(), self.tr("All Files (*);;Text Files (*.txt)")) if not fileName.isEmpty(): self.openFileNameLabel.setText(fileName)
def criticalErrorMessageBox(self, messageTxt): MESSAGE = QtCore.QT_TR_NOOP("<p>" + messageTxt + "</p>") reply = QtGui.QMessageBox.critical( self, self.tr("tGui.QMessageBox.showCritical()"), MESSAGE, QtGui.QMessageBox.Abort)
def __init__(self, *args): QtSql.QSqlRelationalTableModel.__init__(self, *args) self.setTable("pigeon") self.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange) self.setHeaderData( YEAR_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Year")))) self.setHeaderData( IDENTIFICATION_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant( QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Identification")))) self.setRelation(NATION_COLUMN, QtSql.QSqlRelation("nation", "id", "short_name")) self.setHeaderData( NATION_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant( QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Nacionality")))) self.setHeaderData( SEX_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Sex")))) self.setHeaderData( STATE_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("State")))) self.setHeaderData( MOTHER_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant( QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Mother")))) self.setHeaderData( FATHER_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant( QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Father")))) self.setRelation(EYE_COLUMN, QtSql.QSqlRelation("eye_color", "id", "name")) self.setHeaderData( EYE_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Eye")))) self.setRelation( PLUMAGE_COLUMN, QtSql.QSqlRelation("plumage_color", "id", "short_name")) self.setHeaderData( PLUMAGE_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant( QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Plumage")))) self.setHeaderData( NAME_COLUMN, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(self, QtCore.QT_TR_NOOP("Name")))) self.select()
def search(self, server_names, keyword, cursor): """ .. py:attribute:: search() :rtype: UNKNOWN .. note:: .. todo:: """ def run_query(word, words, t_name): pattern = ' OR '.join(['"*{}*"'.format(i) for i in words]) query = u"""SELECT file_path FROM {} WHERE {} MATCH '{}';""" related_query = query.format(t_name, t_name, pattern.strip()) try: cursor.execute(related_query) except: related = set() else: related = set(next(zip(*cursor), [])) try: cursor.execute(query.format(t_name, t_name, word)) except: return set(), related else: exact = set(next(zip(*cursor), [])) return exact, related message = QtCore.QT_TR_NOOP( "<p>You have an error in your connection.</p>" "<p>Please select one of the server names and connect to it.</p>") self.statusLabel.setText( "Search into selected databases. Please wait...") words = self.get_lemmas(keyword) total_find = {} match_path_number = 0 self.dialog.setCursor(QtCore.Qt.WaitCursor) for servername in server_names: t_name = '_'.join(map(str.lower, servername.split())) try: exact, related = run_query(keyword, words, t_name) except Exception as exp: print(exp) message = "There is a problem in running the queries." QtGui.QMessageBox.information(self, "QMessageBox.information()", message) break else: total_find[servername] = exact, related match_path_number += len(exact.union(related)) if any(i for i in total_find.values()): self.dialog.setCursor(QtCore.Qt.ArrowCursor) self.set_recommender(keyword, *words) self.wid = Path_results(self.image_path, self.server_dict, total_find, match_path_number) self.wid.resize(350, 650) self.wid.setWindowTitle('Search') self.wid.show() else: self.dialog.setCursor(QtCore.Qt.ArrowCursor) message = """<p>No results.<p>Please try with another pattern.</p>""" QtGui.QMessageBox.information(self, "QMessageBox.information()", message)