Skip to content

Commit

Permalink
consider hidden zeros for show selection in interpretation fix #442
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed May 29, 2018
1 parent 35b6925 commit 93dd981
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/urh/controller/CompareFrameController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
7 changes: 6 additions & 1 deletion src/urh/plugins/ZeroHide/ZeroHideAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@


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
self.viewtype = view

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:
Expand All @@ -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:
Expand All @@ -31,13 +34,15 @@ 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
end = seq[1] * factor
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):
Expand Down
3 changes: 2 additions & 1 deletion src/urh/plugins/ZeroHide/ZeroHidePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/urh/ui/views/ProtocolTableView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 93dd981

Please sign in to comment.