Rev 608 | Rev 612 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 608 | Rev 611 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | self.button_5 = wx.Button(self, wx.ID_CANCEL, "") |
40 | self.button_5 = wx.Button(self, wx.ID_CANCEL, "") |
41 | self.button_6 = wx.Button(self, wx.ID_OK, "") |
41 | self.button_6 = wx.Button(self, wx.ID_OK, "") |
Line 42... | Line 42... | ||
42 | 42 | ||
43 | self.__set_properties() |
43 | self.__set_properties() |
- | 44 | self.__do_layout() |
|
- | 45 | ||
44 | self.__do_layout() |
46 | self.Bind(wx.EVT_BUTTON, self.onOK, self.button_6) |
Line 45... | Line 47... | ||
45 | # end wxGlade |
47 | # end wxGlade |
46 | 48 | ||
47 | # The first argument that is passed to the constructor is the parent |
49 | # The first argument that is passed to the constructor is the parent |
- | 50 | self.settings = args[0].app.settings |
|
48 | settings = args[0].app.settings |
51 | # Add text-boxes for all settings |
49 | # Add text-boxes for all settings |
52 | self.tb = [] |
50 | self.grid_sizer_2.SetRows(len(settings)) |
53 | self.grid_sizer_2.SetRows(len(self.settings)) |
51 | for setting in settings.iteritems(): |
54 | for setting in self.settings.iteritems(): |
52 | lb = wx.StaticText(self, -1, setting[1].descr, style=wx.ALIGN_RIGHT) |
55 | lb = wx.StaticText(self, -1, setting[1].descr, style=wx.ALIGN_RIGHT) |
53 | tb = wx.TextCtrl(self, -1, str(setting[1].value)) |
56 | tb = wx.TextCtrl(self, -1, str(setting[1].value)) |
- | 57 | self.grid_sizer_2.Add(lb, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0) |
|
54 | self.grid_sizer_2.Add(lb, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0) |
58 | self.grid_sizer_2.Add(tb, 0, 0, 0) |
55 | self.grid_sizer_2.Add(tb, 0, 0, 0) |
59 | self.tb.append(tb) |
Line 56... | Line 60... | ||
56 | self.sizer_5.Fit(self) |
60 | self.sizer_5.Fit(self) |
57 | self.Layout() |
61 | self.Layout() |
Line 85... | Line 89... | ||
85 | # Store some of the items, we will need them later |
89 | # Store some of the items, we will need them later |
86 | self.grid_sizer_2 = grid_sizer_2 |
90 | self.grid_sizer_2 = grid_sizer_2 |
87 | self.sizer_5 = sizer_5 |
91 | self.sizer_5 = sizer_5 |
Line -... | Line 92... | ||
- | 92 | ||
- | 93 | ||
- | 94 | def onOK(self, event): # wxGlade: SettingsDialog.<event_handler> |
|
- | 95 | print "Updating parameters" |
|
- | 96 | try: |
|
- | 97 | i=0 |
|
- | 98 | for setting in self.settings.iteritems(): |
|
- | 99 | print setting[0], self.tb[i].GetValue() |
|
- | 100 | setting[1].set(self.tb[i].GetValue()) |
|
- | 101 | i += 1 |
|
- | 102 | event.Skip() |
|
88 | 103 | except: |
|
89 | 104 | wx.MessageBox("Invalid format for \"%s\" setting." % setting[1].descr) |
|
Line 90... | Line 105... | ||
90 | 105 | ||
91 | # end of class SettingsDialog |
106 | # end of class SettingsDialog |
Line 420... | Line 435... | ||
420 | dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200), |
435 | dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200), |
421 | #style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME, |
436 | #style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME, |
422 | style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX |
437 | style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX |
423 | ) |
438 | ) |
424 | dlg.CenterOnScreen() |
439 | dlg.CenterOnScreen() |
425 | - | ||
426 | # this does not return until the dialog is closed. |
440 | val = dlg.ShowModal() # this does not return until the dialog is closed. |
427 | val = dlg.ShowModal() |
- | |
428 | - | ||
429 | dlg.Destroy() |
441 | dlg.Destroy() |
- | 442 | self.app.onSettingsChanged() |
|
Line 430... | Line 443... | ||
430 | 443 | ||
Line 431... | Line 444... | ||
431 | # end of class MainFrame |
444 | # end of class MainFrame |
432 | 445 | ||
433 | class Setting: |
446 | class Setting: |
434 | def __init__(self, descr, defaultValue): |
447 | def __init__(self, descr, defaultValue): |
- | 448 | self.descr = descr |
|
- | 449 | self.value = defaultValue |
|
- | 450 | ||
- | 451 | def set(self, newValue): |
|
- | 452 | if isinstance(self.value, int): |
|
- | 453 | self.value = int(newValue) |
|
Line 435... | Line 454... | ||
435 | self.descr = descr |
454 | else: |
436 | self.value = defaultValue |
455 | self.value = str(newValue) |
437 | 456 | ||
438 | class VibTest: |
457 | class VibTest: |
Line 495... | Line 514... | ||
495 | self.VibTests = [] |
514 | self.VibTests = [] |
496 | wx.App.__init__(self, par) |
515 | wx.App.__init__(self, par) |
Line 497... | Line 516... | ||
497 | 516 | ||
498 | # Init settings |
517 | # Init settings |
499 | self.settings={} |
518 | self.settings={} |
500 | self.settings["serialPort"] = Setting("SerialPort", "COM1") |
519 | self.settings["serialport"] = Setting("Serial Port", "COM1") |
501 | self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50) |
520 | self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50) |
Line 502... | Line 521... | ||
502 | self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400) |
521 | self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400) |
Line 532... | Line 551... | ||
532 | 551 | ||
533 | file = open(App.SETTINGSFILE, "w") |
552 | file = open(App.SETTINGSFILE, "w") |
534 | cp.write(file) |
553 | cp.write(file) |
Line -... | Line 554... | ||
- | 554 | file.close() |
|
- | 555 | ||
- | 556 | ||
- | 557 | def onSettingsChanged(self): |
|
- | 558 | self.storeSettings() |
|
535 | file.close() |
559 | |
536 | 560 | ||
537 | def AddTest(self, descr, motor, speed, channel, rawData): |
561 | def AddTest(self, descr, motor, speed, channel, rawData): |
538 | test = VibTest(descr, motor, speed, channel, rawData) |
562 | test = VibTest(descr, motor, speed, channel, rawData) |