termux / termux-gui

A plugin for Termux to use native Android GUI components from CLI applications.
GNU General Public License v3.0
670 stars 54 forks source link

Questions regarding this project #6

Open Raj2032 opened 2 years ago

Raj2032 commented 2 years ago

Hi, I have some questions regarding this project.

  1. Using Rust, I want to make a GUI application using either conrod or iced GUI library. Is it easily portable to termux-gui?
  2. Do I have to compile it for Android ARM processor? Or what would I do to compile it?
  3. Is it possible to have like some sort of a shortcut to my launcher for the GUI Linux application that will automatically launch it as soon as I press it?
  4. If I have scrollable content that can be scrolled only using the mouse wheel on Linux, then if I run it on Android (through termux-gui) would I be able to scroll using the touch screen?
  5. Am I expecting things to be difficult to configure, and have a lot of breakage?
tareksander commented 2 years ago
  1. I took a quick look at those libraries and I think it shouldn't be too much work to port it. Depends on the size of your application though.
  2. You have to compile it for the processor your phone has, likely aarch64.
  3. You can create a shortcut with Termux:Widget.
  4. Scrolling with the touch screen is possible.

The biggest problem for you would be that there is no rust library for Termux:GUI at the moment, so you would have to write that yourself. Have a look at the protocol and feel free to ask me if you have any questions. That also helps me to know if the protocol documentation is detailed enough for someone else to implement it.

Raj2032 commented 2 years ago

Thanks mate @tareksander :)

The biggest problem for you would be that there is no rust library for Termux:GUI at the moment

Is C at least supported?

Because I know that Rust has C interop support.

I also wanted to know what would I specifically have to do to get it to work with Termux GUI?

captain0xff commented 2 years ago

Are there any chances that pygame would work with termuxgui?

tareksander commented 2 years ago

Not out-of-the-box, but it can in theory work with anything where you can access the pixel buffer. You can create a RGBA888 buffer in pygame and after drawing each frame you can copy the contents into a buffer that is shared with the plugin that then displays it. It's easier if the library supports drawing into an arbitrary buffer in memory, so you can instruct it to directly draw into the shared buffer. I also want to support sharing an GLES buffer in the future so the data doesn't have to be copied to and from graphics memory. There is a part in the python bindings tutorial that shows how to draw with a library and it uses python SDL bindings as an example.

captain0xff commented 2 years ago

Thank you. :]

m00n-err0r commented 2 years ago

Please, tell me what I'm doing wrong. I'm trying to add TabLayout. I have code like this with tg.Connection() as c: a = tg.Activity(c) tab_list = ['tab1', 'tab2', 'tab3'] tab = tg.TabLayout(a) tab.setlist(tab_list)

But when I run it, it shows black screen. I'm new to coding, thanks

tareksander commented 2 years ago

Please, tell me what I'm doing wrong. I'm trying to add TabLayout. I have code like this with tg.Connection() as c: a = tg.Activity(c) tab_list = ['tab1', 'tab2', 'tab3'] tab = tg.TabLayout(a) tab.setlist(tab_list)

But when I run it, it shows black screen. I'm new to coding, thanks

Do you have some sort of blocking or event loop after that code? I can't reproduce the black screen. My code is:

import termuxgui as tg
import sys

with tg.Connection() as c:
    a = tg.Activity(c)

    tl = tg.TabLayout(a)
    tl.setlist(["tab 1", "tab 2", "tab 3"])

    for ev in c.events():
        if ev.type == tg.Event.destroy and ev.value["finishing"]:
            sys.exit()
        print(ev.type, ev.value)
m00n-err0r commented 2 years ago

I have not event loop, but when I tried your code, nothing has changed, I still have a black screen.

UPD: it freezes after tl = tg.TabLayout(a) No code after this line can be executed

I tried restarting my phone and reinstalling the app, no effect

tareksander commented 2 years ago

Do things other than a TabLayout work? Are you sure you have version 0.1.4 of the app? The symptom of code after that not executing should be from the python code expecting an answer from the plugin, but the plugin doesn't answer because the command from the code is unknown. That should really only happen if the code uses a feature not present in the plugin.

m00n-err0r commented 2 years ago

I'm sure, termux:gui is 0.1.4 version. LinearLayout, ImageView, Button, Horizontal and NestedScrollView, SwipeRefreshLayout, TextView and Buffer working normally.

Jast checked, it can detect screen on/off events, presented in 0.1.4

tareksander commented 2 years ago

Can you upload the output of logcat -d after running your script? I think the plugin log messages should also be in there. Maybe there was an error in the plugin.

m00n-err0r commented 2 years ago

termguilog.txt

m00n-err0r commented 2 years ago

So, any ideas? Please)

tareksander commented 2 years ago

You can try the following script, which runs the event loop in a separate thread. If you see an event printed with "invalidMethod", that means a feature (in this case setlist for TabLayout) isn't present in the plugin, which should really only occur when the plugin is outdated.

import termuxgui as tg
import threading
import sys

with tg.Connection() as c:
    def evloop():
        for ev in c.events():
            print(ev.type, ev.value)

    threading.Thread(target=evloop).start()

    a = tg.Activity(c)

    tl = tg.TabLayout(a)
    tl.setlist(["tab 1", "tab 2", "tab 3"])
m00n-err0r commented 2 years ago

Nothing like "invalidMethod" IMG_20220527_182308

m00n-err0r commented 2 years ago

I reinstalled python plagin and app, nothing has changed. IMG_20220527_190329 IMG_20220527_190225

tareksander commented 2 years ago

What Android version do you have? When you quit the python script with ctrl + c, there should be a stack trace, can I see that?

m00n-err0r commented 2 years ago

Android 11 miui 12.5.2 upload_2022_05_27_21_43_26_965

tareksander commented 2 years ago

The code for TabLayout is there in 0.1.4 and there were no Exceptions in the logcat...

I started a build from the latest source, maybe the problem is already fixed. Install the plugin from here and try again. If that still doesn't work, I have no idea. I'll add much more logging for 1.0, so I can probably diagnose the problem when 1.0 is finished.

m00n-err0r commented 2 years ago

Thanks a lot, now it is working! Another question, how can I specify color for TextView? Tried in hex tv.settextcolor('#ff0000') but activity ends after that

tareksander commented 2 years ago

You need an event loop or wait with time.sleep() so the activity doesn't end, see the Python tutorial. Also the color format is RGBA (as a number and not a string), so 0xaabbggrr.

m00n-err0r commented 2 years ago

It ended even if there was an event loop. But after applying the correct color format, everything works as it should. Thank you, thank you very much

m00n-err0r commented 2 years ago

Hello It is impossimble to use termuxgui python plugin inside proot, right?

tareksander commented 2 years ago

It should work if you allow proot to keep /data/data/com.termux mounted and keep the PATH. It only needs to access the am binary from the termux environment in PATH. Should work in proot-distro by default.

m00n-err0r commented 2 years ago

By default this doesnt work. When I'm trying import module, rises ModuleNotFoundError, after installing module, rises RuntimeError: Plugin doesn't have the same UID. How can I keep /data/data/com.termux mounted and keep the PATH? I know only --termux-home flag, that mounts home dir.

tareksander commented 2 years ago

The uid error is because proot emulates a root user. Try getting the uid used by termux and set proot to use that.

tareksander commented 1 year ago

@Raj2032 The C library is now mostly done: https://github.com/tareksander/termux-gui-c-bindings