Skip to content

Commit

Permalink
Working progress UI
Browse files Browse the repository at this point in the history
  • Loading branch information
moll-re committed Apr 26, 2019
1 parent 76941ea commit 07e94e6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 39 deletions.
13 changes: 8 additions & 5 deletions Backup/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ def compress_1(self):
"""No compression, just copying"""
while len(self.backup_src)>0:
if not self.pause:
working_file = self.backup_src[0]
del self.backup_src[0]
self.copy_single(working_file)
self.update_progress(working_file)
try:
working_file = self.backup_src[0]
del self.backup_src[0]
self.copy_single(working_file)
self.update_progress(working_file)
except:
print("no more files")


def compress_2(self):
Expand Down Expand Up @@ -155,7 +158,7 @@ def write_config(self):
"compression_method" : self.configuration["compression_method"],
"keep_metadata" : self.configuration["keep_metadata"]
}
with open(self.backup_dest+"AlB_config.json","w") as f:
with open(self.backup_dest + "AlB_config.json","w") as f:
json.dump(config_to_write,f)
f.close()

Expand Down
11 changes: 0 additions & 11 deletions IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,3 @@ when more than (10,50,50) files changed
## Destiniaton:
GDrive? use API (LATER, pleaase)
HDD

## Options:
default start window
hidden files?
keep metadata?

## Tips:
preconfigured dirs:

## Applications:
Application chooser: ``` type "Program-name" || which "Program-name"```
1 change: 1 addition & 0 deletions Website/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
width: 100%;
max-height: 20%;
border-radius: 0px 0px 5px 5px;
z-index: 10;
}

.title {
Expand Down
1 change: 1 addition & 0 deletions Website/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function load_links($DB,$language){
<title>
Aluminium Backup - <?php echo $page_all["page_title"];?>
</title>
<link rel="icon" type="image/aluminium.icon" href="icon.ico">
</head>

<body>
Expand Down
87 changes: 64 additions & 23 deletions status.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from threading import Thread
import time
import sys
from threading import Thread #for UI-Threading
import datetime #for elapsed time
import sys #for closing the window

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
#for UI elements

from Restore import activity as RA
from Backup import activity as BA

Expand All @@ -29,21 +30,30 @@ def create_grid_layout(self):
self.setLayout(self.grid)
self.grid.addWidget(self.progress_bar(), 0, 0, 1, 2)
self.grid.addWidget(self.now_copying(), 1, 0, 1, 2)
self.grid.addWidget(self.button_stop(), 2, 0)
self.grid.addWidget(self.button_pause(), 2, 1)
self.grid.addWidget(self.elapsed(), 2, 0, 1, 2)
self.grid.addWidget(self.button_stop(), 3, 0)
self.grid.addWidget(self.button_pause(), 3, 1)


def progress_bar(self):
"""shows progression as a percentage"""
self.progression_bar = QProgressBar()
self.progression_bar.setGeometry(200, 80, 250, 20)
return self.progression_bar


def now_copying(self):
"""shows the path of the file that is being copied at the moment"""
self.label_now_copying = QLabel()
return self.label_now_copying


def elapsed(self):
"""Shows time elapsed since the start"""
self.elapsed_time = QLabel()
return self.elapsed_time


def button_pause(self):
"""switches a bool in activity that interrupts the copying but can be resumed"""
def button_action():
Expand All @@ -68,30 +78,30 @@ def stop_action():
return self.stop_button


def update_progress(self):
def update_progress(self, percentage, now_copying):
"""updates UI ie. progression bar and copied file-message. Creates QUIT button after being finished"""
previous_length = 0
while self.activity.progress != self.activity.max_progress:
if len(self.activity.copied_files) != previous_length:
#self.label_now_copying.clear()
#self.label_now_copying.setText("Copying " + self.activity.copied_files[-1])
#results in a segfault, so I'm using:
print("Copying " + self.activity.copied_files[-1],end="\r")
self.progression_bar.setValue(100 * self.activity.progress / self.activity.max_progress)
previous_length = len(self.activity.copied_files)
self.progression_bar.setValue(100 * percentage)
self.label_now_copying.setText("Copying: " + now_copying)

def update_elapsed(self):
self.elapsed_time.setText("Elapsed: "+str(datetime.datetime.now() - self.start_time))


def finish_ui(self,unsuccesfull_log):
self.stop_button.setText("QUIT")
if len(self.activity.unsuccesfull_log) != 0:
self.show_message("Could not copy the following files:\n" + ''.join([x+"\n" for x in self.activity.unsuccesfull_log]))
self.label_now_copying.setText("Finished")
self.show_message("Could not copy the following files:\n" + ''.join([x+"\n" for x in self.activity.unsuccesfull_log]))


def start_activity(self,B_or_R):
"""starts B or R process
Args: * bool-> True for Backup and False for Restore"""
self.update_UI = Thread(target=self.update_progress)
if B_or_R:
self.activity = BA.activity(self.config)
else:
self.activity = RA.activity(self.config)
self.update_UI.start()
self.start_time = datetime.datetime.now()
self.update_UI = update_UI()
self.update_UI.elapsed.connect(self.update_elapsed)
self.update_UI.update.connect(self.update_progress)
self.update_UI.finished.connect(self.finish_ui)
self.update_UI.run(B_or_R,self.config)


def show_message(self,text_to_show):
Expand All @@ -101,3 +111,34 @@ def show_message(self,text_to_show):
self.message_box.setText(text_to_show)
self.message_box.setStandardButtons(QMessageBox.Ok)
self.message_box.exec()



class update_UI(QThread):
update = pyqtSignal("PyQt_PyObject","PyQt_PyObject")
elapsed = pyqtSignal()
finished = pyqtSignal("PyQt_PyObject")
def __init__(self):
QThread.__init__(self)

def run(self,B_or_R,config):
print("OK")
update_progress = Thread(target=self.update_progress)
if B_or_R:
self.activity = BA.activity(config)
else:
self.activity = RA.activity(config)
update_progress.start()

def update_progress(self):
previous_length = 0
while self.activity.progress != self.activity.max_progress:
self.elapsed.emit()
if len(self.activity.copied_files) != previous_length:
print(str(datetime.datetime.now()), end="\r")
percentage = self.activity.progress / self.activity.max_progress
now_copying = self.activity.copied_files[-1]
previous_length = len(self.activity.copied_files)
self.update.emit(percentage, now_copying)

self.finished.emit(self.activity.unsuccesfull_log)

0 comments on commit 07e94e6

Please sign in to comment.