openwebrx/owrx/form/input/receiverid.py

34 lines
1.1 KiB
Python
Raw Permalink Normal View History

from owrx.form.input import TextAreaInput
2021-04-29 15:17:21 +02:00
from owrx.form.input.converter import Converter
2021-02-08 20:30:12 +01:00
class ReceiverKeysConverter(Converter):
def convert_to_form(self, value):
2021-02-18 15:27:05 +01:00
return "" if value is None else "\n".join(value)
2021-02-08 20:30:12 +01:00
def convert_from_form(self, value):
# \r\n or \n? this should work with both.
stripped = [v.strip("\r ") for v in value.split("\n")]
# omit empty lines
return [v for v in stripped if v]
class ReceiverKeysInput(TextAreaInput):
def __init__(self, id, label):
super().__init__(
id,
label,
infotext="Put the keys you receive on listing sites (e.g. "
+ '<a href="https://www.receiverbook.de" target="_blank">Receiverbook</a>) here, one per line',
)
def input_properties(self, value, errors):
props = super().input_properties(value, errors)
# disable word wrap on the textarea.
# why? keys are longer than the input, and word wrap makes the "one per line" instruction confusing.
props["wrap"] = "off"
return props
def defaultConverter(self):
return ReceiverKeysConverter()