Commit 39fe6b7853d9010d0f55173cc9e208c5f219936e
1 parent
fe298718
Exists in
master
and in
68 other branches
ADD: Dialogs class
Showing
2 changed files
with
60 additions
and
0 deletions
Show diff stats
.gitattributes
@@ -113,6 +113,7 @@ invesalius/gui/__init__.py -text | @@ -113,6 +113,7 @@ invesalius/gui/__init__.py -text | ||
113 | invesalius/gui/data_notebook.py -text | 113 | invesalius/gui/data_notebook.py -text |
114 | invesalius/gui/default_tasks.py -text | 114 | invesalius/gui/default_tasks.py -text |
115 | invesalius/gui/default_viewers.py -text | 115 | invesalius/gui/default_viewers.py -text |
116 | +invesalius/gui/dialogs.py -text | ||
116 | invesalius/gui/frame.py -text | 117 | invesalius/gui/frame.py -text |
117 | invesalius/gui/import_data_wizard.py -text | 118 | invesalius/gui/import_data_wizard.py -text |
118 | invesalius/gui/import_panel.py -text | 119 | invesalius/gui/import_panel.py -text |
@@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
1 | +import wx | ||
2 | +from wx.lib import masked | ||
3 | + | ||
4 | +class NumberDialog(wx.Dialog): | ||
5 | + def __init__(self, message, value=0): | ||
6 | + pre = wx.PreDialog() | ||
7 | + pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize, pos=wx.DefaultPosition, | ||
8 | + style=wx.DEFAULT_DIALOG_STYLE) | ||
9 | + self.PostCreate(pre) | ||
10 | + | ||
11 | + # Static text which contains message to user | ||
12 | + print "message: ", message | ||
13 | + label = wx.StaticText(self, -1, message) | ||
14 | + | ||
15 | + # Numeric value to be changed by user | ||
16 | + num_ctrl = masked.NumCtrl(self, value=value, integerWidth=3, | ||
17 | + fractionWidth=2, allowNegative=True) | ||
18 | + self.num_ctrl = num_ctrl | ||
19 | + | ||
20 | + # Buttons | ||
21 | + btn_ok = wx.Button(self, wx.ID_OK) | ||
22 | + btn_ok.SetHelpText("Above value will be applied.") | ||
23 | + btn_ok.SetDefault() | ||
24 | + | ||
25 | + btn_cancel = wx.Button(self, wx.ID_CANCEL) | ||
26 | + btn_cancel.SetHelpText("Value will not be applied.)") | ||
27 | + | ||
28 | + btnsizer = wx.StdDialogButtonSizer() | ||
29 | + btnsizer.AddButton(btn_ok) | ||
30 | + btnsizer.AddButton(btn_cancel) | ||
31 | + btnsizer.Realize() | ||
32 | + | ||
33 | + | ||
34 | + sizer = wx.BoxSizer(wx.VERTICAL) | ||
35 | + sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) | ||
36 | + sizer.Add(num_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5) | ||
37 | + sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) | ||
38 | + | ||
39 | + self.SetSizer(sizer) | ||
40 | + sizer.Fit(self) | ||
41 | + | ||
42 | + self.Centre() | ||
43 | + | ||
44 | + def SetValue(self, value): | ||
45 | + self.num_ctrl.SetValue(value) | ||
46 | + | ||
47 | + def GetValue(self): | ||
48 | + return self.num_ctrl.GetValue() | ||
49 | + | ||
50 | +def ShowNumberDialog(message, value=0): | ||
51 | + dlg = NumberDialog(message, value) | ||
52 | + dlg.SetValue(value) | ||
53 | + | ||
54 | + if dlg.ShowModal() == wx.ID_OK: | ||
55 | + return dlg.GetValue() | ||
56 | + dlg.Destroy() | ||
57 | + | ||
58 | + return 0 | ||
59 | + |