From 93dd9813829f29cd9a88e6229666e4738844b727 Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Tue, 29 May 2018 13:33:08 +0200 Subject: [PATCH] consider hidden zeros for show selection in interpretation fix #442 --- src/urh/controller/CompareFrameController.py | 8 +++++++- src/urh/plugins/ZeroHide/ZeroHideAction.py | 7 ++++++- src/urh/plugins/ZeroHide/ZeroHidePlugin.py | 3 ++- src/urh/ui/views/ProtocolTableView.py | 10 ++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/urh/controller/CompareFrameController.py b/src/urh/controller/CompareFrameController.py index 94f2bb5955..a71db4144d 100644 --- a/src/urh/controller/CompareFrameController.py +++ b/src/urh/controller/CompareFrameController.py @@ -335,6 +335,7 @@ def set_decoding(self, decoding: Encoding, messages=None): for msg in messages: msg.decoder = decoding + self.ui.tblViewProtocol.zero_hide_offsets.clear() self.clear_search() selected = self.ui.tblViewProtocol.selectionModel().selection() @@ -409,7 +410,7 @@ def fill_message_type_combobox(self): def add_protocol(self, protocol: ProtocolAnalyzer, group_id: int = 0) -> ProtocolAnalyzer: self.__protocols = None self.proto_tree_model.add_protocol(protocol, group_id) - protocol.qt_signals.protocol_updated.connect(self.set_shown_protocols) + protocol.qt_signals.protocol_updated.connect(self.on_protocol_updated) if protocol.signal: protocol.signal.sample_rate_changed.connect(self.set_shown_protocols) # Refresh times protocol.qt_signals.show_state_changed.connect(self.set_shown_protocols) @@ -1438,3 +1439,8 @@ def on_label_shown_link_activated(self, link: str): if link == "reset_filter": self.ui.lineEditSearch.clear() self.show_all_rows() + + @pyqtSlot() + def on_protocol_updated(self): + self.set_shown_protocols() + self.ui.tblViewProtocol.zero_hide_offsets.clear() diff --git a/src/urh/plugins/ZeroHide/ZeroHideAction.py b/src/urh/plugins/ZeroHide/ZeroHideAction.py index a16f7e23d7..87259b146e 100644 --- a/src/urh/plugins/ZeroHide/ZeroHideAction.py +++ b/src/urh/plugins/ZeroHide/ZeroHideAction.py @@ -4,7 +4,7 @@ class ZeroHideAction(QUndoCommand): - def __init__(self, protocol: ProtocolAnalyzer, following_zeros: int, view: int): + def __init__(self, protocol: ProtocolAnalyzer, following_zeros: int, view: int, zero_hide_offsets: dict): super().__init__() self.protocol = protocol self.following_zeros = following_zeros @@ -12,6 +12,8 @@ def __init__(self, protocol: ProtocolAnalyzer, following_zeros: int, view: int): self.setText("Hide zero sequences >= " + str(self.following_zeros)) + self.zero_hide_offsets = zero_hide_offsets + def redo(self): factor = 1 if self.viewtype == 1: @@ -20,6 +22,7 @@ def redo(self): factor = 8 pa = self.protocol + self.zero_hide_offsets.clear() for i in range(pa.num_messages): message = pa.messages[i] if self.viewtype == 0: @@ -31,6 +34,7 @@ def redo(self): zero_sequences = self.__get_zero_seq_indexes(data, self.following_zeros) + self.zero_hide_offsets[i] = {start: end-start for start, end in zero_sequences} for seq in reversed(zero_sequences): full_bits = pa.messages[i].decoded_bits start = seq[0] * factor @@ -38,6 +42,7 @@ def redo(self): pa.messages[i].decoded_bits = full_bits[:start] + full_bits[end:] def undo(self): + self.zero_hide_offsets.clear() self.protocol.clear_decoded_bits() def __get_zero_seq_indexes(self, message: str, following_zeros: int): diff --git a/src/urh/plugins/ZeroHide/ZeroHidePlugin.py b/src/urh/plugins/ZeroHide/ZeroHidePlugin.py index 362daa78e3..316b5fa94d 100644 --- a/src/urh/plugins/ZeroHide/ZeroHidePlugin.py +++ b/src/urh/plugins/ZeroHide/ZeroHidePlugin.py @@ -11,6 +11,7 @@ def __init__(self): self.following_zeros = 5 if 'following_zeros' not in self.qsettings.allKeys() else self.qsettings.value('following_zeros', type=int) self.undo_stack = None self.command = None + self.zero_hide_offsets = dict() def create_connects(self): self.settings_frame.spinBoxFollowingZeros.setValue(self.following_zeros) @@ -25,7 +26,7 @@ def get_action(self, parent, undo_stack: QUndoStack, sel_range, protocol, view: :type parent: QTableView :type undo_stack: QUndoStack """ - self.command = ZeroHideAction(protocol, self.following_zeros, view) + self.command = ZeroHideAction(protocol, self.following_zeros, view, self.zero_hide_offsets) action = QAction(self.command.text(), parent) action.triggered.connect(self.action_triggered) self.undo_stack = undo_stack diff --git a/src/urh/ui/views/ProtocolTableView.py b/src/urh/ui/views/ProtocolTableView.py index 3f04d023bf..a312fb7daf 100644 --- a/src/urh/ui/views/ProtocolTableView.py +++ b/src/urh/ui/views/ProtocolTableView.py @@ -45,6 +45,8 @@ def __init__(self, parent=None): self.addAction(self.ref_message_action) self.addAction(self.hide_row_action) + self.zero_hide_offsets = dict() + def model(self) -> ProtocolTableModel: return super().model() @@ -197,6 +199,9 @@ def create_context_menu(self): if act is not None: menu.addAction(act) + if hasattr(plugin, "zero_hide_offsets"): + self.zero_hide_offsets = plugin.command.zero_hide_offsets + return menu def contextMenuEvent(self, event: QContextMenuEvent): @@ -280,6 +285,11 @@ def on_new_message_type_action_triggered(self): @pyqtSlot() def on_show_in_interpretation_action_triggered(self): min_row, max_row, start, end = self.selection_range() + + offsets = self.zero_hide_offsets.get(min_row, dict()) + start += sum(offsets[i] for i in offsets if i <= start) + end += sum(offsets[i] for i in offsets if i <= end) + self.show_interpretation_clicked.emit(min_row, start, max_row, end - 1) @pyqtSlot()