Exemple #1
0
    def set_degrees_minutes_seconds_from_point(self):
        """ From point in degrees, fill degrees, minutes and seconds QLineEdits"""

        if self.point is not None:

            lat_degrees_text = str(self.point.y())
            lon_degrees_text = str(self.point.x())

            if (validate_custom_double(lat_degrees_text) == QValidator.Acceptable and
                    validate_custom_double(lon_degrees_text) == QValidator.Acceptable):

                lat_dms, lon_dms = degree_to_degree_minute_second(float(lat_degrees_text), float(lon_degrees_text))

                lat_deg, lat_ms = str(lat_dms).split('º')
                lat_ms, unused = lat_ms.split('\'\'')
                lat_min, lat_sec = lat_ms.split('\'')

                lon_deg, lon_ms = str(lon_dms).split('º')
                lon_ms, unused = lon_ms.split('\'\'')
                lon_min, lon_sec = lon_ms.split('\'')

                self.lat_degrees_lineedit.setText("{:d}".format(int(lat_deg)))
                self.lat_minutes_lineedit.setText("{:d}".format(int(lat_min)))
                self.lat_seconds_lineedit.setText("{:.8F}".format(float(lat_sec)))
                self.lon_degrees_lineedit.setText("{:d}".format(int(lon_deg)))
                self.lon_minutes_lineedit.setText("{:d}".format(int(lon_min)))
                self.lon_seconds_lineedit.setText("{:.8F}".format(float(lon_sec)))
Exemple #2
0
    def set_degrees_from_point(self):
        """ From point in degrees, fill degrees QLineEdits"""
        if self.point is not None:

            lat_degrees_text = str(self.point.y())
            lon_degrees_text = str(self.point.x())

            if (validate_custom_double(lat_degrees_text) == QValidator.Acceptable and
                    validate_custom_double(lon_degrees_text) == QValidator.Acceptable):

                self.lat_degrees_lineedit.setText("{:.8F}".format(float(lat_degrees_text)))
                self.lon_degrees_lineedit.setText("{:.8F}".format(float(lon_degrees_text)))
    def test_validations(self):
        white = ''
        yellow = '#fff79a'
        red = '#f6989d'

        self.assertEqual(validate_ip("127.0.0.1"), QValidator.Acceptable)
        self.assertEqual(validate_ip("255.255.255.255"), QValidator.Acceptable)
        self.assertEqual(validate_ip("127.0."), QValidator.Intermediate)
        self.assertEqual(validate_ip("127.0...1"), QValidator.Invalid)
        self.assertEqual(validate_ip("300.0.0.1"), QValidator.Invalid)
        self.assertEqual(validate_ip("255.255.255.256"), QValidator.Invalid)
        self.assertEqual(validate_ip("abc"), QValidator.Invalid)

        self.assertEqual(validate_int("1"), QValidator.Acceptable)
        self.assertEqual(validate_int("0"), QValidator.Acceptable)
        self.assertEqual(validate_int("-1"), QValidator.Acceptable)
        self.assertEqual(validate_int("2310234"), QValidator.Acceptable)
        self.assertEqual(validate_int("a"), QValidator.Invalid)
        self.assertEqual(validate_int("3", 0, 5), QValidator.Acceptable)
        self.assertEqual(validate_int("5", 0, 5), QValidator.Acceptable)
        self.assertEqual(validate_int("0", 0, 5), QValidator.Acceptable)
        self.assertEqual(validate_int("-1", 0, 5), QValidator.Invalid)
        self.assertEqual(validate_int("6", 0, 5), QValidator.Invalid)

        self.assertEqual(validate_port("1"), QValidator.Acceptable)
        self.assertEqual(validate_port("8005"), QValidator.Acceptable)
        self.assertEqual(validate_port("65535"), QValidator.Acceptable)
        self.assertEqual(validate_port("0"), QValidator.Invalid)
        self.assertEqual(validate_port("-1"), QValidator.Invalid)
        self.assertEqual(validate_port("-8005"), QValidator.Invalid)
        self.assertEqual(validate_port("65536"), QValidator.Invalid)
        self.assertEqual(validate_port("99999"), QValidator.Invalid)
        self.assertEqual(validate_port("005"), QValidator.Invalid)

        self.assertEqual(validate_custom_double("1.0"), QValidator.Acceptable)
        self.assertEqual(validate_custom_double("a"), QValidator.Invalid)
        self.assertEqual(validate_custom_double("1,000.0"), QValidator.Invalid)
        self.assertEqual(validate_custom_double("1.000,0"), QValidator.Invalid)

        self.assertEqual(validate_custom_int("1"), QValidator.Acceptable)
        self.assertEqual(validate_custom_int("0"), QValidator.Acceptable)
        self.assertEqual(validate_custom_int("-1"), QValidator.Acceptable)
        self.assertEqual(validate_custom_int("1,000"), QValidator.Invalid)
        self.assertEqual(validate_custom_int("1.000"), QValidator.Invalid)

        self.assertEqual(get_color(QValidator.Acceptable), white)
        self.assertEqual(get_color(QValidator.Intermediate), yellow)
        self.assertEqual(get_color(QValidator.Invalid), red)
    def is_acceptable(self):
        is_acceptable = True

        for i in range(0, self.formLayout_2.count(), 2):
            if isinstance(self.formLayout_2.itemAt(i + 1).widget(), QLineEdit):
                state = validate_custom_double(self.formLayout_2.itemAt(i + 1).widget().text())
                if state != QValidator.Acceptable:
                    is_acceptable = False
        return is_acceptable
 def on_double_text_changed(self, string):
     sender = self.sender()
     state = validate_custom_double(sender.text())
     if state == QValidator.Acceptable:
         color = ''  # white
     elif state == QValidator.Intermediate:
         color = '#fff79a'  # yellow
     else:
         color = '#f6989d'  # red
     sender.setStyleSheet('QLineEdit { background-color: %s }' % color)
Exemple #6
0
    def set_degrees_minutes_from_point(self):
        """ From point in degrees, fill degrees and minutesQLineEdits"""

        if self.point is not None:

            lat_degrees_text = str(self.point.y())
            lon_degrees_text = str(self.point.x())

            if (validate_custom_double(lat_degrees_text) == QValidator.Acceptable and
                    validate_custom_double(lon_degrees_text) == QValidator.Acceptable):

                lat_dm, lon_dm = degree_to_degree_minute(float(lat_degrees_text), float(lon_degrees_text))

                lat_d, lat_m = str(lat_dm).split('º')
                lat_m, unused = lat_m.split('\'')

                lon_d, lon_m = str(lon_dm).split('º')
                lon_m, unused = lon_m.split('\'')

                self.lat_degrees_lineedit.setText("{:d}".format(int(lat_d)))
                self.lat_minutes_lineedit.setText("{:.8F}".format(float(lat_m)))
                self.lon_degrees_lineedit.setText("{:d}".format(int(lon_d)))
                self.lon_minutes_lineedit.setText("{:.8F}".format(float(lon_m)))
Exemple #7
0
    def is_correct(self):
        """Checks if last edited coordinates have the correct format"""
        if self.edited == 1:
            if validate_custom_double(self.lat_degree_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lon_degree_lineEdit.text()) == QValidator.Acceptable:
                return True

        elif self.edited == 2:
            if validate_custom_int(self.lat_dm_degree_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lon_dm_degree_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lat_dm_minute_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lon_dm_minute_lineEdit.text()) == QValidator.Acceptable:
                return True

        elif self.edited == 3:
            if validate_custom_int(self.lat_dms_degree_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lon_dms_degree_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lat_dms_minute_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lon_dms_minute_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lat_dms_second_lineEdit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lon_dms_second_lineEdit.text()) == QValidator.Acceptable:
                return True

        return False
Exemple #8
0
 def validate_coordinates_double(self):
     """validate line edit coordinates with double"""
     sender = self.sender()
     state = validate_custom_double(sender.text())
     color = get_color(state)
     sender.setStyleSheet('QLineEdit { background-color: %s }' % color)
Exemple #9
0
    def set_format(self):
        """ Set widgets on dialog according with combobox coordinates format"""

        if self.previous_coordinates_format == "Decimal degrees":

            if validate_custom_double(self.lon_degrees_lineedit.text()) == QValidator.Acceptable and \
                    validate_custom_double(self.lat_degrees_lineedit.text()) == QValidator.Acceptable:

                self.point = QgsPointXY(float(self.lon_degrees_lineedit.text()),
                                        float(self.lat_degrees_lineedit.text()))
            else:
                self.point = None

        elif self.previous_coordinates_format == "Degrees, minutes":
            lat_d = self.lat_degrees_lineedit.text()
            lat_m = self.lat_minutes_lineedit.text()
            lon_d = self.lon_degrees_lineedit.text()
            lon_m = self.lon_minutes_lineedit.text()

            if validate_custom_int(lat_d) == QValidator.Acceptable \
                and validate_custom_double(lat_m) == QValidator.Acceptable \
                and validate_custom_int(lon_d) == QValidator.Acceptable \
                and validate_custom_double(lon_m) == QValidator.Acceptable:

                lat_dm = [lat_d, lat_m]
                lon_dm = [lon_d, lon_m]

                # convert degree_minute to degree
                lat_degree, lon_degree = degree_minute_to_degree(lat_dm, lon_dm)
                self.point = QgsPointXY(float(lon_degree),
                                        float(lat_degree))
            else:

                self.point = None

        elif self.previous_coordinates_format == "Degrees, minutes, seconds":
            if validate_custom_int(self.lat_degrees_lineedit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lat_minutes_lineedit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lat_seconds_lineedit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lon_degrees_lineedit.text()) == QValidator.Acceptable \
                    and validate_custom_int(self.lon_minutes_lineedit.text()) == QValidator.Acceptable \
                    and validate_custom_double(self.lon_seconds_lineedit.text()) == QValidator.Acceptable:

                lat = self.lat_degrees_lineedit.text() + 'º' + self.lat_minutes_lineedit.text() + '\'' + self.lat_seconds_lineedit.text() + '\'\''
                lon = self.lon_degrees_lineedit.text() + 'º' + self.lon_minutes_lineedit.text() + '\'' + self.lon_seconds_lineedit.text() + '\'\''

                lat_degree, lon_degree = degree_minute_second_to_degree(lat, lon)
                self.point = QgsPointXY(float(lon_degree),
                                        float(lat_degree))

            else:
                self.point = None

        # delete previous widgets
        self.delete_all(self.latitude_layout)
        self.delete_all(self.longitude_layout)

        lat_label = QLabel(self)
        lat_label.setText("Latitude: ")
        lat_label.setFixedWidth(75)
        lon_label = QLabel(self)
        lon_label.setText("Longitude: ")
        lon_label.setFixedWidth(75)

        self.latitude_layout.addWidget(lat_label)
        self.longitude_layout.addWidget(lon_label)

        if self.comboBox.currentText() == "Decimal degrees" or self.previous_coordinates_format is None:
            self.lat_degrees_lineedit = QLineEdit(self)
            self.lon_degrees_lineedit = QLineEdit(self)

            self.lat_degrees_lineedit.textChanged.connect(self.validate_coordinates_double)
            self.lon_degrees_lineedit.textChanged.connect(self.validate_coordinates_double)

            self.latitude_layout.addWidget(self.lat_degrees_lineedit)
            self.longitude_layout.addWidget(self.lon_degrees_lineedit)

            self.set_degrees_from_point()


        if self.comboBox.currentText() == "Degrees, minutes":

            lat_deg_label = QLabel(self)
            lat_deg_label.setText("º")
            lon_deg_label = QLabel(self)
            lon_deg_label.setText("º")
            lat_min_label = QLabel(self)
            lat_min_label.setText("\'")
            lon_min_label = QLabel(self)
            lon_min_label.setText("\'")
            self.lat_degrees_lineedit = QLineEdit(self)
            self.lon_degrees_lineedit = QLineEdit(self)
            self.lat_minutes_lineedit = QLineEdit(self)
            self.lon_minutes_lineedit = QLineEdit(self)

            self.lat_degrees_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lon_degrees_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lat_minutes_lineedit.textChanged.connect(self.validate_coordinates_double)
            self.lon_minutes_lineedit.textChanged.connect(self.validate_coordinates_double)

            self.latitude_layout.addWidget(self.lat_degrees_lineedit)
            self.latitude_layout.addWidget(lat_deg_label)
            self.latitude_layout.addWidget(self.lat_minutes_lineedit)
            self.latitude_layout.addWidget(lat_min_label)

            self.longitude_layout.addWidget(self.lon_degrees_lineedit)
            self.longitude_layout.addWidget(lon_deg_label)
            self.longitude_layout.addWidget(self.lon_minutes_lineedit)
            self.longitude_layout.addWidget(lon_min_label)

            self.set_degrees_minutes_from_point()


        if self.comboBox.currentText() == "Degrees, minutes, seconds":

            lat_deg_label = QLabel(self)
            lat_deg_label.setText("º")
            lon_deg_label = QLabel(self)
            lon_deg_label.setText("º")
            lat_min_label = QLabel(self)
            lat_min_label.setText("\'")
            lon_min_label = QLabel(self)
            lon_min_label.setText("\'")
            lat_sec_label = QLabel(self)
            lat_sec_label.setText("\'\'")
            lon_sec_label = QLabel(self)
            lon_sec_label.setText("\'\'")
            self.lat_degrees_lineedit = QLineEdit(self)
            self.lon_degrees_lineedit = QLineEdit(self)
            self.lat_minutes_lineedit = QLineEdit(self)
            self.lon_minutes_lineedit = QLineEdit(self)
            self.lat_seconds_lineedit = QLineEdit(self)
            self.lon_seconds_lineedit = QLineEdit(self)

            self.lat_degrees_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lon_degrees_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lat_minutes_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lon_minutes_lineedit.textChanged.connect(self.validate_coordinates_int)
            self.lat_seconds_lineedit.textChanged.connect(self.validate_coordinates_double)
            self.lon_seconds_lineedit.textChanged.connect(self.validate_coordinates_double)

            self.latitude_layout.addWidget(self.lat_degrees_lineedit)
            self.latitude_layout.addWidget(lat_deg_label)
            self.latitude_layout.addWidget(self.lat_minutes_lineedit)
            self.latitude_layout.addWidget(lat_min_label)
            self.latitude_layout.addWidget(self.lat_seconds_lineedit)
            self.latitude_layout.addWidget(lat_sec_label)

            self.longitude_layout.addWidget(self.lon_degrees_lineedit)
            self.longitude_layout.addWidget(lon_deg_label)
            self.longitude_layout.addWidget(self.lon_minutes_lineedit)
            self.longitude_layout.addWidget(lon_min_label)
            self.longitude_layout.addWidget(self.lon_seconds_lineedit)
            self.longitude_layout.addWidget(lon_sec_label)

            self.set_degrees_minutes_seconds_from_point()


        self.previous_coordinates_format = self.comboBox.currentText()