protokollGUI.py 3.19 KB
Newer Older
Dominik Woiwode's avatar
Dominik Woiwode committed
1
import tkinter as tk
Dominik Woiwode's avatar
Dominik Woiwode committed
2
3
from functools import wraps

4
import config
Dominik Woiwode's avatar
Dominik Woiwode committed
5
import linkToPDF2 as pter
6
import pterClasses
Dominik Woiwode's avatar
Dominik Woiwode committed
7
8
9


class ProtokollGUI(tk.Tk):
10
    def __init__(self, opt: config.Config):
Dominik Woiwode's avatar
Dominik Woiwode committed
11
        super().__init__(screenName="ProtokollHelper")
12
13
        self.opt = opt
        self.rootPad = pter.PadCollection(pter.CodiMD(self.opt.PAD_COLLECTION_URL))
Dominik Woiwode's avatar
Dominik Woiwode committed
14
15
16

        self.folders = dict()
        self.folderIndex = 0
Dominik Woiwode's avatar
Dominik Woiwode committed
17
18
        self.folders = self.rootPad.getPads()
        self.currentPads = list()
Dominik Woiwode's avatar
Dominik Woiwode committed
19
20
21
22

        self.topRow = tk.Frame(self)
        self.topRow.pack(fill=tk.X, expand=True)
        self.folderLabel = tk.Label(self.topRow)
23
24
        self.leftButton = tk.Button(self.topRow, text="<", state=tk.DISABLED, command=self.updateFolderIndex(-1))
        self.rightButton = tk.Button(self.topRow, text=">", command=self.updateFolderIndex(1))
Dominik Woiwode's avatar
Dominik Woiwode committed
25
26
27
28
29
30
31
32
33
34
35

        self.leftButton.pack(side=tk.LEFT)
        self.folderLabel.pack(side=tk.LEFT, fill=tk.X, expand=True)
        self.rightButton.pack(side=tk.LEFT)

        self.padFrame = tk.Frame(self)
        self.padFrame.pack()

        self.updatePadFrame()

    def updateFolderIndex(self, i):
36
        @wraps(self.updateFolderIndex)
Jakob Marten's avatar
Jakob Marten committed
37
        def wrapper(*args, **kwargs):
Dominik Woiwode's avatar
Dominik Woiwode committed
38
39
            self.folderIndex = (self.folderIndex + i) % len(self.folders)
            self.updatePadFrame()
Dominik Woiwode's avatar
Dominik Woiwode committed
40

Dominik Woiwode's avatar
Dominik Woiwode committed
41
42
43
44
45
        return wrapper

    def updatePadFrame(self):
        folderName = list(self.folders.keys())[self.folderIndex]
        self.folderLabel.configure(text=folderName)
46
        self.currentPads = [p for p in self.folders[folderName] if isinstance(p, pter.ProtocolPad)]
Dominik Woiwode's avatar
Dominik Woiwode committed
47
        for i, pad in enumerate(self.currentPads):
Dominik Woiwode's avatar
Dominik Woiwode committed
48
            assert isinstance(pad, pter.ProtocolPad)
49
50
51
            tk.Label(self.padFrame, text=pad.source.url, anchor=tk.W, bg="red").grid(row=i, column=0,
                                                                                     sticky=tk.W)  # URL
            tk.Label(self.padFrame, text=pad.date, anchor=tk.W, bg="blue").grid(row=i, column=1)  # Date
Dominik Woiwode's avatar
Dominik Woiwode committed
52
            # Button Download
53
            btnDownload = tk.Button(self.padFrame, text="Download", command=pad.download)
Dominik Woiwode's avatar
Dominik Woiwode committed
54
55
56
            btnDownload.grid(row=i, column=2)

            # Button Compile
57
            btnCompile = tk.Button(self.padFrame, text="Compile", command=pad.compile)
Dominik Woiwode's avatar
Dominik Woiwode committed
58
59
60
            btnCompile.grid(row=i, column=3)

            # Button Mail FR
61
            btnMailFR = tk.Button(self.padFrame, text="Vorläufige FR-Mail", command=pad.sendMailAsPreliminary)
Dominik Woiwode's avatar
Dominik Woiwode committed
62
63
64
            btnMailFR.grid(row=i, column=4)

            # Button Mail FR-Info
65
66
            btnMailFRInfo = tk.Button(self.padFrame, text="FR-Info Mail", state=tk.DISABLED,
                                      command=pad.sendMailAsApproved)
Dominik Woiwode's avatar
Dominik Woiwode committed
67
68
69
            btnMailFRInfo.grid(row=i, column=5)

            # Button Website
70
            btnWebsite = tk.Button(self.padFrame, text="Approved Website", state=tk.DISABLED, command=pad.uploadToGrav)
Dominik Woiwode's avatar
Dominik Woiwode committed
71
72
73
            btnWebsite.grid(row=i, column=6)

            # Button Cloud
74
            btnCloud = tk.Button(self.padFrame, text="Approved Cloud", state=tk.DISABLED, command=pad.uploadToCloud)
Dominik Woiwode's avatar
Dominik Woiwode committed
75
76
77
78
            btnCloud.grid(row=i, column=7)


if __name__ == '__main__':
79
80
    pter.opt.GREMIUM = pterClasses.GREMIUM_FR
    gui = ProtokollGUI(pter.opt)
Dominik Woiwode's avatar
Dominik Woiwode committed
81
    gui.mainloop()