Skip to content

Commit

Permalink
fix: Remove file action buttons in case of connection errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdinazor committed Aug 31, 2024
1 parent 83a9ab4 commit 45a13ea
Showing 1 changed file with 67 additions and 66 deletions.
133 changes: 67 additions & 66 deletions finch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ def fill_credentials(self, selected_index=0):

def show_s3_files(self, cred_index):
if self.credential_selector.itemData(cred_index) != 0:
self.removeToolBar(self.about_toolbar)
self.removeToolBar(self.file_toolbar)
self.file_toolbar = self.addToolBar("File")
cred_name = self.credential_selector.itemText(cred_index)
cred = self.credentials_manager.get_credential(cred_name)
self.layout.removeWidget(self.tree_widget)
try:
cred_name = self.credential_selector.itemText(cred_index)
cred = self.credentials_manager.get_credential(cred_name)
s3_session.resource = boto3.resource('s3',
endpoint_url=cred['endpoint'],
aws_access_key_id=cred['access_key'],
Expand All @@ -109,69 +105,73 @@ def show_s3_files(self, cred_index):
),
region_name=cred['region']
)
self.removeToolBar(self.about_toolbar)
self.removeToolBar(self.file_toolbar)
self.file_toolbar = self.addToolBar("File")
self.layout.removeWidget(self.tree_widget)
upload_file_action = QAction(self)
upload_file_action.setText("&Upload File")
upload_file_action.setIcon(QIcon(resource_path('img/upload.svg')))
upload_file_action.triggered.connect(self.upload_file)

create_bucket_action = QAction(self)
create_bucket_action.setText("&Create Bucket")
create_bucket_action.setIcon(QIcon(resource_path('img/new-folder.svg')))
create_bucket_action.triggered.connect(self.create_bucket)

delete_action = QAction(self)
delete_action.setText("&Delete")
delete_action.setIcon(QIcon(resource_path('img/trash.svg')))
delete_action.triggered.connect(self.global_delete)

download_action = QAction(self)
download_action.setText("&Download")
download_action.setIcon(QIcon(resource_path('img/save.svg')))
download_action.triggered.connect(self.download_file)

refresh_action = QAction(self)
refresh_action.setText("&Refresh")
refresh_action.setIcon(QIcon(resource_path('img/refresh.svg')))
refresh_action.triggered.connect(self.refresh_ui)

self.file_toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.file_toolbar.addAction(upload_file_action)
self.file_toolbar.addAction(create_bucket_action)
self.file_toolbar.addAction(delete_action)
self.file_toolbar.addAction(download_action)
self.file_toolbar.addAction(refresh_action)

self.about_toolbar = self.addToolBar("About")
self.about_toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
empty = QWidget()
empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
show_about_action = QAction(self)
show_about_action.setText("&About")
show_about_action.setIcon(QIcon(resource_path('img/about.svg')))
show_about_action.triggered.connect(self.open_about_window)
self.about_toolbar.addWidget(empty)
self.about_toolbar.addAction(show_about_action)

self.tree_widget = QTreeWidget()
self.tree_widget.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree_widget.customContextMenuRequested.connect(self.open_context_menu)
self.tree_widget.setSortingEnabled(True)
self.tree_widget.sortByColumn(0, Qt.AscendingOrder)
header = self.tree_widget.header()
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
header.setStretchLastSection(False)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
self.tree_widget.setColumnCount(4)
self.tree_widget.setHeaderLabels(["Name", "Type", "Size", "Date"])
self.tree_widget.itemExpanded.connect(self.add_files_to_tree)

self.layout.addWidget(self.tree_widget)

self.add_buckets_to_tree()

except Exception as e:
show_error_dialog(str(e))

upload_file_action = QAction(self)
upload_file_action.setText("&Upload File")
upload_file_action.setIcon(QIcon(resource_path('img/upload.svg')))
upload_file_action.triggered.connect(self.upload_file)

create_bucket_action = QAction(self)
create_bucket_action.setText("&Create Bucket")
create_bucket_action.setIcon(QIcon(resource_path('img/new-folder.svg')))
create_bucket_action.triggered.connect(self.create_bucket)

delete_action = QAction(self)
delete_action.setText("&Delete")
delete_action.setIcon(QIcon(resource_path('img/trash.svg')))
delete_action.triggered.connect(self.global_delete)

download_action = QAction(self)
download_action.setText("&Download")
download_action.setIcon(QIcon(resource_path('img/save.svg')))
download_action.triggered.connect(self.download_file)

refresh_action = QAction(self)
refresh_action.setText("&Refresh")
refresh_action.setIcon(QIcon(resource_path('img/refresh.svg')))
refresh_action.triggered.connect(self.refresh_ui)

self.file_toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.file_toolbar.addAction(upload_file_action)
self.file_toolbar.addAction(create_bucket_action)
self.file_toolbar.addAction(delete_action)
self.file_toolbar.addAction(download_action)
self.file_toolbar.addAction(refresh_action)

self.about_toolbar = self.addToolBar("About")
self.about_toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
empty = QWidget()
empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
show_about_action = QAction(self)
show_about_action.setText("&About")
show_about_action.setIcon(QIcon(resource_path('img/about.svg')))
show_about_action.triggered.connect(self.open_about_window)
self.about_toolbar.addWidget(empty)
self.about_toolbar.addAction(show_about_action)

self.tree_widget = QTreeWidget()
self.tree_widget.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree_widget.customContextMenuRequested.connect(self.open_context_menu)
self.tree_widget.setSortingEnabled(True)
self.tree_widget.sortByColumn(0, Qt.AscendingOrder)
header = self.tree_widget.header()
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
header.setStretchLastSection(False)
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
self.tree_widget.setColumnCount(4)
self.tree_widget.setHeaderLabels(["Name", "Type", "Size", "Date"])
self.tree_widget.itemExpanded.connect(self.add_files_to_tree)

self.layout.addWidget(self.tree_widget)

self.add_buckets_to_tree()

def get_bucket_name_from_selected_item(self):
""" Get bucket name data from bucket or file/folder item in treeview """
indexes = self.tree_widget.selectedIndexes()
Expand Down Expand Up @@ -209,6 +209,7 @@ def add_buckets_to_tree(self):
bucket_item.setText(3, StringUtils.format_datetime(bucket['CreationDate']))
bucket_item.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)
except Exception as e:
self.removeToolBar(self.file_toolbar)
show_error_dialog(str(e))

def add_files_to_tree(self, item):
Expand Down

0 comments on commit 45a13ea

Please sign in to comment.