Initial C commit adding main.c and make file
This commit is contained in:
1 parent
17b109e98e
commit
24c48b5372
47 files changed
+43
-991
No files matched your search
+18
@@ -0,0 +1,18 @@
|
||||
CC = gcc
|
||||
CFLAGS = -O3 -Wall -Wextra -std=c11 -pthread
|
||||
LDFLAGS = -lm
|
||||
TARGET = src/main
|
||||
SOURCES = src/main.c
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCES)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@echo "Cleaning Project"
|
||||
rm -f *.o
|
||||
rm -f $(TARGET)
|
||||
@echo "Clean Complete"
|
||||
|
||||
.PHONY: all clean
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void main(int argc, char *argv[]){
|
||||
printf("Hello World!\n");
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -1,489 +0,0 @@
|
||||
<html lang="en-us"><script src="https://pygame-web.github.io/archives/0.9/pythons.js" type=module id=site data-LINES=57 data-CONSOLE=25 data-python=python3.12 data-os=vtx,fs,snd,gui async defer>#<!--
|
||||
|
||||
print("""
|
||||
Loading conway-s-game-of-life-rebuilt from conway-s-game-of-life-rebuilt.apk
|
||||
Pygbag Version : 0.9.2
|
||||
Template Version : 0.9.0
|
||||
Python : 3.12
|
||||
CDN URL : https://pygame-web.github.io/archives/0.9/
|
||||
Screen : 1280x720
|
||||
Title : conway-s-game-of-life-rebuilt
|
||||
Folder : conway-s-game-of-life-rebuilt
|
||||
Authors : pgw
|
||||
SPDX-License-Identifier: cookiecutter.spdx
|
||||
|
||||
""")
|
||||
|
||||
|
||||
# screen pixels (real, hardware)
|
||||
WIDTH=1024 # 1280
|
||||
HEIGHT=600 # 720
|
||||
|
||||
# reference/idealized screen pixels
|
||||
REFX = 1980
|
||||
REFY = 1080
|
||||
|
||||
def u(real, ref, v):
|
||||
if abs(v)<0.9999999:
|
||||
result = int( (float(real)/100.0) * (v*1000))
|
||||
if v<0:
|
||||
return real-result
|
||||
return result
|
||||
return int( (real/ref) * v )
|
||||
|
||||
def ux(*argv):
|
||||
global WIDTH, REFX
|
||||
acc = 0
|
||||
for v in argv:
|
||||
acc += u(WIDTH, REFX, v)
|
||||
return acc
|
||||
|
||||
def uy(*argv):
|
||||
global HEIGHT, REFY
|
||||
acc = 0
|
||||
for v in argv:
|
||||
acc += u(HEIGHT, REFY, v)
|
||||
return acc
|
||||
|
||||
|
||||
|
||||
|
||||
# do not rename
|
||||
async def custom_site():
|
||||
|
||||
import sys
|
||||
import asyncio
|
||||
import platform
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
import embed
|
||||
|
||||
|
||||
platform.document.body.style.background = "#7f7f7f"
|
||||
|
||||
import pygame
|
||||
|
||||
def compose():
|
||||
pygame.display.update()
|
||||
window.chromakey(None, *screen.get_colorkey(), 40)
|
||||
|
||||
pygame.init()
|
||||
pygame.font.init()
|
||||
|
||||
screen = pygame.display.set_mode([ux(.100),uy(.100)], pygame.SRCALPHA, 32)
|
||||
screen.set_colorkey( (0,0,0,0), pygame.RLEACCEL )
|
||||
screen.fill( (0,0,0,0) )
|
||||
|
||||
compose()
|
||||
|
||||
platform.window.transfer.hidden = true
|
||||
platform.window.canvas.style.visibility = "visible"
|
||||
|
||||
|
||||
|
||||
apk = "conway-s-game-of-life-rebuilt.apk"
|
||||
|
||||
bundle = "conway-s-game-of-life-rebuilt"
|
||||
|
||||
# the C or js loader could do that but be explicit.
|
||||
appdir = Path(f"/data/data/{bundle}") # /data/data/conway-s-game-of-life-rebuilt
|
||||
appdir.mkdir()
|
||||
|
||||
|
||||
# mount apk
|
||||
|
||||
cfg = {
|
||||
"io": "url",
|
||||
"type":"mount",
|
||||
"mount" : {
|
||||
"point" : appdir.as_posix(),
|
||||
"path" : "/",
|
||||
},
|
||||
"path" : f"/ => {appdir.as_posix()}",
|
||||
}
|
||||
|
||||
|
||||
track = platform.window.MM.prepare(apk, json.dumps(cfg))
|
||||
|
||||
marginx = ux(.020) # 20%
|
||||
marginy = uy(.045) # 45%
|
||||
|
||||
|
||||
def pg_bar(pos):
|
||||
nonlocal marginx, marginy
|
||||
# resolution of progress bar, recalculate since it may not be know yet.
|
||||
total = track.len or 10 # avoid div0
|
||||
slot = ux(.060)/ total # 60%
|
||||
|
||||
pygame.draw.rect(screen,(10,10,10),( marginx-ux(10), marginy-uy(10), (total*slot)+ux(20), uy(110) ) )
|
||||
pygame.draw.rect(screen,(0,255,0), ( marginx, marginy, track.pos*slot, uy(90)) )
|
||||
|
||||
# wait until zip mount + overlayfs is complete
|
||||
while not track.ready:
|
||||
pg_bar(track.pos)
|
||||
compose()
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
# fill it up in case it was cached and instant download
|
||||
pg_bar(track.len)
|
||||
compose()
|
||||
|
||||
|
||||
# preloader will change dir and prepend it to sys.path
|
||||
platform.run_main(PyConfig, loaderhome= appdir / "assets", loadermain=None)
|
||||
|
||||
|
||||
# wait preloading complete
|
||||
# that includes images and wasm compilation of bundled modules
|
||||
while embed.counter()<0:
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
main = appdir / "assets" / "main.py"
|
||||
|
||||
# start async top level machinery and add a console.
|
||||
await TopLevel_async_handler.start_toplevel(platform.shell, console=window.python.config.debug)
|
||||
|
||||
# now that apk is mounted we have access to font cache
|
||||
# but we need to fill __file__ that is not yet set
|
||||
__import__(__name__).__file__ = str(main)
|
||||
|
||||
|
||||
# now make a prompt
|
||||
fnt = pygame.sysfont.SysFont("freesans", uy(80) )
|
||||
|
||||
def ui_callback(pkg, error=None):
|
||||
nonlocal fnt
|
||||
if error:
|
||||
prompt = fnt.render(f"{error}", True, "black")
|
||||
else:
|
||||
prompt = fnt.render(f"Setting [{pkg}] up", True, "black")
|
||||
pg_bar(track.len)
|
||||
screen.blit(prompt, ( marginx+ ux(80), marginy - uy(10) ) )
|
||||
compose()
|
||||
|
||||
# test/wait if user media interaction required
|
||||
if not platform.window.MM.UME:
|
||||
|
||||
# now make a prompt
|
||||
fnt = pygame.sysfont.SysFont("freesans", uy(80) )
|
||||
prompt = fnt.render("Ready to start !", True, "blue")
|
||||
pg_bar(track.len)
|
||||
screen.blit(prompt, ( marginx+ ux(80), marginy - uy(10) ) )
|
||||
compose()
|
||||
print("""
|
||||
* Waiting for media user engagement : please click/touch page *
|
||||
""")
|
||||
while not platform.window.MM.UME:
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
# cleanup
|
||||
screen.fill( (0,0,0,0) )
|
||||
pygame.display.flip()
|
||||
|
||||
await shell.runpy(main, callback=ui_callback)
|
||||
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
asyncio.run( custom_site() )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# BEGIN BLOCK
|
||||
#
|
||||
# now this is the html part you can (and should) customize
|
||||
# It is not mandatory : pygame-script when it reads the first line (also called
|
||||
# shebang ) of above code create absolute minimal widget set
|
||||
# required for running with default rules
|
||||
#
|
||||
# do not alter that comment block it is separating python code from html code
|
||||
# =============================================================================
|
||||
# --></script><head><!--
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
{%- if cookiecutter.comment != "" -%}
|
||||
{{cookiecutter.comment}}
|
||||
{% endif %}
|
||||
|
||||
--><script type="application/javascript">
|
||||
// END BLOCK
|
||||
|
||||
|
||||
|
||||
// this dict is available under PyConfig.config from __main__
|
||||
|
||||
config = {
|
||||
xtermjs : "1" ,
|
||||
_sdl2 : "canvas",
|
||||
user_canvas : 0,
|
||||
user_canvas_managed : 0,
|
||||
ume_block : 1,
|
||||
can_close : 0,
|
||||
archive : "conway-s-game-of-life-rebuilt",
|
||||
gui_debug : 3,
|
||||
cdn : "https://pygame-web.github.io/archives/0.9/",
|
||||
autorun : 0,
|
||||
PYBUILD : "3.12"
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<title>conway-s-game-of-life-rebuilt</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="viewport" content="height=device-height, initial-scale=1.0">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
|
||||
<link rel="prefetch" href="https://pygame-web.github.io/archives/0.9/pythonrc.py">
|
||||
<link rel="prefetch" href="https://pygame-web.github.io/archives/0.9/vt/xterm.js">
|
||||
<link rel="prefetch" href="https://pygame-web.github.io/archives/0.9/vt/xterm-addon-image.js">
|
||||
<link rel="prefetch" href="https://pygame-web.github.io/archives/0.9/vt/xterm-addon-image.js">
|
||||
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png" sizes="16x16">
|
||||
|
||||
<style>
|
||||
#status {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin-top: 20px;
|
||||
margin-left: 30px;
|
||||
font-weight: bold;
|
||||
color: rgb(120, 120, 120);
|
||||
}
|
||||
|
||||
#progress {
|
||||
height: 20px;
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
div.emscripten { text-align: center; }
|
||||
div.emscripten_border { border: 1px solid black; }
|
||||
div.thick_border { border: 4px solid black; }
|
||||
|
||||
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
|
||||
/* average size of droid screen 470dp x 320dp */
|
||||
canvas.emscripten {
|
||||
border: 0px none;
|
||||
background-color: transparent;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 5;
|
||||
|
||||
padding: 0;
|
||||
margin: 0 auto;
|
||||
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: arial;
|
||||
margin: 0;
|
||||
padding: none;
|
||||
background-color:powderblue;
|
||||
}
|
||||
|
||||
.topright{
|
||||
position:absolute;
|
||||
top:0px;
|
||||
right:0px;
|
||||
}
|
||||
|
||||
.bottomright {
|
||||
position:absolute;
|
||||
top: 40%;
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.trinfo{
|
||||
position:relative;
|
||||
right:0px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.framed{
|
||||
position:relative;
|
||||
top:150px;
|
||||
right:10px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="https://pygame-web.github.io/archives/0.9//browserfs.min.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="transfer" align=center>
|
||||
<!-- <div class="spinner" id='spinner'></div> -->
|
||||
<div class="emscripten" id="status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="progress"></progress>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<canvas class="emscripten" id="canvas"
|
||||
width="1px"
|
||||
height="1px"
|
||||
oncontextmenu="event.preventDefault()" tabindex=1>
|
||||
</canvas>
|
||||
|
||||
<div id=html></div>
|
||||
|
||||
<div id=crt class=bottomright >
|
||||
|
||||
<div id="system" hidden>
|
||||
<div class="button-container">
|
||||
<button id="aiostop" disabled>AIO ⏏︎</button>
|
||||
<button id="aiopaused_true" disabled>AIO ■</button>
|
||||
<button id="aiopaused_false" disabled>AIO ▶</button>
|
||||
<button id="pygame_mixer_music_pause" disabled>Music ■</button>
|
||||
</div>
|
||||
|
||||
<div class="button-container">
|
||||
<div id=load_min>min</div>
|
||||
<div id=load_avg>avg</div>
|
||||
<div id=load_max>max</div>
|
||||
<button id="load_rst" disabled>RESET</button>
|
||||
</div>
|
||||
|
||||
<div id="level">(battery level unknown)</div>
|
||||
<div id="stateBattery">(charging state unknown)</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id=box class="emscripten_border" hidden=true>
|
||||
|
||||
<div id="info" class="trinfo"></div>
|
||||
|
||||
<iframe id="iframe" class="framed" name="iframe"
|
||||
width="470px" height="90%"
|
||||
allowtransparency="true"
|
||||
style="z-index: 10;"
|
||||
style="background: #FFFFFF;"
|
||||
frameborder="1"
|
||||
allowfullscreen="true"
|
||||
webkitallowfullscreen="true"
|
||||
msallowfullscreen="true"
|
||||
mozallowfullscreen="true"
|
||||
sandbox="allow-same-origin allow-top-navigation allow-scripts allow-pointer-lock"
|
||||
allow="autoplay; fullscreen *; geolocation; microphone; camera; midi; monetization; xr-spatial-tracking; gamepad; gyroscope; accelerometer; xr; cross-origin-isolated"
|
||||
src="https://pygame-web.github.io/archives/0.9/empty.html"
|
||||
scrolling="yes">
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="dlg" hidden>
|
||||
<input type="file" id="dlg_multifile" multiple accept="image/*">
|
||||
<label for="dlg_multifile">Select files</label>
|
||||
</div>
|
||||
|
||||
<div id="pyconsole">
|
||||
<div id="terminal" tabIndex=1 align="left"></div>
|
||||
</div>
|
||||
|
||||
<script type="application/javascript">
|
||||
|
||||
async function custom_onload(debug_hidden) {
|
||||
// this is called before anything python is loaded
|
||||
// make your js customization here
|
||||
console.log(__FILE__, "custom_onload")
|
||||
|
||||
pyconsole.hidden = debug_hidden
|
||||
system.hidden = debug_hidden
|
||||
transfer.hidden = debug_hidden
|
||||
info.hidden = debug_hidden
|
||||
box.hidden = debug_hidden
|
||||
|
||||
}
|
||||
|
||||
function custom_prerun(){
|
||||
// no python main and no (MEMFS + VFS) yet.
|
||||
console.log(__FILE__, "custom_prerun")
|
||||
|
||||
}
|
||||
|
||||
function custom_postrun(){
|
||||
// python main and no VFS filesystem yet.
|
||||
console.log(__FILE__, "custom_postrun")
|
||||
|
||||
// prevent ff horizontal scroll
|
||||
window.addEventListener("keydown", function(e) {
|
||||
if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
|
||||
if (!python.config.debug)
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
function debug() {
|
||||
// allow to gain access to dev tools from js console
|
||||
// but only on desktop. difficult to reach when in iframe
|
||||
python.config.debug = true
|
||||
custom_onload(false)
|
||||
Module.PyRun_SimpleString("shell.uptime()")
|
||||
window_resize()
|
||||
}
|
||||
|
||||
function info_inline(data){
|
||||
document.getElementById("info").innerHTML = data
|
||||
}
|
||||
|
||||
function info_online(url) {
|
||||
// display info about current APK
|
||||
fetch( url /*, options */)
|
||||
.then((response) => response.text())
|
||||
.then((html) => {
|
||||
info_inline(html);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(error);
|
||||
});
|
||||
}
|
||||
|
||||
function frame_online(url) {
|
||||
window.frames["iframe"].location = url;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
File renamed without changes.
File renamed without changes.
@@ -11,6 +11,8 @@ SCREEN_Y = 1080
|
||||
SCREEN = None
|
||||
MENU_X = 1
|
||||
MENU_Y = 1
|
||||
SCALE_X = 1
|
||||
SCALE_Y = 1
|
||||
CELL_SIZE = 10
|
||||
RUNNING = True
|
||||
SIMULATE = False
|
||||
@@ -61,10 +63,10 @@ def drawGrid():
|
||||
# Draw the grid lines
|
||||
gridOffset = CELL_SIZE * 10
|
||||
for x in range(0, SCREEN.get_width(), gridOffset):
|
||||
#(display,color, start, end)
|
||||
pygame.draw.line(SCREEN, (0, 0, 60), (x, 0), (x, SCREEN.get_height()))
|
||||
#(display,color, start, end, thickness)
|
||||
pygame.draw.line(SCREEN, (0, 0, 60), (x, 0), (x, SCREEN.get_height()), 2)
|
||||
for y in range(0, SCREEN.get_height(), gridOffset):
|
||||
pygame.draw.line(SCREEN, (0, 0, 60), (0, y), (SCREEN.get_width(), y))
|
||||
pygame.draw.line(SCREEN, (0, 0, 60), (0, y), (SCREEN.get_width(), y), 2)
|
||||
|
||||
def displayMenu():
|
||||
|
||||
@@ -124,8 +126,6 @@ def optionsMenu():
|
||||
return
|
||||
|
||||
def mainMenu():
|
||||
# NOTE: For some reason mouse must click on item 2x on program start
|
||||
|
||||
SCREEN.fill((0, 0, 0))
|
||||
mainTheme = MENU_THEME.copy()
|
||||
mainTheme.title_close_button=False
|
||||
@@ -181,8 +181,8 @@ def game():
|
||||
#Get mouse input
|
||||
mx, my = pygame.mouse.get_pos()
|
||||
#Snap to grid
|
||||
gx = mx // CELL_SIZE
|
||||
gy = my // CELL_SIZE
|
||||
gx = (mx * SCALE_X) // CELL_SIZE
|
||||
gy = (my * SCALE_Y)// CELL_SIZE
|
||||
|
||||
if 0 <= gx < GRID_W and 0 <= gy < GRID_H:
|
||||
|
||||
@@ -243,6 +243,8 @@ def main():
|
||||
global SCREEN_Y
|
||||
global MENU_X
|
||||
global MENU_Y
|
||||
global SCALE_X
|
||||
global SCALE_Y
|
||||
|
||||
if sys.platform != "emscripten":
|
||||
import importlib
|
||||
@@ -254,14 +256,19 @@ def main():
|
||||
SCREEN = pygame.display.set_mode((SCREEN_X,SCREEN_Y), pygame.RESIZABLE | pygame.SCALED)
|
||||
SCREEN_X, SCREEN_Y = SCREEN.get_size()
|
||||
|
||||
MENU_Y = .9 * SCREEN_Y
|
||||
MENU_X = .8 * SCREEN_X
|
||||
window_w, window_h = pygame.display.get_window_size()
|
||||
|
||||
ratio = (MENU_Y / MENU_X)
|
||||
if SCREEN
|
||||
SCALE_X = window_w / SCREEN_X | 1
|
||||
SCALE_Y = window_h / SCREEN_Y | 1
|
||||
|
||||
|
||||
MENU_Y = .9 * SCREEN_Y * SCALE_Y
|
||||
MENU_X = .8 * SCREEN_X * SCALE_X
|
||||
|
||||
#Set the correct Scale for menus
|
||||
MENU_THEME.title_font_size= min(50, math.floor(100 * ratio)) | max(50, math.floor(100 * ratio))
|
||||
MENU_THEME.widget_font_size= min(25, math.floor(50 * ratio)) | max(25, math.floor(100 * ratio))
|
||||
MENU_THEME.title_font_size= min(50, math.floor(100 * SCALE_X)) | max(50, math.floor(100 * SCALE_X))
|
||||
MENU_THEME.widget_font_size= min(25, math.floor(50 * SCALE_X)) | max(25, math.floor(100 * SCALE_X))
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -1 +0,0 @@
|
||||
0.9.2
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
@@ -1,489 +0,0 @@
|
||||
<html lang="en-us"><script src="{{cookiecutter.cdn}}pythons.js" type=module id=site data-LINES={{cookiecutter.LINES}} data-CONSOLE={{cookiecutter.CONSOLE}} data-python=python{{cookiecutter.PYBUILD}} data-os=vtx,fs,snd,gui async defer>#<!--
|
||||
|
||||
print("""
|
||||
Loading {{cookiecutter.title}} from {{cookiecutter.archive}}.apk
|
||||
Pygbag Version : {{cookiecutter.version}}
|
||||
Template Version : 0.9.0
|
||||
Python : {{cookiecutter.PYBUILD}}
|
||||
CDN URL : {{cookiecutter.cdn}}
|
||||
Screen : {{cookiecutter.width}}x{{cookiecutter.height}}
|
||||
Title : {{cookiecutter.title}}
|
||||
Folder : {{cookiecutter.directory}}
|
||||
Authors : {{cookiecutter.authors}}
|
||||
SPDX-License-Identifier: {{cookiecutter.spdx}}
|
||||
|
||||
""")
|
||||
|
||||
|
||||
# screen pixels (real, hardware)
|
||||
WIDTH=1024 # {{cookiecutter.width}}
|
||||
HEIGHT=600 # {{cookiecutter.height}}
|
||||
|
||||
# reference/idealized screen pixels
|
||||
REFX = 1980
|
||||
REFY = 1080
|
||||
|
||||
def u(real, ref, v):
|
||||
if abs(v)<0.9999999:
|
||||
result = int( (float(real)/100.0) * (v*1000))
|
||||
if v<0:
|
||||
return real-result
|
||||
return result
|
||||
return int( (real/ref) * v )
|
||||
|
||||
def ux(*argv):
|
||||
global WIDTH, REFX
|
||||
acc = 0
|
||||
for v in argv:
|
||||
acc += u(WIDTH, REFX, v)
|
||||
return acc
|
||||
|
||||
def uy(*argv):
|
||||
global HEIGHT, REFY
|
||||
acc = 0
|
||||
for v in argv:
|
||||
acc += u(HEIGHT, REFY, v)
|
||||
return acc
|
||||
|
||||
|
||||
|
||||
|
||||
# do not rename
|
||||
async def custom_site():
|
||||
|
||||
import sys
|
||||
import asyncio
|
||||
import platform
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
import embed
|
||||
|
||||
|
||||
platform.document.body.style.background = "#7f7f7f"
|
||||
|
||||
import pygame
|
||||
|
||||
def compose():
|
||||
pygame.display.update()
|
||||
window.chromakey(None, *screen.get_colorkey(), 40)
|
||||
|
||||
pygame.init()
|
||||
pygame.font.init()
|
||||
|
||||
screen = pygame.display.set_mode([ux(.100),uy(.100)], pygame.SRCALPHA, 32)
|
||||
screen.set_colorkey( (0,0,0,0), pygame.RLEACCEL )
|
||||
screen.fill( (0,0,0,0) )
|
||||
|
||||
compose()
|
||||
|
||||
platform.window.transfer.hidden = true
|
||||
platform.window.canvas.style.visibility = "visible"
|
||||
|
||||
|
||||
|
||||
apk = "{{cookiecutter.archive}}.apk"
|
||||
|
||||
bundle = "{{cookiecutter.archive}}"
|
||||
|
||||
# the C or js loader could do that but be explicit.
|
||||
appdir = Path(f"/data/data/{bundle}") # /data/data/{{cookiecutter.archive}}
|
||||
appdir.mkdir()
|
||||
|
||||
|
||||
# mount apk
|
||||
|
||||
cfg = {
|
||||
"io": "url",
|
||||
"type":"mount",
|
||||
"mount" : {
|
||||
"point" : appdir.as_posix(),
|
||||
"path" : "/",
|
||||
},
|
||||
"path" : f"/ => {appdir.as_posix()}",
|
||||
}
|
||||
|
||||
|
||||
track = platform.window.MM.prepare(apk, json.dumps(cfg))
|
||||
|
||||
marginx = ux(.020) # 20%
|
||||
marginy = uy(.045) # 45%
|
||||
|
||||
|
||||
def pg_bar(pos):
|
||||
nonlocal marginx, marginy
|
||||
# resolution of progress bar, recalculate since it may not be know yet.
|
||||
total = track.len or 10 # avoid div0
|
||||
slot = ux(.060)/ total # 60%
|
||||
|
||||
pygame.draw.rect(screen,(10,10,10),( marginx-ux(10), marginy-uy(10), (total*slot)+ux(20), uy(110) ) )
|
||||
pygame.draw.rect(screen,(0,255,0), ( marginx, marginy, track.pos*slot, uy(90)) )
|
||||
|
||||
# wait until zip mount + overlayfs is complete
|
||||
while not track.ready:
|
||||
pg_bar(track.pos)
|
||||
compose()
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
# fill it up in case it was cached and instant download
|
||||
pg_bar(track.len)
|
||||
compose()
|
||||
|
||||
|
||||
# preloader will change dir and prepend it to sys.path
|
||||
platform.run_main(PyConfig, loaderhome= appdir / "assets", loadermain=None)
|
||||
|
||||
|
||||
# wait preloading complete
|
||||
# that includes images and wasm compilation of bundled modules
|
||||
while embed.counter()<0:
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
main = appdir / "assets" / "main.py"
|
||||
|
||||
# start async top level machinery and add a console.
|
||||
await TopLevel_async_handler.start_toplevel(platform.shell, console=window.python.config.debug)
|
||||
|
||||
# now that apk is mounted we have access to font cache
|
||||
# but we need to fill __file__ that is not yet set
|
||||
__import__(__name__).__file__ = str(main)
|
||||
|
||||
|
||||
# now make a prompt
|
||||
fnt = pygame.sysfont.SysFont("freesans", uy(80) )
|
||||
|
||||
def ui_callback(pkg, error=None):
|
||||
nonlocal fnt
|
||||
if error:
|
||||
prompt = fnt.render(f"{error}", True, "black")
|
||||
else:
|
||||
prompt = fnt.render(f"Setting [{pkg}] up", True, "black")
|
||||
pg_bar(track.len)
|
||||
screen.blit(prompt, ( marginx+ ux(80), marginy - uy(10) ) )
|
||||
compose()
|
||||
|
||||
# test/wait if user media interaction required
|
||||
if not platform.window.MM.UME:
|
||||
|
||||
# now make a prompt
|
||||
fnt = pygame.sysfont.SysFont("freesans", uy(80) )
|
||||
prompt = fnt.render("Ready to start !", True, "blue")
|
||||
pg_bar(track.len)
|
||||
screen.blit(prompt, ( marginx+ ux(80), marginy - uy(10) ) )
|
||||
compose()
|
||||
print("""
|
||||
* Waiting for media user engagement : please click/touch page *
|
||||
""")
|
||||
while not platform.window.MM.UME:
|
||||
await asyncio.sleep(.1)
|
||||
|
||||
# cleanup
|
||||
screen.fill( (0,0,0,0) )
|
||||
pygame.display.flip()
|
||||
|
||||
await shell.runpy(main, callback=ui_callback)
|
||||
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
asyncio.run( custom_site() )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# BEGIN BLOCK
|
||||
#
|
||||
# now this is the html part you can (and should) customize
|
||||
# It is not mandatory : pygame-script when it reads the first line (also called
|
||||
# shebang ) of above code create absolute minimal widget set
|
||||
# required for running with default rules
|
||||
#
|
||||
# do not alter that comment block it is separating python code from html code
|
||||
# =============================================================================
|
||||
# --></script><head><!--
|
||||
//=============================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
{%- if cookiecutter.comment != "" -%}
|
||||
{{cookiecutter.comment}}
|
||||
{% endif %}
|
||||
|
||||
--><script type="application/javascript">
|
||||
// END BLOCK
|
||||
|
||||
|
||||
|
||||
// this dict is available under PyConfig.config from __main__
|
||||
|
||||
config = {
|
||||
xtermjs : "{{cookiecutter.xtermjs}}" ,
|
||||
_sdl2 : "canvas",
|
||||
user_canvas : 0,
|
||||
user_canvas_managed : 0,
|
||||
ume_block : {{cookiecutter.ume_block}},
|
||||
can_close : {{cookiecutter.can_close}},
|
||||
archive : "{{cookiecutter.archive}}",
|
||||
gui_debug : 3,
|
||||
cdn : "{{cookiecutter.cdn}}",
|
||||
autorun : {{cookiecutter.autorun}},
|
||||
PYBUILD : "{{cookiecutter.PYBUILD}}"
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<title>{{cookiecutter.title}}</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="viewport" content="height=device-height, initial-scale=1.0">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
|
||||
<link rel="prefetch" href="{{cookiecutter.cdn}}pythonrc.py">
|
||||
<link rel="prefetch" href="{{cookiecutter.cdn}}vt/xterm.js">
|
||||
<link rel="prefetch" href="{{cookiecutter.cdn}}vt/xterm-addon-image.js">
|
||||
<link rel="prefetch" href="{{cookiecutter.cdn}}vt/xterm-addon-image.js">
|
||||
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png" sizes="16x16">
|
||||
|
||||
<style>
|
||||
#status {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin-top: 20px;
|
||||
margin-left: 30px;
|
||||
font-weight: bold;
|
||||
color: rgb(120, 120, 120);
|
||||
}
|
||||
|
||||
#progress {
|
||||
height: 20px;
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
div.emscripten { text-align: center; }
|
||||
div.emscripten_border { border: 1px solid black; }
|
||||
div.thick_border { border: 4px solid black; }
|
||||
|
||||
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
|
||||
/* average size of droid screen 470dp x 320dp */
|
||||
canvas.emscripten {
|
||||
border: 0px none;
|
||||
background-color: transparent;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 5;
|
||||
|
||||
padding: 0;
|
||||
margin: 0 auto;
|
||||
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: arial;
|
||||
margin: 0;
|
||||
padding: none;
|
||||
background-color:powderblue;
|
||||
}
|
||||
|
||||
.topright{
|
||||
position:absolute;
|
||||
top:0px;
|
||||
right:0px;
|
||||
}
|
||||
|
||||
.bottomright {
|
||||
position:absolute;
|
||||
top: 40%;
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.trinfo{
|
||||
position:relative;
|
||||
right:0px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.framed{
|
||||
position:relative;
|
||||
top:150px;
|
||||
right:10px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="{{cookiecutter.cdn}}/browserfs.min.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="transfer" align=center>
|
||||
<!-- <div class="spinner" id='spinner'></div> -->
|
||||
<div class="emscripten" id="status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="progress"></progress>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<canvas class="emscripten" id="canvas"
|
||||
width="1px"
|
||||
height="1px"
|
||||
oncontextmenu="event.preventDefault()" tabindex=1>
|
||||
</canvas>
|
||||
|
||||
<div id=html></div>
|
||||
|
||||
<div id=crt class=bottomright >
|
||||
|
||||
<div id="system" hidden>
|
||||
<div class="button-container">
|
||||
<button id="aiostop" disabled>AIO ⏏︎</button>
|
||||
<button id="aiopaused_true" disabled>AIO ■</button>
|
||||
<button id="aiopaused_false" disabled>AIO ▶</button>
|
||||
<button id="pygame_mixer_music_pause" disabled>Music ■</button>
|
||||
</div>
|
||||
|
||||
<div class="button-container">
|
||||
<div id=load_min>min</div>
|
||||
<div id=load_avg>avg</div>
|
||||
<div id=load_max>max</div>
|
||||
<button id="load_rst" disabled>RESET</button>
|
||||
</div>
|
||||
|
||||
<div id="level">(battery level unknown)</div>
|
||||
<div id="stateBattery">(charging state unknown)</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id=box class="emscripten_border" hidden=true>
|
||||
|
||||
<div id="info" class="trinfo"></div>
|
||||
|
||||
<iframe id="iframe" class="framed" name="iframe"
|
||||
width="470px" height="90%"
|
||||
allowtransparency="true"
|
||||
style="z-index: 10;"
|
||||
style="background: #FFFFFF;"
|
||||
frameborder="1"
|
||||
allowfullscreen="true"
|
||||
webkitallowfullscreen="true"
|
||||
msallowfullscreen="true"
|
||||
mozallowfullscreen="true"
|
||||
sandbox="allow-same-origin allow-top-navigation allow-scripts allow-pointer-lock"
|
||||
allow="autoplay; fullscreen *; geolocation; microphone; camera; midi; monetization; xr-spatial-tracking; gamepad; gyroscope; accelerometer; xr; cross-origin-isolated"
|
||||
src="{{cookiecutter.cdn}}empty.html"
|
||||
scrolling="yes">
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="dlg" hidden>
|
||||
<input type="file" id="dlg_multifile" multiple accept="image/*">
|
||||
<label for="dlg_multifile">Select files</label>
|
||||
</div>
|
||||
|
||||
<div id="pyconsole">
|
||||
<div id="terminal" tabIndex=1 align="left"></div>
|
||||
</div>
|
||||
|
||||
<script type="application/javascript">
|
||||
|
||||
async function custom_onload(debug_hidden) {
|
||||
// this is called before anything python is loaded
|
||||
// make your js customization here
|
||||
console.log(__FILE__, "custom_onload")
|
||||
|
||||
pyconsole.hidden = debug_hidden
|
||||
system.hidden = debug_hidden
|
||||
transfer.hidden = debug_hidden
|
||||
info.hidden = debug_hidden
|
||||
box.hidden = debug_hidden
|
||||
|
||||
}
|
||||
|
||||
function custom_prerun(){
|
||||
// no python main and no (MEMFS + VFS) yet.
|
||||
console.log(__FILE__, "custom_prerun")
|
||||
|
||||
}
|
||||
|
||||
function custom_postrun(){
|
||||
// python main and no VFS filesystem yet.
|
||||
console.log(__FILE__, "custom_postrun")
|
||||
|
||||
// prevent ff horizontal scroll
|
||||
window.addEventListener("keydown", function(e) {
|
||||
if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
|
||||
if (!python.config.debug)
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
function debug() {
|
||||
// allow to gain access to dev tools from js console
|
||||
// but only on desktop. difficult to reach when in iframe
|
||||
python.config.debug = true
|
||||
custom_onload(false)
|
||||
Module.PyRun_SimpleString("shell.uptime()")
|
||||
window_resize()
|
||||
}
|
||||
|
||||
function info_inline(data){
|
||||
document.getElementById("info").innerHTML = data
|
||||
}
|
||||
|
||||
function info_online(url) {
|
||||
// display info about current APK
|
||||
fetch( url /*, options */)
|
||||
.then((response) => response.text())
|
||||
.then((html) => {
|
||||
info_inline(html);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(error);
|
||||
});
|
||||
}
|
||||
|
||||
function frame_online(url) {
|
||||
window.frames["iframe"].location = url;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Reference in new issue
Block a user