Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Python variant #52

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish Python Package

# Restrict the job to run only if files inside the `python/*` directory change
on:
release:
paths:
- python/**
types: [created]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: python/pyproject.toml
- name: Install dependencies
run: |
cd python/
pip install '.[test]'
- name: Run tests
run: |
pytest
deploy:
runs-on: ubuntu-latest
needs: [test]
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: python/pyproject.toml
- name: Install dependencies
run: |
pip install setuptools wheel build
- name: Build
run: |
cd python
python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1

38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

# Restrict the job to run only if files inside the `python/*` directory change
on:
push:
branches: [main, master]
paths:
- python/**
pull_request:
branches: [main, master]
paths:
- python/**

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: python/pyproject.toml
- name: Install dependencies
run: |
cd python
pip install '.[test]'
- name: Run tests
run: |
pytest

14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,15 @@ Network Trash Folder
Temporary Items
.apdisk

/.luarc.json
*.luarc.json
# Pyhton specific blocks
.venv
__pycache__/
*.py[cod]
*$py.class
venv
.eggs
.pytest_cache
*.egg-info
.DS_Store
dist
build
21 changes: 21 additions & 0 deletions python/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2024 countdown authors

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.
43 changes: 42 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
# countdown for Python

[![PyPI](https://img.shields.io/pypi/v/countdown.svg)](https://pypi.org/project/countdown/)
[![Tests](https://github.com/gadenbuie/countdown/actions/workflows/test.yml/badge.svg)](https://github.com/gadenbuie/countdown/actions/workflows/test.yml)
[![Changelog](https://img.shields.io/github/v/release/gadenbuie/countdown?include_prereleases&label=changelog)](https://github.com/gadenbuie/countdown/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/gadenbuie/countdown/blob/main/LICENSE)

A simple countdown timer for slides and HTML documents written in 'Jupyter' or 'Quarto'. Integrates fully into 'Shiny for Python' apps. Countdown to something amazing.

## Coming Soon (TM)

We're currently working toward implementing a Python package for countdown.
This will likely come over the next couple of months.

In the interim, we suggest viewing the [`Quarto`](../quarto) or [`R`](../r/) extensions.
In the interim, we suggest viewing the [`Quarto`](../quarto) or [`R`](../r/) extensions.

<!--
## Installation

Install this library using `pip`:

```bash
pip install countdown
```

## Usage

Usage instructions go here.

-->

## Development

To contribute to this library, first checkout the code. Then create a new virtual environment:
```bash
cd countdown
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```
8 changes: 8 additions & 0 deletions python/countdown/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set the package version here
__version__ = "0.0.1"

# Import public-facing functions
from .countdown import countdown, countdown_style

# Export public functions
__all__ = ["countdown", "countdown_style"]
175 changes: 175 additions & 0 deletions python/countdown/assets/countdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.countdown {
--_margin: 0.6em;
--_running-color: var(--countdown-color-running-text, rgba(0, 0, 0, 0.8));
--_running-background: var(--countdown-color-running-background, #43AC6A);
--_running-border-color: var(--countdown-color-running-border, rgba(0, 0, 0, 0.1));
--_finished-color: var(--countdown-color-finished-text, rgba(0, 0, 0, 0.7));
--_finished-background: var(--countdown-color-finished-background, #F04124);
--_finished-border-color: var(--countdown-color-finished-border, rgba(0, 0, 0, 0.1));

position: absolute;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
background: var(--countdown-color-background, inherit);
font-size: var(--countdown-font-size, 3rem);
line-height: var(--countdown-line-height, 1);
border-color: var(--countdown-color-border, #ddd);
border-width: var(--countdown-border-width, 0.1875rem);
border-style: solid;
border-radius: var(--countdown-border-radius, 0.9rem);
box-shadow: var(--countdown-box-shadow, 0px 4px 10px 0px rgba(50, 50, 50, 0.4));
margin: var(--countdown-margin, var(--_margin, 0.6em));
padding: var(--countdown-padding, 0.625rem 0.9rem);
text-align: center;
z-index: 10;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.countdown.inline {
position: relative;
width: max-content;
max-width: 100%;
}

.countdown .countdown-time {
background: none;
font-size: 100%;
padding: 0;
color: currentColor;
}

.countdown-digits {
color: var(--countdown-color-text);
}

.countdown.running {
border-color: var(--_running-border-color);
background-color: var(--_running-background);
}

.countdown.running .countdown-digits {
color: var(--_running-color);
}

.countdown.finished {
border-color: var(--_finished-border-color);
background-color: var(--_finished-background);
}

.countdown.finished .countdown-digits {
color: var(--_finished-color);
}

.countdown.running.warning {
border-color: var(--countdown-color-warning-border, rgba(0, 0, 0, 0.1));
background-color: var(--countdown-color-warning-background, #E6C229);
}

.countdown.running.warning .countdown-digits {
color: var(--countdown-color-warning-text, rgba(0, 0, 0, 0.7));
}

.countdown.running.blink-colon .countdown-digits.colon {
opacity: 0.1;
}

/* ------ Controls ------ */
.countdown:not(.running) .countdown-controls,
.countdown.no-controls .countdown-controls {
display: none;
}

.countdown-controls {
position: absolute;
top: -0.5rem;
right: -0.5rem;
left: -0.5rem;
display: flex;
justify-content: space-between;
margin: 0;
padding: 0;
}

.countdown-controls>button {
position: relative;
font-size: 1.5rem;
width: 1rem;
height: 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: monospace;
padding: 10px;
margin: 0;
background: inherit;
border: 2px solid;
border-radius: 100%;
transition: 50ms transform ease-in-out, 150ms opacity ease-in;
box-shadow: 0px 2px 5px 0px rgba(50, 50, 50, 0.4);
-webkit-box-shadow: 0px 2px 5px 0px rgba(50, 50, 50, 0.4);
--_button-bump: 0;
opacity: var(--_opacity, 0);
transform: translate(0, var(--_button-bump));
}

/* increase hit area of the +/- buttons */
.countdown .countdown-controls > button::after {
content: "";
height: 200%;
width: 200%;
position: absolute;
border-radius: 50%;
}

.countdown .countdown-controls>button:last-child {
color: var(--_running-color);
background-color: var(--_running-background);
border-color: var(--_running-border-color);
}

.countdown .countdown-controls>button:first-child {
color: var(--_finished-color);
background-color: var(--_finished-background);
border-color: var(--_finished-border-color);
}

.countdown.running:hover, .countdown.running:focus-within {
--_opacity: 1;
}

.countdown.running:hover .countdown-controls>button,
.countdown.running:focus-within .countdown-controls>button {
--_button-bump: -3px;
}

.countdown.running:hover .countdown-controls>button:active,
.countdown.running:focus-within .countdown-controls>button:active {
--_button-bump: 0;
}

/* ---- Quarto Reveal.js ---- */
.reveal .countdown {
--_margin: 0;
}

/* ----- Fullscreen ----- */
.countdown.countdown-fullscreen {
z-index: 0;
}

.countdown-fullscreen.running .countdown-controls {
top: 1rem;
left: 0;
right: 0;
justify-content: center;
}

.countdown-fullscreen.running .countdown-controls>button+button {
margin-left: 1rem;
}
Loading
Loading