---
id: "7c467274-57b5-4170-9c4d-b7140d95076e"
name: implement-session-based-image-viewer-timer-c17dde4dbfb3
description: "Implement a dual-mode timer logic for an image viewer that switches between a standard fixed interval and a session-based interval iterating through a list of image counts and durations."
version: "0.1.0"
tags:
  - "python"
  - "tkinter"
  - "timer"
  - "session-management"
  - "image-viewer"
triggers:
  - "implement session timer logic"
  - "switch between standard and session mode timer"
  - "timer based on image count list"
  - "pause timer after session list ends"
---

# Implement Session-Based Image Viewer Timer

Implement a dual-mode timer logic for an image viewer that switches between a standard fixed interval and a session-based interval iterating through a list of image counts and durations.

## Prompt

# Role & Objective
You are a Python/Tkinter developer implementing a dual-mode timer for an image viewer. The timer must support a standard fixed interval mode and a session-based mode where intervals change based on a predefined list of configurations.

# Operational Rules & Constraints
1. **Mode Toggle**: Use a boolean flag (e.g., `self.togsess_mode`) to determine the active mode.
2. **Standard Mode**:
   - Calculate the interval in seconds from `minutes` and `seconds` inputs.
   - Store the result as an integer.
3. **Session Mode**:
   - Parse a list of strings (e.g., `['5 pics for 30s', '5 pics for 1m']`) into a list of tuples `(num_pics, duration_seconds)`.
   - Initialize `session_index` to 0 and `session_image_count` to the first item's count.
   - Set the initial `timer_interval` to the first item's duration.
4. **Timer Update Logic (`update_timer`)**:
   - If `session_active` is True:
     - Decrement `session_image_count`.
     - If `session_image_count` <= 0:
       - Increment `session_index`.
       - If `session_index` >= length of the session list: Call `pause_timer()` to stop and reset.
       - Else: Update `timer_interval` to the new session's duration and reset `session_image_count`.
   - Else: Use the standard fixed interval.
5. **Pause Logic (`pause_timer`)**:
   - Cancel any scheduled timer event (e.g., `root.after_cancel`).
   - Set `timer_running = False`.
   - If `session_active`: Reset `session_index` to 0 and `session_image_count` to the first session's count.
6. **Initialization**: Ensure `timer_running`, `timer_id`, `session_active`, `session_index`, and `session_image_count` are initialized in `__init__` to prevent AttributeErrors.
7. **Type Safety**: Ensure `dialog.result` is handled as an integer in standard mode and as a list in session mode to avoid TypeErrors/ValueErrors.

## Triggers

- implement session timer logic
- switch between standard and session mode timer
- timer based on image count list
- pause timer after session list ends


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

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.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer, Full-Stack Developer
Specialties: Backend, Cross Platform, Mobile
Tools: Tkinter
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 3b3a16561514866563939804c7024b5bebda4b4ed15d077403cebdfe17894185
