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
|
import threading
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from . import VERSION
from .config import get_config
from .logic import Account
class CtecFrame:
def __init__(self, root: Tk):
self.root = root
root.title('ctec')
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
config = get_config()
self.accounts = [Account(address=section, info=config[section]) for section in config.sections() if '@' in section]
self.accounts_tree = ttk.Treeview(mainframe, columns=('unread', 'all'))
self.accounts_tree.column('unread', width=50, anchor=E)
self.accounts_tree.heading('unread', text='Unread')
self.accounts_tree.column('all', width=50, anchor=E)
self.accounts_tree.heading('all', text='All')
self.accounts_tree.grid(column=0, row=0, sticky=(N, W, E, S))
self.accounts_tree.insert('', 'end', 'all', text='All Accounts')
for account in self.accounts:
unread_count = sum(1 for message in account.inbox() if 'S' not in message.get_flags())
all_count = sum(1 for message in account.inbox())
self.accounts_tree.insert('', 'end', account.address, text=account.address, values=(unread_count, all_count))
threading.Thread(target=lambda: account.fetch_inbox()).start()
# self.messages =
# create a menu bar
self.make_menu_bar(root)
def make_menu_bar(self, root):
root.option_add('*tearOff', FALSE)
menubar = Menu(root)
root['menu'] = menubar
file_menu = Menu(menubar)
menubar.add_cascade(menu=file_menu, label='File', underline=0)
file_menu.add_command(label='Exit', command=self.on_exit, underline=1)
help_menu = Menu(menubar)
menubar.add_cascade(menu=help_menu, label='Help', underline=0)
help_menu.add_command(label='About', command=self.on_about, underline=0)
def on_exit(self, *args):
self.root.destroy()
def on_about(self, *args):
messagebox.showinfo(message=f"ctec {'.'.join(str(x) for x in VERSION)}")
def main():
root = Tk()
frame = CtecFrame(root)
root.mainloop()
main()
|