From 2ff61f7b8d9bde594abbc98548addc8e6ca67fcc Mon Sep 17 00:00:00 2001 From: NaitLee Date: Sat, 10 Feb 2024 22:41:17 +0800 Subject: [PATCH] scripts for seting up an environment; add MX10 --- .gitignore | 4 ++++ README.md | 42 +++++++++++++++++++++++++++++++----------- install.bat | 16 ++++++++++++++++ install.sh | 15 +++++++++++++++ printer.py | 41 +++++++++++++++++++++-------------------- printer_lib/models.py | 7 ++++--- requirements.txt | 1 + 7 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 install.bat create mode 100755 install.sh create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 8449bd1..61f9459 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 547cfba..0acc9b9 100644 --- a/README.md +++ b/README.md @@ -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! +***Didn’t find your feature? Or can’t 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 + + + 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, it’s 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
Further steps -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 there’s 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. diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..7b9925b --- /dev/null +++ b/install.bat @@ -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% diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3bda045 --- /dev/null +++ b/install.sh @@ -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 - <