[WIP] new GUI for debug console

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

hiran wrote: Sun Apr 21, 2024 6:17 am
MrFlibble wrote: Sun Apr 21, 2024 1:01 am
I made a self-contained version with pyinstaller on Linux. Doddle. Should be fairly easy to churn out static versions for most OSes between us so the non-pythoners won't have to get involved.
Would like to know more details on the Doddle part.
Using the system python 3.10, and not wanting to mess with my local setup by shoving things in willy-nilly with pip, I created a venv in a directory where I keep a heap of them. Activated it, and pip installed pyinstaller only in the venv.

Code: Select all


#python3-tk is needed.
# the packaged twisted works to run python scripts but fails
# with pyinstaller. If only building the binary, then no
# need to add it here.

apt install python3-tk python3-twisted

venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
deactivate
Made a tiny script "$HOME/bin/pyinstaller.sh" which activates the venv and runs pyinstaller, passing any arguments from the command line through.

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
source "${venv}"/bin/activate
pyinstaller $*
chmod 755 "$HOME/bin/pyinstaller.sh" #to make it executable

As $HOME/bin is in my path, I can now run pyinstaller.sh from a shell anywhere.

At this point, I can go for it, and with a minimum of swearing and demanding more coffee, I had myself a single executable and a workflow of sorts.

In a clean copy of the DebugConsole2 folder, I put this in a file called makebin.sh

Code: Select all

pyinstaller.sh --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
And makebin-clean.sh, for production.

Code: Select all

pyinstaller.sh --clean --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
From this point forth: . makebin.sh gets it done in one.

...then look in the newly created 'dist' folder.

There are complications where files are included, like for icons etc, but it looks like cag has done most of the work to take care of that.

For now, my version is without an icon on Linux, as the way I've found to get a nice icon working in Linux is not obviously easy to get working properly with pyinstaller. One of us can polish that another day.

(edited to incorporate fixes from below)
Last edited by MrFlibble on Sun Apr 21, 2024 8:34 am, edited 1 time in total.
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: [WIP] new GUI for debug console

Post by hiran »

MrFlibble wrote: Sun Apr 21, 2024 7:26 am
Using the system python 3.10, and not wanting to mess with my local setup by shoving things in willy-nilly with pip, I created a venv in a directory where I keep a heap of them. Activated it, and pip installed pyinstaller only in the venv.

Code: Select all

venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
deactivate
Made a tiny script "$HOME/bin/pyinstaller.sh" which activates the venv and runs pyinstaller, passing any arguments from the command line through.

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
source "${venv}"/bin/activate
pyinstaller $*
chmod 755 "$HOME/bin/pyinstaller.sh" #to make it executable

As $HOME/bin is in my path, I can now run pyinstaller.sh from a shell anywhere.

At this point, I can go for it, and with a minimum of swearing and demanding more coffee, I had myself a single executable and a workflow of sorts.

In a clean copy of the DebugConsole2 folder, I put this in a file called makebin.sh

Code: Select all

pyinstaller.sh --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
From this point forth: . makebin.sh gets it done in one.

...then look in the newly created 'dist' folder.

There are complications where files are included, like for icons etc, but it looks like cag has done most of the work to take care of that.

For now, my version is without an icon on Linux, as the way I've found to get a nice icon working in Linux is not obviously easy to get working properly with pyinstaller. One of us can polish that another day.

Code: Select all

$ ~/.local/bin/pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:." --add-binary "OoJSC.ico:." 
108 INFO: PyInstaller: 6.6.0, contrib hooks: 2024.4
108 INFO: Python: 3.10.12
109 INFO: Platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.35
109 INFO: wrote .../oolite-debug-console/DebugConsole.spec
110 INFO: Extending PYTHONPATH with paths
['.../oolite-debug-console']
161 INFO: Appending 'binaries' from .spec
162 INFO: checking Analysis
163 INFO: checking PYZ
175 INFO: checking PKG
175 INFO: Bootloader $HOME/.local/lib/python3.10/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run
175 INFO: checking EXE
175 INFO: Rebuilding EXE-00.toc because DebugConsole missing
175 INFO: Building EXE from EXE-00.toc
175 INFO: Copying bootloader EXE to .../oolite-debug-console/dist/DebugConsole
176 INFO: Appending PKG archive to custom ELF section in EXE
195 INFO: Building EXE from EXE-00.toc completed successfully.
$ 
Right after that I went to the dist directory and execute

Code: Select all

$ ./DebugConsole 
Traceback (most recent call last):
  File "ooliteConsoleServer/__init__.py", line 16, in <module>
ModuleNotFoundError: No module named 'twisted'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "DebugConsole.py", line 41, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "ooliteConsoleServer/__init__.py", line 18, in <module>
ImportError: ooliteConsoleServer requires Twisted (http://twistedmatrix.com/)
[19709] Failed to execute script 'DebugConsole' due to unhandled exception!
$ 
I guess this is since for non-python developers the computer is not setup like yours. We need to figure out these bits for a successful build on Github.
Sunshine - Moonlight - Good Times - Oolite
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

Cholmondely wrote: Sun Apr 21, 2024 6:52 am
1) How many of our OXPS actually use Python?
Is it just Telescope (+Telescope Options?) and the Debug Console - or are there oodles of them?
The OXP's themselves don't use python at all. Telescope uses the OXP as a convenient place to hold a python script which is an external tool to do something the OXP cannot.

Obviously the DebugConsoles.

Other than that, quite a few of the tools floating around to do things like change other 3d formats to Oolite compatible formats, and the recently mentioned elsewhere OXP sanity checking tools, are python. Many of them are very old.

Once the situation arises that a python script is no longer useable on current installations, anyone wanting to use it can either, fix/rewrite, run it in a venv/emulator, or just give up. The latter are silent, invisible, and probably gone.
Cholmondely wrote: Sun Apr 21, 2024 6:52 am
2) Note: I've not had any problems whatsoever with my 2.7 that I've noticed.
When you told me your "still supported" Mac had 2.7 only, I was shocked. I've not been near commercial OSes for a while.

Running old python scripts on 2.7 will mostly work fine. Anything newer than ten years... less likely as time goes on.
MrFlibble wrote: Sat Apr 20, 2024 9:27 pm
... exactly ...what ... ?
Would a log-in for our wiki be of any use?
[/quote]

Yes please.
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

hiran wrote: Sun Apr 21, 2024 7:55 am
MrFlibble wrote: Sun Apr 21, 2024 7:26 am
Using the system python 3.10, and not wanting to mess with my local setup by shoving things in willy-nilly with pip, I created a venv in a directory where I keep a heap of them. Activated it, and pip installed pyinstaller only in the venv.

Code: Select all

venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
deactivate
Made a tiny script "$HOME/bin/pyinstaller.sh" which activates the venv and runs pyinstaller, passing any arguments from the command line through.

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
source "${venv}"/bin/activate
pyinstaller $*
chmod 755 "$HOME/bin/pyinstaller.sh" #to make it executable

As $HOME/bin is in my path, I can now run pyinstaller.sh from a shell anywhere.

At this point, I can go for it, and with a minimum of swearing and demanding more coffee, I had myself a single executable and a workflow of sorts.

In a clean copy of the DebugConsole2 folder, I put this in a file called makebin.sh

Code: Select all

pyinstaller.sh --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
From this point forth: . makebin.sh gets it done in one.

...then look in the newly created 'dist' folder.

There are complications where files are included, like for icons etc, but it looks like cag has done most of the work to take care of that.

For now, my version is without an icon on Linux, as the way I've found to get a nice icon working in Linux is not obviously easy to get working properly with pyinstaller. One of us can polish that another day.

Code: Select all

$ ~/.local/bin/pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:." --add-binary "OoJSC.ico:." 
108 INFO: PyInstaller: 6.6.0, contrib hooks: 2024.4
108 INFO: Python: 3.10.12
109 INFO: Platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.35
109 INFO: wrote .../oolite-debug-console/DebugConsole.spec
110 INFO: Extending PYTHONPATH with paths
['.../oolite-debug-console']
161 INFO: Appending 'binaries' from .spec
162 INFO: checking Analysis
163 INFO: checking PYZ
175 INFO: checking PKG
175 INFO: Bootloader $HOME/.local/lib/python3.10/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run
175 INFO: checking EXE
175 INFO: Rebuilding EXE-00.toc because DebugConsole missing
175 INFO: Building EXE from EXE-00.toc
175 INFO: Copying bootloader EXE to .../oolite-debug-console/dist/DebugConsole
176 INFO: Appending PKG archive to custom ELF section in EXE
195 INFO: Building EXE from EXE-00.toc completed successfully.
$ 
Right after that I went to the dist directory and execute

Code: Select all

$ ./DebugConsole 
Traceback (most recent call last):
  File "ooliteConsoleServer/__init__.py", line 16, in <module>
ModuleNotFoundError: No module named 'twisted'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "DebugConsole.py", line 41, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "ooliteConsoleServer/__init__.py", line 18, in <module>
ImportError: ooliteConsoleServer requires Twisted (http://twistedmatrix.com/)
[19709] Failed to execute script 'DebugConsole' due to unhandled exception!
$ 
I guess this is since for non-python developers the computer is not setup like yours. We need to figure out these bits for a successful build on Github.
I'd already installed the requirements. You could pip install them in the venv, or if using a recent Ubuntu/Mint:

Code: Select all

apt install python3-tk python3-twisted
Not sure what other deps there are.
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

...I can't recall if the venv needs recreating after adding python packages via apt.

Easy enough to delete the venv directory and redo that part.

(edit) Looks like I did a pip install twisted from inside the venv on mine. I may not have needed to as the system has it already. python3-tk is certainly from apt here.


Nope. I've just tested by ripping out the venv one... The system one is fine to run stuff, but not ok for pyinstaller, It doesn't clash with one in the venv, so can be installed if you want to use twisted 'normally' outside the venv...

Assuming you have the venv, you can add twisted to it thus:

Code: Select all

venv="$HOME/python3/pyinstaller"
pip install twisted
deactivate
otherwise just add the twisted line from that to your earlier recipe to make pyinstaller.

And either preen the pyinstaller fluff by hand, or add --clean to the args in the makebin.sh else it'll strap it together from bad cached parts.

I've tidied the first description of this process above to add this lot.
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: [WIP] new GUI for debug console

Post by hiran »

I now created build.sh with this content:

Code: Select all

#!/bin/bash

venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
$HOME/.local/bin/pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
deactivate
When I run it, I get a dist directory with an executable 'DebugConsole'. Running that still gives me the output:

Code: Select all

olite-debug-console/dist$ ./DebugConsole 
Traceback (most recent call last):
  File "ooliteConsoleServer/__init__.py", line 16, in <module>
ModuleNotFoundError: No module named 'twisted'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "DebugConsole.py", line 41, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "ooliteConsoleServer/__init__.py", line 18, in <module>
ImportError: ooliteConsoleServer requires Twisted (http://twistedmatrix.com/)
[20342] Failed to execute script 'DebugConsole' due to unhandled exception!
oolite-debug-console/dist$
Something is still missing.
Sunshine - Moonlight - Good Times - Oolite
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

hiran wrote: Sun Apr 21, 2024 9:04 am

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
$HOME/.local/bin/pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
deactivate
Is $HOME/.local/bin/pyinstaller a wrapper script? is that also starting the venv we're already in, or is it a symlink to inside the venv?



hiran wrote: Sun Apr 21, 2024 9:04 am
Looks to me like this is the set of instructions:
Assuming a fresh home directory every time, forget making the .sh files and the first example below might serve.

Do remember to apt install python3-tk python3-venv python3-pip. Not knowing what bits of your build system are persistent makes this a tricky target for me.

So... This is for a straight line, do it once from scratch with no existing venv and a clean distdir. Assumes the pwd is the distdir else you'll need to cd to it before the pyinstaller line.

Code: Select all

venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
#We're in the venv, so can call pyinstaller directly.
pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
deactivate # if we're in a bash script you can leave this line out. The venv is auto shut down on the way out.
That is not how I'd do it unless I had good reason to redo from scratch every time.

If troubleshooting, or building multiple binaries from different scripts it might be better to separate that out more like the rest of this post.

This bit to (re)make the venv and pyinstaller. Can be left a while without refresh. Possible to enter the venv and update with pip if wanted.

Code: Select all

venv="$HOME/python3/pyinstaller"
# rm -Rf "$venv"  # uncomment to make fresh venv.
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
deactivate #only needed in an interactive shell. If a bash script, leave it out.
This as a stanza to run pyinstaller in its venv. Suggest as pyinstaller.sh somewhere in the $PATH
The script can be left alone if rebuilding any other part of the setup.

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
source "${venv}"/bin/activate
pyinstaller $*
Then this to build within the clean dist dir. Assumes pwd is the distdir.

Code: Select all

pyinstaller.sh --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
Or this to rebuild, deleting pyinstall caches etc. Assumes pwd is the distdir.

Code: Select all

pyinstaller.sh --clean --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
I'll try from scratch in a vm later if you're still having issues. What base system are you using?
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: [WIP] new GUI for debug console

Post by hiran »

MrFlibble wrote: Sun Apr 21, 2024 9:54 am
hiran wrote: Sun Apr 21, 2024 9:04 am

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
$HOME/.local/bin/pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
deactivate
Is $HOME/.local/bin/pyinstaller a wrapper script? is that also starting the venv we're already in, or is it a symlink to inside the venv?
That is the location I saw printed on the screen when executing 'pip install pyinstaller'. I checked and it is a python script with this content:

Code: Select all

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from PyInstaller.__main__ import _console_script_run
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(_console_script_run())
MrFlibble wrote: Sun Apr 21, 2024 9:54 am
Assuming a fresh home directory every time, forget making the .sh files and the first example below might serve.
One of the prerequisite for good build scripts, yes.
MrFlibble wrote: Sun Apr 21, 2024 9:54 am
Do remember to apt install python3-tk python3-venv python3-pip. Not knowing what bits of your build system are persistent makes this a tricky target for me.
Sorry - I do not want to remember. It needs to be put somewhere into a build script.
But with that we get

Code: Select all

apt install python3-tk python3-venv python3-pip
venv="$HOME/python3/pyinstaller"
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
#We're in the venv, so can call pyinstaller directly.
pyinstaller --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
deactivate # if we're in a bash script you can leave this line out. The venv is auto shut down on the way out.
MrFlibble wrote: Sun Apr 21, 2024 9:54 am
That is not how I'd do it unless I had good reason to redo from scratch every time.

If troubleshooting, or building multiple binaries from different scripts it might be better to separate that out more like the rest of this post.

This bit to (re)make the venv and pyinstaller. Can be left a while without refresh. Possible to enter the venv and update with pip if wanted.

Code: Select all

venv="$HOME/python3/pyinstaller"
# rm -Rf "$venv"  # uncomment to make fresh venv.
python3 -m venv "$venv"
source "${venv}"/bin/activate
pip install pyinstaller
pip install twisted
deactivate #only needed in an interactive shell. If a bash script, leave it out.
This as a stanza to run pyinstaller in its venv. Suggest as pyinstaller.sh somewhere in the $PATH
The script can be left alone if rebuilding any other part of the setup.

Code: Select all

#!/bin/bash
venv="$HOME/python3/pyinstaller"
source "${venv}"/bin/activate
pyinstaller $*
Then this to build within the clean dist dir. Assumes pwd is the distdir.

Code: Select all

pyinstaller.sh --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
Or this to rebuild, deleting pyinstall caches etc. Assumes pwd is the distdir.

Code: Select all

pyinstaller.sh --clean --onefile DebugConsole.py --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:."
I'll try from scratch in a vm later if you're still having issues. What base system are you using?
I think we are good that I try this on Github. At home I am running Ubuntu Desktop 22.04. On Github we also have Ubuntu 22.04 (I believe they strip off the desktop).
Sunshine - Moonlight - Good Times - Oolite
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

hiran wrote: Sun Apr 21, 2024 10:09 am

$HOME/.local/bin/pyinstaller

That is the location I saw printed on the screen when executing 'pip install pyinstaller'. I checked and it is a python script with this content:
I guess you didn''t make the venv and enter it successfully then. The pip installs should end up in the venv, and not leak into the user environment. So it fell through and did the pip installs in the home directory directly. That might be why the twisted thing was going wrong.

Might be worth stepping through as I've shown, until you see how each step behaves, how prompts change when sourcing activate etc.

I generally run the build venv 'by hand' so I get to see where I'm going. It wouldn't be very hard to write it as a proper process with checks, maybe a few "&& proceed || baulk" type bits though they can get tricksy when switching context. I've been doing venvs a while, and as a matter of course on this machine, so it's all in place to do that reliably. Pasting the whole lot from scratch in a cold environment was likely to b0rk.

If I can try it on github, I'll at least be shooting at the same target. For now, I need some kip soon. It's 11:25 here and I'm shattered. I'll stick around for another cuppa though :)
User avatar
Cholmondely
Archivist
Archivist
Posts: 4997
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: [WIP] new GUI for debug console

Post by Cholmondely »

MrFlibble wrote: Sat Apr 20, 2024 9:27 pm
Cholmondely wrote: Sun Apr 21, 2024 6:52 am
Would a log-in for our wiki be of any use?
Yes please.
Thy "pm" awaits...
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

hiran wrote: Sun Apr 21, 2024 10:09 am
I think we are good that I try this on Github. At home I am running Ubuntu Desktop 22.04. On Github we also have Ubuntu 22.04 (I believe they strip off the desktop).
Okay. I've tried this on a current Mint VM that doesn't do much dev, and a headless Deb11 that's used for very little.

This bash build script assumes the zipfile is in the $basedir directory, and named OoliteDebugConsole-latest.zip. It should break with meaningful error if anything is wrong along the way. I just called this build.sh set it executable, and stuck it in $basedir. It looks easier on the eye in a context highlighting editor.

Just zap the builddir within to rebuild.

Code: Select all

#!/bin/bash

q(){ echo "Error at: $*" >&2 ; exit 5 ; } # exit function

basedir="$HOME/OoDC" # the zipfile is expected to be in here
builddir="$basedir/build" # this can be deleted to retry a build
basename=OoliteDebugConsole # gets used a lot
inscript=DebugConsole.py # the name of the script we'll be 'compiling'
zipfile="$basedir/${basename}-latest.zip"
venv="$builddir/pyinstaller"
dist="${basename}2.03" # the directory exracted from zip

step="package install" # might want to do this elsewhere so as to avoid login prompt.
sudo apt install python3-tk python3-pip python3-venv binutils || q "$step"

step="setting up venv and building tools"
python3 -m venv "$venv" &&
source "$venv"/bin/activate &&
pip install twisted &&
pip install pyinstaller || q "$step"

step="preparing dist for build"
cd "$builddir" &&
unzip "$zipfile" &&
cd "$dist" || q "$step"

step="making executable"
pyinstaller --name "$basename" --onefile "$inscript" --add-binary "oojsc.xbm:."  --add-binary "OoJSC.ico:." &&
cd "$basedir" && mv "$builddir/$dist/dist/$basename" . &&
echo "Finibasedir. Your file is at ''$basedir/$basename'" || q "$step"

#end
If the end of your output looks like this:

Code: Select all

Finished. Your file is at ''/home/user/OoDC/OoliteDebugConsole'
We've won!

The output functioned and was the identical to the one generated on my laptop.

I ran it on a headless Debian 11 VM. It failed properly in a few places and helped me identify more missing packages. The resulting binary runs fine on my Mint lappy and is c.700k smaller.

Now we're cooking!

(edit: Revised this 20240421 14:03 to make it more flexible and logical.)
(edit 2: If the apt stuff can be done elsewhere, maybe in a "prep" script before this then this whole shebang can be 2>&1 into a logfile)
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: [WIP] new GUI for debug console

Post by hiran »

Indeed we are getting somewhere. I followed your instructions (the last post of yours came while I was busy testing) and meanwhile get a Linux build out of it.

Here is the Github workflow:
https://github.com/OoliteProject/oolite ... ld.yml#L67

You can see I distinguished between setting up the env vs running the packager.
In the end it produced this prerelease:

https://github.com/OoliteProject/oolite ... tag/v2.0.3

When I downloaded the tgz to my local computer I was able to run the debug console and saw a window popping up.
Excellent work, guys!

These builds will now happen whenever we change something on that branch. And we may look into building for other platforms as well.
Sunshine - Moonlight - Good Times - Oolite
cag
Deadly
Deadly
Posts: 197
Joined: Fri Mar 17, 2017 1:49 am

Re: [WIP] new GUI for debug console

Post by cag »

First, let me thank you for hard work & patience with this - much appreciated!
hiran wrote: Sun Apr 21, 2024 5:46 pm
And we may look into building for other platforms as well.
here's what I used on my last local Windows build, over 2 years ago.

Code: Select all

pyinstaller ^
    --noconfirm ^
    --clean ^
    --log-level=WARN ^
    --paths "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86"  ^
    --onefile ^
    --noconsole ^
    --noupx ^
    --name OoDebugConsole ^
    --icon=OoliteDebugConsole\OoJSC.ico ^
    --add-binary "OoliteDebugConsole\OoJSC.ico:." ^
    --add-binary "OoliteDebugConsole\oojsc.xbm:." ^
    --version-file=OoDebug_version_info.txt ^
    DebugConsole.py
--paths is for the Visual C++ run-time .dlls (3 folders: x86, x64, arm).

You can get the 'Windows Software Development Kit (SDK) for Windows 10' at
https://developer.microsoft.com/en-us/w ... ows-10-sdk

Visual C++ Redistributable for Visual Studio 2015-2022 may be a simpler option (less baggage if nothing else)
https://learn.microsoft.com/en-us/cpp/w ... w=msvc-170

--noupx was used as UPX was causing problems, it gained little in file size and launch was significantly longer

--icon works for Window & MacOS but not Linux

--version-file is Windows only; not sure it's required but here's an updated version:

OoDebug_version_info.txt

Code: Select all

# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
  ffi=FixedFileInfo(
    # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
    # Set not needed items to zero 0.
    filevers=(2, 0, 3, 0),
    prodvers=(2, 0, 3, 0),
    # Contains a bitmask that specifies the valid bits 'flags'r
    mask=0x3f,
    # Contains a bitmask that specifies the Boolean attributes of the file.
    flags=0x0,
    # The operating system for which this file was designed.
    # 0x4 - NT and there is no need to change it.
    OS=0x40004,
    # The general type of file.
    # 0x1 - the file is an application.
    fileType=0x1,
    # The function of the file.
    # 0x0 - the function is not defined for this fileType
    subtype=0x0,
    # Creation date and time stamp.
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'040904B0',
        [StringStruct(u'CompanyName', u'Jens Ayton, Kaks, cag, MrFlibble'),
        StringStruct(u'FileDescription', u'Debug console for Oolite'),
        StringStruct(u'FileVersion', u'2.0.3.0'),
        StringStruct(u'InternalName', u'DebugConsole'),
        StringStruct(u'LegalCopyright', u'CC BY-NC-SA 4.0'),
        StringStruct(u'OriginalFilename', u'OoDebugConsole.exe'),
        StringStruct(u'ProductName', u'OoDebugConsole'),
        StringStruct(u'ProductVersion', u'2.0.3.0')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
  ]
)
"Better to be thought a fool, boy, than to open your trap and remove all doubt." - Grandma [over time, just "Shut your trap... fool"]
"The only stupid questions are the ones you fail to ask." - Dad
How do I...? Nevermind.
User avatar
hiran
Theorethicist
Posts: 2056
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: [WIP] new GUI for debug console

Post by hiran »

cag wrote: Mon Apr 22, 2024 2:17 am
here's what I used on my last local Windows build, over 2 years ago.

Code: Select all

pyinstaller ^
    --noconfirm ^
    --clean ^
    --log-level=WARN ^
    --paths "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86"  ^
    --onefile ^
    --noconsole ^
    --noupx ^
    --name OoDebugConsole ^
    --icon=OoliteDebugConsole\OoJSC.ico ^
    --add-binary "OoliteDebugConsole\OoJSC.ico:." ^
    --add-binary "OoliteDebugConsole\oojsc.xbm:." ^
    --version-file=OoDebug_version_info.txt ^
    DebugConsole.py
I tested my luck by simply applying this. Got an error message in the logs.
See https://github.com/OoliteProject/oolite ... 4087608296

I guess we properly need to configure the build environment.
cag wrote: Mon Apr 22, 2024 2:17 am
--paths is for the Visual C++ run-time .dlls (3 folders: x86, x64, arm).

You can get the 'Windows Software Development Kit (SDK) for Windows 10' at
[...]
We need to properly work out what is required and how we can achieve that in an automated fashion. I do not have a Windows machine at hand so all I can do is copy instructions. Maybe it is more meaningful if you configure the build and I will assist where necessary.

Here you can see what software is preinstalled: https://github.com/actions/runner-image ... -Readme.md

And here is the script executing your command. Since it is executed in PowerShell I had to convert the multiline markers.
https://github.com/OoliteProject/oolite ... d.yml#L105
Sunshine - Moonlight - Good Times - Oolite
User avatar
MrFlibble
Deadly
Deadly
Posts: 170
Joined: Sun Feb 18, 2024 12:13 pm

Re: [WIP] new GUI for debug console

Post by MrFlibble »

cag wrote: Mon Apr 22, 2024 2:17 am
--icon works for Window & MacOS but not Linux
Indeed there is no --icon option in pyinstaller on Linux.

This article may be helpful there. See Kibi's answer. It describes 'normal' way to realise desktop icons for apps in most Linux DE.
https://stackoverflow.com/questions/753 ... python-app

I tried it with a DebugConsole.desktop file in $HOME/.local/share/applications containing:-

Code: Select all

[Desktop Entry]
Type=Application
Name=Oolite DebugConsole 2
GenericName=Oolite DebugConsole 2
Comment=Debugger for Oolite
Exec=/home/user/OoDC/DebugConsole
Icon=/home/user/OoDC/OoJSC128x128.png
Terminal=false
Categories=Application
As soon as I'd done that, I hit the windoze key, started typing debug, and the debugger appeared highlighted in the app llst complete with icon. Sadly it didn't have the alt-tab icon when run. Nonetheless, a desktop file seems essential. This could be installed in users home or even system wide if implemented as e.g. a deb package.

It may be that the attempts to use an icon in the python script are masking that from working for alt-tab et-al. Though a quick test of a bash script launching a very simple python tk program would hint that that's not the case.

I had a quick hack yesterday, and inside the script, I've had some degree of success with something like:-

Code: Select all

	iconFile = PhotoImage(file='OoJSC256x256.png')
	self.top.wm_iconphoto(True, iconFile)
Ok, so it caused other issues when crowbarred in like that, and would need care to work with pyinstaller, but it gave a nice icon for the app in the tray and when alt-tabbing. Better than the monochrome 32x32 xbm or default 'square'.
Post Reply