Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions regarding this project #6

Open
Raj2032 opened this issue Dec 25, 2021 · 27 comments
Open

Questions regarding this project #6

Raj2032 opened this issue Dec 25, 2021 · 27 comments

Comments

@Raj2032
Copy link

Raj2032 commented Dec 25, 2021

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
Copy link
Member

  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
Copy link
Author

Raj2032 commented Dec 25, 2021

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
Copy link

Are there any chances that pygame would work with termuxgui?

@tareksander
Copy link
Member

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
Copy link

Thank you. :]

@m00n-err0r
Copy link

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
Copy link
Member

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
Copy link

m00n-err0r commented May 24, 2022

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
Copy link
Member

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
Copy link

m00n-err0r commented May 25, 2022

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
Copy link
Member

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
Copy link

termguilog.txt

@m00n-err0r
Copy link

So, any ideas? Please)

@tareksander
Copy link
Member

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
Copy link

Nothing like "invalidMethod"
IMG_20220527_182308

@m00n-err0r
Copy link

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

@tareksander
Copy link
Member

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
Copy link

Android 11 miui 12.5.2
upload_2022_05_27_21_43_26_965

@tareksander
Copy link
Member

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
Copy link

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
Copy link
Member

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
Copy link

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
Copy link

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

@tareksander
Copy link
Member

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
Copy link

m00n-err0r commented Jul 10, 2022

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
Copy link
Member

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

@tareksander
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants