|
1 | 1 | import sys |
2 | | -from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QMessageBox, QComboBox, QHBoxLayout, QVBoxLayout, QGroupBox, QCheckBox, QRadioButton, QDialogButtonBox, QFileDialog, QLabel, QLineEdit, QPushButton |
| 2 | +from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QMessageBox, QSlider, QComboBox, QHBoxLayout, QVBoxLayout, QGroupBox, QCheckBox, QRadioButton, QDialogButtonBox, QFileDialog, QLabel, QLineEdit, QPushButton |
3 | 3 | from PyQt5.QtCore import Qt, QThread, pyqtSignal, QEvent, QPoint, QSize |
4 | | -from PyQt5.QtGui import QIntValidator |
| 4 | +from PyQt5.QtGui import QIntValidator, QPixmap |
5 | 5 | import pandas as pd |
6 | 6 | import geopandas as gpd |
7 | 7 | from shapely.geometry import Point |
8 | 8 |
|
9 | | -from consts import SAVE_KEY_MAP, ENUM_LOAD_MODE, ENUM_SEPERATOR, CONST_COORDSYS_STRMAP |
10 | | -from network import get_addr_from_epsg |
| 9 | +from consts import SAVE_KEY_MAP, ENUM_LOAD_MODE, ENUM_SEPERATOR, CONST_COORDSYS_STRMAP, ENUM_STATICMAP_BASEMAP |
| 10 | +from network import get_addr_from_epsg, get_map_img |
11 | 11 |
|
12 | 12 |
|
13 | 13 | def transform_to_epsg4326(x, y, epsg): |
@@ -272,7 +272,7 @@ def __init__(self, gui): |
272 | 272 | self.lineedit_y = lineedit_y |
273 | 273 |
|
274 | 274 | find_button = QPushButton("찾기") |
275 | | - find_button.pressed.connect(self.on_click_find_button) |
| 275 | + find_button.clicked.connect(self.on_click_find_button) |
276 | 276 | layout.addWidget(find_button) |
277 | 277 |
|
278 | 278 | self.setLayout(layout) |
@@ -491,48 +491,148 @@ def on_finished(self, df): |
491 | 491 | self.accept() |
492 | 492 |
|
493 | 493 |
|
| 494 | +# addr, epsg를 주면 알아서 기존 세팅과 api_key를 때마다 받아와 요청한다. |
494 | 495 | class ImageViewerDialog(QDialog): |
495 | | - def __init__(self, parent, title, pixmap): |
| 496 | + def __init__(self, parent, addr, epsg): |
496 | 497 | super(ImageViewerDialog, self).__init__(parent=parent) |
| 498 | + |
| 499 | + self.epsg = epsg |
| 500 | + |
497 | 501 | self.setWindowTitle( |
498 | | - "{title} (정확한 위치가 아닐 수 있습니다. 이 창은 독립적입니다.)".format(title=title)) |
| 502 | + f"{addr} (정확한 위치가 아닐 수 있습니다. 이 창은 독립적입니다.)") |
499 | 503 | self.move(parent.settings.value("ivd_pos", QPoint(300, 300))) |
500 | 504 | self.resize(parent.settings.value("ivd_size", QSize(480, 480))) |
501 | 505 |
|
502 | | - class CustomImageView(QLabel): |
503 | | - def __init__(self, first_src): |
504 | | - super(CustomImageView, self).__init__() |
505 | | - self.set_custom_pixmap(first_src) |
| 506 | + ### main layout |
| 507 | + layout = QVBoxLayout() |
| 508 | + self.setLayout(layout) |
506 | 509 |
|
507 | | - def set_custom_pixmap(self, img_obj): |
508 | | - self.pixmap = img_obj |
| 510 | + ## image |
| 511 | + self.image_result = ImageViewerDialog.CustomImageView() |
| 512 | + self.installEventFilter(self.image_result) |
| 513 | + layout.addWidget(self.image_result) |
| 514 | + |
| 515 | + ## options |
| 516 | + # Get Values |
| 517 | + ivd_zoom = self.parent().settings.value(SAVE_KEY_MAP.IVD_ZOOM, 18) |
| 518 | + ivd_width = self.parent().settings.value(SAVE_KEY_MAP.IVD_WIDTH, 1024) |
| 519 | + ivd_height = self.parent().settings.value(SAVE_KEY_MAP.IVD_HEIGHT, 1024) |
| 520 | + ivd_basemap = self.parent().settings.value(SAVE_KEY_MAP.IVD_BASEMAP, ENUM_STATICMAP_BASEMAP.PHOTO_HYBRID) |
| 521 | + |
| 522 | + # Option layout |
| 523 | + option_layout = QHBoxLayout() |
| 524 | + layout.addLayout(option_layout) |
| 525 | + |
| 526 | + # Zoom |
| 527 | + self.zoom_label = QLabel("줌: 18") |
| 528 | + self.zoom_slider = QSlider(Qt.Horizontal) |
| 529 | + self.zoom_slider.setMinimum(6) |
| 530 | + self.zoom_slider.setMaximum(18) |
| 531 | + self.zoom_slider.setValue(ivd_zoom) |
| 532 | + self.zoom_slider.valueChanged.connect(self.update_zoom_label) |
| 533 | + option_layout.addWidget(self.zoom_label) |
| 534 | + option_layout.addWidget(self.zoom_slider) |
| 535 | + |
| 536 | + # Width |
| 537 | + self.width_label = QLabel("너비:") |
| 538 | + self.width_edit = QLineEdit(str(ivd_width)) |
| 539 | + self.width_edit.setValidator(QIntValidator(0, 1024)) |
| 540 | + option_layout.addWidget(self.width_label) |
| 541 | + option_layout.addWidget(self.width_edit) |
| 542 | + |
| 543 | + # Height |
| 544 | + self.height_label = QLabel("높이:") |
| 545 | + self.height_edit = QLineEdit(str(ivd_height)) |
| 546 | + self.height_edit.setValidator(QIntValidator(0, 1024)) |
| 547 | + option_layout.addWidget(self.height_label) |
| 548 | + option_layout.addWidget(self.height_edit) |
| 549 | + |
| 550 | + # Basemap |
| 551 | + self.basemap_label = QLabel("종류:") |
| 552 | + self.basemap_combo = QComboBox() |
| 553 | + self.basemap_combo.addItems(list(ENUM_STATICMAP_BASEMAP)) |
| 554 | + self.basemap_combo.setCurrentText(ivd_basemap) |
| 555 | + option_layout.addWidget(self.basemap_label) |
| 556 | + option_layout.addWidget(self.basemap_combo) |
| 557 | + |
| 558 | + # Ok Button |
| 559 | + self.refresh_button = QPushButton("반영") |
| 560 | + self.refresh_button.clicked.connect(self.refresh_img) |
| 561 | + option_layout.addWidget(self.refresh_button) |
| 562 | + |
| 563 | + self.refresh_img() |
| 564 | + |
| 565 | + class CustomImageView(QLabel): |
| 566 | + def __init__(self): |
| 567 | + super(ImageViewerDialog.CustomImageView, self).__init__() |
| 568 | + self.setAlignment(Qt.AlignCenter) |
| 569 | + self.setStyleSheet(""" |
| 570 | + background-position: center |
| 571 | + """) |
| 572 | + |
| 573 | + def set_custom_pixmap(self, img_obj): |
| 574 | + self.pixmap = img_obj |
| 575 | + self.refresh_size() |
| 576 | + |
| 577 | + def refresh_size(self): |
| 578 | + self.setPixmap(self.pixmap.scaled( |
| 579 | + self.width(), self.height(), |
| 580 | + aspectRatioMode=Qt.KeepAspectRatio, |
| 581 | + transformMode=Qt.SmoothTransformation)) |
| 582 | + self.setMinimumWidth(100) |
| 583 | + |
| 584 | + def eventFilter(self, obj, event): |
| 585 | + if event.type() == QEvent.Resize: |
509 | 586 | self.refresh_size() |
| 587 | + return True |
| 588 | + return super(ImageViewerDialog.CustomImageView, self).eventFilter(obj, event) |
| 589 | + |
| 590 | + def refresh_img(self): |
| 591 | + # 0. 옵션 가져오기 |
| 592 | + ivd_zoom = self.zoom_slider.value() |
| 593 | + ivd_width = self.width_edit.text() |
| 594 | + ivd_height = self.height_edit.text() |
| 595 | + ivd_basemap = self.basemap_combo.currentText() |
| 596 | + |
| 597 | + # 1. id / secret 체크 |
| 598 | + api_key = self.parent().settings.value(SAVE_KEY_MAP.OPTION_APIKEY, "") |
| 599 | + if not api_key: |
| 600 | + QMessageBox.information( |
| 601 | + self, '경고', "옵션에서 브이월드 API Key를 설정해주세요.") |
| 602 | + self.reject() |
| 603 | + return |
510 | 604 |
|
511 | | - def refresh_size(self): |
512 | | - self.setPixmap(self.pixmap.scaled( |
513 | | - self.width(), self.height(), |
514 | | - aspectRatioMode=Qt.KeepAspectRatio, |
515 | | - transformMode=Qt.SmoothTransformation)) |
516 | | - self.setMinimumWidth(100) |
517 | | - |
518 | | - def eventFilter(self, obj, event): |
519 | | - if event.type() == QEvent.Resize: |
520 | | - self.refresh_size() |
521 | | - return True |
522 | | - return super(CustomImageView, self).eventFilter(obj, event) |
523 | | - |
524 | | - image_result = CustomImageView(pixmap) |
525 | | - image_result.setAlignment(Qt.AlignCenter) |
526 | | - image_result.setStyleSheet(""" |
527 | | - background-position: center |
528 | | - """) |
529 | | - self.installEventFilter(image_result) |
530 | | - self.image_result = image_result |
531 | | - |
532 | | - # 레이아웃 설정 |
533 | | - layout = QVBoxLayout() |
534 | | - layout.addWidget(self.image_result) |
535 | | - self.setLayout(layout) |
| 605 | + # 2. 접속 |
| 606 | + is_success, content = get_map_img(api_key, self.epsg, ivd_zoom, ivd_width, ivd_height, ivd_basemap) |
| 607 | + if not is_success: |
| 608 | + QMessageBox.information( |
| 609 | + self, '경고', "브이월드에 접속하는데 실패했습니다.\n\n" + str(content)) |
| 610 | + self.reject() |
| 611 | + return |
| 612 | + |
| 613 | + # 3. image_data -> pixmap 전환 |
| 614 | + try: |
| 615 | + pixmap = QPixmap() |
| 616 | + pixmap.loadFromData(content) |
| 617 | + self.image_result.set_custom_pixmap(pixmap) |
| 618 | + except Exception as e: |
| 619 | + QMessageBox.information( |
| 620 | + self, '경고', "이미지를 변환하는데 실패했습니다.\n\n" + str(e)) |
| 621 | + self.reject() |
| 622 | + return |
| 623 | + |
| 624 | + # 4. 설정 저장 |
| 625 | + self.parent().settings.setValue(SAVE_KEY_MAP.IVD_ZOOM, ivd_zoom) |
| 626 | + self.parent().settings.setValue(SAVE_KEY_MAP.IVD_WIDTH, ivd_width) |
| 627 | + self.parent().settings.setValue(SAVE_KEY_MAP.IVD_HEIGHT, ivd_height) |
| 628 | + self.parent().settings.setValue(SAVE_KEY_MAP.IVD_BASEMAP, ivd_basemap) |
| 629 | + |
| 630 | + def update_zoom_label(self, value): |
| 631 | + if int(value) > 18 or int(value) < 6: |
| 632 | + QMessageBox.information( |
| 633 | + self, '경고', "zoom은 6이상 18이하여야합니다.") |
| 634 | + return |
| 635 | + self.zoom_label.setText(f"줌: {value}") |
536 | 636 |
|
537 | 637 | def closeEvent(self, e): |
538 | 638 | self.parent().settings.setValue("ivd_pos", self.pos()) |
|
0 commit comments