heuer / segno

Python QR Code and Micro QR Code encoder
https://pypi.org/project/segno/
BSD 3-Clause "New" or "Revised" License
599 stars 52 forks source link

Can't observe support for mixed modes #76

Open ervinoro opened 4 years ago

ervinoro commented 4 years ago

According to the feature comparison table, segno is supposed to support mixing modes, and documentation further specifies that qr.mode is supposed to return None if mixed modes are used. However, I am unable to find any documented API for manually specifying the segmentation, and I can not observe any automatic segmentation either.

>>> qr = segno.make('THE SQUARE ROOT OF 2 IS 1.41421356237309504880168872420969807856967187537694807317667973799')
>>> qr.mode
'alphanumeric'
>>> qr.designator
'4-L'

Optimal solution would be version 3, with two segments: alphanumeric and numeric.

heuer commented 4 years ago

Thanks for bringing up this issue. Segno supports multiple modes but does optimize the input yet.

>>> qr = segno.make(['THE SQUARE ROOT OF 2 IS 1', '.', '41421356237309504880168872420969807856967187537694807317667973799'])
>>> qr.mode
>>> qr.designator
'3-L'

Result:

three-segments

>>> qr = segno.make(['THE SQUARE ROOT OF 2 IS 1.', '41421356237309504880168872420969807856967187537694807317667973799'])
>>> qr.mode
>>> qr.designator
'3-L'

Result: two-segments

I agree that Segno should recognize the modes and divide the content accordingly, see also #25.

ervinoro commented 4 years ago

Ah, thanks, that is fair enough. In that case I would redirect this issue to be against incomplete documentation. It would be helpful if it would be mentioned there that manual segmentation is supported by passing an iterable as content, in addition to the listed str, int and bytes.

https://segno.readthedocs.io/en/stable/api.html#segno.make.params.content

neycyanshi commented 3 years ago

@heuer , currently users can not pass mode in str type for different segments. For example, this is invalid input

>>> qr=segno.make([('abcabcabc', 'byte'), ('123123123', 'numeric')])

I have to write

>>> qr=segno.make([('abcabcabc', 4), ('123123123', 1)])
heuer commented 3 years ago

@neycyanshi, sorry for the late response. You're right. The idea was that the user provides an iterable of chunks and Segno detects the "type" of the chunk automatically. I am not happy with the current solution, though. IMO it would be much better if the user provides the content "as it is" and Segno divides the content into optimal chunks, see #25

neycyanshi commented 3 years ago

Yes, it is better to optimize chunks. Are you working on it? I'd like to help if you are busy now.