forked from ComputacaoNaEscola/Scratchduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratchduino_dialog.py
More file actions
128 lines (85 loc) · 3.11 KB
/
scratchduino_dialog.py
File metadata and controls
128 lines (85 loc) · 3.11 KB
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
# -*- coding: utf-8 -*-
__author__ = 'awangenh'
"""
@author: awangenh
Adaptations for usage with Scratchduino: Aldo von Wangenheim
Copyright (c) 2013-15 Iniciativa Computação na Escola
Adapted from http://effbot.org/tkinterbook
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from Tkinter import *
import os
class Dialog(Toplevel):
def __init__(self, parent, title = None, message = None):
Toplevel.__init__(self, parent)
self.transient(parent)
if title:
self.title(title)
if message:
self.message = message
else:
self.message = ''
self.parent = parent
self.result = None
body = Frame(self)
self.initial_focus = self.body(body)
body.pack(padx=5, pady=5)
self.buttonbox()
self.grab_set()
if not self.initial_focus:
self.initial_focus = self
self.protocol("WM_DELETE_WINDOW", self.cancel)
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
parent.winfo_rooty()+50))
self.initial_focus.focus_set()
self.wait_window(self)
#
# construction hooks
def body(self, master):
# create dialog body. return widget that should have
# initial focus. this method should be overridden
pass
def buttonbox(self):
# add standard button box. override if you don't want the
# standard buttons
box = Frame(self)
self.text = Text(master=self)
self.text.insert(END, self.message)
self.text.pack(side=TOP, pady=5, padx=5)
w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE)
w.pack(side=BOTTOM, pady=5, padx=5)
#w = Button(box, text="Cancel", width=10, command=self.cancel)
#w.pack(side=LEFT, padx=5, pady=5)
self.bind("<Return>", self.ok)
#self.bind("<Escape>", self.cancel)
box.pack()
#
# standard button semantics
def ok(self, event=None):
if not self.validate():
self.initial_focus.focus_set() # put focus back
return
self.withdraw()
self.update_idletasks()
self.apply()
self.cancel()
def cancel(self, event=None):
# put focus back to the parent window
self.parent.focus_set()
self.destroy()
#
# command hooks
def validate(self):
return 1 # override
def apply(self):
pass # override