scripts for seting up an environment; add MX10

This commit is contained in:
NaitLee 2024-02-10 22:41:17 +08:00
parent a7dee14c96
commit 2ff61f7b8d
7 changed files with 92 additions and 34 deletions

4
.gitignore vendored
View File

@ -1,6 +1,10 @@
# python stuffs
__pycache__
venv
.venv
wvenv
_install.bat
server.bat
dist
# Compatibility version of script, for old-old webView,
# generated by typescript tsc

View File

@ -8,7 +8,7 @@ English | [Deutsch](./readme.i18n/README.de-DE.md) | [中文(简体字)](./r
## Models
Known to support: `GB01, GB02, GB03, GT01, YT01, MX05, MX06, MX08`
Known to support: `GB01, GB02, GB03, GT01, YT01, MX05, MX06, MX08, MX10`
You can test other models with the Web UI, in `Settings -> Test Unknown Device`
It may work!
@ -51,6 +51,8 @@ It may work!
- and Fun!
- Do whatever you like!
***Didnt find your feature? Or cant set it up? Try the simple Web-app, [kitty-printer](https://print.unseen-site.fun/).***
## Get Started
### Android
@ -60,23 +62,36 @@ Get the newest apk release and install, then well done!
It may ask for background location permission, you can deny it safely.
(Foreground) Location permission is required for scanning Bluetooth devices in newer Android system.
Recommend to set scan time to 1 second.
It is recommended to set scan time to 1 second.
The 3rd-party F-Droid repository [IzzyOnDroid](https://android.izzysoft.de/repo) is known to include Cat-Printer.
### Windows
Get the newest release archive with “windows” in the file name,
extract to somewhere and run `start.bat`
1. Download [source code](https://github.com/NaitLee/Cat-Printer/archive/refs/heads/main.zip) of this repository and install newest version of [Python](https://www.python.org/).
2. Extract the source code archive, run `install.bat`, wait for it to complete
3. After that, you will get `server.bat` for opening the Web interface. Run it and enjoy
<!-- Build system broken -->
<!-- Get the newest release archive with “windows” in the file name,
extract to somewhere and run `start.bat` -->
Windows typically needs longer scan time. Defaults to 4 seconds, try to find your case.
For those who know Python development — see `requirements.txt` to find your way, its very simple.
### GNU/Linux
You can get the “pure” release, extract it, fire up a terminal and run:
```bash
python3 server.py
Get source code and run `./install.sh` to set the environment up.
After that, you can always use Cat-Printer inside the given virtual environment:
```
(venv) $ python3 server.py
```
It is recommended to set the scan time to 2 seconds.
On Arch Linux based distros you may install `bluez` first, as it may not be installed by default
```bash
sudo pacman -S bluez bluez-utils
@ -85,7 +100,11 @@ sudo pacman -S bluez bluez-utils
<details>
<summary>Further steps</summary>
You may want to use the command line interface for hackiness...
You may want to use the command line interface for hackiness:
```
$ python printer.py --help
```
You may or may not need to install ImageMagick and Ghostscript, depending on your distro.
@ -112,7 +131,7 @@ then install `pyobjc` and `bleak` via `pip` in terminal:
pip3 install pyobjc bleak
```
After that, fetch & use a “bare” release:
After that, get the source code and run:
```bash
python3 server.py
```
@ -133,9 +152,10 @@ Please use Issue or Discussion if theres something in your mind!
Of course Pull Requests are welcome if you can handle them!
## License
## Licensefdroidhowtomarkets
Copyright © 2021-2023 NaitLee Soft. Some rights reserved.
Copyright © 2021-2024 NaitLee Soft. Some rights reserved.
```
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

16
install.bat Normal file
View File

@ -0,0 +1,16 @@
@echo off
set venv_path=wvenv
set inst_next=_install.bat
set server_bat=server.bat
if not exist %venv_path% (set venv_init=1)
if defined venv_init (python -m venv %venv_path%)
type .\wvenv\Scripts\activate.bat > %inst_next%
if defined venv_init (echo pip install -r requirements.txt >> %inst_next%)
set venv_init=
echo echo Testing environment >> %inst_next%
python -c "print('python -c \x22with open(1, \x27wb\x27) as f: f.write(b\x27P4\\n384 0\\n\x27)\x22 | python printer.py -f MX06 -')" >> %inst_next%
type .\wvenv\Scripts\activate.bat > %server_bat%
echo python server.py >> %server_bat%
echo Run server.bat to start Cat-Printer
:: cmd bails out just after activation in batch
%inst_next%

15
install.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
venv_path=".venv"
if [ -d $venv_path ]; then
venv_init=false
else
venv_init=true
fi
$venv_init && python3 -m venv $venv_path
source $venv_path/bin/activate
$venv_init && pip3 install -r requirements.txt
echo "Testing environment"
python3 printer.py -f MX06 - <<EOF
P4
384 0
EOF

View File

@ -751,26 +751,27 @@ def _main():
global Printer
Printer = printer
return
if len(devices) == 0:
error(i18n('no-available-devices-found'), exception=PrinterError)
if len(devices) == 1 or getattr(args, '0th'):
info(i18n('connecting'))
printer.connect(devices[0].name, devices[0].address)
else:
info(i18n('there-are-multiple-devices-'))
for i in range(len(devices)):
d = devices[i]
n = str(d.name) + "-" + d.address[3:5] + d.address[0:2]
info('%4i\t%s' % (i, n))
choice = 0
try:
choice = int(input(i18n('choose-which-one-0-', choice)))
except KeyboardInterrupt:
raise
except:
pass
info(i18n('connecting'))
printer.connect(devices[choice].name, devices[choice].address)
if not args.fake:
if len(devices) == 0:
error(i18n('no-available-devices-found'), exception=PrinterError)
if len(devices) == 1 or getattr(args, '0th'):
info(i18n('connecting'))
printer.connect(devices[0].name, devices[0].address)
else:
info(i18n('there-are-multiple-devices-'))
for i in range(len(devices)):
d = devices[i]
n = str(d.name) + "-" + d.address[3:5] + d.address[0:2]
info('%4i\t%s' % (i, n))
choice = 0
try:
choice = int(input(i18n('choose-which-one-0-', choice)))
except KeyboardInterrupt:
raise
except:
pass
info(i18n('connecting'))
printer.connect(devices[choice].name, devices[choice].address)
# Prepare image / text
if args.text:

View File

@ -19,13 +19,14 @@ class Model():
Models = {}
# all known supported models
for name in '_ZZ00 GB01 GB02 GB03 GT01 MX05 MX06 MX08 MX09 YT01'.split(' '):
for name in '_ZZ00 GB01 GB02 GB03 GT01 MX05 MX06 MX08 MX09 MX10 YT01'.split(' '):
Models[name] = Model()
# that can receive compressed data
for name in 'GB03'.split(' '):
Models[name].is_new_kind = True
# that have problem giving feed command
for name in 'MX05 MX06 MX08 MX09'.split(' '):
# feed message isn't handled corrently in the codebase, and these models have problems with it
# TODO fix that piece of code
for name in 'MX05 MX06 MX08 MX09 MX10'.split(' '):
Models[name].problem_feeding = True

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
bleak