In the next step, we add the code for creating the QApplication and the QMainWindow and QDialog objects for the main window and the dialog for creating a new shapefile with their respective GUIs. For this, please paste the following code into your script directly under the comment “# create app and main window + dialog GUI”:
app = QApplication(sys.argv) # set up main window mainWindow = QMainWindow() ui = gui_main.Ui_MainWindow() ui.setupUi(mainWindow) ui.actionExit.setIcon(app.style().standardIcon(QStyle.SP_DialogCancelButton)) ui.layerRefreshTB.setIcon(app.style().standardIcon(QStyle.SP_BrowserReload)) ui.directInputLatLE.setValidator(QDoubleValidator()) ui.directInputLonLE.setValidator(QDoubleValidator()) ui.nominatimLimitLE.setValidator(QIntValidator()) ui.geonamesLimitLE.setValidator(QIntValidator()) mapWV = WebMapWidget() mapWV.page().profile().setHttpAcceptLanguage("en-US") mapWV.setHtml(core_functions.webMapFromDictionaryList([])) ui.resultsListAndMapHBL.addWidget(mapWV) mapWV.setFixedSize(300,200) mapWV.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)) # set up new shapefile dialog createShapefileDialog = QDialog(mainWindow) createShapefileDialog_ui = gui_newshapefile.Ui_Dialog() createShapefileDialog_ui.setupUi(createShapefileDialog)
In lines 4 to 6, we are creating the mainWindow object and then its GUI by calling the ui.SetupUi(…) method of an object we created from the Ui_MainWindow class defined in gui_main.py. The same happens in lines 23 to 25 for the dialog box for creating a new shapefile. The rest of the code is for creating some additional elements or setting some properties of GUI elements that we couldn’t take care of in QT Designer: