Skip to content

Commit

Permalink
Improve lib_output textfield scrolling
Browse files Browse the repository at this point in the history
- Adding a timer improves scroll
- Made lib_output textfield wider
  • Loading branch information
redromnon committed Apr 6, 2023
1 parent 18a2394 commit 73e3c4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/libutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def backup(self, folder, password):
#Enable encryption if password is given
if password is None:

self.process = subprocess.Popen(["idevicebackup2", "backup", folder], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
self.process = subprocess.Popen(["idevicebackup2", "backup", folder], stdout=subprocess.PIPE)

return self.process

Expand All @@ -47,22 +47,22 @@ def backup(self, folder, password):
self.encrypt_process = subprocess.Popen(["idevicebackup2", "encryption", "on", password, folder])
self.encrypt_process.wait()

self.process = subprocess.Popen(["idevicebackup2", "backup", folder], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
self.process = subprocess.Popen(["idevicebackup2", "backup", folder], stdout=subprocess.PIPE)

return self.process

def restore(self, folder, password):

if password is None:

self.process = subprocess.Popen(["idevicebackup2", "restore", folder], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
self.process = subprocess.Popen(["idevicebackup2", "restore", folder], stdout=subprocess.PIPE)

return self.process

else:

print("Restoring encrypted backup...")
self.process = subprocess.Popen(["idevicebackup2", "restore", "--password", password, folder], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True)
self.process = subprocess.Popen(["idevicebackup2", "restore", "--password", password, folder], stdout=subprocess.PIPE)

return self.process

Expand Down
34 changes: 23 additions & 11 deletions src/ui/operations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import flet as ft
import flet as ft, time
from libutilities import Action

class Operation(ft.UserControl):
Expand All @@ -21,9 +21,9 @@ def build(self):
ft.Column(
[self.lib_output],
horizontal_alignment="center", expand=True, auto_scroll=True, scroll="auto",
width=400
width=600
),
], width=400
], width=600
),
content_padding=30, modal=True,
actions=[self.close_button, self.cancel_button]
Expand All @@ -35,17 +35,23 @@ def backup(self, folder, pwd):

self.result_dialog.open = True
self.result_dialog.title = ft.Text("Backing Up", text_align="center")
self.lib_output.value = "...\n"
self.lib_output.value = "Running backup...\n"
self.update()

process = self.action.backup(folder, pwd)

while True:

for line in process.stdout:
print(line, end="")
#Benefits smoother scrolling of lib_output texfield
time.sleep(0.5)
line = process.stdout.readline().decode()

print(line, end='')
self.lib_output.value += line
self.update()

process.wait()
if process.poll() is not None and line == '':
break

self.close_button.disabled = False
self.cancel_button.disabled = True
Expand All @@ -57,17 +63,23 @@ def restore(self, folder, pwd):

self.result_dialog.open = True
self.result_dialog.title = ft.Text("Restoring", text_align="center")
self.lib_output.value = "...\n"
self.lib_output.value = "Running restore...\n"
self.update()

process = self.action.restore(folder, pwd)

for line in process.stdout:
print(line, end="")
while True:

#Benefits smoother scrolling of lib_output texfield
time.sleep(0.5)
line = process.stdout.readline().decode()

print(line, end='')
self.lib_output.value += line
self.update()

process.wait()
if process.poll() is not None and line == '':
break

self.close_button.disabled = False
self.cancel_button.disabled = True
Expand Down

0 comments on commit 73e3c4a

Please sign in to comment.