termux-gui icon indicating copy to clipboard operation
termux-gui copied to clipboard

Questions regarding this project

Open Raj2032 opened this issue 3 years ago • 27 comments

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?

Raj2032 avatar Dec 25 '21 08:12 Raj2032

  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.

tareksander avatar Dec 25 '21 09:12 tareksander

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?

Raj2032 avatar Dec 25 '21 12:12 Raj2032

Are there any chances that pygame would work with termuxgui?

captain0xff avatar Jan 12 '22 13:01 captain0xff

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.

tareksander avatar Jan 12 '22 15:01 tareksander

Thank you. :]

captain0xff avatar Jan 13 '22 13:01 captain0xff

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

m00n-err0r avatar May 24 '22 16:05 m00n-err0r

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)

tareksander avatar May 24 '22 18:05 tareksander

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

m00n-err0r avatar May 24 '22 19:05 m00n-err0r

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.

tareksander avatar May 24 '22 20:05 tareksander

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

m00n-err0r avatar May 25 '22 01:05 m00n-err0r

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.

tareksander avatar May 25 '22 06:05 tareksander

termguilog.txt

m00n-err0r avatar May 25 '22 06:05 m00n-err0r

So, any ideas? Please)

m00n-err0r avatar May 26 '22 11:05 m00n-err0r

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"])

tareksander avatar May 27 '22 13:05 tareksander

Nothing like "invalidMethod" IMG_20220527_182308

m00n-err0r avatar May 27 '22 15:05 m00n-err0r

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

m00n-err0r avatar May 27 '22 16:05 m00n-err0r

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?

tareksander avatar May 27 '22 18:05 tareksander

Android 11 miui 12.5.2 upload_2022_05_27_21_43_26_965

m00n-err0r avatar May 27 '22 18:05 m00n-err0r

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.

tareksander avatar May 27 '22 19:05 tareksander

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

m00n-err0r avatar May 27 '22 19:05 m00n-err0r

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.

tareksander avatar May 27 '22 20:05 tareksander

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 avatar May 27 '22 21:05 m00n-err0r

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

m00n-err0r avatar Jul 10 '22 10:07 m00n-err0r

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.

tareksander avatar Jul 10 '22 15:07 tareksander

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.

m00n-err0r avatar Jul 10 '22 16:07 m00n-err0r

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

tareksander avatar Jul 10 '22 17:07 tareksander

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

tareksander avatar May 28 '23 17:05 tareksander