sls_calc module polishing
This commit is contained in:
parent
8890216457
commit
f5c786c061
|
|
@ -8,10 +8,10 @@ import tkinter as tk
|
|||
from tkinter import ttk, font as tkfont
|
||||
import sls_py
|
||||
|
||||
class HPCalculator:
|
||||
class SlsCalculator:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.root.title("HP Stack Calculator")
|
||||
self.root.title("SLS Calculator")
|
||||
# self.root.geometry("450x650")
|
||||
self.root.resizable(False, False)
|
||||
|
||||
|
|
@ -30,9 +30,8 @@ class HPCalculator:
|
|||
"""Create all calculator widgets"""
|
||||
# Main container
|
||||
main_frame = ttk.Frame(self.root, padding="10")
|
||||
main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
|
||||
main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) # type: ignore
|
||||
|
||||
# Stack display (shows 4 stack levels like classic HP)
|
||||
self.create_stack_display(main_frame)
|
||||
|
||||
# Entry display
|
||||
|
|
@ -44,27 +43,27 @@ class HPCalculator:
|
|||
def create_stack_display(self, parent):
|
||||
"""Create the 4-level stack display"""
|
||||
stack_frame = ttk.LabelFrame(parent, text="Stack", padding="5")
|
||||
stack_frame.grid(row=0, column=0, columnspan=4, sticky=(tk.W, tk.E), pady=(0, 10))
|
||||
stack_frame.grid(row=0, column=0, columnspan=4, sticky=(tk.W, tk.E), pady=(0, 10)) # type: ignore
|
||||
|
||||
self.stack_labels = []
|
||||
for i in range(4):
|
||||
label = ttk.Label(stack_frame,
|
||||
text=f"T{3-i}: <>",
|
||||
text=f"{3-i}:",
|
||||
anchor='e',
|
||||
width=30)
|
||||
label.grid(row=i, column=0, sticky=(tk.W, tk.E), pady=2)
|
||||
label.grid(row=i, column=0, sticky=(tk.W, tk.E), pady=2) # type: ignore
|
||||
self.stack_labels.append(label)
|
||||
|
||||
def create_entry_display(self, parent):
|
||||
"""Create the current entry display"""
|
||||
entry_frame = ttk.Frame(parent)
|
||||
entry_frame.grid(row=1, column=0, columnspan=4, sticky=(tk.W, tk.E), pady=(0, 10))
|
||||
entry_frame.grid(row=1, column=0, columnspan=4, sticky=(tk.W, tk.E), pady=(0, 10)) # type: ignore
|
||||
|
||||
self.entry_label = ttk.Label(entry_frame,
|
||||
text="0",
|
||||
anchor='e',
|
||||
font=('Courier', 16))
|
||||
self.entry_label.grid(row=0, column=0, sticky=(tk.W, tk.E))
|
||||
self.entry_label.grid(row=0, column=0, sticky=(tk.W, tk.E)) # type: ignore
|
||||
|
||||
def create_button_grid(self, parent):
|
||||
"""Create the calculator button grid"""
|
||||
|
|
@ -84,7 +83,7 @@ class HPCalculator:
|
|||
text=text,
|
||||
command=command,
|
||||
width=8)
|
||||
btn.grid(row=row_idx, column=col_idx, padx=2, pady=2, sticky=(tk.W, tk.E, tk.N, tk.S))
|
||||
btn.grid(row=row_idx, column=col_idx, padx=2, pady=2, sticky=(tk.W, tk.E, tk.N, tk.S)) # type: ignore
|
||||
|
||||
# Keyboard bindings
|
||||
self.root.bind('<Delete>', lambda e: self.drop())
|
||||
|
|
@ -230,9 +229,9 @@ class HPCalculator:
|
|||
if stack_size > level:
|
||||
entry = self.interp.stack[-(level + 1)]
|
||||
value_str = self.format_stack_entry(entry)
|
||||
self.stack_labels[i].config(text=f"T{level}: {value_str}")
|
||||
self.stack_labels[i].config(text=f"{level}: {value_str}")
|
||||
else:
|
||||
self.stack_labels[i].config(text=f"T{level}: <>")
|
||||
self.stack_labels[i].config(text=f"{level}:")
|
||||
|
||||
def format_stack_entry(self, entry):
|
||||
"""Format a stack entry for display"""
|
||||
|
|
@ -255,7 +254,7 @@ class HPCalculator:
|
|||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
app = HPCalculator(root)
|
||||
app = SlsCalculator(root)
|
||||
root.mainloop()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue