Changeset 3311
- Timestamp:
- 08/02/08 17:37:41 (5 years ago)
- Location:
- branch/PacketManipulator
- Files:
-
- 4 modified
-
Tabs/MainTab.py (modified) (3 diffs)
-
Tabs/PropertyTab.py (modified) (2 diffs)
-
widgets/HexView.py (modified) (4 diffs)
-
widgets/PropertyGrid.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/PacketManipulator/Tabs/MainTab.py
r3310 r3311 129 129 self.hexview = HexView() 130 130 131 self. hexview.payload = self.packet.get_raw()131 self.redraw_hexview() 132 132 133 133 def __pack_widgets(self): … … 141 141 pass 142 142 143 def redraw_hexview(self): 144 """ 145 Redraws the hexview 146 """ 147 if self.packet: 148 self.hexview.payload = self.packet.get_raw() 149 else: 150 print "redraw_hexview(): no packet!!!" 151 self.hexview.payload = "" 152 143 153 def get_label(self): 144 154 return self._label … … 157 167 self.append_page(session, session.label) 158 168 self.set_tab_reorderable(session, True) 169 170 def get_current_session(self): 171 """ 172 Get the current SessionPage 173 174 @return a SessionPage instance or None 175 """ 176 177 idx = self.get_current_page() 178 obj = self.get_nth_page(idx) 179 180 if obj and isinstance(obj, SessionPage): 181 return obj 182 183 return None 159 184 160 185 class MainTab(UmitView): -
branch/PacketManipulator/Tabs/PropertyTab.py
r3310 r3311 31 31 def create_ui(self): 32 32 self.grid = PropertyGrid() 33 self.grid.tree.connect('finish-edit', self.__redraw_hex_view) 34 self.grid.tree.connect('field-selected', self.__on_field_selected) 35 33 36 self._main_widget.add(self.grid) 34 37 self._main_widget.show_all() … … 62 65 self.grid.populate(proto) 63 66 self._main_widget.set_sensitive(True) 67 68 def __redraw_hex_view(self, tree, entry_destroyed): 69 # This is called when the user end the edit action on the PropertyGrid 70 # and we could redraw the entire hexview to show changes 71 # The tree argument is the PropertyGridTree object 72 73 from App import PMApp 74 tab = PMApp().main_window.get_tab("MainTab") 75 page = tab.session_notebook.get_current_session() 76 77 if page: 78 page.redraw_hexview() 79 80 # Now reselect the blocks 81 self.__on_field_selected(self.grid.tree, *self.grid.tree.get_selected_field()) 82 83 def __on_field_selected(self, tree, proto=None, field=None): 84 if not proto or not field: 85 return 86 87 # We should select also the bounds in HexView 88 from App import PMApp 89 tab = PMApp().main_window.get_tab("MainTab") 90 page = tab.session_notebook.get_current_session() 91 92 if page: 93 page.hexview.select_block(proto.get_offset(field) / 8, max(field.bits / 8, 1)) -
branch/PacketManipulator/widgets/HexView.py
r3310 r3311 142 142 143 143 def select_blocks(self, start=None, end=None): 144 if self.prev_start and self.prev_end :144 if self.prev_start and self.prev_end and self.prev_start != self.prev_end: 145 145 self.buffer.remove_tag(self._parent.tag_sec_sel, self.prev_start, self.prev_end) 146 146 … … 214 214 215 215 def select_blocks(self, start=None, end=None): 216 if self.prev_start and self.prev_end :216 if self.prev_start and self.prev_end and self.prev_start != self.prev_end: 217 217 self.buffer.remove_tag(self._parent.tag_sec_sel, self.prev_start, self.prev_end) 218 218 … … 398 398 ) 399 399 400 def select_block(self, offset, len, ascii=True): 401 """ 402 Select a block of data in the HexView 403 404 @param offset the offset byte 405 @param len the lenght of selection 406 @param ascii True to set primary selection on ASCII otherwise on HEX 407 """ 408 409 start = offset 410 end = offset + len 411 412 if start > end: 413 start, end = end, start 414 415 if ascii: 416 # We need to get a fucking iter! 417 buffer = self.ascii_text.get_buffer() 418 start_iter = buffer.get_iter_at_offset(start) 419 end_iter = buffer.get_iter_at_offset(end) 420 421 buffer.select_range(end_iter, start_iter) 422 400 423 def get_payload(self): 401 424 return self._payload … … 404 427 405 428 for view in (self.offset_text, self.hex_text, self.ascii_text): 429 430 # Invalidate previous iters 431 if hasattr(view, 'prev_start'): 432 view.prev_start = None 433 if hasattr(view, 'prev_end'): 434 view.prev_end = None 435 406 436 view.render(self._payload) 407 437 -
branch/PacketManipulator/widgets/PropertyGrid.py
r3299 r3311 378 378 class PropertyGridTree(gtk.ScrolledWindow): 379 379 __gsignals__ = { 380 'finish-edit' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT, )), 381 'desc-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )), 380 'finish-edit' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT, )), 381 'field-selected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)), 382 'desc-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )), 382 383 } 383 384 … … 435 436 self.tree.get_selection().connect('changed', self.__on_selection_changed) 436 437 self.tree.connect('button-release-event', self.__on_button_release) 438 439 def get_selected_field(self): 440 """ 441 Get the selected field 442 443 @return a tuple (proto, field) containing the parent 444 protocol for field and the field or None, None 445 """ 446 447 model, iter = self.tree.get_selection().get_selected() 448 449 if not iter: 450 return (None, None) 451 452 # If there's a object than it's a parent so return None, None 453 if model.get_value(iter, 0): 454 return (None, None) 455 456 proto = model.get_value(model.iter_parent(iter), 0) 457 field = model.get_value(iter, 1) 458 459 if not isinstance(field, base.Field) or \ 460 not isinstance(proto, base.Protocol): 461 return (None, None) 462 463 return (proto, field) 437 464 438 465 def __on_selection_changed(self, selection): … … 448 475 self.emit('desc-changed', "%s protocol." % Backend.get_proto_name(proto)) 449 476 else: 450 proto = model.get_value(model.iter_parent(iter), 0) 451 field = model.get_value(iter, 1) 452 453 if not isinstance(field, base.Field) or \ 454 not isinstance(proto, base.Protocol): 455 return 456 477 proto, field = self.get_selected_field() 478 479 self.emit('field-selected', proto, field) 457 480 self.emit('desc-changed', Backend.get_field_desc(field)) 458 481 459 # We should select also the bounds in HexView460 nb = App.PMApp().main_window.get_tab("MainTab").session_notebook461 page = nb.get_nth_page(nb.get_current_page())462 463 # The page *MUST* be a SessionPage otherwise the signal464 # we cannot be here becouse this widget is insentive465 # so no worry about it.466 467 print page.hexview, proto.get_offset(field), field.bits468 469 482 def __on_button_release(self, widget, event): 470 483 # We should get the selection and show the popup
