def get_iface_config(): win = QDialog() win.setWindowTitle('CAN Interface Configuration') win.setWindowIcon(APP_ICON) combo = QtGui.QComboBox(win) combo.setEditable(True) combo.setAutoCompletion(True) combo.setAutoCompletionCaseSensitivity(Qt.CaseSensitive) combo.setInsertPolicy(QtGui.QComboBox.NoInsert) combo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) combo.addItems(list_ifaces()) bitrate = QtGui.QSpinBox() bitrate.setMaximum(1000000) bitrate.setMinimum(10000) bitrate.setValue(1000000) extra_args = QtGui.QLineEdit() ok = QtGui.QPushButton('OK', win) result = None kwargs = {} def on_ok(): nonlocal result, kwargs a = str(extra_args.text()) if a: try: kwargs = dict(eval(a)) except Exception as ex: mbox = QtGui.QMessageBox(win) mbox.setWindowTitle('Invalid parameters') mbox.setText('Could not parse optional arguments') mbox.setInformativeText(str(ex)) mbox.setIcon(QtGui.QMessageBox.Critical) mbox.setStandardButtons(QtGui.QMessageBox.Ok) mbox.exec() return kwargs['bitrate'] = int(bitrate.value()) result = str(combo.currentText()) win.close() ok.clicked.connect(on_ok) layout = QVBoxLayout() layout.addWidget( QtGui.QLabel('Select CAN interface or serial port for SLCAN:')) layout.addWidget(combo) layout.addWidget(QtGui.QLabel('Interface bitrate (SLCAN only):')) layout.addWidget(bitrate) layout.addWidget( QtGui.QLabel('Optional arguments (refer to Pyuavcan for info):')) layout.addWidget(extra_args) layout.addWidget(ok) win.setLayout(layout) win.exec() return result, kwargs
def get_iface_config(): win = QDialog() win.setWindowTitle('CAN Interface Configuration') win.setWindowIcon(APP_ICON) combo = QtGui.QComboBox(win) combo.setEditable(True) combo.setAutoCompletion(True) combo.setAutoCompletionCaseSensitivity(Qt.CaseSensitive) combo.setInsertPolicy(QtGui.QComboBox.NoInsert) combo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) combo.addItems(list_ifaces()) bitrate = QtGui.QSpinBox() bitrate.setMaximum(1000000) bitrate.setMinimum(10000) bitrate.setValue(1000000) extra_args = QtGui.QLineEdit() ok = QtGui.QPushButton('OK', win) result = None kwargs = {} def on_ok(): nonlocal result, kwargs a = str(extra_args.text()) if a: try: kwargs = dict(eval(a)) except Exception as ex: mbox = QtGui.QMessageBox(win) mbox.setWindowTitle('Invalid parameters') mbox.setText('Could not parse optional arguments') mbox.setInformativeText(str(ex)) mbox.setIcon(QtGui.QMessageBox.Critical) mbox.setStandardButtons(QtGui.QMessageBox.Ok) mbox.exec() return kwargs['bitrate'] = int(bitrate.value()) result = str(combo.currentText()) win.close() ok.clicked.connect(on_ok) layout = QVBoxLayout() layout.addWidget(QtGui.QLabel('Select CAN interface or serial port for SLCAN:')) layout.addWidget(combo) layout.addWidget(QtGui.QLabel('Interface bitrate (SLCAN only):')) layout.addWidget(bitrate) layout.addWidget(QtGui.QLabel('Optional arguments (refer to Pyuavcan for info):')) layout.addWidget(extra_args) layout.addWidget(ok) win.setLayout(layout) win.exec() return result, kwargs
class NewSimulationCore(Singleton): def __init__(self, gui_con): self.gui = gui_con self.selected_env = None self.env_map = {} # Connects a environment Name to a list of EnvironmentElements def add_bus_box_to_env(self, cur_pos, bus_type, move_icon): if not self._handle_no_selection(move_icon): return # Load config from Element try: # New Element move_icon.env_view = self.gui.content_gb cur_env_elems = self.env_map[self.selected_env] env_elem = self._get_env_elem_by_icon(cur_env_elems, move_icon) add_ecu = AddSingleBUSDialog(self.gui, bus_type, env_elem.processor, env_elem.gui_map) except: # Edit Element env_elem = EnvironmentElement(move_icon, bus_type) self._dict_add_two(self.env_map, self.selected_env, env_elem) add_ecu = AddSingleBUSDialog(self.gui, bus_type, None) # Save config env_elem.processor = add_ecu.processor env_elem.comp_type = bus_type env_elem.draws_line = True env_elem.gui_map = add_ecu.processor.get_map() def add_ecu_box_to_env(self, cur_pos, ecu_type, move_icon): # No environment selected if not self._handle_no_selection(move_icon): return # Load config from Element try: # New Element move_icon.env_view = self.gui.content_gb cur_env_elems = self.env_map[self.selected_env] env_elem = self._get_env_elem_by_icon(cur_env_elems, move_icon) add_ecu = AddSingleECUDialog(self.gui, ecu_type, env_elem.processor, env_elem.gui_map) env_elem.processor = add_ecu.processor env_elem.comp_type = ecu_type except: # Edit Element env_elem = EnvironmentElement(move_icon, ecu_type) self._dict_add_two(self.env_map, self.selected_env, env_elem) add_ecu = AddSingleECUDialog(self.gui, ecu_type, None) env_elem.processor = add_ecu.processor env_elem.comp_type = ecu_type # Save config env_elem.gui_map = add_ecu.processor.get_map() def run_processes(self): ''' run all processes (pre, main, post) and create a environment from that ''' res_envs = [] for env_name in self.env_map: new_env = api.ecu_sim_api.create_environment(2000) self._run_process(new_env, env_name) res_envs.append(new_env) return res_envs def load_context_menu_actions(self, ecu_type): ''' load the context menu actions for the specific ecu type''' try: act = QtGui.QAction(QtGui.QIcon(os.getcwd() + r'/icons/p.png'), "Connect", self.gui) act.setStatusTip("Connect the selected items") act.triggered.connect(self._connect) return [act] except: return [] def _handle_no_selection(self, move_icon): if self.selected_env == None: q = QMessageBox(QMessageBox.Warning, "Warning", "Element could not be added. No environment selected.") q.exec(); move_icon.setParent(None); return False return True def _connect(self): ''' connect two items''' # open Connect window, self._cur_selected_connection = None self.dia = QDialog(self.gui); main_lo = QVBoxLayout() GBuilder().set_props(self.dia, None, 250, 130, max_sz_x=400, max_sz_y=250) try: self.selected_env_elems = EnvironmentElement.icons_to_env_els(DragSelection().selected, self.env_map[self.selected_env]) self.clicked_elem = EnvironmentElement.icons_to_env_els([DragSelection().clicked], self.env_map[self.selected_env])[0] self.selected_env_elems.remove(self.clicked_elem) except: return # show possible connections if not self.selected_env_elems: return acts = self.clicked_elem.processor.get_actions() main_lo.addWidget(GBuilder().label(self.dia, "Select a connection to be executed between type %s and type %s" % (self.clicked_elem.comp_type, self.selected_env_elems[0].comp_type))) hl, self._con_cb, te = GBuilder().label_combobox(self.dia, "Select Connection ", list(acts.values()), self.dia.show) main_lo.addLayout(hl) # ok cancel main_lo.addWidget(GBuilder().hor_line(self.dia)) ok = GBuilder().pushbutton(self.dia, "Apply", self._ok_dia_hit); ok.setFixedWidth(100) canc = GBuilder().pushbutton(self.dia, "Cancel", self._cancel_dia_hit); canc.setFixedWidth(100) hl = QHBoxLayout() hl.addWidget(GBuilder().label(self.dia, "")) hl.addWidget(ok) hl.addWidget(canc) main_lo.addLayout(hl) self.dia.setLayout(main_lo) self.dia.exec() def _ok_dia_hit(self): # if can connected to ecu, draw a line if self.clicked_elem.draws_line: self._draw_lines(self.clicked_elem, self.selected_env_elems) # Apply selected connection self._clear_selected() new_con = EnvironmentConnection(self.clicked_elem, self.selected_env_elems, self._con_cb.currentText()) self.clicked_elem.add_connection(new_con) self.dia.close() def _cancel_dia_hit(self): self._clear_selected() self.dia.close() def _clear_selected(self): for lab in DragSelection().selected: lab.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}') DragSelection().clicked = [] DragSelection().selected = [] def _draw_lines(self, prime_env_el, connected_env_els): try: DragSelection().connected[self.selected_env] except: DragSelection().connected[self.selected_env] = [] DragSelection().connected[self.selected_env].append(LineConnection(prime_env_el.move_icon, [o.move_icon for o in connected_env_els])) GBuilder().update_connected(self.gui.content_gb, self.gui.environment_gb.pos(), self.gui.content_gb.pos(), self.selected_env) def _run_process(self, my_env, env_name): procs = [] # Run all processors for cur_elem in self.env_map[env_name]: gui_map = cur_elem.gui_map # possibly unnecessary processor = cur_elem.processor procs.append(processor) # pre processes for proc in procs: proc.preprocess(my_env, gui_map) # main processes for proc in procs: proc.main_process(my_env, gui_map) # Post processes for proc in procs: proc.postprocess(my_env, gui_map) def _get_env_elem_by_icon(self, env_elems, move_icon): for elem in env_elems: if str(elem.move_icon) == str(move_icon): return elem return None def _dict_add_two(self, dic, ky1, val): try: dic[ky1] except: dic[ky1] = []
def open_about(self): dial = QDialog() self.about = Ui_Dialog() self.about.setupUi(dial) dial.exec()