forked from bboc/todoist-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
116 lines (89 loc) · 3.94 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from argparse import Namespace
import os
from Tkinter import *
import tkFileDialog
from tdconv.tdconv import convert
class App:
AVAILABLE_FORMATS = [
("TaskPaper", "taskpaper"),
("OPML", "opml"),
("Markdown", "md"),
("Todoist (CSV)", "todoist"),
]
def __init__(self, master):
master.title("todoist-converter v0.3")
# source file
self.filename = StringVar()
source_frame = Frame(master)
source_frame.pack(anchor=NW)
Label(source_frame, text="File to convert:").pack(side=LEFT)
Entry(source_frame, text="foobar", textvariable=self.filename).pack(side=LEFT)
Button(source_frame, text="Select File", command=self.cb_select_file).pack(side=LEFT)
# separator
Frame(height=2, bd=1, relief=SUNKEN).pack(fill=X, padx=5, pady=5)
# output file
self.output_file = StringVar()
output_frame = Frame(master)
output_frame.pack(anchor=NW)
Label(output_frame, text="Output file (optional):").pack(side=LEFT)
self.entry_target_file = Entry(output_frame, text="foobar", textvariable=self.output_file)
self.entry_target_file.pack(side=LEFT)
# separator
Frame(height=2, bd=1, relief=SUNKEN).pack(fill=X, padx=5, pady=5)
# file format
self.format = StringVar()
self.format.set("taskpaper")
format_frame = Frame(master)
format_frame.pack(anchor=NW)
Label(format_frame, text="Convert to: ").pack(side=LEFT)
for text, mode in self.AVAILABLE_FORMATS:
self.select_format = Radiobutton(format_frame, text=text, variable=self.format, value=mode)
self.select_format.pack(side=LEFT)
# separator
Frame(height=2, bd=1, relief=SUNKEN).pack(fill=X, padx=5, pady=5)
# download attachments
self.download = IntVar()
download_frame = Frame(master)
download_frame.pack(anchor=NW)
self.checkbox_download = Checkbutton(download_frame, text="Download Attachments?", variable=self.download)
self.checkbox_download.pack(side=LEFT)
# separator
Frame(height=2, bd=1, relief=SUNKEN).pack(fill=X, padx=5, pady=5)
#buttons: convert, quit
buttons_frame = Frame(master)
buttons_frame.pack(anchor=NW, fill=X)
self.button_quit = Button(buttons_frame, text="Quit", fg="red", command=master.quit)
self.button_quit.pack(anchor=NW, side=LEFT)
self.button_convert = Button(buttons_frame, text="Convert", command=self.convert)
self.button_convert.pack(anchor=NE)
def cb_select_file(self):
filename = tkFileDialog.askopenfilename(initialdir = ".",
title = "Select file",
defaultextension='*.csv',
filetypes = (("Todoist Files", "*.csv"),
("OPML Files", "*.opml"),
("all files","*.*")))
print(filename)
self.filename.set(filename)
def convert(self):
# TODO: warn if filename not set
print("format", self.format.get())
print("download", self.download.get())
print("source", self.filename.get())
print("target", self.output_file.get())
args = Namespace(file=self.filename.get(),
format=self.format.get(),
output=self.output_file.get(),
download=self.download.get())
convert(args)
def main():
root = Tk()
app = App(root)
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "python" to true' ''')
root.mainloop()
root.destroy()
if __name__ == "__main__":
main()