Skip to content

Commit

Permalink
make fileDialog function more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
rifqiharrys committed Jul 24, 2021
1 parent 6400b5f commit f34e358
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions sdb_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def __init__(self):
'Support Vector Machines': self.svmOptionWindow
}

self.working_dir = os.path.abspath(Path.home())

self.dir_dict = {
'image': os.path.abspath(Path.home()),
'sample': os.path.abspath(Path.home()),
Expand Down Expand Up @@ -156,7 +154,7 @@ def initUI(self):
'''

self.setGeometry(300, 100, 480, 640)
self.setWindowTitle('Satellite Derived Bathymetry (v3.1.1)')
self.setWindowTitle('Satellite Derived Bathymetry (v3.1.2)')
self.setWindowIcon(QIcon(resource_path('icons/satellite.png')))

loadImageButton = QPushButton('Load Image')
Expand Down Expand Up @@ -308,14 +306,14 @@ def str2bool(self, v):
return v in ('True')


def fileDialog(self, command, window_text, work_dir, dir_key, file_type, text_browser):
def fileDialog(self, command, window_text, dir_key, file_type, text_browser):
'''
Showing file dialog, whether opening file or saving.
'''

fileFilter = 'All Files (*.*) ;; ' + file_type
selectedFilter = file_type
fname = command(self, window_text, work_dir, fileFilter, selectedFilter)
fname = command(self, window_text, self.dir_dict[dir_key], fileFilter, selectedFilter)

text_browser.setText(fname[0])
self.dir_dict[dir_key] = os.path.splitext(fname[0])[0]
Expand Down Expand Up @@ -345,7 +343,6 @@ def loadImageWindow(self):
lambda: self.fileDialog(
command=QFileDialog.getOpenFileName,
window_text='Open Image File',
work_dir=self.dir_dict['image'],
dir_key='image',
file_type='GeoTIFF (*.tif)',
text_browser=self.imglocList
Expand Down Expand Up @@ -426,7 +423,6 @@ def loadSampleWindow(self):
lambda: self.fileDialog(
command=QFileDialog.getOpenFileName,
window_text='Open Depth Sample File',
work_dir=self.dir_dict['sample'],
dir_key='sample',
file_type='ESRI Shapefile (*.shp)',
text_browser=self.samplelocList
Expand Down Expand Up @@ -1087,7 +1083,6 @@ def saveOptionWindow(self):
lambda:self.fileDialog(
command=QFileDialog.getSaveFileName,
window_text='Save File',
work_dir=self.dir_dict['save'],
dir_key='save',
file_type=self.dataTypeCB.currentText(),
text_browser=self.savelocList
Expand Down

0 comments on commit f34e358

Please sign in to comment.