Skip to content

Commit

Permalink
Merge pull request #25 from Isvvc/multi-qr
Browse files Browse the repository at this point in the history
Multi-QR
  • Loading branch information
skjiisa authored Aug 22, 2021
2 parents e935d90 + 348b1a4 commit 5148c2a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
40 changes: 29 additions & 11 deletions Armor Export/Armor_Export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import json
import os
import math
from PIL import Image, ImageTk
from io import BytesIO
# Must be the MyQR fork at https://github.com/Isvvc/qrcode/
Expand Down Expand Up @@ -122,7 +123,9 @@ def make_images_window(current_images):
]

preview_col = [
[sg.Image(key='-PREVIEW-')]
[sg.Image(key='-PREVIEW-')],
[sg.Text('Mulitple QR codes generated', visible=False, key='-MULTIPLE_QR-')],
[sg.Button('Open QR codes folder', key='ArmorExportFolder')]
]

layout = [
Expand Down Expand Up @@ -159,8 +162,7 @@ def make_images_window(current_images):
[sg.Text('QR codes with backgrounds can be hard to scan. Test before publishing.')]
], visible=False, key='-WARNINGS-')],
[
sg.Button('Quit'),
sg.Button('Open Armor Export folder', key='ArmorExportFolder')
sg.Button('Quit')
]
]

Expand Down Expand Up @@ -234,14 +236,30 @@ def save_ingredients():
background_file = path
except: pass

myqr.run(ingredients_json, level='L', picture=background_file, colorized=True, save_name='qrcode.png', save_dir='Armor Export')

qr = Image.open('Armor Export\\qrcode.png')
img = image_preview(qr)
bio = BytesIO()
img.save(bio, format='PNG')
del img
window['-PREVIEW-'].update(data=bio.getvalue())
# Delete old QR codes
[os.remove('Armor Export\\' + file) for file in os.listdir('Armor Export') if re.search('qrcode[0-9]?.png', file)]

if len(ingredients_json) > 2953:
# Divide JSON into chunks of 2900 characters
numCodes = math.ceil(len(ingredients_json) / 2900)
sizeEach = len(ingredients_json) / numCodes

inputs = [f'{index}/{numCodes - 1}\n{ingredients_json[round(index * sizeEach):round((index + 1) * sizeEach)]}' for index in range(numCodes)]
print(inputs)
[myqr.run(input, level='L', picture=background_file, colorized=True, save_name=f'qrcode{index}.png', save_dir='Armor Export') for index, input in enumerate(inputs)]

window['-MULTIPLE_QR-'].update(visible=True)
else:
myqr.run(ingredients_json, level='L', picture=background_file, colorized=True, save_name='qrcode.png', save_dir='Armor Export')
window['-MULTIPLE_QR-'].update(visible=False)

# Show the QR code preview
qr = Image.open('Armor Export\\qrcode.png')
img = image_preview(qr)
bio = BytesIO()
img.save(bio, format='PNG')
del img
window['-PREVIEW-'].update(data=bio.getvalue())

if background_url:
# Delete the saved background image
Expand Down
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ It is still totally usable without it, though.
+ Calculated level based on type and rating
+ JSON that can be imported into Character Tracker
+ A QR code that can be scanned into Character Tracker if `myqr.exe` is present.
1. A GUI will launch for adding images and generating QR codes.
1. A GUI will launch for adding images and URL and for generating QR codes.
+ Manually add images with the **Image URL** text box
+ Enter a Nexusmods mod page in the **Nexusmods URL** text box to select images from the mod page to load.
+ Currently only the first 5 images will load.
+ Adult-only mod pages will not load as they require a user to be signed in, and this does not currently support signing in to an account.
+ The URL entered here along with the title in "Link Name" will be saved to both the mod and module.
+ When you have the images inputted that you'd like, click any of the **Save images to** buttons to save the images to the `Ingredients.json` file.
+ Check **Generate QR code** to generate a QR code that can be scanned into Character Tracker.
+ Note that this GUI is in early stages and can crash if text fields are left blank.
+ Generating QR codes with no images, however, should work just fine.

## Build

Expand All @@ -66,19 +64,16 @@ Copy the Python folder (will look something like `python-3.8.6.amd64`) to `Armor

To install dependencies, navigate to the xEdit directory in Command Prompt and run the following command:

"Armor Export\Python\python.exe" -m pip install -r requirements.txt
Python38\python.exe -m pip install -r requirements.txt

You should now be able to access the UI from the xEdit script or by running:

"Armor Export\Python\python.exe" "Armor Export\Armor_Export.py"
You should now be able to access the UI from the xEdit script or by running `run.bat`.

Note that you must run this from the xEdit directory, not the `Armor Export` directory, or the relative file paths will be wrong.

#### MyQR

[Isvvc/qrcode](https://github.com/Isvvc/qrcode/) is required to generate QR codes.
This is a slightly modified version of [sylnsfar/qrcode](https://github.com/sylnsfar/qrcode).
The changes I made were simply adding `"` to the supported characters list so it could encode JSON
and allowing it to read input from a file so long JSON could be passed in without having to try to pass it as an argument.

Unlike previous releases, there is no `exe` file to generate. The included `python.exe` is run directly.
The changes I made were
1. adding `"` and the line break character to the supported characters list so it could encode JSON and
1. allowing it to read input from a file so long JSON could be passed in without having to try to pass it as an argument.
2 changes: 2 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Armor Export\Python38\python.exe" "Armor Export\Armor_Export.py"
pause

0 comments on commit 5148c2a

Please sign in to comment.