Skip to content

Commit 22711f2

Browse files
committed
ImageViewerDialog에 옵션들을 추가함. pressed로 묶여있는 버튼들을 clicked로 변경
1 parent c8d02f2 commit 22711f2

4 files changed

Lines changed: 155 additions & 75 deletions

File tree

consts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@
9494
OPTION_APIKEY="OPTION_APIKEY",
9595
OPTION_FONTSIZE="OPTION_FONTSIZE", # 9
9696
OPTION_TABLEPAGESIZE="OPTION_TABLEPAGESIZE", # 20
97-
OPTION_LOWSPECMODE="OPTION_LOWSPECMODE"
97+
OPTION_LOWSPECMODE="OPTION_LOWSPECMODE",
98+
IVD_ZOOM="IVD_ZOOM",
99+
IVD_WIDTH="IVD_WIDTH",
100+
IVD_HEIGHT="IVD_HEIGHT",
101+
IVD_BASEMAP="IVD_BASEMAP",
98102
)
99103

100104
CONST_TABLEKEY_STRMAP = DotMap(

gui.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from gui_mapinfotable import MapInfoTable
1414
from gui_search import SearchWidget
1515
from gui_dialog import OptionDialog, LoadOptionDialog, SaveOptionDialog, ImageViewerDialog, FuncLoadingDialog, CoordDialog, SimpleInputDialog
16-
from network import get_mapinfo_from_pnu, get_map_img
16+
from network import get_mapinfo_from_pnu
1717
from clipboard import clipboard_copy_csvte_info, clipboard_paste_csvte_info
1818
from theme import apply_theme
1919

@@ -180,16 +180,16 @@ def init_content(self):
180180
layout_right.addLayout(buttons_layout)
181181

182182
openimg_button = QPushButton("사진열기") # 첫인자가 텍스트임.
183-
openimg_button.pressed.connect(self.open_img) # pressed 콜백에 함수를 묶고 있음.
183+
openimg_button.clicked.connect(self.open_img) # clicked 콜백에 함수를 묶고 있음.
184184
openimg_button.setEnabled(False) # 처음 실행시에는 꺼놓음.
185185
self.openimg_button = openimg_button
186186
buttons_layout.addWidget(openimg_button)
187187
load_button = QPushButton("불러오기")
188-
load_button.pressed.connect(self.start_load)
188+
load_button.clicked.connect(self.start_load)
189189
buttons_layout.addWidget(load_button)
190190
export_button = QPushButton("내보내기")
191191
export_button.setEnabled(False)
192-
export_button.pressed.connect(self.show_save_dialog)
192+
export_button.clicked.connect(self.show_save_dialog)
193193
self.export_button = export_button
194194
buttons_layout.addWidget(export_button)
195195

@@ -253,43 +253,19 @@ def load(self, src, load_mode):
253253
QMessageBox.information(self, '불러오기 실패', error_message)
254254

255255
def open_img(self, info_dict={}):
256-
# 1.epsg 체크
257256
if not info_dict:
258257
if not self.mapinfo_table.epsg:
259258
QMessageBox.information(self, '경고', "주소를 확인할 수 없습니다.")
260259
return
261-
addr = self.mapinfo_table.datalist[0]
262-
else:
263-
addr = info_dict["addr"]
260+
info_dict = {
261+
"addr": self.mapinfo_table.datalist[0],
262+
"epsg": self.mapinfo_table.epsg
263+
}
264264

265-
# 2. id / secret 체크
266-
api_key = self.settings.value(SAVE_KEY_MAP.OPTION_APIKEY, "")
267-
if not api_key:
268-
QMessageBox.information(
269-
self, '경고', "옵션에서 브이월드 API Key를 설정해주세요.")
270-
return
271-
272-
# 3. 이미지 얻어오기, content로 뱉어줌.
265+
addr = info_dict["addr"]
273266
epsg = self.mapinfo_table.epsg if not info_dict else info_dict['epsg']
274-
is_success, content = get_map_img(api_key, epsg)
275-
if not is_success:
276-
QMessageBox.information(
277-
self, '경고', "브이월드에 접속하는데 실패했습니다.\n\n" + str(content))
278-
return
279-
280-
# 4. image_data -> pixmap 전환
281-
try:
282-
# image_data = io.BytesIO(content)
283-
# image = Image.open(image_data)
284-
# pixmap = pil2pixmap(image)
285-
pixmap = QPixmap()
286-
pixmap.loadFromData(content)
287-
288-
except Exception as e:
289-
QMessageBox.information(
290-
self, '경고', "이미지를 변환하는데 실패했습니다.\n\n" + str(e))
291267

292-
ImageViewerDialog(self, addr, pixmap).show()
268+
ImageViewerDialog(self, addr, epsg).show()
293269

294270
def show_save_dialog(self):
295271
dialog = SaveOptionDialog()

gui_dialog.py

Lines changed: 138 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
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
33
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QEvent, QPoint, QSize
4-
from PyQt5.QtGui import QIntValidator
4+
from PyQt5.QtGui import QIntValidator, QPixmap
55
import pandas as pd
66
import geopandas as gpd
77
from shapely.geometry import Point
88

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
1111

1212

1313
def transform_to_epsg4326(x, y, epsg):
@@ -272,7 +272,7 @@ def __init__(self, gui):
272272
self.lineedit_y = lineedit_y
273273

274274
find_button = QPushButton("찾기")
275-
find_button.pressed.connect(self.on_click_find_button)
275+
find_button.clicked.connect(self.on_click_find_button)
276276
layout.addWidget(find_button)
277277

278278
self.setLayout(layout)
@@ -491,48 +491,148 @@ def on_finished(self, df):
491491
self.accept()
492492

493493

494+
# addr, epsg를 주면 알아서 기존 세팅과 api_key를 때마다 받아와 요청한다.
494495
class ImageViewerDialog(QDialog):
495-
def __init__(self, parent, title, pixmap):
496+
def __init__(self, parent, addr, epsg):
496497
super(ImageViewerDialog, self).__init__(parent=parent)
498+
499+
self.epsg = epsg
500+
497501
self.setWindowTitle(
498-
"{title} (정확한 위치가 아닐 수 있습니다. 이 창은 독립적입니다.)".format(title=title))
502+
f"{addr} (정확한 위치가 아닐 수 있습니다. 이 창은 독립적입니다.)")
499503
self.move(parent.settings.value("ivd_pos", QPoint(300, 300)))
500504
self.resize(parent.settings.value("ivd_size", QSize(480, 480)))
501505

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)
506509

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:
509586
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
510604

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}")
536636

537637
def closeEvent(self, e):
538638
self.parent().settings.setValue("ivd_pos", self.pos())

gui_tableview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def init_ui(self, current_selected_columns):
4646
checkbuttons_layout = QHBoxLayout()
4747
button_layout.addLayout(checkbuttons_layout)
4848
button_allcheck = QPushButton("모두 선택")
49-
button_allcheck.pressed.connect(self.check_all)
49+
button_allcheck.clicked.connect(self.check_all)
5050
checkbuttons_layout.addWidget(button_allcheck)
5151
button_alluncheck = QPushButton("모두 해제")
52-
button_alluncheck.pressed.connect(self.uncheck_all)
52+
button_alluncheck.clicked.connect(self.uncheck_all)
5353
checkbuttons_layout.addWidget(button_alluncheck)
5454

5555
button_box = QDialogButtonBox(

0 commit comments

Comments
 (0)