Skip to content

Commit

Permalink
Now action dialog has a working progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
codernayeem committed Jul 2, 2020
1 parent 7821868 commit 2038752
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PyQt5 import QtGui, QtWidgets, QtCore
from main_ui import Ui_MainWindow
from dialogs import Ui_AboutPage
from tools import FileData, is_valid_dir, join, Path, get_filename_extension, get_files, get_prefferd_text
from tools import FileData, is_valid_dir, join, Path, get_filename_extension, get_files, get_prefferd_text, get_file_count
from shutil import copyfile, move
from action_dialog import Ui_ActionDialog

Expand Down Expand Up @@ -230,6 +230,8 @@ def go_for_work(self):
self.action_dialog.ui.pushButton_finish.setEnabled(False)

self.action_dialog.ui.stackedWidget.setCurrentIndex(0)

self.action_dialog.ui.progressBar.setMaximum(get_file_count(self.action_dialog.data_folders) or 1)

self.thread = actionThread(self.action_dialog.data_action, self.action_dialog.data_folders, self.action_dialog.data_data, self.action_dialog.data_des)
self.thread.finished.connect(self.on_action_finish)
Expand Down Expand Up @@ -273,6 +275,7 @@ def start_action_dialog(self):
self.action_dialog.ui.setupUi(self.action_dialog)
self.action_dialog.setFixedHeight(223)
self.action_dialog.setFixedWidth(515)
self.action_dialog.ui.progressBar.setMinimum(0)
self.action_dialog.ui.pushButton_start.clicked.connect(self.go_for_work)
self.action_dialog.ui.pushButton_cancel.clicked.connect(self.action_dialog.close)
self.action_dialog.ui.pushButton_finish.clicked.connect(self.action_dialog.close)
Expand All @@ -297,10 +300,13 @@ def start_action_dialog(self):
self.action_dialog.ui.label_notAllowed.setText("0")
self.action_dialog.ui.label_ignored.setText("0")

self.action_dialog.ui.progressBar.setValue(0)

self.action_dialog.data_data = data
self.action_dialog.data_folders = folders
self.action_dialog.data_action = i1
self.action_dialog.data_des = i2
self.action_dialog.action_done = 0

self.action_dialog.destroy()
self.action_dialog.show()
Expand All @@ -311,11 +317,17 @@ def on_action_update(self, done, fail, not_allowed, ignored):
self.action_dialog.ui.label_notAllowed.setText(str(not_allowed))
self.action_dialog.ui.label_ignored.setText(str(ignored))

self.action_dialog.action_done += 1
self.action_dialog.ui.progressBar.setValue(self.action_dialog.action_done)

def on_action_finish(self):
self.action_dialog.ui.pushButton_start.setEnabled(False)
self.action_dialog.ui.pushButton_cancel.setEnabled(False)
self.action_dialog.ui.pushButton_finish.setEnabled(True)

self.action_dialog.ui.progressBar.setMaximum(100)
self.action_dialog.ui.progressBar.setValue(100)

self.action_dialog.ui.stackedWidget.setCurrentIndex(1)

self.action_dialog.ui.label_statBar.setText("""<html><body><p align="center"><span style="font-size:18pt;">Finished</span></p></body></html>""")
Expand Down
10 changes: 9 additions & 1 deletion src/main/python/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from os.path import join, isfile, isdir, getsize, getctime, getmtime
from os import listdir, rename
from os import listdir, rename, walk
import time, json
from datetime import datetime

Expand Down Expand Up @@ -61,6 +61,14 @@ def check_plural(c):
return 's'
return ''

def get_file_count(folders):
total = 0
for i in folders:
for ii in listdir(i):
if isfile(join(i, ii)):
total += 1
return total

def get_prefferd_text(text):
if len(text) > 51:
return text[:47] + '.....'
Expand Down

0 comments on commit 2038752

Please sign in to comment.