コード例 #1
0
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Airport Query System")
        self.setWindowIcon(QIcon("icon.svg"))
        #self.setStyleSheet('background-color:grey')

        self.top = 200
        self.left = 1800
        self.width = 500
        self.height = 700
        self.setGeometry(self.left, self.top, self.width, self.height)

        vbox = QVBoxLayout()
        tabWidget = QTabWidget()

        buttonbox = QDialogButtonBox(QDialogButtonBox.Close)
        buttonbox.rejected.connect(self.reject)
        buttonbox.setFont(QtGui.QFont("MS Sans Serif", 10))
        buttonbox.setToolTip("<h4>Close the application。<h4>")

        tabWidget.setFont(QtGui.QFont("MS Sans Serif", 10))
        tabWidget.addTab(InstantSearch(), "Flight")
        tabWidget.addTab(Library(), "Library")
        #tabWidget.addTab(TabPeronsalDetails(), "Personal Details")

        vbox.addWidget(tabWidget)
        vbox.addWidget(buttonbox)

        self.setLayout(vbox)
コード例 #2
0
class ServerDialog(QDialog):
    """Class for setting up the Server ip and port"""
    host_ip = ""
    port = None
    default_host = '127.0.0.1'
    default_port = 33002

    def __init__(self):
        super().__init__()

        self.is_host_valid = False
        self.is_port_valid = False

        self.resize(400, 200)
        self.setWindowTitle("Server Settings")

        self.set_palette()

        self.layout = QFormLayout(self)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.settings_message = QLabel(self)
        self.use_default_label = QLabel(self)
        self.radio_button = QRadioButton(self)
        self.host_label = QLabel(self)
        self.host_edit_line = QLineEdit(self)
        self.port_label = QLabel(self)
        self.port_edit_line = QLineEdit(self)
        self.button_box = QDialogButtonBox(self)
        self.setup_buttons()

        self.setup_ui()

        self.host_edit_line.textChanged.connect(self.validate_host)
        self.port_edit_line.textChanged.connect(self.validate_port)
        self.radio_button.toggled.connect(self.handle_checked_radiobtn)

    def setup_ui(self):
        """Define the main components of Dialog Gui"""
        self.setup_labels()
        self.setup_edit_lines()
        self.setup_buttons()
        self.setup_radio_btn()

    def setup_labels(self):
        """Define the labels of the Dialog Gui"""
        # settings label
        self.settings_message.setFont(QFont('Courier New', 12))
        self.settings_message.setText('Server Settings')
        self.settings_message.setAlignment(Qt.AlignCenter)
        self.layout.setWidget(0, QFormLayout.SpanningRole, self.settings_message)
        # default label
        self.use_default_label.setFont(QFont('Courier New', 12))
        self.use_default_label.setText('use default settings:')
        self.layout.setWidget(2, QFormLayout.LabelRole, self.use_default_label)
        # host label
        self.host_label.setFont(QFont('Courier New', 12))
        self.host_label.setText('HOST: ')
        self.layout.setWidget(3, QFormLayout.LabelRole, self.host_label)
        # port label
        self.port_label.setFont(QFont('Courier New', 12))
        self.port_label.setText('PORT: ')
        self.layout.setWidget(4, QFormLayout.LabelRole, self.port_label)

    def setup_edit_lines(self):
        """Define the edid lines of the Dialog Gui"""
        # host edit line
        self.host_edit_line.setFont(QFont('Courier New', 12))
        self.host_edit_line.setPlaceholderText("127.0.0.1")
        self.host_edit_line.setEnabled(False)
        self.host_edit_line.setSizePolicy(QSizePolicy.MinimumExpanding,
                                          QSizePolicy.MinimumExpanding)
        self.layout.setWidget(3, QFormLayout.FieldRole, self.host_edit_line)
        # port edit line
        self.port_edit_line.setFont(QFont('Courier New', 12))
        self.port_edit_line.setPlaceholderText('33002')
        self.port_edit_line.setEnabled(False)
        self.host_edit_line.setSizePolicy(QSizePolicy.MinimumExpanding,
                                          QSizePolicy.MinimumExpanding)
        self.layout.setWidget(4, QFormLayout.FieldRole, self.port_edit_line)

    def setup_buttons(self):
        """Define the buttons of the Dialog Gui"""
        self.button_box.setOrientation(Qt.Horizontal)
        self.button_box.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
        self.button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
        self.button_box.setFont(QFont('Courier New', 12))
        self.layout.setWidget(5, QFormLayout.SpanningRole, self.button_box)

        self.button_box.button(QDialogButtonBox.Ok).clicked.connect(self.ok_clicked)
        self.button_box.button(QDialogButtonBox.Cancel).clicked.connect(self.cancel_clicked)

    def setup_radio_btn(self):
        """Radio button is checked by default, to use the default settings"""
        self.radio_button.setChecked(True)
        self.layout.setWidget(2, QFormLayout.FieldRole, self.radio_button)

    def get_settings(self):
        return self.host_ip, int(self.port)

    def handle_checked_radiobtn(self):
        """The radio button enables the user to use default
           values to connect to the server if checke"""
        print('radioButton checked: {}'.format(self.radio_button.isChecked()))
        if self.radio_button.isChecked():
            #dissable the input for host and port
            self.host_edit_line.setEnabled(False)
            self.port_edit_line.setEnabled(False)
        elif not self.radio_button.isChecked():
            #enable the input for host and port
            self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
            self.host_edit_line.setEnabled(True)
            self.port_edit_line.setEnabled(True)
        self.validate_ok_btn()

    def validate_host(self):
        """To pass the validation, the user has to insert a valid ipV4 addres"""
        patrn = (r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)"
                 "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
        ipv4_pattern = re.compile(patrn)
        isa_match = ipv4_pattern.match(self.host_edit_line.text())

        # check to see if the ip match and
        #if the port edit line is not empty
        if isa_match:
            self.host_edit_line.setStyleSheet("""
                QWidget {
                    background-color: rgba(0, 155, 118, 50)
                    }
                """)

            self.is_host_valid = True
        else:
            self.host_edit_line.setStyleSheet("""
                QWidget {
                    background-color: rgba(177, 4, 14, 50)
                    }
                """)
            self.is_host_valid = False

        self.validate_ok_btn()

    def validate_port(self):
        port_str = self.port_edit_line.text()

        if port_str.isnumeric():
            self.port_edit_line.setStyleSheet("""
                QWidget {
                    background-color: rgba(0, 155, 118, 50)
                    }
                """)
            self.is_port_valid = True
        else:
            self.port_edit_line.setStyleSheet("""
                QWidget {
                    background-color: rgba(177, 4, 14, 50)
                    }
                """)
            self.is_port_valid = False

        self.validate_ok_btn()

    def validate_ok_btn(self):
        if self.radio_button.isChecked():
            self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
        elif self.is_host_valid and self.is_port_valid:
            self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
        else:
            self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)

    def ok_clicked(self):
        if self.radio_button.isChecked():
            self.host_ip = self.default_host
            self.port = self.default_port
        else:
            self.host_ip = self.host_edit_line.text()
            self.port = self.port_edit_line.text()
        self.done(1)

    def cancel_clicked(self):
        self.done(0)

    def set_palette(self):
        palette = QPalette()
        gradient = QLinearGradient(0, 0, 0, 100)
        gradient.setColorAt(1.0, Colors.light_sandstone)
        gradient.setColorAt(0.0, Colors.stone)
        palette.setBrush(QPalette.Window, QBrush(gradient))
        self.setPalette(palette)
コード例 #3
0
    def initUI(self):
        lblFind = QLabel(self)
        lblFind.setGeometry(QRect(10, 10, 47, 21))
        defaultFont = QFont()
        defaultFont.setPointSize(10)
        lblFind.setFont(defaultFont)
        lblFind.setText("Find")

        lblReplace = QLabel(self)
        lblReplace.setGeometry(QRect(10, 53, 61, 20))
        lblReplace.setFont(defaultFont)
        lblReplace.setText("Replace")

        self.txtFind = QLineEdit(self)
        self.txtFind.setGeometry(QRect(80, 10, 261, 20))
        self.txtFind.setFont(defaultFont)

        self.txtReplace = QLineEdit(self)
        self.txtReplace.setGeometry(QRect(80, 50, 261, 21))
        self.txtReplace.setFont(defaultFont)

        self.chkRE = QCheckBox(self)
        self.chkRE.setGeometry(QRect(10, 110, 261, 17))
        self.chkRE.setFont(defaultFont)
        self.chkRE.setText("Regular Expression")

        self.chkCS = QCheckBox(self)
        self.chkCS.setGeometry(QRect(10, 140, 261, 17))
        self.chkCS.setFont(defaultFont)
        self.chkCS.setText("Case sensitive")

        self.chkWord = QCheckBox(self)
        self.chkWord.setGeometry(QRect(10, 170, 261, 17))
        self.chkWord.setFont(defaultFont)
        self.chkWord.setText("Whole word")

        self.chkWrap = QCheckBox(self)
        self.chkWrap.setGeometry(QRect(10, 200, 261, 17))
        self.chkWrap.setFont(defaultFont)
        self.chkWrap.setText("Wrap around")

        defaultDialogButtons = QDialogButtonBox(self)
        defaultDialogButtons.setGeometry(QRect(250, 340, 156, 23))
        defaultDialogButtons.setFont(defaultFont)
        defaultDialogButtons.setStandardButtons(QDialogButtonBox.Cancel
                                                | QDialogButtonBox.Ok)

        btnReplace = QPushButton(self)
        btnReplace.setGeometry(QRect(150, 340, 91, 23))
        btnReplace.setFont(defaultFont)
        btnReplace.setText("Replace...")

        directionBox = QGroupBox(self)
        directionBox.setGeometry(QRect(20, 240, 120, 80))
        directionBox.setFont(defaultFont)
        directionBox.setTitle("Direction")

        self.rbFwd = QRadioButton(directionBox)
        self.rbFwd.setGeometry(QRect(10, 20, 82, 17))
        self.rbFwd.setFont(defaultFont)
        self.rbFwd.setText("Forward")
        self.rbFwd.setChecked(True)

        self.rbBwd = QRadioButton(directionBox)
        self.rbBwd.setGeometry(QRect(10, 50, 82, 17))
        self.rbBwd.setFont(defaultFont)
        self.rbBwd.setText("Backward")

        btnReplace.clicked.connect(self.ReplaceText)
        defaultDialogButtons.accepted.connect(self.accept)
        defaultDialogButtons.rejected.connect(self.reject)