def _fill_bus_boxes(self): kys = BusFactory().createable_objects() row = 0 col = 0 for ky in list(kys): # Information gathering name = self._load_gui_name(ky, BusFactory()) ico = self._load_gui_icon(ky, BusFactory()) # New Element per Object gb = GBuilder().groupbox(self, name, None, None) gb.setFont(QtGui.QFont('SansSerif', 7)) gb.setFixedHeight(70) gb.setFixedWidth(70) db = GBuilder().dragbutton(gb, '', self._add_component_boxes, ico, icon_x=45, icon_y=45, size_x=60, size_y=50, pos_x=5, pos_y=15) db.set_drop_func(self.core.add_bus_box_to_env) db.set_move_icon_context_acts(self.core.load_context_menu_actions(ky)) db.ecu_key = ky db.setCheckable(True) db.setStyleSheet('QPushButton {background-color: #F2F2F2; color: red;border: 0px solid gray;border-radius: 12px;}') # Add to Layout self.bus_box.addWidget(gb, row, col, Qt.AlignTop) col += 1 if col == 3: row += 1 col = 0 # Add Widget self.bus_box.addWidget(QWidget())
class CreateSimulationPluginGUI(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) self.create_widgets(parent) def create_widgets(self, parent): # Main Layout vbox = QtGui.QVBoxLayout() self.setLayout(vbox) # Label vl_left = QVBoxLayout() self.top_label = GBuilder().label(parent, "Create a new Simulation or select a existing one from the list", None, None) vl_left.addWidget(self.top_label) hl_out = QHBoxLayout() vbox.addLayout(hl_out) # Buttons vl_right = QVBoxLayout() self.new_button = GBuilder().pushbutton(parent, "New", self._new_hit, os.getcwd() + r'/icons/new.png') vl_right.addWidget(self.new_button) self.import_button = GBuilder().pushbutton(parent, "Import", self._import_hit, os.getcwd() + r'/icons/import.png') vl_right.addWidget(self.import_button) self.save_button = GBuilder().pushbutton(parent, "Export", self._save_hit, os.getcwd() + r'/icons/save.png') vl_right.addWidget(self.save_button) self.build_button = GBuilder().pushbutton(parent, "Build Simulation", self._build_hit, os.getcwd() + r'/icons/build.png', 35, 35) self.build_button.setFixedHeight(40) vl_right.addWidget(self.build_button) # Table self.sims_table = GBuilder().table(parent, 5, 2, ["A"], False) self.sims_table.horizontalHeader().setResizeMode(1, QHeaderView.Fixed); self.sims_table.horizontalHeader().setResizeMode(0, QHeaderView.Stretch); self.sims_table.setColumnWidth(1, 32) # self.check_buts = GBuilder().add_checkbuttons(self.sims_table, 0, 1) self.sims_table.verticalHeader().setDefaultSectionSize(25) self.sims_table.verticalHeader().hide() self.sims_table.horizontalHeader().hide() self.sims_table.setFixedHeight(110) vl_left.addWidget(self.sims_table) hl_out.addLayout(vl_left) hl_out.addLayout(vl_right) def _build_hit(self): self.build_window = BuildWindow(self) def _save_hit(self): self.save_window = SaveWindow(self) def _new_hit(self): self.new_window = NewSimulationWindow(self) def _import_hit(self): self.import_window = ImportWindow(self)
def create_widgets(self, parent): # Layout GBuilder().set_props(self, min_sz_x=900, min_sz_y=700) self.setWindowTitle("Simulation Configuration") self.setFixedHeight(700) self.setFixedWidth(1350) main_lo = QVBoxLayout() self.setLayout(main_lo) # Label self.desc_label = GBuilder().label(self, "Create a new simulation. Create one or more environments and"\ " fill them with components. Then connect the components.", None, None) self.desc_label.setFixedHeight(20) main_lo.addWidget(self.desc_label) # Horizontal Layout hl_1 = QHBoxLayout() main_lo.addLayout(hl_1) # Groupboxes self.components_gb = GBuilder().hand_groupbox(self, "Components", None, None) self.components_gb.setFixedWidth(300) self.environment_gb = GBuilder().groupbox(self, "Environments", None, None) hl_1.addWidget(self.components_gb) hl_1.addWidget(self.environment_gb) # Components Boxes self.comps_layout = QVBoxLayout() self.components_gb.setLayout(self.comps_layout) self._add_component_boxes() # Buttons main_lo.addWidget(GBuilder().hor_line(self)) hl = QHBoxLayout() hl.addWidget(GBuilder().label(self, "")) ok_but = GBuilder().pushbutton(self, "OK", self._ok_hit) ok_but.setFixedWidth(150) ok_but.setFixedHeight(25) cancel_but = GBuilder().pushbutton(self, "Cancel", self._ok_hit) cancel_but.setFixedWidth(150) cancel_but.setFixedHeight(25) hl.addWidget(ok_but) hl.addWidget(cancel_but) main_lo.addLayout(hl) # Fill Components Boxes self._fill_ecu_boxes() self._fill_bus_boxes() self._fill_others_boxes() # Fill environment self._fill_environment_box() # Style self._set_stle()
def _create_widgets(self, parent): # Layout GBuilder().set_props(self, None, 100, 100) main_lo = QVBoxLayout() self.setLayout(main_lo) # Title main_lo.addWidget(GBuilder().label(parent, "<b>Description:</b>")) hl = QHBoxLayout() self.desc_label = GBuilder().label(parent, "Add a new SecureECU. This ECU resembles the ECU Part in a Lightweight Authentication Mechanism.") self.desc_label.setFixedWidth(400) self.icon = GBuilder().image(parent, SecLwAuthSecurityModuleAddWidget.GUI_ICON, 2) hl.addWidget(self.desc_label) hl.addWidget(self.icon) main_lo.addLayout(hl) line = GBuilder().hor_line(parent) main_lo.addWidget(line); # Constructor Inputs main_lo.addWidget(GBuilder().label(parent, "<b>General Information:</b>")) lo0, self.id_list = GBuilder().label_text(parent, "List of IDs (optional):", label_width=120) lo1, self.send_buf_textedit = GBuilder().label_text(parent, "Sending BufferSize:", label_width=120) lo2, self.rec_buf_textedit = GBuilder().label_text(parent, "Receiving Buffer Size:", label_width=120) lo3, self.nr_ecus_textedit = GBuilder().label_text(parent, "Number of ECUs:", label_width=120) main_lo.addLayout(lo0) main_lo.addLayout(lo1) main_lo.addLayout(lo2) main_lo.addLayout(lo3) # ECU Settings items = self._get_ecu_settings() hl, self.ecu_set_cb, self.ecu_set_te = GBuilder().combobox_text(parent, items, self._set_cb_changed) self._cur_set_entry = self.ecu_set_cb.currentText() main_lo.addLayout(hl) # Timing Mapping line = GBuilder().hor_line(parent) main_lo.addWidget(line) lab = GBuilder().label(parent, "<b>Timing and Certification:</b>") lab.setFixedHeight(20) main_lo.addWidget(lab) itm = StdSecurLwSecModTimingFunctions() avail_items = itm.available_tags items = itm.function_map.keys() hl1 = QHBoxLayout() self.ecu_set_time_cb = GBuilder().combobox(parent, items, self._set_time_cb_changed) self._cur_set_time_entry = self.ecu_set_time_cb.currentText() self.ecu_set_time_sel_cb = GBuilder().combobox(parent, avail_items, self._set_time_cb_changed) self._cur_set_time_sel_entry = self.ecu_set_time_sel_cb.currentText() hl1.addWidget(self.ecu_set_time_cb) hl1.addWidget(self.ecu_set_time_sel_cb) main_lo.addLayout(hl1)
class NewSimulationWindow(QDialog): def __init__(self, parent): QDialog.__init__(self, parent) self.core = NewSimulationCore(self) self.create_widgets(parent) self.environments = [] self.env_wid = {} # Environment Name to Environment Widget self.env_obj = {} # Environment Name to Environment Objects self.exec() def create_widgets(self, parent): # Layout GBuilder().set_props(self, min_sz_x=900, min_sz_y=700) self.setWindowTitle("Simulation Configuration") self.setFixedHeight(700) self.setFixedWidth(1350) main_lo = QVBoxLayout() self.setLayout(main_lo) # Label self.desc_label = GBuilder().label(self, "Create a new simulation. Create one or more environments and"\ " fill them with components. Then connect the components.", None, None) self.desc_label.setFixedHeight(20) main_lo.addWidget(self.desc_label) # Horizontal Layout hl_1 = QHBoxLayout() main_lo.addLayout(hl_1) # Groupboxes self.components_gb = GBuilder().hand_groupbox(self, "Components", None, None) self.components_gb.setFixedWidth(300) self.environment_gb = GBuilder().groupbox(self, "Environments", None, None) hl_1.addWidget(self.components_gb) hl_1.addWidget(self.environment_gb) # Components Boxes self.comps_layout = QVBoxLayout() self.components_gb.setLayout(self.comps_layout) self._add_component_boxes() # Buttons main_lo.addWidget(GBuilder().hor_line(self)) hl = QHBoxLayout() hl.addWidget(GBuilder().label(self, "")) ok_but = GBuilder().pushbutton(self, "OK", self._ok_hit) ok_but.setFixedWidth(150) ok_but.setFixedHeight(25) cancel_but = GBuilder().pushbutton(self, "Cancel", self._ok_hit) cancel_but.setFixedWidth(150) cancel_but.setFixedHeight(25) hl.addWidget(ok_but) hl.addWidget(cancel_but) main_lo.addLayout(hl) # Fill Components Boxes self._fill_ecu_boxes() self._fill_bus_boxes() self._fill_others_boxes() # Fill environment self._fill_environment_box() # Style self._set_stle() def _add_component_boxes(self): # ECU Box self.ecu_box_wid = QScrollArea() wid = QWidget() self.ecu_box_wid.setWidget(wid) self.ecu_box_wid.setWidgetResizable(True) self.ecu_box = QGridLayout() wid.setLayout(self.ecu_box) self.ecu_box_wid_wid = wid self.comps_layout.addWidget(self.ecu_box_wid) # Bus Box self.bus_box_wid = QScrollArea() wid = QWidget() self.bus_box_wid.setWidget(wid) self.bus_box_wid.setWidgetResizable(True) self.bus_box = QGridLayout() wid.setLayout(self.bus_box) self.bus_box_wid_wid = wid self.comps_layout.addWidget(self.bus_box_wid) # Others Box self.others_box_wid = QScrollArea() wid = QWidget() self.others_box_wid.setWidget(wid) self.others_box_wid.setWidgetResizable(True) self.others_box = QGridLayout() wid.setLayout(self.others_box) self.others_box_wid_wid = wid self.comps_layout.addWidget(self.others_box_wid) def _fill_ecu_boxes(self): # Creatable Objects kys = ECUFactory().createable_objects() row = 0 col = 0 for ky in list(kys): # Information gathering name = self._load_gui_name(ky, ECUFactory()) ico = self._load_gui_icon(ky, ECUFactory()) # New Element per Object gb = GBuilder().groupbox(self, name, None, None) gb.setFont(QtGui.QFont('SansSerif', 7)) gb.setFixedHeight(70) gb.setFixedWidth(70) db = GBuilder().dragbutton(gb, '', self._add_component_boxes, ico, icon_x=45, icon_y=45, size_x=60, size_y=50, pos_x=5, pos_y=15) db.set_drop_func(self.core.add_ecu_box_to_env) db.set_move_icon_context_acts(self.core.load_context_menu_actions(ky)) db.ecu_key = ky db.setCheckable(True) db.setStyleSheet('QPushButton {background-color: #F2F2F2; color: red;border: 0px solid gray;border-radius: 12px;}') # Add to Layout self.ecu_box.addWidget(gb, row, col, Qt.AlignTop) col += 1 if col == 3: row += 1 col = 0 # Add Widget self.ecu_box.addWidget(QWidget()) def _fill_bus_boxes(self): kys = BusFactory().createable_objects() row = 0 col = 0 for ky in list(kys): # Information gathering name = self._load_gui_name(ky, BusFactory()) ico = self._load_gui_icon(ky, BusFactory()) # New Element per Object gb = GBuilder().groupbox(self, name, None, None) gb.setFont(QtGui.QFont('SansSerif', 7)) gb.setFixedHeight(70) gb.setFixedWidth(70) db = GBuilder().dragbutton(gb, '', self._add_component_boxes, ico, icon_x=45, icon_y=45, size_x=60, size_y=50, pos_x=5, pos_y=15) db.set_drop_func(self.core.add_bus_box_to_env) db.set_move_icon_context_acts(self.core.load_context_menu_actions(ky)) db.ecu_key = ky db.setCheckable(True) db.setStyleSheet('QPushButton {background-color: #F2F2F2; color: red;border: 0px solid gray;border-radius: 12px;}') # Add to Layout self.bus_box.addWidget(gb, row, col, Qt.AlignTop) col += 1 if col == 3: row += 1 col = 0 # Add Widget self.bus_box.addWidget(QWidget()) def _fill_others_boxes(self): kys = ECUFactory().createable_objects() row = 0 col = 0 def _fill_environment_box(self): # Main Layout main_lo = QVBoxLayout() self.environment_gb.setLayout(main_lo) # Combobox lo, self.env_select_cb, lab = GBuilder().label_combobox(self, "Current Environment:", [], self._env_select_changed) hl = QHBoxLayout() hl.addLayout(lo) but = GBuilder().pushbutton(self, "New", self._new_env_hit) but.setFixedWidth(40) hl.addWidget(but) lab.setFixedWidth(140) self.env_select_cb.setFixedHeight(22) self.env_select_cb.setFixedWidth(350) main_lo.addLayout(hl) # Groupbox (to make it look nicer) self.content_gb = EnvironmentView(self.environment_gb) main_lo.addWidget(self.content_gb) self.content_gb.setFixedHeight(550) self.content_gb.setFixedWidth(1000) self.content_gb.setLayout(lo) # QStackedWidget with environments self.stacked_env = QStackedWidget() lo.addWidget(self.stacked_env) def _set_stle(self): self.content_gb.setStyleSheet('QGroupBox {background-color: #F2F2F2; color: red; border: 2px solid gray;border-radius: 12px;} EnvironmentView {background-color: #F2F2F2; color: red; border: 2px solid gray;border-radius: 12px;}') self.ecu_box_wid_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') self.ecu_box_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') self.bus_box_wid_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') self.bus_box_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') self.others_box_wid_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') self.others_box_wid.setStyleSheet('QWidget { border: 0.5px solid gray;border-radius: 3px;}') def _ok_hit(self): # 1. Create environments using defined processing methods environments_list = NewSimulationCore().run_processes() # 2. Save environments via API / Load them via API as well self.close() def _cancel_hit(self): print("Cancel") self.close() def _new_env_hit(self): # Add to list nr = len(self.environments) self.environments.append("Environment %s" % nr) self.env_select_cb.addItem(self.environments[-1]) self.env_select_cb.setCurrentIndex(nr) # Create new Stacked widget entry wid = QWidget() self.stacked_env.addWidget(wid) self.env_wid["Environment %s" % nr] = wid lo = QVBoxLayout() wid.setLayout(lo) self.stacked_env.setCurrentIndex(nr) def _env_select_changed(self): idx = self.env_select_cb.currentIndex() self.stacked_env.setCurrentIndex(idx) NewSimulationCore().selected_env = self.env_select_cb.currentText() self.content_gb.selected_env = self.env_select_cb.currentText() self._show_env(NewSimulationCore().selected_env, NewSimulationCore().env_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 _load_gui_name(self, ky, factory): try: cls = factory.get_class(ky) name = cls.GUI_NAME except: name = ky return name def _load_gui_icon(self, ky, factory): try: cls = factory.get_class(ky) name = cls.GUI_ICON except: name = os.getcwd() + r'/icons/standard_ecu.png' return name def _show_env(self, selected_env, env_map): GBuilder().update_connected(self.content_gb, self.environment_gb.pos(), self.content_gb.pos(), self.content_gb.selected_env) # Mainwindow for chil in self.children(): if isinstance(chil, DragLabel): try: a = self._get_env_elem_by_icon(env_map[selected_env], chil) if a == None: chil.hide() else: chil.show() except: chil.hide()