8

I work as a teacher. There are certain routines in my lesson, announced with timed events in Orage, sent to notifications. E.g.:

  • Clean Up
  • Put Chairs Up

My students requested I put a countdown clock on the screen to warn how much time is left until an event. I use XFce, so this could be either displayed on a panel at the top of the screen, never covered by full screen items, or as a non-clickable, transparent heads-up display that is always present above every window.

E.g.:

  • 3:10 until cleanup.
  • 6:10 until end of class.

These are not countdowns that are manually activated, but happen at specific times every day, e.g. a 10 minute countdown begins at 3:00 pm and ends at zero at 3:10 pm. I can use orage to activate the scripts, but need some way to display the counters and information.

Is there any way to display such count-down timers on the screen?

5
  • 2
    A conky widget with always-on-top might do the trick
    – muru
    Aug 15, 2019 at 2:31
  • 1
    All X11 programs can be started, and controlled from bash. And don't use a while loop to do busy waiting, you can use sleep. Aug 15, 2019 at 6:56
  • Did you already consider a (weekly (Mon - Fri) or daily) cron job might be suitable? I'm sure it could activate the above-mentioned conky widget starting to count down.
    – Nepumuk
    Sep 23, 2019 at 13:04
  • I'm not familiar with how that works.
    – Village
    Sep 23, 2019 at 23:40
  • @Village: As discussed in the comments here unix.stackexchange.com/questions/535666/… when you're talking about full screen you actually mean maximized, right? Sep 28, 2019 at 15:04

4 Answers 4

6

Python with ‍‍tkinter outputs the fastest and easiest way to create the GUI applications and widget. Creating a GUI using tkinter is an easy task.

You just need to use the following command to install the tkinter

apt-get install python-tk python3-tk

For Fedora users, use the following command.

dnf install python-tkinter python3-tkinter

This is a simple script for countdown with tkinter, always ontop and transparent:

import tkinter as tk
from datetime import datetime, time

def dateDiffInSeconds(date1, date2):
    timedelta = date2 - date1
    return timedelta.days * 24 * 3600 + timedelta.seconds

def daysHoursMinutesSecondsFromSeconds(seconds):
    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)
    days, hours = divmod(hours, 24)
    return (days, hours, minutes, seconds)

def counter_label(label):
    leaving_date = datetime.strptime('2022-01-01 01:00:00', '%Y-%m-%d %H:%M:%S')    #end time to count down
    def count():
        now = datetime.now()
        counter = daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, leaving_date))
        label.config(text=str("%d days, %d hours, %d minutes, %d seconds" % counter))
        label.after(1000, count)
    count()


root = tk.Tk()
root.attributes('-topmost', True)       #always on top
root.title("Counting Seconds")          #title
label = tk.Label(root, fg="dark green") #font color
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy)   #stop button
button.pack()
root.wait_visibility(root)
root.wm_attributes('-alpha',0.5)    # transparent windows  0.1 - 1
root.mainloop()

Image

6
  • 1
    I use fluxbox and this solution doesn't work for me. A window titled Counting seconds shows up in the left upper corner but it's blocked by full-screen windows. For example, press F11 in Firefox or Evince and notice that the window is not visible. Sep 28, 2019 at 12:09
  • I've run xfce4 inside Xephyr and tkinter windows is blocked by full-screen apps as well. So I think this answer is wrong and doesn't answer OP's question. Sep 28, 2019 at 12:14
  • If you press f11 in firefox you can't see any other things even xfce clock and other xfce plugins. so all the other answers is wrong too. i think by full screen she/he means maximized windows becuse she/he said 'this could be either displayed on a panel at the top of the screen,' @Arkadiusz Drabczyk Sep 28, 2019 at 12:46
  • i think by full screen she/he means maximized windows - I think that too but in that case the question should be rephrased. Sep 28, 2019 at 12:47
  • Yes, it needs to be visible even when a window is full screen, so either it is a transparent layer or on a panel, but some settings must be changed so the panel is always visible and not covered by full screen apps if a solution using the panel is used.
    – Village
    Sep 29, 2019 at 12:59
3
+750

With xfce4-genmon-plugin, you can create such a panel widget yourself.

Install the plugin from your distro's repositories. Then create a script which generates the countdown display:

#!/usr/bin/env python3
from datetime import date, time, datetime

now = datetime.now()

def show_countdown(target, event):
    if now >= target:
        print(("{} NOW!").format(event))
        return

    time_left = target - now
    min, sec = divmod(time_left.seconds, 60)
    hrs, min = divmod(min, 60)
    print("{} in {}:{:02}:{:02}".format(event, hrs, min, sec))  

show_countdown(
    datetime.combine(date.today(), time(10, 25)),
    "Cleanup"
)
show_countdown(
    datetime.combine(date.today(), time(10, 30)),
    "Class ends"
)

Modify it as you see fit, save it in some unobtrusive place and grant it execution permission (chmod +x). Then add a "Generic monitor" item to your panel. Point the panel item to your script and configure a suitable refresh interval (if you removed seconds display, you should probably leave it at 30 seconds to save power/performance). And there you have it.

2
  • So does xfce4-genmon-plugin simply run whatever script is selected, printing what would have been displayed in the terminal, but instead on the panel?
    – Village
    Sep 21, 2019 at 2:19
  • That's right. There is also some formatting markup available, described on the page I linked. Sep 21, 2019 at 6:53
2

There are many ways and widgets to have a timer or countdown, but considering you are using xfce and want something graphical on the panel, you might want to try xfce4-timer-plugin.

It does require xfce >= 4.6 though. I don't know which version of xfce you are running, but this plugin might very well work for your needs.

The xfce4-timer-plugin allows you to set a countdown and an alarm with repeat options if you wish to set it daily for example,:

enter image description here

It also displays a countdown bar in the panel if you wish:

Countdown running: enter image description here

Countdown empty: enter image description here

You can read more about the plugin in the link above, but, here is the about and usage paragraphs just in case:

About

This is a simple plugin that lets the user run an alarm at a specified time or at the end of a specified countdown period.

Usage

The plugin is quite simple – it displays a progressbar showing the percentage of the time elapsed. Left-clicking on the plugin area opens a menu of available alarms. After selecting one, the user can start or stop the timer by selecting “start/stop timer” entry in the same menu. New alarms are added through the preferences window. Each alarm is either a countdown or is run at a specified time. By default a simple dialog pops up at the end of the countdown. The user can choose an external command to be run as the alarm and may also choose to have this repeated a specified number of times with a given interval between repetitions.

4
  • Does this app allow setting a countdown timer to begin automatically at a given time? Is there a way to change the appearance from the bar to a counting timer as the bar isn't very easy to see?
    – Village
    Sep 23, 2019 at 23:32
  • It seems the alarm is programmable, but the countdown only allows for a duration. As far as I know, there is no option for changing the bar. Can you use Gnome widgets in XFCE for ex.?. Sep 25, 2019 at 16:38
  • @Village if i edit this timer plugin to make it handle automatic startup at a given time, would it worth the bounty ?, what's your distro and version of xfce?
    – intika
    Sep 28, 2019 at 23:15
  • The two problems with the timer app is it is very difficult to see as the little bar is too small, so a count-down clock is better, and it doesn't start autoamtically.
    – Village
    Sep 29, 2019 at 12:57
2

You could use crontab, and a bash script using yad.

For example, for a cleanup at 15:10, with countdown beginning at 15:00, and end of class at 18:10 with countdown starting at 18:00:

Create a script for countdown:

#!/bin/bash
export max=$1
export action=$2
for i in `seq $max`
do
  echo "$[i* 100/max]"
  echo "#${action} in $[max-i] second" 
  sleep 1
done | yad --on-top --progress --no-buttons --auto-close

Edit the crontab of the user who has access to the display (I guess it should be your own user), and adapt the DISPLAY variable if echo $DISPLAY in your shell is different than :0:

crontab -e

0 15 * * *  DISPLAY=:0 /path/to/script.sh 600 Cleanup
0 18 * * *  DISPLAY=:0 /path/to/script.sh 600 "End of Class"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .