11import sys
22from PyQt5 .QtWidgets import QApplication , QWidget , QDialog , QMessageBox , QSlider , QComboBox , QHBoxLayout , QVBoxLayout , QGroupBox , QCheckBox , QRadioButton , QDialogButtonBox , QFileDialog , QLabel , QLineEdit , QPushButton
3- from PyQt5 .QtCore import Qt , QThread , pyqtSignal , QEvent , QPoint , QSize
3+ from PyQt5 .QtCore import Qt , QThread , pyqtSignal , QEvent , QPoint , QSize , QTimer
44from PyQt5 .QtGui import QIntValidator , QPixmap
55import pandas as pd
66import geopandas as gpd
@@ -96,10 +96,6 @@ def create_lineedit_key(title, placeholder, savekey):
9696
9797 self .le_apikey = create_lineedit_key (
9898 'VWorld API 키 입력:' , "API 키를 입력해주세요." , SAVE_KEY_MAP .OPTION_APIKEY )
99- self .le_naver_id = create_lineedit_key (
100- 'Naver Cloud Client ID 입력:' , "API 키를 입력해주세요." , SAVE_KEY_MAP .OPTION_CLIENTID )
101- self .le_naver_secret = create_lineedit_key (
102- 'Naver Cloud Client Secret 입력:' , "API 키를 입력해주세요." , SAVE_KEY_MAP .OPTION_CLIENTSECRET )
10399
104100 layout .addStretch (1 )
105101
@@ -159,10 +155,6 @@ def on_click_select_button(self, code):
159155 def on_click_close_button (self ):
160156 self .parent .settings .setValue (
161157 SAVE_KEY_MAP .OPTION_APIKEY , self .le_apikey .text ())
162- self .parent .settings .setValue (
163- SAVE_KEY_MAP .OPTION_CLIENTID , self .le_naver_id .text ())
164- self .parent .settings .setValue (
165- SAVE_KEY_MAP .OPTION_CLIENTSECRET , self .le_naver_secret .text ())
166158 self .parent .settings .setValue (
167159 SAVE_KEY_MAP .OPTION_FONTSIZE , int (self .lineedit_font .text ()))
168160 self .parent .settings .setValue (
@@ -503,21 +495,22 @@ def __init__(self, parent, addr, epsg):
503495 self .move (parent .settings .value ("ivd_pos" , QPoint (300 , 300 )))
504496 self .resize (parent .settings .value ("ivd_size" , QSize (480 , 480 )))
505497
506- ### main layout
498+ # main layout
507499 layout = QVBoxLayout ()
508500 self .setLayout (layout )
509501
510- ## image
502+ # image
511503 self .image_result = ImageViewerDialog .CustomImageView ()
512504 self .installEventFilter (self .image_result )
513505 layout .addWidget (self .image_result )
514506
515- ## options
507+ # options
516508 # Get Values
517509 ivd_zoom = self .parent ().settings .value (SAVE_KEY_MAP .IVD_ZOOM , 18 )
518510 ivd_width = self .parent ().settings .value (SAVE_KEY_MAP .IVD_WIDTH , 1024 )
519511 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 )
512+ ivd_basemap = self .parent ().settings .value (
513+ SAVE_KEY_MAP .IVD_BASEMAP , ENUM_STATICMAP_BASEMAP .PHOTO_HYBRID )
521514
522515 # Option layout
523516 option_layout = QHBoxLayout ()
@@ -537,13 +530,15 @@ def __init__(self, parent, addr, epsg):
537530 self .width_label = QLabel ("너비:" )
538531 self .width_edit = QLineEdit (str (ivd_width ))
539532 self .width_edit .setValidator (QIntValidator (0 , 1024 ))
533+ self .width_edit .textChanged .connect (self .update_width_edit )
540534 option_layout .addWidget (self .width_label )
541535 option_layout .addWidget (self .width_edit )
542536
543537 # Height
544538 self .height_label = QLabel ("높이:" )
545539 self .height_edit = QLineEdit (str (ivd_height ))
546540 self .height_edit .setValidator (QIntValidator (0 , 1024 ))
541+ self .height_edit .textChanged .connect (self .update_height_edit )
547542 option_layout .addWidget (self .height_label )
548543 option_layout .addWidget (self .height_edit )
549544
@@ -564,22 +559,26 @@ def __init__(self, parent, addr, epsg):
564559
565560 class CustomImageView (QLabel ):
566561 def __init__ (self ):
562+ self .is_inited = False
563+
567564 super (ImageViewerDialog .CustomImageView , self ).__init__ ()
568565 self .setAlignment (Qt .AlignCenter )
569566 self .setStyleSheet ("""
570567 background-position: center
571568 """ )
572569
573570 def set_custom_pixmap (self , img_obj ):
571+ self .is_inited = True
574572 self .pixmap = img_obj
575573 self .refresh_size ()
576574
577575 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 )
576+ if self .is_inited :
577+ self .setPixmap (self .pixmap .scaled (
578+ self .width (), self .height (),
579+ aspectRatioMode = Qt .KeepAspectRatio ,
580+ transformMode = Qt .SmoothTransformation ))
581+ self .setMinimumWidth (100 )
583582
584583 def eventFilter (self , obj , event ):
585584 if event .type () == QEvent .Resize :
@@ -594,20 +593,30 @@ def refresh_img(self):
594593 ivd_height = self .height_edit .text ()
595594 ivd_basemap = self .basemap_combo .currentText ()
596595
596+ if not ivd_width :
597+ self .width_edit .setText ("1024" )
598+ ivd_width = 1024
599+
600+ if not ivd_height :
601+ self .height_edit .setText ("1024" )
602+ ivd_height = 1024
603+
597604 # 1. id / secret 체크
598605 api_key = self .parent ().settings .value (SAVE_KEY_MAP .OPTION_APIKEY , "" )
599606 if not api_key :
600607 QMessageBox .information (
601608 self , '경고' , "옵션에서 브이월드 API Key를 설정해주세요." )
602- self .reject ()
609+
610+ self .reserve_close ()
603611 return
604612
605613 # 2. 접속
606- is_success , content = get_map_img (api_key , self .epsg , ivd_zoom , ivd_width , ivd_height , ivd_basemap )
614+ is_success , content = get_map_img (
615+ api_key , self .epsg , ivd_zoom , ivd_width , ivd_height , ivd_basemap )
607616 if not is_success :
608617 QMessageBox .information (
609618 self , '경고' , "브이월드에 접속하는데 실패했습니다.\n \n " + str (content ))
610- self .reject ()
619+ self .reserve_close ()
611620 return
612621
613622 # 3. image_data -> pixmap 전환
@@ -618,7 +627,7 @@ def refresh_img(self):
618627 except Exception as e :
619628 QMessageBox .information (
620629 self , '경고' , "이미지를 변환하는데 실패했습니다.\n \n " + str (e ))
621- self .reject ()
630+ self .reserve_close ()
622631 return
623632
624633 # 4. 설정 저장
@@ -634,6 +643,21 @@ def update_zoom_label(self, value):
634643 return
635644 self .zoom_label .setText (f"줌: { value } " )
636645
646+ def update_width_edit (self , value ):
647+ if value and not (0 <= int (value ) <= 1024 ):
648+ QMessageBox .information (
649+ self , '경고' , "너비는 0 이상 1024 이하여야합니다." )
650+ self .width_edit .setText ("1024" )
651+
652+ def update_height_edit (self , value ):
653+ if value and not (0 <= int (value ) <= 1024 ):
654+ QMessageBox .information (
655+ self , '경고' , "높이는 0 이상 1024 이하여야합니다." )
656+ self .height_edit .setText ("1024" )
657+
658+ def reserve_close (self ):
659+ QTimer .singleShot (100 , self .close )
660+
637661 def closeEvent (self , e ):
638662 self .parent ().settings .setValue ("ivd_pos" , self .pos ())
639663 self .parent ().settings .setValue ("ivd_size" , self .size ())
0 commit comments