[WIP | Guide] Adding Projects to the System Menu

Please note that this is based on a clean install and unmodified pt-sys-oled files, if you have made any modifications to the files already, its your responsibility to find what is required to modify

To add projects to the system menu, first you need to make some edits to the system meny python files. these are located in /usr/lib/pt-sys-oled/components

Setting up the menu
The main edit is the Menu.py file so that you can enable the projects option on the pi-top[4] screen. these are the steps

You can use sudo nano (you do not get line numbers to make edits or you can open it in VSCode, when saving look to the bottom right as it will give you an error, click retry as sudo and enter your password
image

  • Line 15 | uncomment the code #title as projects_title by deleting the #
    image
  • Line 146 to 156 | uncomment all these lines by deleting the #
  • Line 214 | make an edit replacing ~/Desktop/My Projects to a path you want, i use /home/pi/OledProjects
    image
  • Make a folder in the location that you have specified (its Case Sensitive)
  • In terminal type the following sudo systemctl stop pt-sys-oled.service , this stops the screen service and turns it off
  • In terminal type the following sudo systemctl stop pt-sys-oled.service , This starts the service back up and you will get the battery screen displayed
  • On the pi-top[4] - press the O button and then press the down arrow and you should see projects. pressing O again will show “No Projects Found”

of you add a folder it will create a menu item automatically when pressing O on projects

Now your ready to start some projects to display on the OLED mini screen

2 Likes

Reserved for further guide

Research into getting Projects running
This is as far as i can get. I have looked into the projects to start a project and i can see it calls start_stop_project(project_path) so looked in the helpers/menu_page_actions.py and can see that there is this code

def start_stop_project(path_to_project):
    def run():
        start_script = path_to_project + "/start.sh"
        stop_script = path_to_project + "/stop.sh"

        PTLogger.debug("Checking if process is already running...")

        cmd = 'pgrep -f "' + path_to_project + '" || true'
        output = check_output(cmd, shell=True).decode("ascii", "ignore")
        pids = list(filter(None, output.split("\n")))

        try:
            if len(pids) > 1:
                PTLogger.info(
                    "Project already running: "
                    + str(path_to_project)
                    + ". Attempting to stop..."
                )

                if path.exists(stop_script):
                    Popen([stop_script])
                else:
                    for pid in pids:
                        try:
                            kill(int(pid), signal.SIGTERM)
                        except ValueError:
                            pass
            else:
                PTLogger.info("Starting project: " + str(path_to_project))

                if path.exists(start_script):
                    PTLogger.debug(
                        "Code file found at " + start_script + ". Running..."
                    )
                    Popen([start_script])
                else:
                    PTLogger.info("No code file found at " + start_script)

        except Exception as e:
            PTLogger.warning("Error starting/stopping process: " + str(e))

    return run

but when i make a start.sh and with the code python3 test.py it does nothing even with doing chmod +x

@pi-topMIKE any info on how to get this working and also does the project python file have to follow the same format as the widgets?

1 Like

Reserved for further guide again

1 Like

I can confirm that you’ve correctly identified how to set up the projects folder! hehe.

So it does work. You have to use chmod u+x *filename.sh* to get it working. I am able to get my google drive mounted using rclone in a single lined bash script :slight_smile:

So I can at least verify it will run a bash script from the projects menu. As far as why python wouldn’t run, did you try just python instead of python3? Have you tried making both the bash and python script executable? Start with chmod +x and then try u+x if that doesn’t work. It worked for me!

1 Like

Ah nice, I think my mistake was doing chmod -x instead of chmod +x

-x will remove the executable flag hehe.

So it seams that the projects folder is a way to start up independent scripts instead of the way system widgets work which is interesting. May be that way to be able to start a project without a screen attached.

Nice testing @Supernovali thanks for the info. Will sort that out later when I get home, just got to work hehe

Question for you. When the script was running did the display show anything different and did you have to push the O button to start the script? Just planning ahead for screenshots etc for the 2nd part of the write up

  • Things I need to look into is how to show that the script is running without taking control of the screen if needed if it does not show that it’s running

  • Stopping a script if it’s one that runs on a continuous loop

  • Possibly using a project to provide information for a system widget as a possible use case

@Supernovali one thing I did find, you may have noticed that you do not have to start and stop the pt-sys-oled service when working with projects which is really nice unlike system widgets

1 Like

Yeah, I did notice that. I saw in the Menu.py that it refreshes every half second? You can actually adjust parameters in Menu.py to make the cpu monitor refresh however fast you want it to. That was the very first thing I did weeks ago haha made it refresh @10Hz.

I’m not sure if it can take over the screen but no, it doesnt show any indication from the Oled that it’s running or not. Wed probably have to use the api to start showing information there.

You could include logic to check the thread if it’s running. As long as execution pauses on the script. Or you would have to write 2 projects, which would be easier but clunky.

So, also, if your code that runs from start.sh doesnt have a corresponding stop.sh, then it will kill the process while it’s in the middle of whatever it’s doing. But if the project is already running, then it will run the stop script.

I was actually playing with the widget system initially, not the project menu initially. I couldnt get it running but I only spent a couple hours trying to understand how it was operating to build a widget. But i saw someone else getting a widget running… i think. I’ll have to go back and check it out again.

I’m not sure what pgrep does exactly, but it looks like it just checks the project folder looking for something running and if something is running from the folder, will run the stop script.

I’ll have to read on the command. I just got to work as well. I’m -7 hours in my time zone so sorry for the long wait.

Each system widget can have its own refresh rate which I will go into in my other post about it.

Had a thought that might be the case

There is something about pid in the code I remember not sure what it’s about

That was me :slight_smile: and doing a write up on how to do that too :slight_smile:

Haha, yeah, I found the post and have been deep diving into the oled system. Refresh rate was the first tweak I made hehe.

Yeah, if there is no stop script, it will search for the running process and attempt to kill it.

I’m about to post on a helper “project” that I’m using to quickly start and stop the oled service haha

Hey! It’s great that you’ve both been looking into this - I don’t really have anything to add to this right now! This will work if you want it to, but it is definitely not optimal - an improved software design pattern is needed that supports more flexibility. I’ll be writing about this more when I’ve had a chance to write it up in a way that doesn’t just make sense to me :joy:

3 Likes

News:
https://forum.pi-top.com/t/pt-sys-oled-repo-is-now-public/741

I have included a link to this page until we have a rework design completed :slight_smile:

1 Like