コード例 #1
0
          
 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)
コード例 #2
0
    def create_widgets(self, parent, mapp=False):    
        
        # Layout
        GBuilder().set_props(self, min_sz_x=500, min_sz_y=150)
        main_lo = QVBoxLayout()
        self.setLayout(main_lo)

        # Get Add Dialog
        try:
            
            # Read API Spec that I need
            cls = ECUFactory().get_class(self.ecu_type)
            self.processor = cls.get_add_plugin(parent)
            if mapp:
                self.processor.set_gui(mapp)
            main_lo.addWidget(self.processor)
        except:
            print(traceback.format_exc())
            ECULogger().log_traceback()
        
        # Ok and Cancel
        main_lo.addWidget(GBuilder().hor_line(parent))
        hl = QHBoxLayout() 
        hl.addWidget(GBuilder().label(parent, ""))
        ok = GBuilder().pushbutton(parent, "OK", self._ok_hit)
        ok.setFixedWidth(100)
        hl.addWidget(ok)
        canc = GBuilder().pushbutton(parent, "Cancel", self._cancel_hit)
        canc.setFixedWidth(100)
        hl.addWidget(canc)
コード例 #3
0
 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())
コード例 #4
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)
コード例 #5
0
    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()
コード例 #6
0
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()
コード例 #7
0
class CheckpointViewPluginGUI(QWidget):
            
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        self.create_widgets(parent)
            
        self._ecu_ids = []    
        self.prev = {}
        self.idx = {}
        self._plot_vals = {}
        self._extender = 1
        self._cp_collections = {}
        self._show_sets = {}        
        self._ex_comps = []
        
    def create_widgets(self, parent):
        
        hbox = QHBoxLayout()
        
        # Left side
        
        # Layout and Label
        vbox_left = QtGui.QVBoxLayout()      
        vbox_right = QtGui.QVBoxLayout()    
             
        # Header
        up_hbox = QHBoxLayout()
                
        self._label = QtGui.QLabel(self)
        self._label.setText("Choose the communication partner")      
        self._label.setFixedWidth(170)  
        self._ecu_1_label = QtGui.QLabel(self)
        self._ecu_1_label.setText("   ECU 1:")    
        self._ecu_1_label.setFixedWidth(50)
        self._ecu_2_label = QtGui.QLabel(self)
        self._ecu_2_label.setText("    ECU 2:")      
        self._ecu_2_label.setFixedWidth(50)     
        self._ecu_1_cb = GBuilder().combobox(self, [], self._on_ecu_selection_changed)
        self._ecu_1_cb.addItem("<< No Selection >>")
        self._ecu_1_cb.addItem("Unknown")
        self._ecu_2_cb = GBuilder().combobox(self, [], self._on_ecu_selection_changed)
        self._ecu_2_cb.addItem("<< No Selection >>")
        self._ecu_2_cb.addItem("Unknown")
        self._ass_cb = QCheckBox("Show only associated")
        self._ass_cb.setFixedWidth(130)
        self._ass_cb.stateChanged.connect(self._on_ecu_selection_changed)
        
        up_hbox.addWidget(self._label)
        up_hbox.addWidget(self._ecu_1_label)
        up_hbox.addWidget(self._ecu_1_cb)
        up_hbox.addWidget(self._ecu_2_label)
        up_hbox.addWidget(self._ecu_2_cb)
        up_hbox.addWidget(self._ass_cb)

        # Table
        self._time_table = GBuilder().table(self, 0, 3, ["Time", "ECU", 'Event'], False)
        self._time_table.setColumnWidth(0, 100)
        self._time_table.setColumnWidth(1, 170)
        self._time_table.setSortingEnabled(True)
        self._time_table.horizontalHeader().setResizeMode(0, QHeaderView.Fixed);
        self._time_table.horizontalHeader().setResizeMode(1, QHeaderView.Fixed);
        self._time_table.horizontalHeader().setResizeMode(2, QHeaderView.Stretch);
        
        # Layout
        vbox_left.addLayout(up_hbox)
        vbox_left.addWidget(self._time_table)
        
        # Right side
        v_lay = QVBoxLayout()
        self._times_gb = GBuilder().groupbox(self, "Times") 
        self._times_gb.setFixedWidth(450)
        self._times_gb.setLayout(v_lay)
        vbox_right.addWidget(self._times_gb)
        
        self._up_info = GBuilder().label(self, self._label_up("-", "-", "-", "-", "-"))
        self._down_info = GBuilder().label(self, self._label_down("-"))
        v_lay.addWidget(self._up_info)
        v_lay.addWidget(self._down_info)

        hbox.addLayout(vbox_left)
        hbox.addLayout(vbox_right)
        self.setLayout(hbox)
         
    def save(self):
        data = [self._cp_collections]
        return data
         
    def load(self, data):
        self.update_gui([data[0]])
         
    def update_gui(self, monitor_input_lst):

        # add new entries
        for monitor_input in monitor_input_lst:
            self._add_missing_keys(monitor_input[1])
             
            self._extend_table(monitor_input)
 
             
    def _extend_table(self, monitor_input):           
         
        # row already existing -> Continue
        txt = EventlineInterpreter().core.cp_string(eval(monitor_input[3]), monitor_input[2], monitor_input[7], monitor_input[5])

        txt_2 = str([monitor_input[0], monitor_input[1], txt])
        if txt_2 in self._ex_comps:
            return
          
        # insert a row at right point
        row_nr = self._get_suiting_row(self._time_table, monitor_input[0], 0)
          

          
        self._time_table.insertRow(row_nr)
          
        itab = TableCheckpointItem(); itab.set_checkpoint(monitor_input); itab.setText(str(monitor_input[0]));      
        itab_2 = TableCheckpointItem(); itab_2.set_checkpoint(monitor_input); itab_2.setText(monitor_input[1]);
        itab_3 = TableCheckpointItem(); itab_3.set_checkpoint(monitor_input); itab_3.setText(txt);
          
        self._time_table.setItem(row_nr, 0, itab);
        self._time_table.setItem(row_nr, 1, itab_2);
        self._time_table.setItem(row_nr, 2, itab_3);
        self._time_table.setSelectionBehavior(QAbstractItemView.SelectRows); 
        self._time_table.itemSelectionChanged.connect(self._selection_changed)
          
        self._set_row_color(self._time_table, EventlineInterpreter().core._category_by_tag(eval(monitor_input[3])), row_nr)
          
        # Add to show set
        self._show_sets[monitor_input[1]].add(row_nr, monitor_input[2])
        self._ex_comps.append(str([monitor_input[0], monitor_input[1], txt]))
                  
    def _add_missing_keys(self, comp_id):
             
        if comp_id not in self._ecu_ids:
            self._show_sets[comp_id] = TableShowSet(self._time_table)
             
            # Add entry to comboboxes
            self._ecu_1_cb.addItem(comp_id)
            self._ecu_2_cb.addItem(comp_id)            
            self._ecu_ids.append(comp_id)
        

    
    def _get_suiting_row(self, table, val, col_idx):
        ''' returns the row where val is bigger than the upper and smaller than the lower'''
        prev = 0
        for r in range(table.rowCount()):
            item = table.item(r, col_idx)            
            if val < float(item.text()):
                break            
            prev = r 
        return prev
         
    def _hide_all_rows(self, table):        
        for r in range(table.rowCount()):
            table.setRowHidden(r, True)
#         
    def _label_up(self, msg_id, msg_ctnt, msg_size, msg_cat, msg_stream):
        return "Checkpoint Details:\n\nMessage ID:\t\t\n%s\nMessage Content:\t\t\n%s\nMessage Size\t\t\n%s\nMessage Category\t\t\n%s\n Message Stream\t\t\n%s" % (msg_id, msg_ctnt, msg_size, msg_cat, msg_stream)
             
    def _label_down(self, time_passed):
        return"Selection Details:\nTime passed:%s" % (time_passed)
#             
    def _on_ecu_selection_changed(self):
        self._show_selection()
#     
    def _selection_changed(self):
         
        # show the first selected
        lst = self._time_table.selectedIndexes()
        for it in lst:
            r = it.row()
            c = it.column()            
            itm = self._time_table.item(r, c)
            cp = itm.checkpoint()
            self._up_info.setText(self._label_up(cp[4], cp[5], cp[6], EventlineInterpreter().core._category_by_tag(eval(cp[3])), cp[7]))
            break
         
        # Show the connected information
        if len(lst) > 4:
            itm_2 = self._time_table.item(lst[4].row(), lst[4].column())
            cp_2 = itm_2.checkpoint()
            self._down_info.setText(self._label_down(abs(cp.time - cp_2.time)))
         
         
        print(list)
     
    def _set_row_color(self, table, category, row_nr):
        red = QColor(255, 143, 143)
        green = QColor(204, 255, 204)
        blue = QColor(204, 230, 255)
         
        for c in range(table.columnCount()):
            item = table.item(row_nr, c)
         
            if category in [CPCategory.ECU_AUTHENTICATION_ENC, CPCategory.ECU_AUTHENTICATION_TRANS]:
                item.setData(QtCore.Qt.BackgroundRole, red);
                 
            if category in [CPCategory.STREAM_AUTHORIZATION_ENC, CPCategory.STREAM_AUTHORIZATION_TRANS]:
                item.setData(QtCore.Qt.BackgroundRole, green);
                 
            if category in [CPCategory.SIMPLE_MESSAGE_ENC, CPCategory.SIMPLE_MESSAGE_TRANS]:
                item.setData(QtCore.Qt.BackgroundRole, blue);
                 
    def _show_selection(self):
        try:
            # Hide all sets 
            self._hide_all_rows(self._time_table)
             
            # No selection made in either of the boxes -> show all
            if self._ecu_1_cb.currentText() == "<< No Selection >>" and self._ecu_2_cb.currentText() == "<< No Selection >>":
                for ky in self._show_sets:
                    self._show_sets[ky].show()
                return
                 
            # one of the boxes has no selection: show other
            if self._ecu_1_cb.currentText() == "<< No Selection >>":
                self._show_sets[self._ecu_2_cb.currentText()].show()
                return            
            if self._ecu_2_cb.currentText() == "<< No Selection >>":
                self._show_sets[self._ecu_1_cb.currentText()].show()
                return
             
            # Show all selected sets / option show only associated             
            # If show associated hit: Show only associated
            if self._ass_cb.isChecked():
                self._show_sets[self._ecu_1_cb.currentText()].show_asc(self._ecu_2_cb.currentText())
                self._show_sets[self._ecu_2_cb.currentText()].show_asc(self._ecu_1_cb.currentText())
                 
            # Show both
            else:
                self._show_sets[self._ecu_1_cb.currentText()].show()
                self._show_sets[self._ecu_2_cb.currentText()].show()
                 
        except:
            pass
コード例 #8
0
class StdBusAddWidget(AbstractAddPlugin):
    ''' This is the interface that connects the GUI and the actions to
        execute '''

    GUI_NAME = "CAN BUS"
    GUI_ICON = os.getcwd() + r'/icons/can.png'

    def __init__(self, parent):
        AbstractAddPlugin.__init__(self, parent)        
        self._create_widgets(parent)        
        self.parent = parent
                
        self.id = uuid.uuid4()        
        self.bus_group = None
        
    def set_gui(self, mapp):
        ''' set the gui from the map received '''
        try:
            if "id_list" in mapp: self.id_list.setText(str(mapp["id_list"]))
            if "nr_busses" in mapp: self.nr_ecus_textedit.setText(str(mapp["nr_busses"]))
            
        except:
            ECULogger().log_traceback()

    def get_map(self):
                
        mapping_values = {}
        # Read the values from the gui and save them  
        # General Information      
        mapping_values["id_list"] = self._wrap(eval, self.id_list.text(), [])
        mapping_values["nr_busses"] = self._wrap(int, self.nr_ecus_textedit.text(), 0)
                
        return mapping_values

    def preprocess(self, env, mapp):
        pass
    
    def get_actions(self):
        ''' returns the connections that can be made '''        
        
        actions = {}
        
        actions['connect_group'] = 'Connect ECU Group'

        return actions
        
    def execute_action(self, env_connect, *args):
        pass
                
    def main_process(self, env, mapp):
        print("Main")

    def postprocess(self, env, mapp):
        print("Post")
        
    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 Standard Bus. This CAN Bus is a simple implementation of a automotive link.")
        self.desc_label.setFixedWidth(400)
        self.icon = GBuilder().image(parent, StdBusAddWidget.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.nr_ecus_textedit = GBuilder().label_text(parent, "Number of Busses:", label_width=120)
        main_lo.addLayout(lo0)
        main_lo.addLayout(lo1)
                
        
    def _wrap(self, func, prime, second):
        try:
            el = func(prime)
            return el
        except:
            return second
コード例 #9
0
class SecureECUAddWidget(AbstractAddPlugin):
    ''' This is the interface that connects the GUI and the actions to
        execute for a SecureECU when it is to be created in the new
        simulation window '''
    
    GUI_NAME = "ECU Secure"
    GUI_ICON = os.getcwd() + r'/icons/secure_ecu.png'

    def __init__(self, parent):
        AbstractAddPlugin.__init__(self, parent)        
        self._create_widgets(parent)
        self.parent = parent
                
        self.set_ecu_settings = {}
        self.set_time_lib = {}
        self.has_sec_mod_cert = False
        self.id = uuid.uuid4()
        
        self.ecu_group = None
        
    def set_gui(self, mapp):
        ''' set the gui from the map received '''
        try:
            if "id_list" in mapp: self.id_list.setText(str(mapp["id_list"]))
            if "send_buffer" in mapp: self.send_buf_textedit.setText(str(mapp["send_buffer"]))
            if "rec_buffer" in mapp: self.rec_buf_textedit.setText(str(mapp["rec_buffer"]))
            if "nr_ecus" in mapp: self.nr_ecus_textedit.setText(str(mapp["nr_ecus"]))
            
            if "ecu_settings" in mapp: self.set_ecu_settings = mapp["ecu_settings"]
            self._set_cb_changed()
            
            if "ecu_timing" in mapp: self.set_time_lib = mapp["ecu_timing"]
            index = self.ecu_set_time_sel_cb.findText(self.set_time_lib[self.ecu_set_time_cb.currentText()])
            self.ecu_set_time_sel_cb.setCurrentIndex(index)  
            self._cur_set_time_entry = self.ecu_set_time_cb.currentText()  
            
            if "has_sec_mod_cert" in mapp: self.has_sec_mod_cert = mapp["has_sec_mod_cert"]
            if not self.has_sec_mod_cert: self.has_sec_mod_cert_cb.setCurrentIndex(0)
            
        except:
            ECULogger().log_traceback()

    def get_map(self):
        
        
        mapping_values = {}
        # Read the values from the gui and save them  
        # General Information      
        mapping_values["id_list"] = self._wrap(eval, self.id_list.text(), [])
        mapping_values["send_buffer"] = self._wrap(int, self.send_buf_textedit.text(), 200)
        mapping_values["rec_buffer"] = self._wrap(int, self.rec_buf_textedit.text(), 200)
        mapping_values["nr_ecus"] = self._wrap(int, self.nr_ecus_textedit.text(), 0)
        
        if self.ecu_set_te.text():
            self.set_ecu_settings[self._cur_set_entry] = self.ecu_set_te.text()
        mapping_values["ecu_settings"] = self.set_ecu_settings
        
        # Certification and Timing
        self.set_time_lib[self._cur_set_time_entry] = self.ecu_set_time_sel_cb.currentText()  # Final entry
        mapping_values['ecu_timing'] = self.set_time_lib
        mapping_values['has_sec_mod_cert'] = self.has_sec_mod_cert        

#         mapping_values['connected_sec_mod'] = None
        
        return mapping_values

    def preprocess(self, env, mapp):
        
        self.ecu_spec = SimpleECUSpec(mapp["id_list"] , mapp["send_buffer"], mapp["rec_buffer"])        
        for k in mapp["ecu_settings"]:
            self.ecu_spec.set_ecu_setting(k, mapp["ecu_settings"][k])  
                
        self.ecu_group = api.ecu_sim_api.set_ecus(env, mapp["nr_ecus"], 'SecureECU', self.ecu_spec)
    
    def get_actions(self):
        ''' returns the connections that can be made '''        
        
        actions = {}
        
        actions['valid_cert'] = 'Generate Valid Certificate'
                
        return actions
        
    def execute_action(self, env_connect, *args):
        pass

    def main_process(self, env, mapp):
        print("Main")

    def postprocess(self, env, mapp):
        print("Post")

    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, SecureECUAddWidget.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 = StdSecurECUTimingFunctions()
        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)

        # Certification (has a valid certificate or not)
#         hl, self.has_sec_mod_cert_cb, lab = GBuilder().label_combobox(parent, "Has Security Module Certificate", ["Yes", "No"], self._has_sec_mod_cb_changed)
#         main_lo.addLayout(hl)

    def _get_ecu_settings(self):
        SecureECU().settings = sorted(SecureECU().settings, key=lambda key: SecureECU().settings[key])
        
        return SecureECU().settings
        
    def _has_sec_mod_cb_changed(self):
        try:
            if self.has_sec_mod_cert_cb.currentText() == "Yes":
                self.has_sec_mod_cert = True
            else:
                self.has_sec_mod_cert = False
        except:
            pass
        
    def _set_time_cb_changed(self):   

        try:
            # Save old value
            if self._cur_set_time_entry == self.ecu_set_time_cb.currentText():
                self.set_time_lib[self._cur_set_time_entry] = self.ecu_set_time_sel_cb.currentText()
                self._cur_set_time_entry = self.ecu_set_time_cb.currentText()
                return
            
            # Load the next one
            try:
                index = self.ecu_set_time_sel_cb.findText(self.set_time_lib[self.ecu_set_time_cb.currentText()])
                self.ecu_set_time_sel_cb.setCurrentIndex(index)                           
            except:
                self.ecu_set_time_sel_cb.setCurrentIndex(0)        
            self._cur_set_time_entry = self.ecu_set_time_cb.currentText()                           
        except:
            pass
        
    def _set_cb_changed(self):        
        try:
            # Save old value
            if self.ecu_set_te.text():
                self.set_ecu_settings[self._cur_set_entry] = self.ecu_set_te.text()
            
            # Load the next one
            try:
                self.ecu_set_te.setText(self.set_ecu_settings[self.ecu_set_cb.currentText()])                
            except:
                self.ecu_set_te.setText('')            
            self._cur_set_entry = self.ecu_set_cb.currentText()
        except:
            pass
        
    def _wrap(self, func, prime, second):
        try:
            el = func(prime)
            return el
        except:
            return second