Getting output from adb command in python pygui to populate combo

246 Views Asked by At

im using python and pygui to make a simple window that has a combo box that will list the files in a directory of an ADB device. For example if the folder has pictures, i would like to list all the pictures in phone directory and have them populate the combo box.

what i have

out2 = subprocess.getstatusoutput('adb shell ls SOMEDIRECTORY') combo_id = dpg.add_combo(out2)

this works (no errors) but it gives me 1 selection that i can choose (0) and all the files are in one big section and cannot be selected individually in the combo box.

if i do

print(out[1])

this shows me what i want but when i input that into the combo it gives and error

combo_id = dpg.add_combo(out2[1])

the error is

Exception: Error: [1008] Message: Python value error. Must be List[str].

combo_id = dpg.add_combo(out2[1]) File "/Users/Library/Python/3.8/lib/python/site-packages/dearpygui/dearpygui.py", line 3544, in add_combo return internal_dpg.add_combo(items, label=label, user_data=user_data, *use_internal_label=use_internal_label, tag=tag, width=width, indent=indent, parent=parent, before=before, source=source, payload_type=payload_type, callback=callback, drag_callback=drag_callback, drop_callback=drop_callback, show=show, enabled=enabled, pos=pos, filter_key=filter_key, tracked=tracked, track_offset=track_offset, default_value=default_value, popup_align_left=popup_align_left, no_arrow_button=no_arrow_button, no_preview=no_preview, height_mode=height_mode, **kwargs) SystemError: returned a result with an error set

Thanks

2

There are 2 best solutions below

0
On

Not sure what's the format you are expecting but you may need something like this to split the lines

p = subprocess.run(['adb', 'ls', SOMEDIRECTORY], capture_output=True)
out2 = [l.split()[3].decode('UTF-8') for l in p.stdout.splitlines()]
1
On

So i was able to do something similar to this https://stackoverflow.com/a/58630684/19080534

my problem was that i needed to do a list[str], its similar to the answer posted above.

thanks!