Skip to content

Instantly share code, notes, and snippets.

@Steampunkery
Created November 2, 2018 08:22
Show Gist options
  • Save Steampunkery/fedc80d899e286e33b9fb24eb6cfdf7a to your computer and use it in GitHub Desktop.
Save Steampunkery/fedc80d899e286e33b9fb24eb6cfdf7a to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import re
import subprocess
import tkinter as tk
from Xlib import display
def lambda_factory(index):
global labels
global buttons
return lambda: remove(index, labels, buttons)
def remove(index, labels, buttons):
global root
subprocess.call(['todo', '-r', str(index)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
for label in labels:
label.destroy()
for button in buttons:
button.destroy()
labels.clear()
buttons.clear()
todo_items = esc_seq_reg.sub('', subprocess.check_output(['todo']).decode()).split('\n')[1:-1]
buttons_and_labels(root, todo_items, buttons, labels)
def buttons_and_labels(root, todo_items, buttons, labels):
for index, item in enumerate(todo_items):
labels.append(tk.Label(root, text=item))
labels[index].grid(column=0, row=index, sticky="w")
buttons.append(tk.Button(root, text='x', command=lambda_factory(index)))
buttons[index].grid(column=1, row=index, sticky="e")
root = tk.Tk()
esc_seq_reg = re.compile(r'\x1b[^m]*m')
m_pos = display.Display().screen().root.query_pointer()
todo_items = esc_seq_reg.sub('', subprocess.check_output(['todo']).decode()).split('\n')[1:-1]
labels = []
buttons = []
buttons_and_labels(root, todo_items, buttons, labels)
root.bind('<Escape>', lambda a: root.destroy())
root.bind('<FocusOut>', lambda a: root.destroy())
root.wait_visibility(root)
root.wm_attributes('-type', 'splash', '-topmost', True, '-alpha', 0.0)
root.focus_force()
root.update_idletasks()
root.wm_attributes('-alpha', 1)
width = root.winfo_width()
height = root.winfo_height()
root.geometry(f"+{m_pos.root_x - int(width / 2)}+{m_pos.root_y - (height + 20)}")
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment