3 This handles the TkInter GUI for making backups of projects.
4 It also handles it properly if the current machine isn't
5 capable of running TkInter.
14 from tkinter
import filedialog
16 print("Skipping importing tkinter, because it's not installed.")
20 def configure_backup(export_path
):
22 Opens a GUI in which the user can select where the backup is saved.
24 # Return the default export_path if no GUI can be made.
28 iconfile
= "editor_icon16.ico"
29 if not hasattr(sys
, "frozen"):
30 iconfile
= os
.path
.join(os
.path
.dirname(__file__
), iconfile
)
32 iconfile
= os
.path
.join(sys
.prefix
, iconfile
)
35 root
.iconbitmap(iconfile
)
36 app
= CryConfigureBackup(export_path
=export_path
, master
=root
)
39 path
= app
.export_path
44 def center_window(win
):
48 win
.update_idletasks()
49 width
= win
.winfo_width()
50 height
= win
.winfo_height()
51 position_x
= (win
.winfo_screenwidth() // 2) - (width
// 2)
52 position_y
= (win
.winfo_screenheight() // 2) - (height
// 2)
53 win
.geometry('{}x{}+{}+{}'.format(width
, height
, position_x
, position_y
))
57 class CryConfigureBackup(tk
.Frame
):
59 TK class that handles the window to configure the backup.
63 def __init__(self
, export_path
=None, master
=None):
64 super().__init
__(master
)
66 self
.parent
.title("CRYENGINE backup project")
67 self
.parent
.minsize(400, 100)
68 self
.pack(expand
=True, fill
=tk
.BOTH
)
69 center_window(self
.parent
)
70 self
.create_widgets(export_path
)
72 def create_widgets(self
, export_path
):
74 Sets up the main window.
76 # Export path browse dialog
77 self
.browse_frame
= tk
.Frame(self
)
78 self
.browse_frame
.pack(
79 side
='top', fill
=tk
.BOTH
, expand
=True, padx
=5, pady
=5)
81 tk
.Label(self
.browse_frame
, text
="Backup location:").pack()
83 self
.browse_button
= tk
.Button(
84 self
.browse_frame
, text
="...", width
=3,
85 command
=self
.browse_cmd
)
86 self
.browse_button
.pack(side
="right", padx
=2)
88 self
.path_value
= tk
.StringVar()
89 self
.path_value
.set(export_path
)
90 self
.dir_box
= tk
.Entry(
91 self
.browse_frame
, textvariable
=self
.path_value
)
92 self
.dir_box
.pack(fill
=tk
.X
, expand
=True, side
="right", padx
=2)
95 self
.confirm
= tk
.Button(self
)
96 self
.confirm
["text"] = "Confirm"
97 self
.confirm
["command"] = self
.confirm_cmd
98 self
.confirm
.pack(padx
=5, pady
=5)
100 def confirm_cmd(self
):
102 Called when the select button is pressed.
104 self
.export_path
= self
.path_value
.get()
107 def browse_cmd(self
):
109 Called when the browse button is pressed.
111 folder
= filedialog
.askdirectory(mustexist
=False)
113 self
.path_value
.set(folder
)
119 self
.parent
.destroy()