-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
131 lines (100 loc) · 4.78 KB
/
gui.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
PyBackup - A simple personal backup utility
Copyright (C) 2023 Robert T. Fowler IV
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from tkinter import messagebox
from pathlib import Path
from backup import *
from config import *
import json
# TODO Add Log Window
class PyBackup:
def __init__(self,root):
root.title("PyBackup")
mnuMain = MainMenu(root)
root.config(menu=mnuMain)
Main = MainFrame(root)
class MainMenu(Menu):
def __init__(self,root):
Menu.__init__ (self,root)
mnuFile = Menu(self,tearoff=0)
self.add_cascade(label="File",menu=mnuFile)
mnuFile.add_command(label="Quit",command=root.quit)
mnuEdit = Menu(self,tearoff=0)
self.add_cascade(label="Edit",menu=mnuEdit)
mnuEdit.add_command(label="Preferences")
mnuHelp = Menu(self,tearoff=0)
self.add_cascade(label="Help",menu=mnuHelp)
mnuHelp.add_command(label="About")
class MainFrame(Frame):
def __init__(self,parent):
Frame.__init__ (self,parent)
global varSaveBackup
# Load list of saved backups
with open(varSavedBackups,"r",encoding="utf-8") as f:
saved_backups = json.load(f)
backups_list = list(saved_backups.keys())
def SelectSource():
varSource.set(filedialog.askdirectory(title = "Select Source Folder"))
def SelectDestination():
varDest.set(filedialog.askdirectory(title = "Select Destination Folder"))
def RunNow():
zip_backup(varSource.get(), varDest.get())
messagebox.showinfo("PyBackup","Backup complete.")
def SaveBackupPopup():
Popup = Toplevel(parent)
def SaveBackupName():
varSaveBackup = txtValue.get()
save_backup(varSource.get(),varDest.get(),varSaveBackup, cboSelectSaved)
Popup.destroy()
def Cancel():
Popup.destroy()
lblEntry = Label(Popup,text="Enter a name for this backup:",font=("Helvetica",10))
txtValue = Entry(Popup, font=("Helvetica",10))
btnOK = Button(Popup,text="OK",width=10,command=SaveBackupName)
btnCancel= Button(Popup,text="Cancel",width=10,command=Cancel)
lblEntry.grid(row=0,column=0,columnspan=2,padx=10,pady=5)
txtValue.grid(row=1,column=0,columnspan=2,padx=5,pady=5)
btnOK.grid(row=2,column=0,sticky=(W,E),padx=5,pady=5)
btnCancel.grid(row=2,column=1,sticky=(W,E),padx=5,pady=5)
def LoadBackup(e):
backup = load_backup(varSavedBackup.get())
varSource.set(backup['source'])
varDest.set(backup['dest'])
# create widgets
varSource=StringVar()
btnSource = Button(self,text="Select Source",command=SelectSource)
txtSource = Entry(self, textvariable=varSource,font=("Helvetica",10),width=30)
varDest=StringVar()
btnDest = Button(self,text="Select Destination",command=SelectDestination)
txtDest = Entry(self, textvariable=varDest,font=("Helvetica",10),width=50)
btnRunNow = Button(self,text="Run Now",command=RunNow)
btnSaveBackup = Button(self,text="Save Backup",command=SaveBackupPopup)
lblSelectSaved = Label(self,text="Select Saved Backup",font=("Helvetica",10))
varSavedBackup = StringVar()
cboSelectSaved = ttk.Combobox(self,textvariable=varSavedBackup,font=("Helvetica",10))
cboSelectSaved['values'] = backups_list
cboSelectSaved.bind("<<ComboboxSelected>>",LoadBackup)
# grid the widgets
btnSource.grid(row=0,column=0,sticky=(W),padx=5,pady=5)
txtSource.grid(row=1,column=0,sticky=(W,E),padx=5,pady=5,columnspan=2)
btnDest.grid(row=2,column=0,sticky=(W),padx=5,pady=5)
txtDest.grid(row=3,column=0,sticky=(W,E),padx=5,pady=5,columnspan=2)
btnRunNow.grid(row=4,column=0,padx=5,pady=5)
btnSaveBackup.grid(row=4,column=1,padx=5,pady=5)
lblSelectSaved.grid(row=5,column=0,padx=5,pady=5,columnspan=2)
cboSelectSaved.grid(row=6,column=0,padx=5,pady=5,columnspan=2)
self.grid(row=0,column=0,sticky=(W,E))