-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-v13-question_dialog.py
More file actions
97 lines (75 loc) · 2.7 KB
/
app-v13-question_dialog.py
File metadata and controls
97 lines (75 loc) · 2.7 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
"""
Question Dialog
"""
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size=(600, 500))
self.SetMinSize(wx.Size(500, 400)) # ajusta tamanho minimo da janela
panel = MyPanel(self)
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
vbox = wx.BoxSizer(wx.VERTICAL)
widgetSizer = wx.BoxSizer(wx.VERTICAL)
widgetPanel = wx.Panel(self)
self.button = wx.Button(widgetPanel, label='Open Question Dialog')
self.Bind(wx.EVT_BUTTON, self.questionDialog, self.button)
self.button2 = wx.Button(widgetPanel, label='Open Confirmation Dialog')
self.Bind(wx.EVT_BUTTON, self.confirmationDialog, self.button2)
widgetSizer.Add(self.button)
widgetSizer.Add(self.button2, 0, wx.TOP, 20)
widgetPanel.SetSizer(widgetSizer)
vbox.Add(widgetPanel, 0, wx.ALL, 100)
self.SetSizer(vbox)
def questionDialog(self, event):
dialog = wx.MessageDialog(
# None,
self,
message='Are you sure you want to close?',
caption='Question',
style=wx.YES_NO | wx.ICON_QUESTION)
""" Opções para style:
Botões:
wx.YES_NO
wx.YES_DEFAULT
wx.NO_DEFAULT
wx.OK
wx.OK_DEFAULT
wx.CANCEL
wx.CANCEL_DEFAULT
wx.YES_NO | wx.CANCEL (com três botões)
Ícones:
wx.ICON_EXCLAMATION (exclamação)
wx.ICON_ERROR (erro)
wx.ICON_INFORMATION (informação)
wx.ICON_QUESTION (pergunta)
wx.ICON_WARNING (aviso)"""
result = dialog.ShowModal()
if result == wx.ID_YES:
print('Yes, close the app')
self.GetParent().Close(True)
else:
print('No, the app still open')
def confirmationDialog(self, event):
dialog = wx.MessageDialog(
# None,
self,
message='Do you want to proceed with this action?',
caption='Confirm Action',
style=wx.OK | wx.CANCEL | wx.ICON_EXCLAMATION)
result = dialog.ShowModal()
if result == wx.ID_OK:
print('Ok, close the app')
self.GetParent().Close(True)
else:
print('Cancel action')
class MyApp(wx.App):
def OnInit(self):
title = 'Question Dialog'
self.frame = MyFrame(parent=None, title=title)
self.frame.Show()
return True
if __name__ == '__main__':
app = MyApp()
app.MainLoop()