commit 41f1a72190324344d0bbe561f34b447f7752d3e1 Author: Robert Date: Fri Jun 13 16:19:26 2025 -0400 Calc init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c112790 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/venv/ +/build/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee5603f --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) <2025> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/calc.desktop b/calc.desktop new file mode 100644 index 0000000..1f1ce3e --- /dev/null +++ b/calc.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Name=Bobs Calculator +Comment=Bobs Calculator +GenericName=Calculator +Keywords=calc,calculator +Exec=/usr/local/bin/calc +Terminal=false +Type=Application +Icon=/usr/share/icons/gnome/32x32/apps/calc.png +Categories=GNOME;GTK; diff --git a/calc.py b/calc.py new file mode 100644 index 0000000..35ecf68 --- /dev/null +++ b/calc.py @@ -0,0 +1,57 @@ +import tkinter as tk +from tkinter import messagebox + +def on_click(event): + text = event.widget.cget("text") + if text == "=": + calculate_result() + elif text == "C": + clear_entry() + else: + entry_var.set(entry_var.get() + text) + +def calculate_result(event=None): + try: + result = eval(str(entry.get())) + result = round(float(result), 2) # Format to 2 decimal places + entry_var.set(f"{result:.2f}") + except Exception as e: + messagebox.showerror("Error", f"Invalid Expression: {e}") + +def clear_entry(event=None): + entry_var.set("") + return "break" # Prevents default behavior of inserting 'c' or 'C' + +# Main window +root = tk.Tk() +root.title("Bobs Calc") +root.geometry("215x250") + +entry_var = tk.StringVar() +entry = tk.Entry(root, textvariable=entry_var, font="Arial 20") +entry.pack(fill=tk.BOTH, ipadx=8, pady=10, padx=10) +entry.focus_set() # Set focus to the entry widget +entry.bind("", calculate_result) # Bind Enter key to calculate_result +entry.bind("", calculate_result) # Bind NumPad Enter key +entry.bind("", clear_entry) # Bind 'c' key to clear_entry +entry.bind("", clear_entry) # Bind 'C' key to clear_entry + +button_frame = tk.Frame(root) +button_frame.pack() + +buttons = [ + ["7", "8", "9", "/"], + ["4", "5", "6", "*"], + ["1", "2", "3", "-"], + ["C", "0", "=", "+"] +] + +for row in buttons: + row_frame = tk.Frame(button_frame) + row_frame.pack(expand=True, fill="both") + for btn_text in row: + btn = tk.Button(row_frame, text=btn_text, font="Arial 18", relief=tk.RAISED) + btn.pack(side=tk.LEFT, expand=True, fill="both") + btn.bind("", on_click) + +root.mainloop() diff --git a/calc.spec b/calc.spec new file mode 100644 index 0000000..16df180 --- /dev/null +++ b/calc.spec @@ -0,0 +1,38 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['calc.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='calc', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) diff --git a/dist/calc b/dist/calc new file mode 100755 index 0000000..b7bba4b Binary files /dev/null and b/dist/calc differ