-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_download.py
87 lines (70 loc) · 3.42 KB
/
gui_download.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
import tkFileDialog
import tkMessageBox
from Tkinter import *
from messages import Msg
class DownloadGui(Toplevel):
def __init__(self, parent, controller, folders_dictionary):
Toplevel.__init__(self, parent)
self.controller = controller
self.download_path=""
self.location_value = ""
self.transient(parent)
self.parent = parent
body = Frame(self)
self.create_window()
self.galleries_dictionary = folders_dictionary
self.galleries_list = folders_dictionary.keys()
self.create_body(body, self.galleries_list)
body.pack()
self.wait_window(self)
def create_window(self):
self.grab_set()
self.title("Download Gallery")
self.geometry("340x212")
self.resizable(width=False, height=False)
self.iconbitmap('images/icon.ico')
self.protocol('WM_DELETE_WINDOW', lambda: self.exit_action())
def create_body(self, body, folders_list):
frame = LabelFrame(body, text="Download Gallery:")
frame.pack(side=TOP, fill=BOTH, pady=5, padx=5)
frame_buttons = Frame(frame)
frame_gallery = Frame(frame)
frame_location = Frame(frame)
label_info = Label(frame, justify=LEFT, wraplength=320, text=Msg.dialog_download_explanation)
label_gallery = Label(frame_gallery, text="Choose gallery:")
label_location = Label(frame_location, text="Download loc:")
gallery_chosen = StringVar(frame)
gallery_chosen.set(folders_list[0])
cloud_value = apply(OptionMenu, (frame_gallery, gallery_chosen) + tuple(folders_list))
self.location_value = Entry(frame_location, width=30)
button_ok = Button(frame_buttons, text="Download", width=17, height=1 ,command=lambda: self.prepare_download(gallery_chosen))
button_cancel = Button(frame_buttons, text="Cancel", width=12, height=1 ,command=lambda: self.exit_action())
button_location = Button(frame_location, text="...", width=2, height=1, command=lambda: self.choose_location())
cloud_value.configure(width=30)
cloud_value.configure(justify=LEFT)
cloud_value.configure(anchor=W)
label_info.grid(row=0, column=0, padx=5, columnspan=2)
frame_gallery.grid(row=1, column=0, sticky=W, columnspan=2, pady=(15, 5))
label_gallery.pack(side=LEFT, anchor=W, padx=4)
cloud_value.pack(side=LEFT, anchor=W)
frame_location.grid(row=2, column=0, sticky=W, columnspan=2, pady=10)
label_location.pack(side=LEFT, anchor=W, padx=5)
self.location_value.pack(side=LEFT, anchor=W, padx=5)
button_location.pack(side=LEFT, anchor=W, padx=8)
frame_buttons.grid(row=3, column=0, sticky=E, columnspan=2, pady=(10,15))
button_ok.pack(side=RIGHT, anchor=E, padx=8)
button_cancel.pack(side=RIGHT, anchor=E, padx=8)
def choose_location(self):
options = {}
self.download_path = tkFileDialog.askdirectory(**options)
self.location_value.insert(10,self.download_path)
def exit_action(self):
self.destroy()
def prepare_download(self, gallery_chosen):
if self.download_path == "":
tkMessageBox.showerror(Msg.location_missing_title, Msg.location_missing_message)
return
key = gallery_chosen.get()
value = self.galleries_dictionary[key]
self.destroy()
self.controller.download_action(value, key, self.download_path)