def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() self.nameEdit = LineEdit() self.nameEdit.setPlaceholderText('Project Name') self.nameEdit.setValidator( QRegExpValidator(QRegExp('[^\\\*<>:"/\|?*]+'))) self.nameEdit.textChanged.connect(self.checkFields) #horizontal layout containing save and cancel buttons hLayout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) hLayout.addWidget(self.saveButton) hLayout.addWidget(self.cancelButton) mainLayout.addWidget(self.nameEdit) mainLayout.addLayout(hLayout) self.setLayout(mainLayout) self.setModal(True) self.show()
def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.latEdit = LineEdit() self.latEdit.setPlaceholderText('Latitude') self.latEdit.textChanged.connect(self.checkFields) self.lonEdit = LineEdit() self.lonEdit.setPlaceholderText('Longitude') self.lonEdit.textChanged.connect(self.checkFields) hLayout.addWidget(self.latEdit) hLayout.addWidget(self.lonEdit) #horizontal layout to hold description box h2Layout = QHBoxLayout() self.descBox = QTextEdit() self.descBox.setFixedHeight(100) self.descBox.setPlaceholderText('Description') h2Layout.addWidget(self.descBox) #horizontal layout containing save and cancel buttons h3Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.saveButton.setEnabled(False) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h3Layout.addWidget(self.saveButton) h3Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) mainLayout.addLayout(h3Layout) self.setLayout(mainLayout) self.setModal(True) self.show()
def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.pixelEdit = LineEdit(str(self.dist_px)) self.pixelEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.pixelEdit.textChanged.connect(self.checkFields) self.scaleEdit = LineEdit(str(self.scale)) self.scaleEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.scaleEdit.textChanged.connect(self.checkFields) label = QLabel('Pixels:') units = ['km', 'm', 'ft', 'mi'] self.comboBox = QComboBox() self.comboBox.addItems(units) hLayout.addWidget(label) hLayout.addWidget(self.pixelEdit) hLayout.addWidget(self.scaleEdit) hLayout.addWidget(self.comboBox) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show()
class ProjectSettingsWindow(QDialog): def __init__(self, parent=None): super(ProjectSettingsWindow, self).__init__(parent) self.setWindowTitle('Edit Project Data') self.setAttribute(Qt.WA_QuitOnClose, False) self.setModal(True) self.initUI() def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() self.nameEdit = LineEdit() self.nameEdit.setPlaceholderText('Project Name') self.nameEdit.setValidator( QRegExpValidator(QRegExp('[^\\\*<>:"/\|?*]+'))) self.nameEdit.textChanged.connect(self.checkFields) #horizontal layout containing save and cancel buttons hLayout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) hLayout.addWidget(self.saveButton) hLayout.addWidget(self.cancelButton) mainLayout.addWidget(self.nameEdit) mainLayout.addLayout(hLayout) self.setLayout(mainLayout) self.setModal(True) self.show() def checkFields(self): ''' Check if all mandatory fields are entered ''' if self.nameEdit.text(): self.saveButton.setEnabled(True) else: self.saveButton.setEnabled(False) def save(self): ''' Send data back to MainWindow to update project data ''' self.parent().setProjectName(self.nameEdit.text()) self.close() def cancel(self): ''' Return to mouse tracker screen if cancel button is clicked ''' self.close()
def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() hLayout = QHBoxLayout() self.apiKeyEdit = LineEdit() self.apiKeyEdit.setPlaceholderText('Google API Key') self.apiKeyEdit.textChanged.connect(self.checkFields) self.helpButton = Button('?') self.helpButton.setMaximumWidth(25) self.helpButton.clicked.connect(lambda: webbrowser.open( 'https://developers.google.com/maps/documentation/javascript/get-api-key' )) hLayout.addWidget(self.apiKeyEdit) hLayout.addWidget(self.helpButton) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show()
def setupUI(self): self.setTitle("Project Data") self.setSubTitle("Please fill all fields.") self.nameLabel = QLabel("Project Name:") self.nameLineEdit = LineEdit() self.nameLineEdit.setValidator(QtGui.QRegExpValidator(QRegExp('[^\\\*<>:"/\|?*]+'))) self.registerField('projectName*', self.nameLineEdit) self.refLabel = QLabel("Reference Point:") self.latLineEdit = LineEdit() self.latLineEdit.setPlaceholderText('Latitude') self.registerField('latitude*', self.latLineEdit) self.lonLineEdit = LineEdit() self.lonLineEdit.setPlaceholderText('Longitude') self.registerField('longitude*', self.lonLineEdit) self.mapGraphic = QLabel(self) self.pixmap = QPixmap('Resources/LatLongImg_v0.2.png') self.mapGraphic.setPixmap(self.pixmap) self.resize(self.pixmap.width(), self.pixmap.height()) self.layout = QVBoxLayout() self.layout2 = QGridLayout() self.layout2.addWidget(self.nameLabel, 0, 0) self.layout2.addWidget(self.nameLineEdit, 0, 1, 1, 3) self.layout2.addWidget(self.refLabel, 1, 0) self.layout2.addWidget(self.latLineEdit, 1, 1) self.layout2.addWidget(self.lonLineEdit, 1, 2) self.layout.addLayout(self.layout2) self.layout.addWidget(self.mapGraphic) self.setLayout(self.layout)
class WizardDataPage(QWizardPage): def __init__(self, parent): super(WizardDataPage, self).__init__(parent) self.setupUI() def setupUI(self): self.setTitle("Project Data") self.setSubTitle("Please fill all fields.") self.nameLabel = QLabel("Project Name:") self.nameLineEdit = LineEdit() self.nameLineEdit.setValidator(QtGui.QRegExpValidator(QRegExp('[^\\\*<>:"/\|?*]+'))) self.registerField('projectName*', self.nameLineEdit) self.refLabel = QLabel("Reference Point:") self.latLineEdit = LineEdit() self.latLineEdit.setPlaceholderText('Latitude') self.registerField('latitude*', self.latLineEdit) self.lonLineEdit = LineEdit() self.lonLineEdit.setPlaceholderText('Longitude') self.registerField('longitude*', self.lonLineEdit) self.mapGraphic = QLabel(self) self.pixmap = QPixmap('Resources/LatLongImg_v0.2.png') self.mapGraphic.setPixmap(self.pixmap) self.resize(self.pixmap.width(), self.pixmap.height()) self.layout = QVBoxLayout() self.layout2 = QGridLayout() self.layout2.addWidget(self.nameLabel, 0, 0) self.layout2.addWidget(self.nameLineEdit, 0, 1, 1, 3) self.layout2.addWidget(self.refLabel, 1, 0) self.layout2.addWidget(self.latLineEdit, 1, 1) self.layout2.addWidget(self.lonLineEdit, 1, 2) self.layout.addLayout(self.layout2) self.layout.addWidget(self.mapGraphic) self.setLayout(self.layout) def getProjectName(self): ''' Returns project name entered in nameLineEdit field ''' return self.nameLineEdit.text() def getReferencePoint(self): ''' Returns reference lat/lon as tuple from latLineEdit and lonLineEdit fields ''' lat = self.latLineEdit.text() lon = self.lonLineEdit.text() try: point = Point(lat + ' ' + lon) except: QMessageBox.information( self, 'Reference Point Error', f'Invalid reference point: ({lat}, {lon})' ) return False else: lat = round(point.latitude, 6) lon = round(point.longitude, 6) return [(lat, lon)]
class APIKeyWindow(QDialog): def __init__(self, parent=None): super(APIKeyWindow, self).__init__(parent) self.setWindowTitle('Enter API Key') self.setAttribute(Qt.WA_QuitOnClose, False) self.setModal(True) self.resize(400, 150) self.initUI() def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() hLayout = QHBoxLayout() self.apiKeyEdit = LineEdit() self.apiKeyEdit.setPlaceholderText('Google API Key') self.apiKeyEdit.textChanged.connect(self.checkFields) self.helpButton = Button('?') self.helpButton.setMaximumWidth(25) self.helpButton.clicked.connect(lambda: webbrowser.open( 'https://developers.google.com/maps/documentation/javascript/get-api-key' )) hLayout.addWidget(self.apiKeyEdit) hLayout.addWidget(self.helpButton) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show() def checkFields(self): ''' Check if all mandatory fields are entered ''' if self.apiKeyEdit.text(): self.saveButton.setEnabled(True) def getConfirmedData(self): return self.apiKeyEdit.text() def save(self): ''' Send scale and unit values entered by user back to mouse tracker screen when save button is clicked. ''' self.accept() self.close() def cancel(self): ''' Return to mouse tracker screen if cancel button is clicked ''' self.reject() self.close()
class LocationWindow(QDialog): def __init__(self, lat, lon, parent=None): super(LocationWindow, self).__init__(parent) self.lat = lat self.lon = lon #self.setFixedSize(300, 100) self.setWindowTitle('Confirm Location') self.setAttribute(Qt.WA_QuitOnClose, False) self.initUI() def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.latEdit = LineEdit(str(self.lat)) self.latEdit.textChanged.connect(self.checkFields) hLayout.addWidget(self.latEdit) self.lonEdit = LineEdit(str(self.lon)) self.lonEdit.textChanged.connect(self.checkFields) hLayout.addWidget(self.lonEdit) self.descBox = QTextEdit() self.descBox.setFixedHeight(100) self.descBox.setPlaceholderText('Description') #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addWidget(self.descBox) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show() def checkFields(self): ''' Check if all mandatory fields are entered ''' if self.latEdit.text() and self.lonEdit.text(): self.saveButton.setEnabled(True) else: self.saveButton.setEnabled(False) def getConfirmedData(self): return { 'Latitude': self.lat, 'Longitude': self.lon, 'Date': QDateTime().currentDateTime().toString('MM-dd-yyyy hh:mm:ss ap'), 'Description': self.desc } def save(self): ''' Send scale and unit values entered by user back to mouse mainwindow screen when save button is clicked. ''' lat = self.latEdit.text() lon = self.lonEdit.text() self.desc = self.descBox.toPlainText() lat = self.latEdit.text() lon = self.lonEdit.text() try: point = Point(lat + ' ' + lon) except: QMessageBox.information(self, 'Point Location Error', f'Invalid location: ({lat}, {lon})') else: self.lat = round(point.latitude, 6) self.lon = round(point.longitude, 6) self.accept() self.close() def cancel(self): ''' Return to mouse tracker screen if cancel button is clicked ''' self.reject() self.close()
class ScaleWindow(QDialog): def __init__(self, dist_px, parent=None): super(ScaleWindow, self).__init__(parent) self.dist_px = dist_px self.scale = 1 self.setWindowTitle('Scale') self.initUI() def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.pixelEdit = LineEdit(str(self.dist_px)) self.pixelEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.pixelEdit.textChanged.connect(self.checkFields) self.scaleEdit = LineEdit(str(self.scale)) self.scaleEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.scaleEdit.textChanged.connect(self.checkFields) label = QLabel('Pixels:') units = ['km', 'm', 'ft', 'mi'] self.comboBox = QComboBox() self.comboBox.addItems(units) hLayout.addWidget(label) hLayout.addWidget(self.pixelEdit) hLayout.addWidget(self.scaleEdit) hLayout.addWidget(self.comboBox) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show() def checkFields(self): ''' Check if all mandatory fields are entered ''' if self.pixelEdit.text() and self.scaleEdit.text(): self.saveButton.setEnabled(True) else: self.saveButton.setEnabled(False) def getConfirmedData(self): return self.pxPerUnit, self.units def save(self): ''' Send scale and unit values entered by user back to mouse tracker screen when save button is clicked. ''' #Get text values from each element self.scale = eval(self.scaleEdit.text()) self.dist_px = eval(self.pixelEdit.text()) self.units = self.comboBox.currentText() self.pxPerUnit = self.dist_px / self.scale #check values entered by user are correct if self.scale > 0 and self.dist_px > 0: self.accept() self.close() def cancel(self): ''' Return to mouse tracker screen if cancel button is clicked ''' self.reject() self.close()
class ReferenceWindow(QDialog): def __init__(self, parent=None): super(ReferenceWindow, self).__init__(parent) self.resize(400, 100) self.setWindowTitle('Add Reference Point') self.initUI() def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.latEdit = LineEdit() self.latEdit.setPlaceholderText('Latitude') self.latEdit.textChanged.connect(self.checkFields) self.lonEdit = LineEdit() self.lonEdit.setPlaceholderText('Longitude') self.lonEdit.textChanged.connect(self.checkFields) hLayout.addWidget(self.latEdit) hLayout.addWidget(self.lonEdit) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.saveButton.setEnabled(False) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show() def checkFields(self): ''' Check if all mandatory fields are entered ''' lat = self.latEdit.text() lon = self.lonEdit.text() if lat and lon: self.saveButton.setEnabled(True) else: self.saveButton.setEnabled(False) def getConfirmedData(self): return self.lat, self.lon def save(self): ''' Send reference point back to main window to be stored ''' lat = self.latEdit.text() lon = self.lonEdit.text() try: point = Point(lat + ' ' + lon) except: QMessageBox.information( self, 'Reference Point Error', f'Invalid reference point: ({lat}, {lon})') else: self.lat = round(point.latitude, 6) self.lon = round(point.longitude, 6) self.accept() self.close() def cancel(self): ''' Return to mouse tracker screen if cancel button is clicked ''' self.reject() self.close()