A little reorganizing
This commit is contained in:
parent
a4208b0ad9
commit
59958c286f
1 changed files with 26 additions and 26 deletions
|
|
@ -46,12 +46,12 @@ calc_group.append(bg_sprite)
|
|||
font = bitmap_font.load_font("/fonts/Arial-12.bdf")
|
||||
buttons = []
|
||||
|
||||
# Some button placement functions
|
||||
# Some button functions
|
||||
def button_grid(row, col):
|
||||
return Coords(BUTTON_MARGIN * (row + 1) + BUTTON_WIDTH * row + 20,
|
||||
BUTTON_MARGIN * (col + 1) + BUTTON_HEIGHT * col + 40)
|
||||
|
||||
def make_button(row, col, label, width=1, color=WHITE, text_color=BLACK):
|
||||
def add_button(row, col, label, width=1, color=WHITE, text_color=BLACK):
|
||||
pos = button_grid(row, col)
|
||||
new_button = Button(x=pos.x, y=pos.y,
|
||||
width=BUTTON_WIDTH * width + BUTTON_MARGIN * (width - 1),
|
||||
|
|
@ -60,30 +60,6 @@ def make_button(row, col, label, width=1, color=WHITE, text_color=BLACK):
|
|||
buttons.append(new_button)
|
||||
return new_button
|
||||
|
||||
border = Rect(20, 8, 280, 35, fill=WHITE, outline=BLACK, stroke=2)
|
||||
calc_display = Label(font, text="0", color=BLACK, max_glyphs=MAX_DIGITS)
|
||||
calc_display.y = 25
|
||||
|
||||
clear_button = make_button(0, 0, "AC")
|
||||
make_button(1, 0, "+/-")
|
||||
make_button(2, 0, "%")
|
||||
make_button(3, 0, "/", 1, ORANGE, WHITE)
|
||||
make_button(0, 1, "7")
|
||||
make_button(1, 1, "8")
|
||||
make_button(2, 1, "9")
|
||||
make_button(3, 1, "x", 1, ORANGE, WHITE)
|
||||
make_button(0, 2, "4")
|
||||
make_button(1, 2, "5")
|
||||
make_button(2, 2, "6")
|
||||
make_button(3, 2, "-", 1, ORANGE, WHITE)
|
||||
make_button(0, 3, "1")
|
||||
make_button(1, 3, "2")
|
||||
make_button(2, 3, "3")
|
||||
make_button(3, 3, "+", 1, ORANGE, WHITE)
|
||||
make_button(0, 4, "0", 2)
|
||||
make_button(2, 4, ".")
|
||||
make_button(3, 4, "=", 1, ORANGE, WHITE)
|
||||
|
||||
def find_button(label):
|
||||
result = None
|
||||
for _, btn in enumerate(buttons):
|
||||
|
|
@ -91,6 +67,30 @@ def find_button(label):
|
|||
result = btn
|
||||
return result
|
||||
|
||||
border = Rect(20, 8, 280, 35, fill=WHITE, outline=BLACK, stroke=2)
|
||||
calc_display = Label(font, text="0", color=BLACK, max_glyphs=MAX_DIGITS)
|
||||
calc_display.y = 25
|
||||
|
||||
clear_button = add_button(0, 0, "AC")
|
||||
add_button(1, 0, "+/-")
|
||||
add_button(2, 0, "%")
|
||||
add_button(3, 0, "/", 1, ORANGE, WHITE)
|
||||
add_button(0, 1, "7")
|
||||
add_button(1, 1, "8")
|
||||
add_button(2, 1, "9")
|
||||
add_button(3, 1, "x", 1, ORANGE, WHITE)
|
||||
add_button(0, 2, "4")
|
||||
add_button(1, 2, "5")
|
||||
add_button(2, 2, "6")
|
||||
add_button(3, 2, "-", 1, ORANGE, WHITE)
|
||||
add_button(0, 3, "1")
|
||||
add_button(1, 3, "2")
|
||||
add_button(2, 3, "3")
|
||||
add_button(3, 3, "+", 1, ORANGE, WHITE)
|
||||
add_button(0, 4, "0", 2)
|
||||
add_button(2, 4, ".")
|
||||
add_button(3, 4, "=", 1, ORANGE, WHITE)
|
||||
|
||||
# Add the display and buttons to the main calc group
|
||||
calc_group.append(border)
|
||||
calc_group.append(calc_display)
|
||||
|
|
|
|||
Loading…
Reference in a new issue