|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # See COPYING file for copyrights details. |
|
5 |
|
6 from __future__ import absolute_import |
|
7 import wx |
|
8 |
|
9 # class RichMessageDialog is still not available in wxPython 3.0.2 |
|
10 class IDMergeDialog(wx.Dialog): |
|
11 def __init__(self, parent, title, question, optiontext, button_texts): |
|
12 wx.Dialog.__init__(self, parent, title=title) |
|
13 |
|
14 main_sizer = wx.BoxSizer(wx.VERTICAL) |
|
15 |
|
16 message = wx.StaticText(self, label=question) |
|
17 main_sizer.AddWindow(message, border=20, |
|
18 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.LEFT | wx.RIGHT) |
|
19 |
|
20 self.check = wx.CheckBox(self, label=optiontext) |
|
21 main_sizer.AddWindow(self.check, border=20, |
|
22 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL) |
|
23 |
|
24 buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
25 for label,wxID in zip(button_texts, [wx.ID_YES, wx.ID_NO, wx.ID_CANCEL]): |
|
26 Button = wx.Button(self, label=label) |
|
27 def OnButtonFactory(_wxID): |
|
28 return lambda event: self.EndModal(_wxID) |
|
29 self.Bind(wx.EVT_BUTTON, OnButtonFactory(wxID), Button) |
|
30 buttons_sizer.AddWindow(Button) |
|
31 |
|
32 main_sizer.AddSizer(buttons_sizer, border=20, |
|
33 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT) |
|
34 |
|
35 self.SetSizer(main_sizer) |
|
36 self.Fit() |
|
37 |
|
38 self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey) |
|
39 |
|
40 def OnEscapeKey(self, event): |
|
41 keycode = event.GetKeyCode() |
|
42 if keycode == wx.WXK_ESCAPE: |
|
43 self.EndModal(wx.ID_CANCEL) |
|
44 else: |
|
45 event.Skip() |
|
46 |
|
47 def OptionChecked(self): |
|
48 return self.check.GetValue() |