Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
super(ContactView, self).__init__(screen,
screen.height * 2 // 3,
screen.width * 2 // 3,
hover_focus=True,
can_scroll=False,
title="Contact Details",
reduce_cpu=True)
# Save off the model that accesses the contacts database.
self._model = model
# Create the form for displaying the list of contacts.
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
layout.add_widget(Text("Name:", "name"))
layout.add_widget(Text("Address:", "address"))
layout.add_widget(Text("Phone number:", "phone"))
layout.add_widget(Text("Email address:", "email"))
layout.add_widget(TextBox(
Widget.FILL_FRAME, "Notes:", "notes", as_string=True, line_wrap=True))
layout2 = Layout([1, 1, 1, 1])
self.add_layout(layout2)
layout2.add_widget(Button("OK", self._ok), 0)
layout2.add_widget(Button("Cancel", self._cancel), 3)
self.fix()
on_select=self._on_select)
self._edit_button = Button("Edit", self._edit)
self._delete_button = Button("Delete", self._delete)
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
layout.add_widget(self._list_view)
layout.add_widget(Divider(line_char="#"))
layout2 = Layout([1, 1, 1, 1])
self.add_layout(layout2)
layout2.add_widget(Button("Add", self._add), 0)
layout2.add_widget(self._edit_button, 1)
layout2.add_widget(self._delete_button, 2)
layout2.add_widget(Button("Quit", self._quit), 3)
layout3 = Layout([100])
self.add_layout(layout3)
self._info_text = Text(label="Selected:", name="selected")
self._info_text.disabled = True
layout3.add_widget(self._info_text)
self.fix()
self._on_pick()
label="My First Box:",
name="TA",
on_change=self._on_change), 1)
self.layout.add_widget(
Text(label="Alpha:",
name="TB",
on_change=self._on_change,
validator="^[a-zA-Z]*$"), 1)
self.layout.add_widget(
Text(label="Number:",
name="TC",
on_change=self._on_change,
validator="^[0-9]*$",
), 1)
self.layout.add_widget(
Text(label="Email:",
name="TD",
on_change=self._on_change,
validator=self._check_email), 1)
self.layout.add_widget(Divider(height=2), 1)
self.layout.add_widget(Label("Group 2:"), 1)
self.layout.add_widget(RadioButtons([("Option 1", 1),
("Option 2", 2),
("Option 3", 3)],
label="A Longer Selection:",
name="Things",
on_change=self._on_change), 1)
self.layout.add_widget(CheckBox("Field 1",
label="A very silly long name for fields:",
name="CA",
on_change=self._on_change), 1)
self.layout.add_widget(
def test_max_len(self):
"""
Check that the max_length setting works as expected.
"""
# Now set up the Frame ready for testing
screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
scene = Scene([], duration=-1)
canvas = Canvas(screen, 10, 40, 0, 0)
form = Frame(canvas, canvas.height, canvas.width)
layout = Layout([100])
form.add_layout(layout)
# Simple form with a limited length Text field.
text = Text(label="Text", name="max_len_text", max_length=4)
layout.add_widget(text)
form.fix()
form.register_scene(scene)
scene.add_effect(form)
scene.reset()
# Check it stops accepting text after hitting limit.
self.process_keys(form, "123456")
form.save()
self.assertEqual(form.data["max_len_text"], "1234")
def test_password(self):
"""
Check that we can do password input on Text widgets.
"""
# Create a dummy screen.
screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
scene = MagicMock(spec=Scene)
canvas = Canvas(screen, 2, 40, 0, 0)
# Create the form we want to test.
form = Frame(canvas, canvas.height, canvas.width, has_border=False)
layout = Layout([100], fill_frame=True)
form.add_layout(layout)
text = Text("Password", hide_char="*")
layout.add_widget(text)
form.fix()
form.register_scene(scene)
form.reset()
# Check that input still saves off values as expected
self.process_keys(form, ["1234"])
form.save()
self.assertEqual(text.value, "1234")
# Check that it is drawn with the obscuring character, though.
form.update(0)
self.assert_canvas_equals(
canvas,
"Password **** \n" +
" \n")
def __init__(self, screen, interface):
super(SendBox, self).__init__(screen, 21, 59, interface, tx_func=self._ok, cancel_func=self._cancel, name="sendbox", title="Send Crypto")
layout = Layout([100])#, fill_frame=True)
self.prepend_layout(layout)
layout.add_widget(Text("To Address:", "address"))
layout.add_widget(Divider(draw_line=False))
self.everything_checkbox = CheckBox("Send Everything", on_change=self.checkbox_change)
self.amount_text = Text(" Amount:", "amount", on_change=self.amount_change)
layout.add_widget(self.amount_text)
layout.add_widget(self.everything_checkbox)
layout.add_widget(Divider(draw_line=False))
balances = [{'name':'ETH', 'balance': interface.node.eth_balance}]
balances += [x for x in interface.node.erc20_balances if x['balance'] > 0]
currency_options = [(x['name'], x) for x in balances]
logging.info(currency_options)
logging.info(currency_options)
self.set_theme('shadowlands')
self._interface = interface
self._screen = screen
self._gas_price_wei = None
self._tx_func = tx_func
# subclass sets this to Decimal(something)
self.estimated_gas = None
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
self.nonce_text = Text(" Nonce:", "nonce", default_value=str(self._interface.node.next_nonce()))
layout.add_widget(self.nonce_text)
layout.add_widget(Divider(draw_line=False))
layout.add_widget(GasPricePicker(on_change=self._on_option_change, interface=interface))
custgas = Text(" CustGas:", "custgas", on_change=self._on_text_change)
custgas._is_disabled = True
layout.add_widget(Divider(draw_line=False))
layout.add_widget(custgas)
layout.add_widget(Divider(draw_line=False))
layout.add_widget(Label("", name='gas_est_label'))
layout.add_widget(Divider(draw_line=False))
layout2 = Layout([1, 1, 1, 1])
self.add_layout(layout2)
layout2.add_widget(Button("Sign Tx", self.validate), 0)
layout2.add_widget(Button("Cancel", cancel_func), 3)
self._on_option_change()
def __init__(self, screen, longitude, latitude, on_ok):
super(EnterLocation, self).__init__(
screen, 7, 40, data={"long": str(longitude), "lat": str(latitude)}, name="loc",
title="Enter New Location", is_modal=True)
self._on_ok = on_ok
layout = Layout([1, 18, 1])
self.add_layout(layout)
layout.add_widget(Divider(draw_line=False), 1)
layout.add_widget(Text(label="Longitude:", name="long", validator=r"^[-]?\d+?\.\d+?$"), 1)
layout.add_widget(Text(label="Latitude:", name="lat", validator=r"^[-]?\d+?\.\d+?$"), 1)
layout.add_widget(Divider(draw_line=False), 1)
layout2 = Layout([1, 1, 1])
self.add_layout(layout2)
layout2.add_widget(Button("OK", self._ok), 1)
layout2.add_widget(Button("Cancel", self._cancel), 2)
self.fix()
raise InvalidOperation
if self.radiobutton_value() == 'sell':
if amt > self.exchange.eth_reserve:
raise InvalidOperation
self._value = "{:f}".format(self.exchange.sell_token_calc_token_input(amt)['value'])[:19]
elif self.radiobutton_value() == 'buy':
token_amt = self.exchange.buy_token_calc_token_output(amt)['value']
self._value = "{:f}".format(token_amt)[:19]
except InvalidOperation:
self._value=""
self.eth_value_dirty_flag = False
super(TokenValueText, self).update(frame_no)
class EthValueText(Text):
def __init__(self, radiobutton, exchange, **kwargs):
self.token_value_dirty_flag = False
self.radiobutton_value = radiobutton
self.token_amount = None
self.exchange = exchange
super(EthValueText, self).__init__(**kwargs)
def set_token_field(self, textfield):
self.token_amount = textfield
def update(self, frame_no):
if self.token_value_dirty_flag:
try:
amt = Decimal(self.token_amount._value)
if amt < 0:
raise InvalidOperation
def _init_gui( self ):
# TODO: Look into setting up a custom palette
# self.set_theme( "default" )
self.set_theme( "bright" )
self.layout = Layout( [ 1, 1, 1 ] )
self.add_layout(self.layout)
label = Label( "Character Profile:" )
self.layout.add_widget( label, 1 )
char_name = Text(
label = "NAME:",
name = "name",
on_change = self._on_change,
validator = "^[a-zA-Z]*$" )
self.layout.add_widget( char_name, 1 )
char_age = Text(
label = "AGE:",
name = "age",
on_change =self._on_change,
validator = "^[0-9]*$" )
self.layout.add_widget( char_age, 1 )
# self.layout.add_widget( Divider( height = 2 ), 1 )
# self.layout.add_widget(Label("Group 2:"), 1)
char_gender = RadioButtons( [ ( "MALE", 1 ), ( "FEMALE", 2 ) ],