Last active
August 29, 2015 14:23
-
-
Save eric-cc-su/da29b6a93354099439dc to your computer and use it in GitHub Desktop.
Formerly reminders.py. Command Line program that produces a popup reminder of choice at given time interval in seconds (default: "Stand up and stretch!" every 60 minutes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
author: eric-cc-su | |
This is a command line program that produces a popup with text of choice at given time inteval in seconds | |
(default: "Stand up and stretch!" every 60 minutes) | |
This code is under the MIT License (end of file) and copyrighted by Eric Su | |
""" | |
import argparse, os, sys, time, traceback | |
try: | |
import tkinter as tk | |
except ImportError: | |
try: | |
print("Consider Python 3...") | |
time.sleep(1) | |
import Tkinter as tk | |
except ImportError: | |
sys.exit(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1])[0]) | |
stand_time = time.time() | |
frame = None | |
def clear_screen(): | |
if 'win' in str(sys.platform): | |
os.system('cls') | |
else: | |
os.system('clear') | |
# Create reminder window | |
def remind(master, message): | |
global frame | |
frame = tk.Frame(master) | |
frame.pack() | |
label = tk.Message(frame, text=message, padx=50, pady= 20, width=400).pack() | |
button = tk.Button(frame, text="OK", command=lambda: quit(frame), padx=15, pady=5, takefocus=True).pack() | |
# Close reminder window, set new stand time | |
def quit(frame): | |
frame.quit() | |
global stand_time | |
stand_time = time.time() | |
def main(args): | |
while True: | |
if time.time() - stand_time >= args.time: # Waits until args.time seconds have passed since standing | |
root = tk.Tk() | |
root.title("Clingycat - Constant Reminders") | |
root.geometry("400x100") | |
root.attributes('-topmost', True) # Popup is above all windows | |
reminder = remind(root, args.message) | |
root.mainloop() | |
root.destroy() | |
# Command Line parser | |
parser = argparse.ArgumentParser(description="Reminder to stand up at given time interval") | |
parser.add_argument("-m","--message", help="The reminder message", default="Stand up and stretch!") | |
parser.add_argument("-t","--time", help="Frequency of time to notify user to stand", default=3600, type=int) | |
args = parser.parse_args() | |
clear_screen() | |
print("\nReminder set to {} seconds\n".format(args.time)) | |
print("reminders.py running...\n") | |
print("Press Ctrl+C to quit or click 'x' in reminder window") | |
try: | |
main(args) | |
except KeyboardInterrupt: # User has quit with Ctrl+C | |
clear_screen() | |
print("reminders closed") | |
except tk.TclError: # User has quit with "x" window button | |
clear_screen() | |
print("reminders closed") | |
except Exception: # Unexpected exception | |
clear_screen() | |
print(traceback.print_exc()) | |
print() | |
print("Looks like you found a bug!") | |
print("Please message eric-cc-su on GitHub, he's curious to know about it!") | |
sys.exit(0) | |
""" | |
The MIT License (MIT) | |
Copyright (c) 2015 Eric Su | |
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. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment