Skip to content

Commit

Permalink
Merge pull request #6835 from drew2a/fix/6834
Browse files Browse the repository at this point in the history
Add `is_dir()` check to  `add_directory_dialog`
  • Loading branch information
drew2a authored Mar 28, 2022
2 parents 2c24688 + 8f0955e commit 948f908
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/tribler/gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
get_ui_file_path,
is_dir_writable,
set_api_key,
show_message_box,
tr,
)
from tribler.gui.widgets.channelsmenulistwidget import ChannelsMenuListWidget
Expand Down Expand Up @@ -967,6 +968,10 @@ def on_confirm_add_directory_dialog(self, action):
if self.dialog.checkbox.isChecked():
# TODO: add recursive directory scanning
def on_add_button_pressed(channel_id):
if not Path(self.chosen_dir).is_dir():
show_message_box(f'"{self.chosen_dir}" is not a directory')
return

TriblerNetworkRequest(
f"collections/mychannel/{channel_id}/torrents",
lambda _: self.tray_show_message(
Expand Down
25 changes: 22 additions & 3 deletions src/tribler/gui/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
from urllib.parse import quote_plus
from uuid import uuid4

from PyQt5.QtCore import QCoreApplication, QLocale, QPoint, QSettings, QTranslator, pyqtSignal
from PyQt5.QtCore import (
QCoreApplication,
QLocale,
QPoint,
QSettings,
QTranslator,
pyqtSignal,
)
from PyQt5.QtGui import QPixmap, QRegion
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QApplication, QMessageBox

import tribler.gui
from tribler.gui.defs import HEALTH_DEAD, HEALTH_GOOD, HEALTH_MOOT, HEALTH_UNCHECKED

# fmt: off

logger = logging.getLogger(__name__)

NUM_VOTES_BARS = 8
Expand Down Expand Up @@ -357,7 +366,8 @@ def format_votes_rich_text(votes=0.0):
votes_count_empty = votes_count(1.0) - votes_count_full

rating_rich_text = (
f"<font color=#BBBBBB>{'┃' * votes_count_full}</font>" + f"<font color=#444444>{'┃' * votes_count_empty}</font>"
f"<font color=#BBBBBB>{'┃' * votes_count_full}</font>" +
f"<font color=#444444>{'┃' * votes_count_empty}</font>"
)
return rating_rich_text

Expand Down Expand Up @@ -471,3 +481,12 @@ def take_screenshot(window, screenshots_dir):
screenshots_dir.mkdir(exist_ok=True)
img_name = 'exception_screenshot_%d.jpg' % timestamp
pixmap.save(str(screenshots_dir / img_name))


def show_message_box(text: str = '', title: str = 'Error', icon: QMessageBox.Icon = QMessageBox.Critical):
message_box = QMessageBox()
message_box.setIcon(icon)
message_box.setStandardButtons(QMessageBox.Yes)
message_box.setWindowTitle(title)
message_box.setText(text)
message_box.exec_()

0 comments on commit 948f908

Please sign in to comment.