def popup_add_packet(self, popup, path, packet_class): logger.debug("add packet %s to position: %s" %(packet_class.name, path)) if(path is None): pos = len(self.model.packets) else: pos = path[0] + 1 self.model.add(pos, packet_class())
def notify(self, signal, event = None): for h in self.handlers[signal]: try: h[0](event, *h[1]) except Exception, e: import traceback traceback.print_exc() logger.warning("%s sent %s signal to bad handler %s: %s" %(self.__class__.__name__, signal, h[0], e))
def packet_updated(self, event): expanded_lines = self.save_expanded_lines() self.make_treestore() try: self.restore_expanded_lines(expanded_lines) except Exception, e: print e logger.debug("cannot restore expanded lines")
def remove_handler_concrete(self, signal, handler, *params): #удаление не зарегистрированного обработчика это не ошибка! try: handlers = self.handlers[signal] handlers.remove((handler, params)) logger.debug("remove handler %s with concrete user params: %s" %(handler, params)) except Exception, e: pass
def edited_cb(self, cell, path, new_text): scapy_object = self.get_treestore_object(path) elem, top = scapy_object if(isinstance(elem,Packet)): #заголовок пакета return try: top.__setattr__(elem.name, eval(new_text)) except Exception, e: logger.debug("bad value: %s"%new_text)
def remove_handler(self, signal, handler): #удаление не зарегистрированного обработчика это не ошибка! try: handlers = self.handlers[signal] new_handlers = [] for h in handlers: if(h[0] <> handler): new_handlers.append(h) self.handlers[signal] = new_handlers logger.debug("remove handler %s with all user params" %handler) except Exception, e: pass
def popup_set_packet(self, popup, packet, packet_class): new_packet = packet_class() new_packet.add_payload(packet.payload) if(packet == self.model.packet): #корневой заголовок self.model.set_packet(new_packet) else: u = packet.underlayer if(u is None): logger.warning("None underlayer for no root layer!") else: u.remove_payload() u.add_payload(new_packet) self.model.update()
def popup_remove_packet(self, popup, packet): if(packet == self.model.packet): #корневой заголовок if(not packet.payload): self.model.set_packet(None) else: self.model.set_packet(packet.payload) else: u = packet.underlayer if(u is None): logger.warning("None underlayer for no root layer!") else: u.remove_payload() u.add_payload(packet.payload) self.model.update()
def popup_remove_packets(self, popup, paths): logger.debug("remove packets : %s" %paths) pp = [p[0] for p in paths] self.model.remove(pp)
def make_popup(self, pth): def make_popup_packet(packet, top): popup = gtk.Menu() if(top is None): popup = gtk.Menu() #----under_layer u_items = gtk.Menu() #remove if(packet.underlayer is not None): make_item("remove", u_items, self.popup_remove_packet_underlayer, packet) make_separator(u_items) #наиболее часто используемые слои make_layers(self.common_layers, u_items, self.popup_set_packet_underlayer, packet) #все u_all_items = gtk.Menu() make_layers(self.all_layers, u_all_items, self.popup_set_packet_underlayer, packet) add_submenu(u_items, "all", u_all_items) add_submenu(popup, "under layer", u_items) #----this_layer u_items = gtk.Menu() #наиболее часто используемые слои make_layers(self.common_layers, u_items, self.popup_set_packet, packet) #все u_all_items = gtk.Menu() make_layers(self.all_layers, u_all_items, self.popup_set_packet, packet) add_submenu(u_items, "all", u_all_items) add_submenu(popup, "this layer", u_items) #----upper_layer(payload) u_items = gtk.Menu() #remove if(packet.payload is not None and packet.payload): make_item("remove", u_items, self.popup_remove_packet_payload, packet) make_separator(u_items) #наиболее часто используемые слои make_layers(self.common_layers, u_items, self.popup_set_packet_payload, packet) #все u_all_items = gtk.Menu() make_layers(self.all_layers, u_all_items, self.popup_set_packet_payload, packet) add_submenu(u_items, "all", u_all_items) add_submenu(popup, "upper layer", u_items) #----default make_item("default", popup, self.popup_packet_default, packet) return popup def make_popup_list(list, top): popup = gtk.Menu() #текущее содержимое(обычый python list) value = top.getfieldval(list.name) #добавление add_item = gtk.MenuItem("add") add_items = gtk.Menu() #возможные варианты #DEV: всегда ли у list есть поле cls #у PacketListField точно есть for sub in subclasses(list.cls): sub_item = gtk.MenuItem(sub.__name__) sub_item.connect("activate", self.popup_list_add, value, sub) add_items.append(sub_item) sub_item.show() if(len(add_items) > 0): add_item = gtk.MenuItem("add") add_item.set_submenu(add_items) popup.append(add_item) add_item.show() #удаление remove_items = gtk.Menu() for elem in value: sub_item = gtk.MenuItem(elem.name) sub_item.connect("activate", self.popup_list_remove, value, elem) remove_items.append(sub_item) sub_item.show() if(len(remove_items) > 0): remove_item = gtk.MenuItem("remove") remove_item.set_submenu(remove_items) popup.append(remove_item) remove_item.show() return popup def make_popup_field(field, top): popup = gtk.Menu() if isinstance(field, EnumField): if isinstance(field, MultiEnumField): v = field.depends_on(top) if v in field.s2i_multi: s2i = field.s2i_multi[v] else: s2i = {} else: s2i = field.s2i keys = s2i.keys() keys.sort() #возможные варианты var_items = gtk.Menu() for var in keys: sub_item = gtk.MenuItem(var) sub_item.connect("activate", self.popup_field_set_value, top, field, s2i[var]) var_items.append(sub_item) sub_item.show() if(len(var_items) > 0): popup = var_items return popup def make_popup_empty(): popup = gtk.Menu() #----тип пакета p_items = gtk.Menu() #наиболее часто используемые слои make_layers(self.common_layers, p_items, self.popup_set_packet) #все p_all_items = gtk.Menu() make_layers(self.all_layers, p_all_items, self.popup_set_packet) add_submenu(p_items, "all", p_all_items) add_submenu(popup, "packet", p_items) #----default all make_item("default all", popup, self.popup_packet_default, self.model.packet, True) return popup if pth is not None: #щелчок по ячейке path = pth[0] scapy_object = self.get_treestore_object(path) elem, top = scapy_object if(isinstance(elem, Packet)): #пакет logger.debug("make popup for packet") popup = make_popup_packet(elem, top) elif(elem.islist and elem.holds_packets and type(top.getfieldval(elem.name)) is list): #список logger.debug("make popup for list") popup = make_popup_list(elem, top) else: #поле logger.debug("make popup for field") popup = make_popup_field(elem, top) else: #пустое место popup = None return popup
def add_handler(self, signal, handler, *params): self.handlers[signal].append((handler, params)) logger.debug("packet model add new handler %s, user params: %s for signal: %s" %(handler, params, signal))