tareksander / termux-gui-python-bindings

A Python library to interact with the Termux:GUI plugin
https://tareksander.github.io/termux-gui-python-bindings/index.html
Mozilla Public License 2.0
97 stars 7 forks source link

Overlay doesn't work without specifying `tid` #4

Open cheadrian opened 10 months ago

cheadrian commented 10 months ago

When creating an overlay activity without specifying TID, there's an error about unpack. Python 3.11.6, termuxgui 0.1.6 running on Android 12, MIUI 14.

The code that is not working as expected:

import termuxgui as tg
import time

def main():
    with tg.Connection() as connection:
        activity = tg.Activity(connection, overlay=True)
        tv = tg.TextView(activity, "Hello world!")
        time.sleep(10)

if __name__ == "__main__":
    main()

Error:

Traceback (most recent call last):
  File "/data/data/com.termux/files/home/mergebot/bot_gui_overlay.py", line 11, in <module>
    main()
  File "/data/data/com.termux/files/home/mergebot/bot_gui_overlay.py", line 6, in main
    activity = tg.Activity(connection, overlay=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/termuxgui/activity.py", line 29, in __init__
    self.aid, tid = self.c.send_read_msg({"method": "newActivity", "params": params})
    ^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable int object

Adding a random tid to the tg.Activity makes the overlay to appear and fix the problem

activity = tg.Activity(connection, tid=123, overlay=True)

The overlay activity isn't documented in the TUTORIAL.md and would be useful.

tareksander commented 8 months ago

You can try out the new overlay-fix branch I just created and see if that resolves the issue.