class TodoListWidget(VBox): def __init__(self): super().__init__() self.entry = HBox() self.input = Input() self.entry.children = [self.input] self.todolist = VBox() self.clear_button = Button("Clear Completed") self.children = [self.entry, self.todolist, self.clear_button] # This form of attaching an event handler is for "secondary" # hanlers. Primary handlers are attached with @event_handler, # which are for events of its own widget. The primary handler # calls the secondary handlers. This is a secondary handler # beause it is an event of self.input, not self. self.input.register('change', self.on_add_todo) self.clear_button.register('click', self.on_clear_completed) def on_add_todo(self, source, message): new_todo = TodoWidget(self.input.value) self.todolist.children.append(new_todo) print(f"Added {repr(new_todo)}") def on_clear_completed(self, source, message): print(f'{self.__class__.__name__}.on_clear_completed({repr(source)}') for todo in self.todolist.children: if todo.completed: self.todolist.children.remove(todo)
def __init__(self, connection): super().__init__(connection) self.btn_go2b = Button(label='Go to B') self.btn = Button() self.input = Input(value='The value') self.redir = Redirect() self.children = [self.btn_go2b, self.btn, self.input, self.redir] self.btn.register('click', self.on_button_click) self.btn_go2b.register("click", self.on_go2b)
def __init__(self): super().__init__() self.entry = HBox() self.input = Input() self.entry.children = [self.input] self.todolist = VBox() self.clear_button = Button("Clear Completed") self.children = [self.entry, self.todolist, self.clear_button] # This form of attaching an event handler is for "secondary" # hanlers. Primary handlers are attached with @event_handler, # which are for events of its own widget. The primary handler # calls the secondary handlers. This is a secondary handler # beause it is an event of self.input, not self. self.input.register('change', self.on_add_todo) self.clear_button.register('click', self.on_clear_completed)
def __init__(self, connection): super().__init__(connection) self.button = Button() self.inbox = Input() self.box1 = HBox() self.box1.children = [self.button, self.inbox] self.children = [self.box1] self.button.register('click', self.on_button_click)
def __init__(self, connection): super().__init__(connection) # Nothing is sent to the browser during the construction. # However, as soon as we start adding children, messages # announcing the children are being queued for delivery. # Only when this widget is ready on the browser side, # these messages will be sent. # Note: This "serial" delivery is slow and probably # unnecessary. self.children = [Button(), Input(value='The value')] self.children[0].register('click', self.on_button_click)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.input = Input() self.add = Button('Add') self.taskentry = HBox() self.taskentry.children = [self.input, self.add] self.tasksarea = VBox() self.delete = Button('Delete') self.children = [self.taskentry, self.tasksarea, self.delete]
def __init__(self, connection): # Widget.__init__: A lot of stuff. # MainApp.__init__: self.connection = connection super().__init__(connection) # #### Authentication Verification ##### sid = connection.get_cookie('sessionid') session = connection.application.get_session(sid) print(f'[{__class__.__name__}] Session: {session}') if not session.authenticated: self.children = [Label('Not authorized')] # Will never happen connection.close() return # ### Done with authentication verification #### self.button = Button() self.inbox = Input() self.box1 = HBox() self.box1.children = [ self.button, self.inbox ] self.logoutbtn = Button('Log out') self.box2 = VBox() self.box2.children = [ Label("This the main app. You have been successfully authenticated."), self.box1, self.logoutbtn ] self.redir = Redirect() self.children = [self.box2, self.redir] self.button.register('click', self.on_button_click) self.logoutbtn.register('click', self.on_logout)
def __init__(self, connection): super().__init__(connection) self.label = Label('Password') self.pwinput = Input() self.btn = Button('Login') # TODO: If not a child, should raise error when calling redirect(). self.redir = Redirect() self.status = Label('Please enter your password.') lg = HBox() lg.children = [ self.label, self.pwinput, self.btn, self.redir ] vb = VBox() vb.children = [ lg, self.status ] self.children = [ vb ] self.btn.register("click", self.on_click) # ---- Authentication Verification ---- # If authenticated, redirect immediately to the # main (restricted app). sid = connection.get_cookie('sessionid') session = connection.application.get_session(sid) print(f'[{__class__.__name__}] Session: {session}') if session.authenticated: self.redir.redirect('/b')