Skip to content

Refactor duplicated code into shared helpers#3

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784470192-refactor-shared-utils
Open

Refactor duplicated code into shared helpers#3
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784470192-refactor-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

calc.py repeated the same tk.Button(...) + .grid(...) construction ~11 times and the same tk.Label(...) + .pack(...) 3 times, each with identical styling (fg=LABEL_COLOR, borderwidth=0, padx=24, etc.). This collapses those into two shared helpers and removes several smaller copy-paste blocks. Pure refactor — no behavior change (verified with a headless smoke test covering arithmetic, , √x, and memory M+/MR).

Net: -81 / +50 lines.

Key changes:

  • New helpers on Calculator:
    • _create_button(text, command, row, column, bg=OFF_WHITE, font=DEFAULT_FONT_STYLE, columnspan=1) — builds + grids a styled button and returns it.
    • _create_label(text, font) — builds + packs a styled display label.
  • All create_*_button methods now delegate to _create_button. create_operator_buttons uses enumerate instead of a manual counter.
  • The four near-identical memory buttons (create_mc/mr/mplus/mminus_button, which even used \ line continuations) are replaced by a data-driven create_memory_buttons() iterating a new self.memory_buttons = {"MC": (1,0), ...} map.
  • square/sqrt/perc shared the self.current_expression = str(eval(...)); self.update_label() idiom — extracted into _apply(expression):
    def _apply(self, expression):
        self.current_expression = str(eval(expression))
        self.update_label()
  • Repeated self.memol.config(text="M: "+str(self.mem)) (in MS/M+/M-) extracted into _update_memory_label().
  • add_to_expression had three branches that all did the same append; simplified to one guarded append (only skip a . when one is already present):
    if self.entrou == 0:
        if value != '.' or '.' not in self.current_expression:
            self.current_expression += str(value)

Note: the pre-existing iconphoto(... calc3.png) reference (file not in repo) is left untouched as out of scope.

Link to Devin session: https://app.devin.ai/sessions/1fcf820df6684c45bdbd4f6851761fc1
Requested by: @martlyma

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@martlyma martlyma self-assigned this Jul 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant