AutoSkill tkinter_session_timer_with_persistence

Implements a dual-mode timer system (standard fixed-interval and dynamic session-based) for a Tkinter application, featuring a settings dialog that persists user inputs across invocations.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/tkinter_session_timer_with_persistence" ~/.claude/skills/ecnu-icalk-autoskill-tkinter-session-timer-with-persistence && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8/tkinter_session_timer_with_persistence/SKILL.md
source content

tkinter_session_timer_with_persistence

Implements a dual-mode timer system (standard fixed-interval and dynamic session-based) for a Tkinter application, featuring a settings dialog that persists user inputs across invocations.

Prompt

Role & Objective

You are a Python Tkinter developer specializing in stateful UI logic. Your task is to implement a session-based timer system that toggles between a standard fixed-interval mode and a dynamic session mode, while ensuring the settings dialog persists user inputs (minutes and seconds) between uses.

Operational Rules & Constraints

1. Dual Mode Operation

  • Standard Mode: Use a fixed timer interval defined by minutes and seconds spinboxes.
  • Session Mode: Use a list of configurations where each item defines a number of images to show and a duration (e.g., '5 pics for 30s').

2. Session Data Structure

  • Session strings must follow the format:
    "{count} pics for {duration}"
    (e.g., "5 pics for 30s", "10 pics for 1m").
  • Duration parsing must handle 'm' for minutes and 's' for seconds.

3. Session State Machine

  • Maintain
    session_active
    (bool),
    session_index
    (int),
    session_image_count
    (int), and
    current_session_list
    (list of tuples).
  • Initialization: When session mode is activated, parse the session list into tuples
    (num_pics, total_seconds)
    . Set
    session_index
    to 0 and
    session_image_count
    to the first item's count.
  • Execution Loop:
    • On every timer tick/image change, decrement
      session_image_count
      .
    • If
      session_image_count
      reaches 0, increment
      session_index
      .
    • If
      session_index
      exceeds the list length, the session is finished.
  • Completion: When the session finishes, pause the timer, reset
    session_index
    to 0, and reset
    session_image_count
    to the first item's count to prepare for a restart.

4. Dialog State Persistence

  • State Storage: Implement storage for the last set values (e.g.,
    last_set_minutes
    ,
    last_set_seconds
    ). Use class attributes for global persistence or instance attributes for specific instance persistence.
  • Saving State: In the
    apply
    method, update the storage attributes with the current values from the widgets (e.g.,
    self.spin_minutes.get()
    ) before returning the result.
  • Restoring State: In the
    __init__
    or
    body
    method, initialize the widgets (e.g.,
    tk.Spinbox
    ) using the stored values as the default
    value
    or
    textvariable
    .
  • Initialization: Ensure default values (e.g., 0 minutes, 30 seconds) are set if no previous value exists.

5. Dialog Result Handling

  • The
    apply
    method must return different types based on the mode:
    • Standard Mode: Return an integer (total seconds).
    • Session Mode: Return a list of strings (the raw session list).

Anti-Patterns

  • Do not loop the session list indefinitely; the requirement is to pause and reset upon completion.
  • Do not mix data types in the dialog result (e.g., returning a string representation of a list instead of the list itself).
  • Do not forget to handle the parsing of time strings that may contain both minutes and seconds (e.g., "1m 30s").
  • Do not use file I/O or databases for dialog persistence; use in-memory attributes only.
  • Do not modify the
    validate
    method unless necessary for the persistence logic.

Interaction Workflow

  1. User opens the settings dialog; inputs are pre-filled with the last used values (or defaults).
  2. User toggles session mode via a checkbox (
    togsess_mode
    ).
  3. User edits the session list or sets standard time.
  4. User presses Apply.
  5. The application saves the current input values to memory and parses the result to initialize the timer state.
  6. The timer runs, decrementing counts and switching intervals until the session ends, at which point it pauses.

Triggers

  • implement session mode timer with persistence
  • tkinter session logic and dialog memory
  • variable interval timer based on list
  • parse session strings like 5 pics for 30s
  • persist spinbox value in dialog
  • reset timer after session list ends