-
Notifications
You must be signed in to change notification settings - Fork 3
/
dialogs.py
77 lines (60 loc) · 2.24 KB
/
dialogs.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
from functools import partial
from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import asksaveasfilename
from utils import openfile, openfolder
root = Tk()
root.wm_attributes('-topmost', 1)
root.withdraw()
saveas_dialog = partial(asksaveasfilename, parent=root)
class DownloadCompleteDialog(object):
def __init__(self, url=None, path=None, message=None):
self._dialog = Toplevel()
self._url = url
self._path = path
self._message = message
self._set_properties()
self._add_url()
self._add_path()
self._add_message()
self._add_buttons()
self._show()
def _set_properties(self):
self._dialog.geometry('500x276+730+360')
self._dialog.title('Download completed')
self._dialog.resizable(0, 0)
self._dialog.bind('<Escape>', self._close)
def _add_url(self):
url = LabelFrame(self._dialog, text='URL')
url.pack(fill=X, padx=10, pady=10)
Label(url, text=self._url).pack(side=LEFT)
def _add_path(self):
path = LabelFrame(self._dialog, text='Path')
path.pack(fill=X, padx=10, pady=10)
Label(path, text=self._path).pack(side=LEFT)
def _add_message(self):
message = Frame(self._dialog)
message.pack(fill=X, padx=5, pady=10)
Message(message, text=self._message, width=10**6).pack(side=LEFT)
def _add_buttons(self):
buttons = Frame(self._dialog)
buttons.pack(fill=X, pady=10)
open_button = Button(buttons, text='Open', command=self._open)
open_button.pack(ipadx=10, padx=10, side=LEFT)
open_folder_button = Button(
buttons, text='Open folder', command=self._open_folder)
open_folder_button.pack(ipadx=10, side=LEFT)
close_button = Button(buttons, text='Close', command=self._close)
close_button.pack(ipadx=10, padx=10, side=RIGHT)
def _open(self):
openfile(self._path)
self._close()
def _open_folder(self):
openfolder(self._path)
self._close()
def _close(self, event=None):
self._dialog.destroy()
def _show(self):
self._dialog.wm_attributes('-topmost', 1)
self._dialog.focus_force()
self._dialog.wait_window()