示例#1
0
class ItemWidget(QWidget):
    def __init__(self, section, name="", parent=None):
        super(ItemWidget, self).__init__(parent)

        self.section = section

        self.item = Label({'txt': name})
        button = Button({
            'txt': "Edit",
            'stt': "Edit character name",
            'cl': self.setText
        })
        layout = QHBoxLayout()
        layout.addWidget(self.item)
        layout.addWidget(button)
        self.setLayout(layout)

    def setText(self):
        text, ok = QInputDialog.getText(self, "Change To",
                                        "{0} name:".format(self.section),
                                        QLineEdit.Normal, self.item.text())
        if ok and text != "":
            self.item.setText(text)
示例#2
0
class FindFiles(QWidget):

    key = 'findFile'
    showLayout = pyqtSignal(str, str)

    def __init__(self, parent=None):
        super(FindFiles, self).__init__(parent)
        self.setWindowIcon(IconPth(32, "FindFiles"))

        central_widget = QWidget(self)
        self.layout = QGridLayout(self)
        central_widget.setLayout(self.layout)

        self.buildUI()

    def buildUI(self):

        browseButton = Button({'txt': "&Browse...", 'cl': self.browse})
        findButton = Button({'txt': "&Find", 'cl': self.find})

        self.fileComboBox = self.createComboBox("*")
        self.textComboBox = self.createComboBox()
        self.directoryComboBox = self.createComboBox(QDir.currentPath())

        fileLabel = Label({'txt': "Named:"})
        textLabel = Label({'txt': "Containing text: "})
        directoryLabel = Label({'txt': "In directory: "})

        self.filesFoundLabel = Label()
        self.createFilesTable()

        buttonsLayout = QHBoxLayout()
        buttonsLayout.addStretch()
        buttonsLayout.addWidget(findButton)

        self.layout = QGridLayout()
        self.layout.addWidget(fileLabel, 0, 0)
        self.layout.addWidget(self.fileComboBox, 0, 1, 1, 2)
        self.layout.addWidget(textLabel, 1, 0)
        self.layout.addWidget(self.textComboBox, 1, 1, 1, 2)
        self.layout.addWidget(directoryLabel, 2, 0)
        self.layout.addWidget(self.directoryComboBox, 2, 1)
        self.layout.addWidget(browseButton, 2, 2)
        self.layout.addWidget(self.filesTable, 3, 0, 1, 3)
        self.layout.addWidget(self.filesFoundLabel, 4, 0)
        self.layout.addLayout(buttonsLayout, 5, 0, 1, 3)
        self.setLayout(self.layout)

        self.resize(700, 300)

    def browse(self):
        directory = QFileDialog.getExistingDirectory(self, "Find Files",
                                                     QDir.currentPath())

        if directory:
            if self.directoryComboBox.findText(directory) == -1:
                self.directoryComboBox.addItem(directory)

            self.directoryComboBox.setCurrentIndex(self.directoryComboBox.findText(directory))

    @staticmethod
    def updateComboBox(comboBox):
        if comboBox.findText(comboBox.currentText()) == -1:
            comboBox.addItem(comboBox.currentText())

    def find(self):
        self.filesTable.setRowCount(0)

        fileName = self.fileComboBox.currentText()
        text = self.textComboBox.currentText()
        path = self.directoryComboBox.currentText()

        self.updateComboBox(self.fileComboBox)
        self.updateComboBox(self.textComboBox)
        self.updateComboBox(self.directoryComboBox)

        self.currentDir = QDir(path)
        if not fileName:
            fileName = "*"
        files = self.currentDir.entryList([fileName],
                                          QDir.Files | QDir.NoSymLinks)

        if text:
            files = self.findFiles(files, text)
        self.showFiles(files)

    def findFiles(self, files, text):
        progressDialog = QProgressDialog(self)

        progressDialog.setCancelButtonText("&Cancel")
        progressDialog.setRange(0, files.count())
        progressDialog.setWindowTitle("Find Files")

        foundFiles = []

        for i in range(files.count()):
            progressDialog.setValue(i)
            progressDialog.setLabelText("Searching file number %d of %d..." % (i, files.count()))
            QApplication.processEvents()

            if progressDialog.wasCanceled():
                break

            inFile = QFile(self.currentDir.absoluteFilePath(files[i]))

            if inFile.open(QIODevice.ReadOnly):
                stream = QTextStream(inFile)
                while not stream.atEnd():
                    if progressDialog.wasCanceled():
                        break
                    line = stream.readLine()
                    if text in line:
                        foundFiles.append(files[i])
                        break

        progressDialog.close()

        return foundFiles

    def showFiles(self, files):
        for fn in files:
            file = QFile(self.currentDir.absoluteFilePath(fn))
            size = QFileInfo(file).size()

            fileNameItem = QTableWidgetItem(fn)
            fileNameItem.setFlags(fileNameItem.flags() ^ Qt.ItemIsEditable)
            sizeItem = QTableWidgetItem("%d KB" % (int((size + 1023) / 1024)))
            sizeItem.setTextAlignment(Qt.AlignVCenter | Qt.AlignRight)
            sizeItem.setFlags(sizeItem.flags() ^ Qt.ItemIsEditable)

            row = self.filesTable.rowCount()
            self.filesTable.insertRow(row)
            self.filesTable.setItem(row, 0, fileNameItem)
            self.filesTable.setItem(row, 1, sizeItem)

        self.filesFoundLabel.setText("%d file(s) found (Double click on a file to open it)" % len(files))

    def createComboBox(self, text=""):
        comboBox = QComboBox()
        comboBox.setEditable(True)
        comboBox.addItem(text)
        comboBox.setSizePolicy(SiPoExp, SiPoPre)
        return comboBox

    def createFilesTable(self):
        self.filesTable = QTableWidget(0, 2)
        self.filesTable.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.filesTable.setHorizontalHeaderLabels(("File Name", "Size"))
        self.filesTable.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
        self.filesTable.verticalHeader().hide()
        self.filesTable.setShowGrid(False)

        self.filesTable.cellActivated.connect(self.openFileOfItem)

    def openFileOfItem(self, row, column):
        item = self.filesTable.item(row, 0)
        QDesktopServices.openUrl(QUrl(self.currentDir.absoluteFilePath(item.text())))

    def hideEvent(self, event):
        # self.specs.showState.emit(False)
        pass

    def closeEvent(self, event):
        self.showLayout.emit(self.key, 'hide')
        event.ignore()
示例#3
0
class ForgotPassword(QWidget):

    key = 'forgotPW'
    showLayout = pyqtSignal(str, str)

    def __init__(self):
        super(ForgotPassword, self).__init__()
        self.setContentsMargins(0,0,0,0)

        self.layout = QVBoxLayout()
        self.buildUI()
        self.setLayout(self.layout)

    def buildUI(self):

        self.step1_form = self.step1_layout()
        self.step2_form = self.step2_layout()
        self.step2_form.setVisible(False)

        self.layout.addWidget(self.step1_form)
        self.layout.addWidget(self.step2_form)

    def step1_layout(self):

        step1_groupBox = QGroupBox("Step 1")
        step1_layout = QFormLayout()
        step1_groupBox.setLayout(step1_layout)

        self.user_account = QLineEdit()
        self.user_email = QLineEdit()

        step1_btn_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        step1_btn_box.accepted.connect(self.on_step1_btn_clicked)
        step1_btn_box.rejected.connect(self.close)

        step1_layout.addRow(Label({'txt': "Username: "******"Email adress: "}), self.user_email)
        step1_layout.addRow(step1_btn_box)

        return step1_groupBox

    def step2_layout(self):

        step2_groupBox = QGroupBox("Step 2")
        step2_layout = QVBoxLayout()
        step2_groupBox.setLayout(step2_layout)

        self.question1 = Label({'txt': "Question 1"})
        self.question2 = Label({'txt': "Question 2"})

        self.answer1 = QLineEdit()
        self.answer2 = QLineEdit()

        step2_btn_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        step2_btn_box.accepted.connect(self.on_step2_btn_clicked)
        step2_btn_box.rejected.connect(self.close)

        step2_layout.addWidget(self.question1)
        step2_layout.addWidget(self.answer1)
        step2_layout.addWidget(self.question2)
        step2_layout.addWidget(self.answer2)
        step2_layout.addWidget(step2_btn_box)

        return step2_groupBox

    def on_step1_btn_clicked(self):

        question1 = "What is the question 1"
        question2 = "What is the question 2"

        self.question1.setText(question1)
        self.question2.setText(question2)

        self.step1_form.setDisabled(True)
        self.step2_form.setVisible(True)

        # username = self.user_account.text()
        #
        # if len(username) == 0:
        #     QMessageBox.critical(self, 'Failed', mess.USER_BLANK)
        # else:
        #     checkUserExists = usql.check_data_exists(username)
        #     if not checkUserExists:
        #         QMessageBox.critical(self, 'Failed', mess.USER_NOT_EXSIST)
        #         question1, question2 = usql.query_user_security_question(username)
        #
        #         self.question1.setText(question1)
        #         self.question2.setText(question2)
        #
        #         self.step1_form.setDisabled(True)
        #         self.step2_form.setVisible(True)

    def on_step2_btn_clicked(self):
        pass

    def closeEvent(self, event):
        self.showLayout.emit(self.key, 'hide')
        event.ignore()