protokollGUI.py 3.32 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

Dominik Woiwode's avatar
Dominik Woiwode committed
4
5
6
7
import linkToPDF2 as pter


class ProtokollGUI(tk.Tk):
Jakob Marten's avatar
Jakob Marten committed
8
    def __init__(self, rootPad: pter.SourceTypes):
Dominik Woiwode's avatar
Dominik Woiwode committed
9
10
        super().__init__(screenName="ProtokollHelper")
        self.rootPad = pter.PadCollection(rootPad)
Jakob Marten's avatar
Jakob Marten committed
11
        # print(self.rootPad.getPads())
Dominik Woiwode's avatar
Dominik Woiwode committed
12
13
14

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

        self.topRow = tk.Frame(self)
        self.topRow.pack(fill=tk.X, expand=True)
        self.folderLabel = tk.Label(self.topRow)
Jakob Marten's avatar
Jakob Marten committed
21
22
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):
Jakob Marten's avatar
Jakob Marten committed
36
        def wrapper(*args, **kwargs):
Dominik Woiwode's avatar
Dominik Woiwode committed
37
38
            self.folderIndex = (self.folderIndex + i) % len(self.folders)
            self.updatePadFrame()
Dominik Woiwode's avatar
Dominik Woiwode committed
39

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

    def updatePadFrame(self):
        folderName = list(self.folders.keys())[self.folderIndex]
        self.folderLabel.configure(text=folderName)
Jakob Marten's avatar
Jakob Marten committed
45
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)
Jakob Marten's avatar
Jakob Marten committed
49
50
51
52
            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
53
            # Button Download
Jakob Marten's avatar
Jakob Marten committed
54
55
            btnDownload = tk.Button(
                self.padFrame, text="Download", command=pad.download)
Dominik Woiwode's avatar
Dominik Woiwode committed
56
57
58
            btnDownload.grid(row=i, column=2)

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

            # Button Mail FR
Jakob Marten's avatar
Jakob Marten committed
64
65
            btnMailFR = tk.Button(
                self.padFrame, text="Vorläufige FR-Mail", command=pad.sendMailAsUnapproved)
Dominik Woiwode's avatar
Dominik Woiwode committed
66
67
68
            btnMailFR.grid(row=i, column=4)

            # Button Mail FR-Info
Jakob Marten's avatar
Jakob Marten committed
69
70
            btnMailFRInfo = tk.Button(
                self.padFrame, text="FR-Info Mail", state=tk.DISABLED, command=pad.sendMailAsApproved)
Dominik Woiwode's avatar
Dominik Woiwode committed
71
72
73
            btnMailFRInfo.grid(row=i, column=5)

            # Button Website
Jakob Marten's avatar
Jakob Marten committed
74
75
            btnWebsite = tk.Button(
                self.padFrame, text="Approved Website", command=pad.uploadToGrav)
Dominik Woiwode's avatar
Dominik Woiwode committed
76
77
78
            btnWebsite.grid(row=i, column=6)

            # Button Cloud
Jakob Marten's avatar
Jakob Marten committed
79
80
            btnCloud = tk.Button(self.padFrame, text="Approved Cloud",
                                 state=tk.DISABLED, command=pad.uploadToCloud)
Dominik Woiwode's avatar
Dominik Woiwode committed
81
82
83
84
            btnCloud.grid(row=i, column=7)


if __name__ == '__main__':
Dominik Woiwode's avatar
Dominik Woiwode committed
85
    # gui = ProtokollGUI(pter.LocalCache("data/rootPad.md"))
Jakob Marten's avatar
Jakob Marten committed
86
87
88
89
    pter.DEFAULT_GREMIUM = pter.GREMIUM_FR
    pter.initGit()
    gui = ProtokollGUI(pter.CodiMD(
        "https://pad.finf.uni-hannover.de/protokolllinks_terces"))
Dominik Woiwode's avatar
Dominik Woiwode committed
90
    gui.mainloop()