Skip to content

Commit

Permalink
#269: Fix toolboxes crash on close
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Mar 21, 2017
1 parent b345d20 commit c45e778
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/cfclient/ui/toolboxes/ConsoleToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ def __init__(self, helper, *args):
def getName(self):
return 'Console'

def _console_updated(self, data):
self.update.emit(data)

def enable(self):
self.helper.cf.console.receivedChar.add_callback(self.update.emit)
self.helper.cf.console.receivedChar.add_callback(self._console_updated)

def disable(self):
self.helper.cf.console.receivedChar.remove_callback(self.update.emit)
self.helper.cf.console.receivedChar.remove_callback(
self._console_updated)

def preferedDockArea(self):
return Qt.BottomDockWidgetArea
25 changes: 18 additions & 7 deletions src/cfclient/ui/toolboxes/CrtpSharkToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""
import os
from time import time
from binascii import hexlify

from PyQt5 import QtWidgets
from PyQt5 import uic
Expand Down Expand Up @@ -71,17 +72,21 @@ def __init__(self, helper, *args):
self._data = []

def _packet(self, dir, pk):
if self.masterCheck.isChecked():
if self.masterCheck.isChecked() and \
not (pk.port == 15 and pk.channel == 3):
line = QtWidgets.QTreeWidgetItem()

ms_diff = int(round(time() * 1000)) - self._ms_offset
line.setData(0, Qt.DisplayRole, "%d" % ms_diff)
line.setData(1, Qt.DisplayRole, "%s" % dir)
line.setData(2, Qt.DisplayRole, "%d/%d" % (pk.port, pk.channel))
line.setData(3, Qt.DisplayRole, pk.data.decode("UTF-8"))

line.setData(3, Qt.DisplayRole, hexlify(pk.data).decode('utf8'))
print(pk.data)
print(hexlify(pk.data))

s = "%d, %s, %d/%d, %s" % (ms_diff, dir, pk.port, pk.channel,
pk.data.decode("UTF-8"))
hexlify(pk.data).decode('utf8'))
self._data.append(s)

self.logTree.addTopLevelItem(line)
Expand All @@ -98,17 +103,23 @@ def getName(self):
def getTabName(self):
return 'Crtp sniffer'

def _incoming_packet(self, pk):
self._incoming_packet_signal.emit(pk)

def _outgoing_packet(self, pk):
self._outgoing_packet_signal.emit(pk)

def enable(self):
self.helper.cf.packet_received.add_callback(
self._incoming_packet_signal.emit)
self._incoming_packet)
self.helper.cf.packet_sent.add_callback(
self._outgoing_packet_signal.emit)
self._outgoing_packet)

def disable(self):
self.helper.cf.packet_received.remove_callback(
self._incoming_packet_signal.emit)
self._incoming_packet)
self.helper.cf.packet_sent.remove_callback(
self._outgoing_packet_signal.emit)
self._outgoing_packet)

def preferedDockArea(self):
return Qt.RightDockWidgetArea
Expand Down

0 comments on commit c45e778

Please sign in to comment.