def __init__(self, ac_ids, settings_names): arduino_dangerboard.__init__(self) self.last_values = [0] * self.SLIDER_COUNT self.ac_settings = IvySettingsInterface(ac_ids) self.settings = [] for name in settings_names: self.settings.append(self.ac_settings.name_lookup[name])
def __init__(self, ac_ids, settings_names, port): arduino_dangerboard.__init__(self, port) if (len(settings_names) > self.SLIDER_COUNT): raise Exception("Number of settings greater than number of sliders") if (len(ac_ids) < 1): raise Exception("Need at least one ac_id") self.last_values = [0] * len(settings_names) self.ac_settings = IvySettingsInterface(ac_ids) self.settings = [] for name in settings_names: self.settings.append(self.ac_settings.name_lookup[name])
def __init__(self, parent, ac_ids): self.settings = IvySettingsInterface(ac_ids) title = "Settings %s (%s)" % (ac_ids, self.settings.GetACName()) wx.Frame.__init__(self, name=u'SettingsFrame', parent=parent, title=title, size=(480, 320)) self.book = wx.Notebook(self) self.updates = [] self.Bind(wx.EVT_CLOSE, self.OnClose) for setting_group in self.settings.groups: page = wx.Panel(self.book) vert_box = wx.BoxSizer(orient=wx.VERTICAL) for setting in setting_group.member_list: horz_box = wx.BoxSizer(orient=wx.HORIZONTAL) text = wx.StaticText(page, label=setting.shortname, size=(100, 30)) # Edit edit = TextCtrlSetting(page, setting) edit.RegisterUpdateCallback(self.editUpdate) self.edits.append(edit) # Slider slider = SettingCtrl(page, setting) slider.RegisterUpdateCallback(self.updateEditFromSlider) self.sliders.append(slider) # Button button = wx.Button(page, id=setting.index + BUTTON_ID_OFFSET, label="Apply") self.Bind(wx.EVT_BUTTON, self.onButton) horz_box.AddWindow(text) horz_box.AddWindow(edit) horz_box.AddWindow(slider) horz_box.AddWindow(button) vert_box.AddWindow(horz_box) page.SetSizer(vert_box) self.book.AddPage(page, setting_group.name) self.settings.RegisterCallback(self.onUpdate)
class IvyStick(arduino_dangerboard): def __init__(self, ac_ids, settings_names): arduino_dangerboard.__init__(self) self.last_values = [0] * self.SLIDER_COUNT self.ac_settings = IvySettingsInterface(ac_ids) self.settings = [] for name in settings_names: self.settings.append(self.ac_settings.name_lookup[name]) def ScalePot(self, pot_value, min_value, max_value, step_size): scale_factor = (max_value - min_value) / (POT_MAX - POT_MIN) offset = (POT_MIN - min_value) / scale_factor return int((pot_value - offset) * scale_factor / step_size) * step_size def HandleEvent(self): for setting_index in range(0, self.SLIDER_COUNT): value = self.ScalePot(self.sliders[setting_index], self.settings[setting_index].min_value, self.settings[setting_index].max_value, self.settings[setting_index].step) # keep track of last value and only send a value # if the value has changed since last update if (value != self.last_values[setting_index]): self.settings[setting_index].value = value self.ac_settings.SendSetting( self.settings[setting_index].index) self.last_values[setting_index] = value
class SettingsFrame(wx.Frame): edits = [] sliders = [] def __init__(self, parent, ac_ids): self.settings = IvySettingsInterface(ac_ids) title = "Settings %s (%s)" % (ac_ids, self.settings.GetACName()) wx.Frame.__init__(self, name=u'SettingsFrame', parent=parent, title=title, size=(480, 320)) self.book = wx.Notebook(self) self.updates = [] self.Bind( wx.EVT_CLOSE, self.OnClose) for setting_group in self.settings.groups: page = wx.Panel(self.book) vert_box = wx.BoxSizer(orient=wx.VERTICAL) for setting in setting_group.member_list: horz_box = wx.BoxSizer(orient=wx.HORIZONTAL) text = wx.StaticText(page, label=setting.shortname, size=(100,30)) # Edit edit = TextCtrlSetting(page, setting) edit.RegisterUpdateCallback(self.editUpdate) self.edits.append(edit) # Slider slider = SettingCtrl(page, setting) slider.RegisterUpdateCallback(self.updateEditFromSlider) self.sliders.append(slider) # Button button = wx.Button(page, id=setting.index + BUTTON_ID_OFFSET, label="Apply") self.Bind(wx.EVT_BUTTON, self.onButton) horz_box.AddWindow(text) horz_box.AddWindow(edit) horz_box.AddWindow(slider) horz_box.AddWindow(button) vert_box.AddWindow(horz_box) page.SetSizer(vert_box) self.book.AddPage(page, setting_group.name) self.settings.RegisterCallback(self.onUpdate) # Copy slider value into associated edit box def updateEditFromSlider(self, index, value): self.edits[index].ChangeValue(str(value)) self.edits[index].setBold(True) # Called on edit box update def editUpdate(self, index, value): self.sliders[index].SetSettingValue(value) self.edits[index].setBold(True) # Called on button push def onButton(self, event): button = event.GetEventObject() index = int(button.GetId()) if index >= BUTTON_ID_OFFSET: index = index - BUTTON_ID_OFFSET self.settings.lookup[index].value = self.sliders[index].GetSettingValue() self.settings.SendSetting(index) # Called for remote settings updates def onUpdate(self, index, value, fromRemote): # Schedule the call for later via wx (run after events) # to prevent crashy crashy wx.CallAfter(self.update_value, index, value, fromRemote) # Called to update GUI with new values def update_value(self, index, value, fromRemote): editCtrl = self.edits[index] if fromRemote and editCtrl.FindFocus() == editCtrl: # don't process remote updates if the control is focused return editCtrl.SetSettingValue(value) editCtrl.setBold(not fromRemote) self.sliders[index].SetSettingValue(value) def OnClose(self, event): # need to forward close to canvas so that ivy is shut down, otherwise ivy hangs the shutdown self.settings.OnClose() self.Destroy()