class MapDisplay(QMainWindow): def __init__(self): super().__init__() uic.loadUi(join(UI, "map_output_hw1.ui"), self) self.map_api = MapAPI("Океанский просп., 17, Владивосток") self.map_api.set_zoom(10) self.name = f"map_{str(len(listdir(RESULTS)) + 1)}.png" self.update() self.hybrid_rb.toggled.connect(self.hybrid) self.satellite_rb.toggled.connect(self.satellite) self.scheme_rb.toggled.connect(self.scheme) def update(self): img = Image.open(self.map_api.get_image()) img.save(join(split(getcwd())[0], f"results/{self.name}")) scene = QGraphicsScene() scene.addPixmap(QPixmap(join(split(getcwd())[0], f"results/{self.name}"))) self.display.setScene(scene) def keyPressEvent(self, event): if event.key() == Qt.Key_W: #вверх self.map_api.move_up() self.update() if event.key() == Qt.Key_S: #вниз self.map_api.move_down() self.update() if event.key() == Qt.Key_A: #влево self.map_api.move_left() self.update() if event.key() == Qt.Key_D: #вправо self.map_api.move_right() self.update() if event.key() == Qt.Key_R: #приближение self.map_api.zoom_in(1) self.update() if event.key() == Qt.Key_F: #отдаление self.map_api.zoom_in(-1) self.update() def scheme(self): self.map_api.set_style("map") self.update() def satellite(self): self.map_api.set_style("sat") self.update() def hybrid(self): self.map_api.set_style("sat,trf") self.update()
class MapDisplay(QMainWindow): def __init__(self): super().__init__() uic.loadUi(join(UI, "map_output_extra3.ui"), self) self.find_b.clicked.connect(self.find_place) self.clear_b.clicked.connect(self.cancel) self.hybrid_rb.toggled.connect(self.hybrid) self.satellite_rb.toggled.connect(self.satellite) self.scheme_rb.toggled.connect(self.scheme) def find_place(self): self.place = self.place_input.text() if self.place == "": return self.form_map() self.update() if self.index_chb.isChecked(): ad = " ".join(list(map(str, self.map_api.get_full_data().values()))) else: ad = " ".join( list(map(str, self.map_api.get_full_data().values()))[:-1]) self.adress_d.setText(ad) def form_map(self): self.map_api = MapAPI(self.place) self.map_api.set_zoom(10) self.name = f"map_{str(len(listdir(RESULTS)) + 1)}.png" place = self.place self.map_api.add_pin(place) def update(self): img = Image.open(self.map_api.get_image()) img.save(join(split(getcwd())[0], f"results/{self.name}")) self.scene = QGraphicsScene() self.scene.addPixmap( QPixmap(join(split(getcwd())[0], f"results/{self.name}"))) self.display.setScene(self.scene) def cancel(self): self.place_input.clear() self.map_api.clear_pin() self.place = '' self.adress_d.setText( " " ) self.update() def keyPressEvent(self, event): if event.key() == Qt.Key_W: # вверх self.map_api.move_up() self.update() if event.key() == Qt.Key_S: # вниз self.map_api.move_down() self.update() if event.key() == Qt.Key_A: # влево self.map_api.move_left() self.update() if event.key() == Qt.Key_D: # вправо self.map_api.move_right() self.update() if event.key() == Qt.Key_R: # приближение self.map_api.zoom_in(1) self.update() if event.key() == Qt.Key_F: # отдаление self.map_api.zoom_in(-1) self.update() def scheme(self): self.find_place() if self.place == "": return self.map_api.set_style("map") self.update() def satellite(self): self.find_place() if self.place == "": return self.map_api.set_style("sat") self.update() def hybrid(self): self.find_place() if self.place == "": return self.map_api.set_style("sat,trf") self.update()