[f3d51f6] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | # version |
---|
| 4 | __id__ = "$Id: aboutdialog.py 1193 2007-05-03 17:29:59Z dmitriy $" |
---|
| 5 | __revision__ = "$Revision: 1193 $" |
---|
| 6 | |
---|
| 7 | import wx |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | class ParsDialog(wx.Dialog): |
---|
| 11 | """ |
---|
| 12 | Dialog box to let the user edit detector settings |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | def __init__(self, *args, **kwds): |
---|
| 16 | |
---|
| 17 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
| 18 | wx.Dialog.__init__(self, *args, **kwds) |
---|
| 19 | |
---|
| 20 | self.label_nfunc = wx.StaticText(self, -1, "Number of terms") |
---|
| 21 | self.label_alpha = wx.StaticText(self, -1, "Regularization constant") |
---|
| 22 | self.label_dmax = wx.StaticText(self, -1, "Max distance [A]") |
---|
| 23 | self.label_file = wx.StaticText(self, -1, "Input file") |
---|
| 24 | |
---|
| 25 | # Npts, q max |
---|
| 26 | self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20)) |
---|
| 27 | self.alpha_ctl = wx.TextCtrl(self, -1, size=(60,20)) |
---|
| 28 | self.dmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) |
---|
| 29 | self.file_ctl = wx.TextCtrl(self, -1, size=(120,20)) |
---|
| 30 | |
---|
| 31 | self.static_line_3 = wx.StaticLine(self, -1) |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | self.button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
| 35 | self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_OK) |
---|
| 36 | |
---|
| 37 | self.button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
| 38 | |
---|
| 39 | self.button_load = wx.Button(self, 1, "Choose file") |
---|
| 40 | self.Bind(wx.EVT_BUTTON, self._load_file, id = 1) |
---|
| 41 | |
---|
| 42 | self.__set_properties() |
---|
| 43 | self.__do_layout() |
---|
| 44 | |
---|
| 45 | self.Fit() |
---|
| 46 | |
---|
| 47 | def _load_file(self, evt): |
---|
| 48 | import os |
---|
| 49 | path = None |
---|
| 50 | dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt", wx.OPEN) |
---|
| 51 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 52 | path = dlg.GetPath() |
---|
| 53 | mypath = os.path.basename(path) |
---|
| 54 | dlg.Destroy() |
---|
| 55 | |
---|
| 56 | if path and os.path.isfile(path): |
---|
| 57 | self.file_ctl.SetValue(str(path)) |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | def checkValues(self, event): |
---|
| 61 | flag = True |
---|
| 62 | try: |
---|
| 63 | float(self.alpha_ctl.GetValue()) |
---|
| 64 | self.alpha_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 65 | self.alpha_ctl.Refresh() |
---|
| 66 | except: |
---|
| 67 | flag = False |
---|
| 68 | self.alpha_ctl.SetBackgroundColour("pink") |
---|
| 69 | self.alpha_ctl.Refresh() |
---|
| 70 | |
---|
| 71 | try: |
---|
| 72 | float(self.dmax_ctl.GetValue()) |
---|
| 73 | self.dmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 74 | self.dmax_ctl.Refresh() |
---|
| 75 | except: |
---|
| 76 | flag = False |
---|
| 77 | self.dmax_ctl.SetBackgroundColour("pink") |
---|
| 78 | self.dmax_ctl.Refresh() |
---|
| 79 | |
---|
| 80 | try: |
---|
| 81 | int(self.nfunc_ctl.GetValue()) |
---|
| 82 | self.nfunc_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 83 | self.nfunc_ctl.Refresh() |
---|
| 84 | except: |
---|
| 85 | flag = False |
---|
| 86 | self.nfunc_ctl.SetBackgroundColour("pink") |
---|
| 87 | self.nfunc_ctl.Refresh() |
---|
| 88 | |
---|
| 89 | if flag: |
---|
| 90 | event.Skip(True) |
---|
| 91 | |
---|
| 92 | def setContent(self, nfunc, alpha, dmax, file): |
---|
| 93 | self.nfunc_ctl.SetValue(str(nfunc)) |
---|
| 94 | self.alpha_ctl.SetValue(str(alpha)) |
---|
| 95 | self.dmax_ctl.SetValue(str(dmax)) |
---|
| 96 | self.file_ctl.SetValue(str(file)) |
---|
| 97 | |
---|
| 98 | def getContent(self): |
---|
| 99 | nfunc = int(self.nfunc_ctl.GetValue()) |
---|
| 100 | alpha = float(self.alpha_ctl.GetValue()) |
---|
| 101 | dmax = float(self.dmax_ctl.GetValue()) |
---|
| 102 | file = self.file_ctl.GetValue() |
---|
| 103 | return nfunc, alpha, dmax, file |
---|
| 104 | |
---|
| 105 | def __set_properties(self): |
---|
| 106 | self.SetTitle("P(r) inversion parameters") |
---|
| 107 | self.SetSize((600, 595)) |
---|
| 108 | |
---|
| 109 | def __do_layout(self): |
---|
| 110 | sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
| 111 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 112 | sizer_params = wx.GridBagSizer(5,5) |
---|
| 113 | |
---|
| 114 | iy = 0 |
---|
| 115 | sizer_params.Add(self.label_nfunc, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 116 | sizer_params.Add(self.nfunc_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 117 | iy += 1 |
---|
| 118 | sizer_params.Add(self.label_alpha, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 119 | sizer_params.Add(self.alpha_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 120 | iy += 1 |
---|
| 121 | sizer_params.Add(self.label_dmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 122 | sizer_params.Add(self.dmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 123 | iy += 1 |
---|
| 124 | sizer_params.Add(self.label_file, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 125 | sizer_params.Add(self.file_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 126 | |
---|
| 127 | sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) |
---|
| 128 | sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 132 | sizer_button.Add(self.button_load, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) |
---|
| 133 | sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) |
---|
| 134 | sizer_button.Add(self.button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) |
---|
| 138 | self.SetAutoLayout(True) |
---|
| 139 | self.SetSizer(sizer_main) |
---|
| 140 | self.Layout() |
---|
| 141 | self.Centre() |
---|
| 142 | # end wxGlade |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | # end of class DialogAbout |
---|
| 146 | |
---|
| 147 | ##### testing code ############################################################ |
---|
| 148 | class MyApp(wx.App): |
---|
| 149 | def OnInit(self): |
---|
| 150 | wx.InitAllImageHandlers() |
---|
| 151 | dialog = ParsDialog(None, -1, "") |
---|
| 152 | self.SetTopWindow(dialog) |
---|
| 153 | dialog.setContent(10, 0.05) |
---|
| 154 | nfunc, alpha = dialog.getContent() |
---|
| 155 | print nfunc, alpha |
---|
| 156 | dialog.Destroy() |
---|
| 157 | return 1 |
---|
| 158 | |
---|
| 159 | # end of class MyApp |
---|
| 160 | |
---|
| 161 | if __name__ == "__main__": |
---|
| 162 | app = MyApp(0) |
---|
| 163 | app.MainLoop() |
---|
| 164 | |
---|
| 165 | ##### end of testing code ##################################################### |
---|