Skip to content

Commit 940e9d6

Browse files
authored
Fix the bug with the progress bar percentages (#256)
2 parents 96a6876 + a4320b8 commit 940e9d6

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

openandroidinstaller/views/install_addons_view.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def run_install_addons(self, e):
203203
self.error_text.value = "Installation failed! Try again or make sure everything is setup correctly."
204204
else:
205205
sleep(4) # wait to make sure everything is fine
206+
self.progress_indicator.set_progress_bar(100)
207+
self.progress_indicator.update()
206208
logger.success("Installation process was successful. Allow to continue.")
207209
# enable the confirm button and disable the call button
208210
self.confirm_button.disabled = False

openandroidinstaller/views/install_view.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def run_install(self, e):
210210
self.error_text.value = "Installation failed! Try again or make sure everything is setup correctly."
211211
else:
212212
sleep(5) # wait to make sure everything is fine
213+
self.progress_indicator.set_progress_bar(100)
214+
self.progress_indicator.update()
213215
logger.success("Installation process was successful. Allow to continue.")
214216
# enable the confirm button and disable the call button
215217
self.confirm_button.disabled = False

openandroidinstaller/views/start_view.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def check_bootloader_unlocked(e):
104104
self.state.steps = []
105105
else:
106106
logger.info("Enabled unlocking the bootloader again.")
107-
self.state.steps = copy.deepcopy(
108-
self.state.config.unlock_bootloader
109-
)
107+
self.state.steps = copy.deepcopy(self.state.config.unlock_bootloader)
110108
# if the recovery is already flashed, skip flashing it again
111109
if self.recovery_switch.value == False:
112110
self.state.steps += copy.deepcopy(self.state.config.boot_recovery)
@@ -122,12 +120,10 @@ def check_bootloader_unlocked(e):
122120
# toggleswitch to allow skipping flashing recovery
123121
def check_recovery_already_flashed(e):
124122
"""Enable skipping flashing recovery if selected."""
125-
123+
126124
# manage the bootloader unlocking switch
127125
if self.bootloader_switch.value == False:
128-
self.state.steps = copy.deepcopy(
129-
self.state.config.unlock_bootloader
130-
)
126+
self.state.steps = copy.deepcopy(self.state.config.unlock_bootloader)
131127
else:
132128
self.state.steps = []
133129

@@ -140,7 +136,7 @@ def check_recovery_already_flashed(e):
140136
self.recovery_switch = Switch(
141137
label="Custom recovery is already flashed.",
142138
on_change=check_recovery_already_flashed,
143-
disabled=False,
139+
disabled=True,
144140
inactive_thumb_color=colors.YELLOW,
145141
active_color=colors.GREEN,
146142
)
@@ -283,6 +279,7 @@ def search_devices_clicked(self, e):
283279
if device_name:
284280
self.continue_button.disabled = False
285281
self.bootloader_switch.disabled = False
282+
self.recovery_switch.disabled = False
286283
# overwrite the text field with the real name from the config
287284
self.device_name.value = (
288285
f"{device_name} (code: {self.state.config.device_code})"

openandroidinstaller/widgets.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ def display_progress_bar(self, line: str):
114114
"""Display and update the progress bar for the given line."""
115115
percentage_done = None
116116
result = None
117+
# create the progress bar
118+
if self.progress_bar == None:
119+
self.progress_bar = ProgressBar(
120+
value=1 / 100,
121+
width=500,
122+
bar_height=32,
123+
color="#00d886",
124+
bgcolor="#eeeeee",
125+
)
126+
# text to display the percentage
127+
self.percentage_text = Text("1%")
128+
self._container.content.controls.append(
129+
Row([self.percentage_text, self.progress_bar])
130+
)
117131
# get the progress numbers from the output lines
118132
if (type(line) == str) and line.strip():
119133
result = re.search(
@@ -122,23 +136,29 @@ def display_progress_bar(self, line: str):
122136
)
123137
if result:
124138
if result.group(2):
125-
percentage_done = 100
139+
percentage_done = 99
126140
elif result.group(1):
127141
percentage_done = int(result.group(1))
142+
if percentage_done == 0:
143+
percentage_done = 1
144+
elif percentage_done == 100:
145+
percentage_done = 99
128146

129-
# create the progress bar on first occurrence
130-
if percentage_done == 0:
131-
self.progress_bar = ProgressBar(
132-
width=500, bar_height=32, color="#00d886", bgcolor="#eeeeee"
133-
)
134-
self.percentage_text = Text(f"{percentage_done}%")
135-
self._container.content.controls.append(
136-
Row([self.percentage_text, self.progress_bar])
137-
)
138147
# update the progress bar
139-
if self.progress_bar:
140-
self.progress_bar.value = percentage_done / 100
141-
self.percentage_text.value = f"{percentage_done}%"
148+
self.set_progress_bar(percentage_done)
149+
150+
def set_progress_bar(self, percentage_done: int):
151+
"""Set the progress bar to the given percentage.
152+
153+
Args:
154+
percentage_done (int): Percentage of the progress bar to be filled.
155+
"""
156+
assert (
157+
percentage_done >= 0 and percentage_done <= 100
158+
), "Percentage must be between 0 and 100"
159+
if self.progress_bar:
160+
self.progress_bar.value = percentage_done / 100
161+
self.percentage_text.value = f"{percentage_done}%"
142162

143163
def display_progress_ring(
144164
self,

tests/test_progress_bar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def test_init():
3030
def test_update_progress_bar():
3131
"""Test if the progress bar is updated properly based on lines."""
3232
progress_indicator = ProgressIndicator(expand=True)
33-
build_indicator = progress_indicator.build()
33+
progress_indicator.build()
3434

3535
# test if other line is fine
3636
progress_indicator.display_progress_bar(
3737
line="Failed to mount '/data' (Device or resource busy)"
3838
)
39-
assert not progress_indicator.progress_bar
39+
assert progress_indicator.progress_bar
4040

4141
# test if percentages are parsed correctly and update is performed
4242
for percentage in range(0, 47):
@@ -46,4 +46,4 @@ def test_update_progress_bar():
4646

4747
# test if the finishing print is detected and updated correctly.
4848
progress_indicator.display_progress_bar(line="Total xfer: 1.00x\n")
49-
assert progress_indicator.progress_bar.value == 1.0
49+
assert progress_indicator.progress_bar.value == 0.99

0 commit comments

Comments
 (0)