-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from nicegui import ui | ||
|
||
from P001.p001 import solution | ||
|
||
class Options: | ||
def __init__(self): | ||
self.visible = False | ||
self.first = True | ||
|
||
options = Options() | ||
|
||
def show_ui(visible): | ||
options.visible = visible | ||
if options.first: | ||
options.first = False | ||
root = create_ui() | ||
|
||
def create_ui(): | ||
with ui.column().bind_visibility_from(options, 'visible') as root: | ||
numberInput = ui.input('Number') | ||
ui.button('Check Number', on_click=lambda: check_number()) | ||
output = ui.label() | ||
|
||
def check_number(): | ||
number = int(numberInput.value) | ||
result = solution(number) | ||
output.text = result | ||
|
||
return root | ||
|
||
if __name__ in {"__main__", "__mp_main__"}: | ||
show_ui(True) | ||
ui.run() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from nicegui import ui | ||
from P001.p001 import * | ||
from P002.p002 import add, divide, multiply, subtract | ||
|
||
class Options: | ||
def __init__(self): | ||
self.visible = False | ||
self.first = True | ||
|
||
options = Options() | ||
|
||
def show_ui(visible): | ||
options.visible = visible | ||
if options.first: | ||
options.first = False | ||
create_ui() | ||
|
||
def create_ui(): | ||
with ui.column().bind_visibility_from(options, 'visible') as root: | ||
numberInput1 = ui.input('Number 1') | ||
numberInput2 = ui.input('Number 2') | ||
with ui.row(): | ||
ui.button('+', on_click=lambda e: calculate(e)) | ||
ui.button('-', on_click=lambda e: calculate(e)) | ||
ui.button('/', on_click=lambda e: calculate(e)) | ||
ui.button('*', on_click=lambda e: calculate(e)) | ||
output = ui.label() | ||
|
||
def calculate(e): | ||
operation = e.sender.text | ||
number1 = int(numberInput1.value) | ||
number2 = int(numberInput2.value) | ||
|
||
if operation == '+': | ||
result = add(number1, number2) | ||
elif operation == '-': | ||
result = subtract(number1, number2) | ||
elif operation == '/': | ||
result = divide(number1, number2) | ||
elif operation == '*': | ||
result = multiply(number1, number2) | ||
|
||
output.text = result | ||
|
||
if __name__ in {"__main__", "__mp_main__"}: | ||
show_ui(True) | ||
ui.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from nicegui import ui | ||
from P001 import p001_ui | ||
from P002 import p002_ui | ||
|
||
class Problem: | ||
def __init__(self): | ||
self.number = 1 | ||
|
||
def gen_dict(a, b): | ||
return dict(map(lambda x: (x, str(x)),range(a, b + 1))) | ||
|
||
def show_problem(problem_number): | ||
problem.visible = problem_number > 0 | ||
|
||
p001_ui.show_ui(problem_number == 1) | ||
p002_ui.show_ui(problem_number == 2) | ||
|
||
|
||
problem = Problem() | ||
|
||
with ui.row(): | ||
with ui.column(): | ||
ui.label('Select a problem:') | ||
problems = gen_dict(1, 50) | ||
ui.select(problems, on_change=lambda e: show_problem(e.value)).bind_value(problem, 'number') | ||
ui.separator() | ||
|
||
|
||
ui.run() |