2626 icons ,
2727 TextField ,
2828 Container ,
29+ Switch ,
2930 alignment ,
3031 colors ,
3132 ProgressBar ,
@@ -68,6 +69,29 @@ def __init__(
6869
6970 def build (self ):
7071 """Create the content of a view from step."""
72+ # error text
73+ self .error_text = Text ("" , color = colors .RED )
74+
75+ # switch to enable advanced output - here it means show terminal input/output in tool
76+ def check_advanced_switch (e ):
77+ """Check the box to enable advanced output."""
78+ if self .advanced_switch .value :
79+ logger .info ("Enable advanced output." )
80+ self .state .advanced = True
81+ self .terminal_box .visible = True
82+ # add terminal box if enabled
83+ self .right_view .update ()
84+ else :
85+ logger .info ("Disable advanced output." )
86+ self .state .advanced = False
87+ self .terminal_box .visible = False
88+ self .right_view .update ()
89+
90+ self .advanced_switch = Switch (
91+ label = "Advanced output" ,
92+ on_change = check_advanced_switch ,
93+ disabled = False ,
94+ )
7195 # text box for terminal output
7296 self .terminal_box = Container (
7397 content = Column (scroll = "auto" , expand = True ),
@@ -78,6 +102,7 @@ def build(self):
78102 height = 300 ,
79103 border_radius = 2 ,
80104 expand = True ,
105+ visible = False
81106 )
82107 # main controls
83108 self .right_view .controls = [
@@ -95,19 +120,33 @@ def build(self):
95120 self .call_button = call_button (
96121 self .call_to_phone , command = self .step .command
97122 )
98- self .right_view .controls .append (
99- Row ([self .call_button , self .confirm_button ]),
100- )
101- # add terminal box if enabled
102- if self .state .advanced :
103- self .right_view .controls .append (Row ([self .terminal_box ]))
123+ self .right_view .controls .extend ([
124+ Row ([self .error_text ]),
125+ Column (
126+ [
127+ self .advanced_switch ,
128+ Row ([self .call_button , self .confirm_button ]),
129+ ]
130+ ),
131+ Row ([self .terminal_box ])
132+ ])
104133 elif self .step .type == "call_button_with_input" :
105134 self .confirm_button .disabled = True
106135 self .call_button = call_button (
107136 self .call_to_phone , command = self .step .command
108137 )
109138 self .right_view .controls .extend (
110- [self .inputtext , Row ([self .call_button , self .confirm_button ])]
139+ [
140+ self .inputtext ,
141+ Row ([self .error_text ]),
142+ Column (
143+ [
144+ self .advanced_switch ,
145+ Row ([self .call_button , self .confirm_button ]),
146+ ]
147+ ),
148+ Row ([self .terminal_box ])
149+ ]
111150 )
112151 elif self .step .type == "link_button_with_confirm" :
113152 self .right_view .controls .extend (
@@ -147,16 +186,11 @@ def call_to_phone(self, e, command: str):
147186 if self .state .advanced :
148187 self .terminal_box .content .controls = []
149188 # display a progress bar to show something is happening
150- self .right_view .controls .append (
151- Row (
152- [
153- ProgressBar (
154- width = 600 , color = "#00d886" , bgcolor = "#eeeeee" , bar_height = 16
155- )
156- ],
157- alignment = "center" ,
158- ),
189+ progress_bar = Row (
190+ [ProgressBar (width = 600 , color = "#00d886" , bgcolor = "#eeeeee" , bar_height = 16 )],
191+ alignment = "center" ,
159192 )
193+ self .right_view .controls .append (progress_bar )
160194 self .right_view .update ()
161195
162196 cmd_mapping = {
@@ -171,7 +205,7 @@ def call_to_phone(self, e, command: str):
171205 # run the right command
172206 if command in cmd_mapping .keys ():
173207 for line in cmd_mapping .get (command )(bin_path = self .state .bin_path ):
174- if self . state . advanced and (type (line ) == str ) and line .strip ():
208+ if (type (line ) == str ) and line .strip ():
175209 self .terminal_box .content .controls .append (
176210 Text (f">{ line .strip ()} " , selectable = True )
177211 )
@@ -181,7 +215,7 @@ def call_to_phone(self, e, command: str):
181215 for line in adb_sideload (
182216 bin_path = self .state .bin_path , target = self .state .image_path
183217 ):
184- if self . state . advanced and (type (line ) == str ) and line .strip ():
218+ if (type (line ) == str ) and line .strip ():
185219 self .terminal_box .content .controls .append (
186220 Text (f">{ line .strip ()} " , selectable = True )
187221 )
@@ -195,7 +229,7 @@ def call_to_phone(self, e, command: str):
195229 Path (f"{ self .state .config .metadata .get ('devicecode' )} .yaml" )
196230 ),
197231 ):
198- if self . state . advanced and (type (line ) == str ) and line .strip ():
232+ if (type (line ) == str ) and line .strip ():
199233 self .terminal_box .content .controls .append (
200234 Text (f">{ line .strip ()} " , selectable = True )
201235 )
@@ -205,7 +239,7 @@ def call_to_phone(self, e, command: str):
205239 for line in fastboot_flash_recovery (
206240 bin_path = self .state .bin_path , recovery = self .state .recovery_path
207241 ):
208- if self . state . advanced and (type (line ) == str ) and line .strip ():
242+ if (type (line ) == str ) and line .strip ():
209243 self .terminal_box .content .controls .append (
210244 Text (f">{ line .strip ()} " , selectable = True )
211245 )
@@ -215,7 +249,7 @@ def call_to_phone(self, e, command: str):
215249 for line in fastboot_unlock_with_code (
216250 bin_path = self .state .bin_path , unlock_code = self .inputtext .value
217251 ):
218- if self . state . advanced and (type (line ) == str ) and line .strip ():
252+ if (type (line ) == str ) and line .strip ():
219253 self .terminal_box .content .controls .append (
220254 Text (f">{ line .strip ()} " , selectable = True )
221255 )
@@ -225,35 +259,31 @@ def call_to_phone(self, e, command: str):
225259 for line in heimdall_flash_recovery (
226260 bin_path = self .state .bin_path , recovery = self .state .recovery_path
227261 ):
228- if self . state . advanced and (type (line ) == str ) and line .strip ():
262+ if (type (line ) == str ) and line .strip ():
229263 self .terminal_box .content .controls .append (
230264 Text (f">{ line .strip ()} " , selectable = True )
231265 )
232266 self .terminal_box .update ()
233267 success = line
234268 else :
235- logger .error (f"Unknown command type: { command } . Stopping." )
236- raise Exception (f"Unknown command type: { command } . Stopping." )
269+ msg = f"Unknown command type: { command } . Stopping."
270+ logger .error (msg )
271+ self .error_text .value = msg
272+ raise Exception (msg )
237273
238274 # update the view accordingly
239275 if not success :
240276 # enable call button to retry
241277 self .call_button .disabled = False
242278 # pop the progress bar
243- self .right_view .controls .pop ( )
279+ self .right_view .controls .remove ( progress_bar )
244280 # also remove the last error text if it happened
245- if isinstance (self .right_view .controls [- 1 ], Text ):
246- self .right_view .controls .pop ()
247- self .right_view .controls .append (
248- Text (
249- f"Command { command } failed! Try again or make sure everything is setup correctly."
250- )
251- )
281+ self .error_text .value = f"Command { command } failed! Try again or make sure everything is setup correctly."
252282 else :
253283 sleep (5 ) # wait to make sure everything is fine
254284 logger .success (f"Command { command } run successfully. Allow to continue." )
255285 # pop the progress bar
256- self .right_view .controls .pop ( )
286+ self .right_view .controls .remove ( progress_bar )
257287 # emable the confirm buton and disable the call button
258288 self .confirm_button .disabled = False
259289 self .call_button .disabled = True
0 commit comments