def __init__(self, parent_win, event): BaseWidget.__init__(self, 'Edit frame', parent_win=parent_win) self.event = event self._widget = parent_win self.set_margin(5) self._applybtn = ControlButton('Apply', default=self.__apply_evt) self._label = ControlText('Label', default=event.title) self._begin = ControlNumber( 'Begin', default=event.begin, minimum=0, maximum=100000000000000, changed_event=self.__begin_changed_event ) self._end = ControlNumber( 'End', default=event.end, minimum=0, maximum=100000000000000, changed_event=self.__end_changed_event ) self._color = ControlButton(str(event.color.name()), default=self.__pick_color_evt) self._lock = ControlCheckBox('Locked', default=event.lock) self.formset = [ '_label', ('_begin', '_end'), ('_color', '_lock'), '_applybtn' ]
def __init__(self): """ This implements the Path edition functionality """ super(Module, self).__init__() self.toolbar.append( ControlButton('Import Git Repo', icon=conf.ANNOTATOR_ICON_IMPORTDB)) self.toolbar.append( ControlButton('Sync Git', icon=conf.ANNOTATOR_ICON_SYNC))
def __init__(self, timeline=None): super(GraphsEventsGenerator, self).__init__('Apply a function to the graph values', parent_win=timeline) self.setContentsMargins(10, 10, 10, 10) self._timeline = timeline # Definition of the forms fields self._graphs_list = ControlList('Graphs list (try double click)', readonly=False, select_entire_row=True) self._equation = ControlTextArea('Equation') self._graphname = ControlText('Graph name') self._genevts_btn = ControlButton('Generate graph') self._formset = [ ( ['_graphs_list'], '||', [ '_graphname', '_equation', '_genevts_btn', ] ), ] self._graphs_list.cell_double_clicked_event = self.__cell_double_clicked_evt self._graphs_list.readonly = True self._graphs_list.select_entire_row = True self._genevts_btn.value = self.__generage_events_evt
def __init__(self, control): super(ImportWindow, self).__init__('Import file', parent_win=control.parent) self.setContentsMargins(10, 10, 10, 10) self._timeline = control # Definition of the forms fields self._filetype = ControlCombo('Please select the type of file you would like to import:') self._importButton = ControlButton('Import') self._panel = ControlEmptyWidget('Panel') self._file = ControlFile('File to import') self._panel.value = self._file self._filetype.add_item('Events file', 0) self._filetype.add_item('Graph file', 1) self._filetype.add_item('Bonsai events file', 2) self._filetype.add_item('Bonsai events file (old format)', 3) self._formset = [ ('_filetype', ' '), '_panel', (' ', '_importButton'), ' ' ] self._filetype.changed_event = self.__fileTypeChanged self._importButton.value = self.__importData from pyforms_gui.dialogs.csv_parser import CsvParserDialog self._graphCsvParserDlg = CsvParserDialog(control) self._graphCsvParserDlg.xField.label = "Value column" self._graphCsvParserDlg.yField.hide() self._graphCsvParserDlg.zField.hide() self._graphCsvParserDlg.loadButton.hide() self._bonsai_import_dlg = BonsaiImportFileDlg()
def __init__(self, experiment=None): super(SetupWindowEmulator, self).__init__(experiment) self._emulator = ControlButton('Test protocol IO', default=self.__emulator_btn_evt, icon=conf.EMULATOR_LAUNCH_ICON, enabled=False) self._formset = [ '_name', '_board', '_task', '_emulator', '_detached', ('_run_task_btn', '_kill_task_btn'), ('_stoptrial_btn', '_pause_btn'), #'=', { 'Subjects': [ # '_allsubjects', '', '_add_subject', '_subjects_list', ], 'Variables': [ '_varspanel', ], } ]
def __init__(self, timeline=None): super(Graph2Event, self).__init__('Graph to event', parent_win=timeline) self.setContentsMargins(10, 10, 10, 10) self._timeline = timeline # Definition of the forms fields self._graphs_list = ControlList('Graphs list (try double click)') self._equation = ControlTextArea('Equation') self._eventname = ControlText('Event name', 'New event') self._rownumber = ControlNumber('Row number', 0, 0, 1000) self._mindiff = ControlNumber('Minimum of frames', 0, 0, 1000000) self._genevts_btn = ControlButton('Generate events') self._formset = [ (['_graphs_list'], '||', [ ('_eventname', '_rownumber', '_mindiff'), '_equation', '_genevts_btn', ]), ] self._graphs_list.cell_double_clicked_event = self.__cell_double_clicked_evt self._graphs_list.readonly = True self._graphs_list.select_entire_row = True self._genevts_btn.value = self.__generage_events_evt
def __init__(self, parent_win=None, win_flag=None): BaseWidget.__init__(self, 'Load sound panel', parent_win=parent_win, win_flag=win_flag) self._loaded = False self._filename = ControlText('Sound file', '') self._read_btn = ControlButton('Browse', default=self.__prompt_read_file_evt) self._wave_int = [] self.formset = [ ('_filename', '_read_btn') ] self.set_margin(10)
def __init__(self, parent_win, label, begin, end): BaseWidget.__init__(self, 'Edit frame', parent_win=parent_win) self.set_margin(5) self._label = ControlText('Label', default=label) self._begin = ControlNumber('Begin', default=begin, minimum=0, maximum=100000000000000) self._end = ControlNumber('End', default=end, minimum=0, maximum=100000000000000) self._applybtn = ControlButton('Apply') self.formset = ['_label', ('_begin', '_end'), '_applybtn'] self._begin.changed_event = self.__begin_changed_event self._end.changed_event = self.__end_changed_event
def __init__(self, timelineWidget=None, parent_win=None): super(GraphsProperties, self).__init__('Graphs properties', parent_win=parent_win) self.setContentsMargins(10, 10, 10, 10) self._mainwindow = parent_win self._timeline = timelineWidget #self.setMaximumWidth(300) # Definition of the forms fields self._graphs_list = ControlList('Graphs list') self._name = ControlText('Name') self._min_value = ControlNumber('Min', default=0, minimum=-sys.float_info.max, maximum=sys.float_info.max) self._max_value = ControlNumber('Max', default=0, minimum=-sys.float_info.max, maximum=sys.float_info.max) self._values_zoom = ControlSlider('Amplitude', default=100, minimum=60, maximum=400) self._values_top = ControlNumber('Bottom', default=0, minimum=-1000, maximum=1000) self._remove_graph_btn = ControlButton('Remove graph') self._value = ControlLabel() self._pickcolor = ControlButton('Pick color', default=self.__pickcolor_evt) self._graphs_list.readonly = True self._formset = [ (['_graphs_list', '_remove_graph_btn'], '||', [ ' ', '_name', ('_min_value', '_max_value', ' '), ('_values_top', '_pickcolor'), '_values_zoom', 'info:Choose one graph and move the mouse over \nthe timeline to visualize the coordenates.', '_value' ]), ] self._graphs_list.select_entire_row = True self._graphs_list.item_selection_changed_event = self.__graphs_list_selection_changed self._loaded = False self._current_selected_graph = None self._name.changed_event = self.__save_graphs_changes self._min_value.changed_event = self.__save_graphs_changes self._max_value.changed_event = self.__save_graphs_changes self._values_zoom.changed_event = self.__save_graphs_changes self._values_top.changed_event = self.__save_graphs_changes self._name.enabled = False self._min_value.enabled = False self._max_value.enabled = False self._values_zoom.enabled = False self._values_top.enabled = False self._remove_graph_btn.enabled = False self._pickcolor.enabled = False self._remove_graph_btn.value = self.__remove_chart
def __init__(self, parent_win=None, win_flag=None): BaseWidget.__init__(self, 'Sound Generation panel', parent_win=parent_win, win_flag=win_flag) self._generated = False self._save_file_checkbox = ControlCheckBox('Write sound to file', default=False, changed_event=self.__save_file_checkbox_evt) self._filename = ControlText('Sound filename', '', changed_event=self.__filename_changed_evt, enabled=False) self._saveas_btn = ControlButton('Save As...', default=self.__prompt_save_file_evt, enabled=False) self._freq_label = ControlLabel('Frequency (Hz)', style='margin-left:0') self._freq_left = ControlNumber('Left channel', default=1000, minimum=0, maximum=20000) self._freq_right = ControlNumber('Right channel', default=1000, minimum=0, maximum=20000) self._duration = ControlNumber('Duration (s)', default=1, minimum=0, maximum=10000, decimals=2) self._sample_rate = ControlCombo('Sample rate') self._sample_rate.add_item('96 KHz', SampleRate._96000HZ) self._sample_rate.add_item('192 KHz', SampleRate._192000HZ) self._create_window = ControlCheckBox('Create window', default=True, changed_event=self.__create_window_checkbox_evt) self._left_window_duration = ControlNumber(default=100, minimum=0, maximum=20000) self._right_window_duration = ControlNumber(default=100, minimum=0, maximum=20000) self._left_apply_window_start = ControlCheckBox(default=True) self._right_apply_window_start = ControlCheckBox(default=True) self._left_apply_window_end = ControlCheckBox(default=True) self._right_apply_window_end = ControlCheckBox(default=True) self._left_window_functions = ControlCombo('Left channel window') self._left_window_functions.add_item('Hanning', 'Hanning') self._left_window_functions.add_item('Hamming', 'Hamming') self._left_window_functions.add_item('Blackman', 'Blackman') self._left_window_functions.add_item('Bartlett', 'Bartlett') self._right_window_functions = ControlCombo('Right channel window') self._right_window_functions.add_item('Hanning', 'Hanning') self._right_window_functions.add_item('Hamming', 'Hamming') self._right_window_functions.add_item('Blackman', 'Blackman') self._right_window_functions.add_item('Bartlett', 'Bartlett') self._gen_btn = ControlButton('Generate sound', default=self.__generate_sound_and_save) self._wave_int = [] # Define the organization of the forms self.formset = [ ( ['_save_file_checkbox', ('_filename', '_saveas_btn'), ['_duration', '_sample_rate'], ('h5:Frequency', ['_freq_left', '_freq_right'])], ' ', ['_create_window', ('', 'Left channel', 'Right channel'), ('Duration (ms)', '_left_window_duration', '_right_window_duration'), ('Apply window to start', '_left_apply_window_start', '_right_apply_window_start'), ('Apply window to end', '_left_apply_window_end', '_right_apply_window_end'), '_left_window_functions', '_right_window_functions'] ), '_gen_btn' ] self.set_margin(10)
def __init__(self, parent_win=None): BaseWidget.__init__(self, self.TITLE, parent_win=parent_win) self._msg_duration = 3000 self._usb_port = ControlCombo('USB port', changed_event=self.__combo_usb_ports_changed_evt) self._refresh_usb_ports = ControlButton('', icon=QtGui.QIcon(conf.REFRESH_SMALL_ICON), default=self.__refresh_usb_ports_btn_pressed, helptext="Press here to refresh the list of available devices.") self._connect_btn = ControlButton('Connect', default=self.__connect_btn_pressed) # Send data self._send_btn = ControlButton('Send to sound card', default=self.__send_btn_pressed, enabled=False) self._index_to_send = ControlNumber('Index to send', default=2, minimum=2, maximum=32) self._user_metadata_send = ControlTextArea('User metadata (optional)') self._description_send = ControlTextArea('Description (optional)') self._send_panel = ControlEmptyWidget() self._send_panel.value = [self._index_to_send, self._user_metadata_send, self._description_send, self._send_btn] self._send_panel.setContentsMargins(10, 10, 10, 10) # Receive data self._index_to_read = ControlNumber('Index to read', default=2, minimum=2, maximum=32) self._read_all_checkbox = ControlCheckBox('Read all indexes', default=False, changed_event=self.__read_all_checkbox_evt) self._clear_folder_checkbox = ControlCheckBox('Clear destination folder', default=False) self._dest_folder = ControlText('Destination folder', '', changed_event=self.__folder_changed_evt) self._browse_btn = ControlButton('Browse', default=self.__prompt_browse_file_evt) self._read_btn = ControlButton('Read data', default=self.__read_btn_pressed, enabled=False) self._receive_panel = ControlEmptyWidget() self._receive_panel.value = [self._read_all_checkbox, self._index_to_read, self._clear_folder_checkbox, self._dest_folder, self._browse_btn, self._read_btn] self._receive_panel.setContentsMargins(10, 10, 10, 10) self._sound_generation = SoundGenerationPanel(parent_win=self) self._sound_generation.sound_generated = self._sound_generated_evt self._sound_gen_panel = ControlEmptyWidget() self._sound_gen_panel.value = self._sound_generation self._sound_load = LoadSoundPanel(parent_win=self) self._sound_load.sound_loaded = self._sound_loaded_evt self._sound_load_panel = ControlEmptyWidget() self._sound_load_panel.value = self._sound_load self._sound_card = SoundCardModule() self._wave_int = [] self.formset = [ ('_usb_port', '_refresh_usb_ports', '_connect_btn'), { 'a:Generate sound': ['_sound_gen_panel'], 'b:Load sound from disk': ['_sound_load_panel'], }, ' ', { 'a:Send data': ['_send_panel'], 'b:Receive data': ['_receive_panel'] } ] self._fill_usb_ports() self.set_margin(10) self._status_bar = QStatusBar(parent=self)
def __init__(self, parent_win=None): self.setup = parent_win self.started_correctly = False title = 'Emulator for setup: ' + self.setup.name BaseWidget.__init__(self, title, parent_win=parent_win) self.CHECKED_ICON = conf.EMULATOR_CHECKED_ICON self.UNCHECKED_ICON = conf.EMULATOR_UNCHECKED_ICON self._currentSetup = ControlLabel(self.setup.name) self._selectedBoard = ControlLabel(self.setup.board.name) self._selectedProtocol = ControlLabel(self.setup.task.name) self._run_task_btn = ControlButton('Run protocol', default=self.__run_protocol_btn_evt, checkable=True, helptext="When a task is running, you can skip all remaining trials by pressing this button. <br/> <b>NOTE:</b> This means that you will need to break the cycle in your task code when the run_state_machine method returns False.") self._kill_task_btn = ControlButton('Kill', default=self.__kill_btn_evt, style="background-color:rgb(255,0,0);font-weight:bold;", helptext="<b>NOTE:</b>This will exit the task process abruptly. The code you might have after the trial loop won't execute.") self._kill_task_btn.enabled = False self._stop_trial_btn = ControlButton('Skip trial', default=self.__stop_trial_btn_evt, enabled=False) self._pause_btn = ControlButton('Pause', default=self.__pause_btn_evt, checkable=True, enabled=False) try: bpod = Bpod(self.setup.board.serial_port) except SerialException: self.critical('No Bpod device connected, cannot continue until one is connected.', 'Bpod not connected') return except Exception: # NOTE: try again in case of the first connection attempt where we always get the utf-8 exception bpod = Bpod(self.setup.board.serial_port) number_ports = bpod.hardware.inputs.count('P') number_bnc = bpod.hardware.outputs.count('B') number_wire_in = bpod.hardware.inputs.count('W') number_wire_out = bpod.hardware.outputs.count('W') self._valve_buttons = [] self._valve_label = ControlLabel("Valve") self._led_buttons = [] self._led_label = ControlLabel("LED") self._poke_buttons = [] self._poke_label = ControlLabel("Poke") self._time_control = ControlText() # HH for n in range(1, number_ports + 1): btn_valve = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_led = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_poke = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_valve.value = make_lambda_func(self.__button_on_click_evt, btn=btn_valve) btn_led.value = make_lambda_func(self.__button_on_click_evt, btn=btn_led) btn_poke.value = make_lambda_func(self.__button_on_click_evt, btn=btn_poke) setattr(self, f'_btn_Valve{n}', btn_valve) setattr(self, f'_btn_PWM{n}', btn_led) setattr(self, f'_btn_Port{n}', btn_poke) self._valve_buttons.append(btn_valve) self._led_buttons.append(btn_led) self._poke_buttons.append(btn_poke) self._bnc_in_buttons = [] self._bnc_in_label = ControlLabel("BNC In") self._bnc_out_buttons = [] self._bnc_out_label = ControlLabel("BNC Out") for n in range(1, number_bnc + 1): btn_bnc_in = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_bnc_out = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_bnc_in.value = make_lambda_func(self.__button_on_click_evt, btn=btn_bnc_in) btn_bnc_out.value = make_lambda_func(self.__button_on_click_evt, btn=btn_bnc_out) setattr(self, f'_btn_BNC_in{n}', btn_bnc_in) setattr(self, f'_btn_BNC_out{n}', btn_bnc_out) self._bnc_in_buttons.append(btn_bnc_in) self._bnc_out_buttons.append(btn_bnc_out) self._wire_in_buttons = [] self._wire_in_label = ControlLabel("Wire In") self._wire_out_buttons = [] self._wire_out_label = ControlLabel("Wire Out") for n in range(1, number_wire_in + 1): btn_wire_in = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_wire_in.value = make_lambda_func(self.__button_on_click_evt, btn=btn_wire_in) setattr(self, f'_btn_Wire_in{n}', btn_wire_in) self._wire_in_buttons.append(btn_wire_in) for n in range(1, number_wire_out + 1): btn_wire_out = ControlButton(str(n), icon=self.UNCHECKED_ICON, checkable=True) btn_wire_out.value = make_lambda_func(self.__button_on_click_evt, btn=btn_wire_out) setattr(self, f'_btn_Wire_out{n}', btn_wire_out) self._wire_out_buttons.append(btn_wire_out) self._modules_indexes_loaded = [] for idx, mod in enumerate(bpod.modules): n = mod.serial_port self._modules_indexes_loaded.append(n) module_label = ControlLabel(f'{mod.name}') control_text_bytes_msg = ControlText() btn_send_msg_module = ControlButton(f'Send bytes') btn_send_msg_module.value = make_lambda_func(self.__send_msg_btn_evt, btn=btn_send_msg_module, control_text=control_text_bytes_msg) setattr(self, f'_module_label{n}', module_label) setattr(self, f'_control_text_bytes_msg{n}', control_text_bytes_msg) setattr(self, f'_btn_send_msg_module{n}', btn_send_msg_module) if bpod: bpod.close() self.formset = [ ([('Current setup:', '_currentSetup'), ('Selected board:', '_selectedBoard'), ('Selected protocol:', '_selectedProtocol')], '', ['_run_task_btn', '_kill_task_btn', '_stop_trial_btn', '_pause_btn']), '', 'Behaviour Ports', ('_valve_label', tuple([f'_btn_Valve{n.label}' for n in self._valve_buttons])), ('_led_label', tuple([f'_btn_PWM{n.label}' for n in self._led_buttons])), ('_poke_label', tuple([f'_btn_Port{n.label}' for n in self._poke_buttons])), '', ('Time Control (sec)', '_time_control'), '', 'BNC', ('_bnc_in_label', tuple([f'_btn_BNC_in{n.label}' for n in self._bnc_in_buttons]), '_bnc_out_label', tuple([f'_btn_BNC_out{n.label}' for n in self._bnc_out_buttons]) ), 'Wire' if number_wire_in != 0 else '', ('_wire_in_label' if number_wire_in != 0 else '', tuple([f'_btn_Wire_in{n.label}' for n in self._wire_in_buttons]), '_wire_out_label' if number_wire_out != 0 else '', tuple([f'_btn_Wire_out{n.label}' for n in self._wire_out_buttons]) ), '', 'Send bytes to modules' if self._modules_indexes_loaded else '', [(f'_module_label{n}', f'_control_text_bytes_msg{n}', f'_btn_send_msg_module{n}') for n in self._modules_indexes_loaded] ] self.set_margin(10) self.started_correctly = True