Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
weee-open-bot committed Nov 10, 2024
1 parent e4acc76 commit 91bc125
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 74 deletions.
16 changes: 4 additions & 12 deletions dialogs/NetworkSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_settings(self):
if self.current_config_key is None:
self.host, self.port = (LOCAL_IP, str(DEFAULT_PORT))
else:
self.host, self.port, self.images_directory, self.default_image = self.settings.value(self.current_config_key)
self.host, self.port, self.images_directory, self.default_image = self.settings.value(self.current_config_key)
self.settings.endGroup()

# get disk image settings
Expand Down Expand Up @@ -137,9 +137,7 @@ def save_configuration(self):
config = self.settings.value(key) # [ip, port, ]

if self.host in config:
self.settings.setValue(key, [
self.host, self.port, self.images_directory, self.default_image
])
self.settings.setValue(key, [self.host, self.port, self.images_directory, self.default_image])
self.settings.endGroup()
self.settings.setValue(CURRENT_SERVER_CONFIG_KEY, key) # save current configuration key
break
Expand Down Expand Up @@ -201,10 +199,7 @@ def find_image(self):
connection = self.parent.connection_factory.protocol_instance
requested_connection = False
if not connection:
warning_dialog(
"No connection. Connect to the server and retry.",
"ok"
)
warning_dialog("No connection. Connect to the server and retry.", "ok")
return
image_directory = self.imagesDirectoryLineEdit.text()
if image_directory == "":
Expand All @@ -230,10 +225,7 @@ def set_default_image_path(self, path: str):
self.defaultImageLineEdit.setText(os.path.basename(path))

def connect(self):
dialog = warning_dialog(
"Do you want to save the current settings and connect to the server?",
"yes_no"
)
dialog = warning_dialog("Do you want to save the current settings and connect to the server?", "yes_no")
if dialog == QMessageBox.No:
return
self.save_configuration()
Expand Down
5 changes: 3 additions & 2 deletions dialogs/SmartDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
if TYPE_CHECKING:
from pinolo import PinoloMainWindow


class SmartDialog(QDialog, Ui_SmartDataDialog):
close_signal = pyqtSignal(QDialog)

def __init__(self, parent: 'PinoloMainWindow', drive: str, smart_results: dict):
def __init__(self, parent: "PinoloMainWindow", drive: str, smart_results: dict):
super(SmartDialog, self).__init__(parent)
self.setupUi(self)

Expand Down Expand Up @@ -146,4 +147,4 @@ def export_data(self):
json.dump(self.smart_results, json_file, indent=4)

def closeEvent(self, a0):
self.close_signal.emit(self)
self.close_signal.emit(self)
90 changes: 30 additions & 60 deletions pinolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from typing import Union
from dotenv import load_dotenv
from PyQt5.QtGui import QIcon, QDesktopServices, QPixmap, QCloseEvent
from PyQt5.QtCore import Qt, QSettings, pyqtSignal, QThread, QUrl, pyqtSlot, QCoreApplication, \
QAbstractTableModel, QModelIndex, QPoint
from PyQt5.QtCore import Qt, QSettings, pyqtSignal, QThread, QUrl, pyqtSlot, QCoreApplication, QAbstractTableModel, QModelIndex, QPoint
from PyQt5.QtWidgets import (
QTableWidgetItem,
QTableWidget,
Expand All @@ -32,7 +31,7 @@
QLineEdit,
QDialog,
QStyledItemDelegate,
QTableView
QTableView,
)
from constants import *
from typing import List
Expand Down Expand Up @@ -108,9 +107,7 @@ def setup(self):
self.queueTableView.setItemDelegateForColumn(QUEUE_TABLE_PROGRESS, delegate)
delegate = QueueStatusIconDelegate(self.queueTableView)
self.queueTableView.setItemDelegateForColumn(QUEUE_TABLE_STATUS, delegate)
self.queueTableView.addActions(
[self.actionStop, self.actionRemove, self.actionRemove_All, self.actionRemove_completed, self.actionRemove_Queued]
)
self.queueTableView.addActions([self.actionStop, self.actionRemove, self.actionRemove_All, self.actionRemove_completed, self.actionRemove_Queued])
self.actionStop.triggered.connect(self.queue_stop)
self.actionRemove.triggered.connect(self.queue_remove)
self.actionRemove_All.triggered.connect(self.queue_clear)
Expand Down Expand Up @@ -212,10 +209,7 @@ def show_version(self):
def queue_stop(self):
"""This function set the "stop" button behaviour on the queue table
context menu."""
dialog = warning_dialog(
"Do you want to stop the selected processes?",
"yes_no"
)
dialog = warning_dialog("Do you want to stop the selected processes?", "yes_no")
if dialog == QMessageBox.No:
return

Expand All @@ -227,17 +221,14 @@ def queue_stop(self):
def queue_remove(self):
"""This function set the "remove" button behaviour on the queue table
context menu."""
dialog = warning_dialog(
"With this action you will also stop the selected processes.\nDo you want to proceed?",
"yes_no"
)
dialog = warning_dialog("With this action you will also stop the selected processes.\nDo you want to proceed?", "yes_no")
if dialog == QMessageBox.No:
return

rows = self.queueTableView.selectionModel().selectedRows()
for index in rows:
pid = self.queueTableViewModel.get_pid(index)
self.send_command(f'remove {pid}')
self.send_command(f"remove {pid}")
self.queueTableViewModel.remove_row(rows)

def queue_clear(self):
Expand Down Expand Up @@ -274,24 +265,17 @@ def upload_to_tarallo(self, standard_procedure: bool = False):
for drive in drives:
if not standard_procedure:
if drive.tarallo_id is not None:
warning_dialog(
f"The drive {drive.name} already has a TARALLO id.",
dialog_type="ok"
)
warning_dialog(f"The drive {drive.name} already has a TARALLO id.", dialog_type="ok")
continue
dialog = warning_dialog(
f"Do you want to create the disk item for {drive.name} in TARALLO?",
dialog_type="yes_no"
)
dialog = warning_dialog(f"Do you want to create the disk item for {drive.name} in TARALLO?", dialog_type="yes_no")
if dialog == QMessageBox.No:
continue

else:
if drive.tarallo_id != "":
continue

location, ok = tarallo_location_dialog(f"Please, set the Tarallo location of drive {drive.name}.\n"
f"Leave blank to avoid upload to Tarallo")
location, ok = tarallo_location_dialog(f"Please, set the Tarallo location of drive {drive.name}.\n" f"Leave blank to avoid upload to Tarallo")

# If no location is provided or cancel is selected, stop the operation
if not ok or location is None or location == "":
Expand Down Expand Up @@ -343,9 +327,9 @@ def umount(self):
message = "Are you really sure you want to unmount all partitions of the following drives?\n\n"
for drive in drives:
if drive.mounted:
mountpoints = str(drive.mountpoints).strip('[').strip(']').strip("'")
mountpoints = str(drive.mountpoints).strip("[").strip("]").strip("'")
else:
mountpoints = ''
mountpoints = ""
message += f"- {drive.name}\t{mountpoints}\n"
message += "\n\nBe careful not to unmount and erase something important!"

Expand Down Expand Up @@ -408,10 +392,7 @@ def standard_procedure(self):
if len(rows) == 0:
return

standard_procedure_dialog = warning_dialog(
"Do you want to wipe all disk's data and load a fresh system image?",
dialog_type="yes_no_chk"
)
standard_procedure_dialog = warning_dialog("Do you want to wipe all disk's data and load a fresh system image?", dialog_type="yes_no_chk")

if standard_procedure_dialog[0] == QMessageBox.No:
return
Expand Down Expand Up @@ -625,7 +606,7 @@ def update(self, command_data: dict):
def _update_eta(self):
elapsed_time = time.time() - self.start_time
if 0 < self.progress < 100:
predicted_total_time = elapsed_time / (self.progress/100)
predicted_total_time = elapsed_time / (self.progress / 100)
eta = predicted_total_time - elapsed_time
self.eta = time.strftime("%H:%M:%S", time.gmtime(eta))
else:
Expand Down Expand Up @@ -670,25 +651,19 @@ def __init__(self, parent: QTableView):
self.parent = parent
super().__init__()
self.jobs: List[Job] = []
self.header_labels = [
"Drive",
"Process",
"Status",
"Eta",
"Progress"
]

def rowCount(self, parent = ...) -> int:
self.header_labels = ["Drive", "Process", "Status", "Eta", "Progress"]

def rowCount(self, parent=...) -> int:
return len(self.jobs)

def columnCount(self, parent = ...) -> int:
def columnCount(self, parent=...) -> int:
return len(self.header_labels)

def headerData(self, section, orientation, role = ...):
def headerData(self, section, orientation, role=...):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.header_labels[section]

def data(self, index: QModelIndex, role = ...):
def data(self, index: QModelIndex, role=...):
# index: specific cell in the table

match role:
Expand Down Expand Up @@ -782,7 +757,7 @@ def clear(self):


class ProgressBarDelegate(QStyledItemDelegate):
def __init__(self, parent = None):
def __init__(self, parent=None):
super(ProgressBarDelegate, self).__init__(parent)
self.margin = 1

Expand All @@ -795,8 +770,8 @@ def paint(self, painter, option, index):
# Create a progress bar widget
progress_bar = QProgressBar()
progress_bar.setMinimum(0)
progress_bar.setMaximum(100*PROGRESS_BAR_SCALE)
progress_bar.setValue(int(progress*PROGRESS_BAR_SCALE))
progress_bar.setMaximum(100 * PROGRESS_BAR_SCALE)
progress_bar.setValue(int(progress * PROGRESS_BAR_SCALE))

# Render the progress bar inside the cell
rect = option.rect.adjusted(self.margin, 0, -self.margin, 0)
Expand All @@ -815,7 +790,7 @@ def paint(self, painter, option, index):


class QueueStatusIconDelegate(QStyledItemDelegate):
def __init__(self, parent = None):
def __init__(self, parent=None):
super(QueueStatusIconDelegate, self).__init__(parent)
self.icons = {
"error": QIcon("assets/table/error.png"),
Expand Down Expand Up @@ -862,24 +837,19 @@ def __init__(self, parent: QTableView):
super().__init__()
self.parent = parent
self.drives: List[Drive] = []
self.header_labels = [
"Drive",
"Status",
"Tarallo ID",
"Size"
]

def rowCount(self, parent = ...) -> int:
self.header_labels = ["Drive", "Status", "Tarallo ID", "Size"]

def rowCount(self, parent=...) -> int:
return len(self.drives)

def columnCount(self, parent = ...) -> int:
def columnCount(self, parent=...) -> int:
return len(self.header_labels)

def headerData(self, section, orientation, role = ...):
def headerData(self, section, orientation, role=...):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.header_labels[section]

def data(self, index: QModelIndex, role = ...):
def data(self, index: QModelIndex, role=...):
# index: specific cell in the table

match role:
Expand Down Expand Up @@ -944,7 +914,7 @@ def clear(self):


class DrivesStatusIconDelegate(QStyledItemDelegate):
def __init__(self, parent = None):
def __init__(self, parent=None):
super(DrivesStatusIconDelegate, self).__init__(parent)
self.icons = {
"started": QIcon("assets/table/progress.png"),
Expand Down
1 change: 1 addition & 0 deletions ui/PinoloMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def retranslateUi(self, MainWindow):

if __name__ == "__main__":
import sys

app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
Expand Down

0 comments on commit 91bc125

Please sign in to comment.